13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

208CHAPTER 7: User Interfaces: The Application Kitabout the Core Image pipeline will also apply here: the compositing pipelinewill combine all filters and backing store composite operations into a singleoperation per destination pixel, resulting in an optimized, high-throughputmechanism to update the window. Additionally, the compositing will run onthe GPU, gaining not only greater performance through the GPU’s specialtyprocessing core, but freeing the CPU for the more important work ofhandling user input and processing user data.Core Animation was originally designed for iOS; as a totally new system and applicationframework, it made sense to avoid porting across a rendering pipeline originally designed for20-year-old computers. Instead, something much closer to the way OpenGL handles individualtextures was devised. This actually happened around the time of OS X 10.4, albeit in absolutesecrecy until the first version of the iPhone was released. When iOS 2.0 was published, the APIwas made public (and adopted the “Core” naming convention). It was also brought into OS X toprovide the same benefits to the desktop operating system.In OS X, however, the legacy API and system still needed to exist to support many years’worth of applications. As a result, Core Animation is an opt-in mechanism on OS X. To opt in,you tell your NSView instances to use a Core Animation layer as their backing store using the-setWantsLayer: method or -setLayer: methods, the former of which is available as a simplecheckbox in Interface Builder. Once a view is set to use a layer, all its subviews are automaticallyset to use layers as well, all the way down the view hierarchy. The AppKit drawing system thendoes all the work of managing that layer, and your own rendering code likely never needs tochange; you will simply notice that your view’s -drawRect: method is called much less and onlyupon certain occasions.There is one distinction to be made here: when you use -setWantsLayer: or the Interface Builder“wants layer” checkbox, you are asking the App Kit to create and manage a layer for this viewon your behalf. The layer is available to you, but most of the interaction is handled for you bythe App Kit; frame rectangles and borders are automatically translated into similar calls thatoperate directly on the view’s layer. This gives you what is termed a layer-backed view. If, on theother hand, you create a Core Animation CALayer object yourself and pass that to your view’s-setLayer: method, App Kit will back off and will expect you to handle that work yourself. Thusany borders set using the NSView API will render using the CPU-based pipeline into the layer’sbacking store; if you set a border color and width on your layer, however, that border will beapplied at composition time on the GPU instead.AnimatingWhat about animation, you ask? Well, Core Animation gets its name from the fact that its layerbackedimplementation makes it ideal for performing animations. A layer can have its frame setonce to its final value and be drawn once. Then its backing store will be resized and repositionedback to its original position, and that image is moved from the view’s original position to its newone. All this work is done during the compositing phase and thus makes best use of the GPU.The plain Cocoa animation system, on the other hand, performs animation by updating theframe of the view itself in an iterative manner, usually meaning that the frame must be redrawn(using the slower CPU-based path outlined above) for each stage of the animation. As a result,www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!