UIView draw principle, asynchronous rendering

Drawing principle

First look at a flowchart

After calling setNeedsDisplay UIView method, in fact, the current view of the drawing work did not happen, but working in a draw after opportunity, why would working in a draw after the timing of it?
When UIView calling setNeedDisplay, the system will call to view the corresponding layer setNeedsDisplay method, equivalent to put a dirty mark on the current layer, and then calls the display method of CALayer when the current runloop coming to an end, will really drawn into the flow of the current view of them, so the view draw the timing, is only the beginning. when the end of the current runloop
internal CALayer display method of implementation, will first determine whether the layer of delegete response display method, if the agent does not respond will be drawn into the flow of the system which, if the response in fact it provides an interface asynchronous draw for us, this constitutes a principle drawing of UIView

Draw flow system

First CALayer created inside a backing store (CGContextRef), we generally can get drawRect the top of the stack the current context by context stack them. Then layer to determine whether there is a proxy, the proxy will be called if there is no layer of drawInContext method, if realized the agency will call delegete of drawLayer: inContext method, which is happening within the system which then give a callback method at the right time, that is, drawRect method View can do some other work drawn by drawRect method then. No matter which of the two branches have calayer upload backing store (final bitmap) to the GPU. then the end of the drawing process systems.

Asynchronous rendering

How asynchronous rendering it, in fact, based on the system gave us the hole in layer.delegate, if comply with or implement a displayLayer method, we can enter into asynchronous rendering process which, in the process of drawing asynchronous

It is responsible for generating the bitmap to delegete bitmap
is provided as the value of change layer.content attribute bitmap
to understand the mechanisms and processes asynchronous timing chart drawn by a

Guess you like

Origin www.cnblogs.com/Lanht/p/11706949.html
Recommended