Graphics Reference
In-Depth Information
Figure 13.3 The frame rate and line quality degrades as we draw.
To cut down on unnecessary drawing, both Mac OS and iOS divide the screen into regions
that need redrawing and ones that don't. The part that needs to be redrawn is known as the
“dirty” region. Because it's not practical to redraw nonrectangular regions due to the
complexity of clipping and blending the edges, the entire containing rectangle around the
part of the dirty region that overlaps a given view will be redrawn—this is the dirty
rectangle.
When a view is modified, it may need to be redrawn. But often, only part of the view has
changed, so redrawing the entire backing image would be wasteful. Because Core
Animation doesn't usually know anything about your custom drawing code, it cannot
calculate the dirty rectangle by itself. You can provide this information, however.
When you detect that a specific part of your view/layer needs to be redrawn, you mark it
as dirty by calling -setNeedsDisplayInRect: passing the affected rectangle as a
parameter. This will cause the view's -drawRect: method (or the layer delegate's
-drawLayer:inContext: method) to be called automatically prior to the next display
update.
The CGContext that is passed to -drawLayer:inContext: will automatically be clipped to
match the dirty rectangle. To find out the dimensions of that rectangle, you can use the
Search WWH ::




Custom Search