Graphics Reference
In-Depth Information
animate without stuttering took a great deal of time and usually involved working with
the graphics processing unit (GPU) through OpenGL or some other technology. With Core
Animation, you get the hardware acceleration for free! All you need to do is define the
animation, kick it off, and let it run. You don't have to worry about loading it onto the
GPU because Core Animation handles that automatically.
This is something to keep in mind while designing your user interfaces. What might be
considered a complicated animation is more than likely trivial for the GPU to perform.
Sliding rectangles around on the screen, transforming them in a 3D space, and so on is
what the GPU was designed to do. Only when we start to push the limits of the GPU do
we start to see performance degradation.
iPhone Hardware Rendering
Hardware acceleration occurs on both the desktop and in Cocoa Touch for the iPhone and
iPod touch. Although the GPU is smaller on a Cocoa Touch device, we still get its benefit and
get to hand off that animation to the GPU. However, unlike the desktop, there is a limited
amount of resources on Cocoa Touch devices. As such, it is generally not a good idea to do
processor-intensive work while the animation runs.
Your application should wait until any animations have finished running before performing any
other tasks that might consume vital resources. Having said that, it is possible to perform
other activities on background threads, or even on the main thread, while an animation runs.
However, there is a balancing act between having the animation run smoothly and getting
several tasks completed at the same time.
If you need to perform other tasks during an animation, be sure to flag them as potential
performance bottlenecks, so they can be reviewed later, just in case it becomes obvious that
the animations perform poorly.
Rules of Thumb
The following sections present those guidelines mentioned in the introduction as some-
thing that you need to keep in mind as you create your animations.
Avoid Offscreen Rendering
Whether you work with a desktop application or a Cocoa Touch device, you want to limit
your drawing to only those areas visible to the user. Fortunately the -drawRect: method
passes in only the rectangle that is dirty, so you can control exactly how much is drawn in
each cycle of the run loop.
 
Search WWH ::




Custom Search