QuickDraw applications often draw in an offscreen graphics world and use CopyBits to blit the image to the screen in one operation. Prior to Mac OS X, this was the recommended way to prevent flicker during lengthy drawing operations. Windows in Mac OS X are double-buffered, and window buffers are flushed automatically inside the application event loop. Therefore the use of offscreen graphics worlds for this purpose should no longer be necessary.
There are occasions when it still makes sense to draw offscreen and move the offscreen image into a window in a single operation. In Mac OS X, the primary motivation for drawing offscreen is to cache content. For example, you may want to cache an image that’s used more than once, or move selected areas of a large image into a window at different times. During rapid animation sequences, some applications prepare a background image offscreen, move the background to the window as a unit, and draw the animated parts of the scene over the background.
Quartz provides two offscreen drawing environments: bitmap graphics contexts and CGLayer objects (introduced in Mac OS X 10.4). The HIView function HIViewCreateOffscreenImage is also worth considering if your application is HIView based. This function creates a CGImage object for the HIView passed to it.
If your application runs in Mac OS X v10.4 and later, you should consider using CGLayer objects for offscreen drawing. Prior to that version, offscreen drawing is done to a bitmap graphics context.
Using a Bitmap Context for Offscreen Drawing
Using a CGLayer Object for Offscreen Drawing
Relevant Resources
Last updated: 2006-09-05