Graphics Reference
In-Depth Information
The Stages of an Animation
Core Animation lies at the heart of iOS: It is used not just within applications but between
them. A single animation may actually display content from multiple apps simultaneously,
such as when you use gestures on an iPad to switch between apps, causing views from both
to briefly appear onscreen at once. It wouldn't make sense for this animation to be
performed inside the code of any particular app because then it wouldn't be possible for
iOS to implement these kinds of effects. (Apps are sandboxed and cannot access each
others' views.)
Animating and compositing layers onscreen is actually handled by a separate process,
outside of your application. This process is known as the render server. On iOS 5 and
earlier, this is the SpringBoard process (which also runs the iOS home screen). On iOS 6
and later, this is handled by a new process called BackBoard.
When you perform an animation, the work breaks down into four discrete phases:
Layout —This is the phase where you prepare your view/layer hierarchy and set up
the properties of the layers (frame, background color, border, and so on).
Display —This is where the backing images of layers are drawn. That drawing may
involve calling routines that you have written in your -drawRect: or
-drawLayer:inContext: methods.
Prepare —This is the phase where Core Animation gets ready to send the animation
data to the render server. This is also the point at which Core Animation will perform
other duties such as decompressing images that will be displayed during the
animation (more on this later).
Commit —This is the final phase, where Core animation packages up the layers and
animation properties and sends them over IPC (Inter-Process Communication) to the
render server for display.
But those are just the phases that take place inside your application—there is still more
work to be done before the animation appears onscreen. Once the packaged layers and
animations arrive in the render server process, they are deserialized to form another layer
tree called the render tree (mentioned in Chapter 1, “The Layer Tree”). Using this tree, the
render server does the following for each frame of the animation:
Calculates the intermediate values for all the layer properties and sets up the OpenGL
geometry (textured triangles) to perform the rendering
Renders the visible triangles to the screen
So that's six phases in total; the last two are repeated over and over for the duration of the
animation. The first five of these phases are handled in software (by the CPU), only the last
is handled by the GPU. Furthermore, you only really have direct control of the first two
phases: layout and display. The Core Animation framework handles the rest internally and
you have no control over it.
Search WWH ::




Custom Search