Better performance using images with an “opaque” property? What for?

I just found something on this site: iphoneexamples.com . Looking at the "Show Images", I found something new for me.

myImage.opaque = YES; // clearly opaque to performance

Can someone explain this to me please? And for what kind (or usecase) of images does this work? When not? It would be great to know. Thank you for your time...

+6
performance ios iphone cocoa-touch uiimageview
source share
4 answers

The iPhone GPU is a tile-based rendering. If the overlapping layer is completely opaque over the entire slab, the GPU can ignore the setting and processing of any graphic commands related to the bottom layer for this particular tile, in addition to not having to arrange the pixels in this fragment.

If your image does not cover the full tile, the GPU will still have to process several layers. The size of the tile is implementation dependent, but tiny graphics are much less likely to cover the tile. Huge images that cover multiple fragments will have the greatest advantage from opacity.

+13
source share

From Viewing the Programming Guide for iOS :

Declare Views as Opaque Possible

UIKit uses the opaque properties of each viewpoint to determine if a view can optimize compositional operations. Setting the value of this property to YES for the Custom view tells UIKit that it does not need to provide any content behind your opinion. Less rendering can lead to better performance for your code drawing and is generally recommended. Of course, if you set the opaque property to YES, your view should fill it; the rectangle limits the completely opaque content to the rectangle.

hotpaw2 points to a common reason for this, which can be found in the OpenGL ES Programming Guide for iOS :

Another advantage of deferred rendering is that it allows the GPU to remove the hidden surface before fragments are processed. Pixels that are not visible are discarded without fetching textures or performing fragment processing, reducing the calculations that the GPU must perform to make the tiles. To get the most benefit from this feature, draw as many frames with opaque content as possible, and minimize the use of blending, alpha testing and undo the command in the GLSL shaders. Because the hardware performs hidden surface removal, it is not necessary for your application to sort the primitives from front to back.

+9
source share

You get better performance if the view or layer is opaque than when not. If it is not opaque, the graphics system should connect this layer with the layers below to get the final image. If it's opaque, then it's just a matter of copying pixels to the frame buffer.

+3
source share

It's a little tricky to understand that a UIImageView will reset the opaque FALSE property at any time when the image property is changed to a new UIImage. You can explicitly check your code and set an opaque property after any change in the image property, or you can extend the UIImageView and provide you with your own setImage implementation that gains opacity after calling the super setImage method. I found out about it by chance.

0
source share

All Articles