Graphics Reference
In-Depth Information
That's not really a problem, because in the layout and display phases, you get to decide
what work will be done upfront on the CPU and what will get passed down to the GPU. So
how do you make that decision?
GPU-Bound Operations
The GPU is optimized for a specific task: It takes images and geometry (triangles),
performs transforms, applies texturing and blending, and then puts them on the screen. The
programmable GPUs in modern iOS devices allow for a lot of flexibility in how those
operations are performed, but Core Animation does not expose a direct interface to any of
that. Unless you are prepared to bypass Core Animation and start writing your own
OpenGL shaders, you are basically stuck with a fixed set of things that are hardware
accelerated, and everything else must be done in software on the CPU.
Broadly speaking, most properties of CALayer are drawn using the GPU. If you set the
layer background or border colors, for example, those can be drawn really efficiently using
colored triangles. If you assign an image to the contents property—even if you scale and
crop it—it gets drawn using textured triangles, without the need for any software drawing.
A few things can slow down this (predominantly GPU-based) layer drawing, however:
Too much geometry —This is where too many triangles need to be transformed and
rasterized (turned into pixels) for the processor to cope. The graphics chip on modern
iOS devices can handle millions of triangles, so geometry is actually unlikely to be a
GPU bottleneck when it comes to Core Animation. But because of the way that layers
must be preprocessed and sent to the render server via IPC before display (layers are
fairly heavy objects, composed of several subobjects), too many layers will cause a
CPU bottleneck. This limits the practical number of layers that you can display at
once (see the section “CPU-Bound Operations,” later in this chapter).
Too much overdraw —This is predominantly caused by overlapping semitransparent
layers. GPU's have a finite fill-rate (the rate at which they can fill pixels with color),
so overdraw (filling the same pixel multiple times per frame) is something to be
avoided. That said, modern iOS device GPUs are fairly good at coping with
overdraw; even an iPhone 3GS can handle an overdraw ratio of 2.5 over the whole
screen without dropping below 60 FPS (that means that you can draw one-and-a-half
whole screenfuls of redundant information without impacting performance), and
newer devices can handle more.
Offscreen drawing —This occurs when a particular effect cannot be achieved by
drawing directly onto the screen, but must instead be first drawn into an offscreen
image context. Offscreen drawing is a generic term that may apply to either CPU or
GPU-based drawing, but either way it involves allocating additional memory for the
offscreen image and switching between drawing contexts, both of which will slow
down the GPU performance. The use of certain layer effects, such as rounded corners,
layer masks, drop shadows, or layer rasterization will force Core Animation to pre-
Search WWH ::




Custom Search