Graphics Reference
In-Depth Information
15
Layer Performance
Doing more things faster is no substitute for doing the right things.
Stephen R. Covey
Chapter 14, “Image IO,” discussed how we can efficiently load and display images, with a
view to avoiding performance glitches that might impact animation frame rate. In this final
chapter, we study the performance of the layer tree itself and how to get the best out of it.
Inexplicit Drawing
The layer backing image can be drawn on-the-fly using Core Graphics, or set directly using
the contents property by supplying an image loaded from a file, or drawn beforehand in an
offscreen CGContext . In the previous two chapters, we talked about optimizing both of
these scenarios. But in addition to explicitly creating a backing image, you can also create
one implicitly through the use of certain layer properties, or by using particular view or
layer subclasses.
It is important to understand exactly when and why this happens so that you can avoid
accidentally introducing software drawing if it's not needed.
Text
Both CATextLayer and UILabel draw their text directly into the backing image of the
layer. These two classes actually use radically different approaches for rendering text: In
iOS 6 and earlier, UILabel uses WebKit's HTML rendering engine to draw its text,
whereas CATextLayer uses Core Text. The latter is faster and should be used preferentially
for any cases where you need to draw a lot of text, but they both require software drawing
and are therefore inherently slow compared to hardware-accelerated compositing.
 
 
Search WWH ::




Custom Search