| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On May 31, 2006, at 1:55 PM, Olaf Krzikalla wrote:
As you've noticed, the peculiarity of working with CGLayers is that they require you to pass them a context to use as a model when they are created. The CGLayer will look at the attributes of that context and will set itself up so that it can reproduce its image on that context quickly. The general problem with mixing HIViews and CGLayers is the fact that the HIView doesn't know what context it will be drawing itself on until it actually draws. In most cases you would hope it is going to draw to the screen, but you don't know which screen that might be (on a computer with many displays). Or it could be the case that the HIView is going to be drawn somewhere else entirely (say with HIViewCreateOffscreenImage). In short, using a CGLayer to cache the contents of an HIView may not be the best approach. (however, CGLayer would still be a handy tool use when rubber stamping a lot of copies of an image, say a radio button or something, into a window) I can think of two workarounds. One is to create the CGLayer from the context returned by CGDisplayGetDrawingContext. I guess you will have to capture the display, create the layer from the context, and then release the display. Every time the display configuration changes, you will probably want to recreate your cached layers. Another approach in this case would be to bypass layers altogether and use an offscreen bitmap context. To optimize the drawing of the cached image for the screen, you could set up the CGBitmapContext to use the same color space as the system display. The bitmap context need only live long enough to draw your image into the cached pixel map and then you could get rid of it (unless you want to draw into that same pixel map again later). When you want to draw the cached data you could create a CGImage from the same pixel map that the CGBitmapContext is used. You could then repeatedly draw that CGImage in the HIView drawing call. The tricky part is that the CGImage is only good so long as the data it was created from doesn't change. If you keep the CGBitmapContext around and draw in the pixel map after a CGImage has been created on it, you should recreate it. The disadvantage of this approach is that you may not be able to supply as many optimizations to your offscreen pixel map that the system might be able to apply to a CGLayer. Scott |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartz-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartz-dev/email@hidden This email sent to email@hidden
| References: | |
| >How to get an CGLayer from an HIView? (From: "Olaf Krzikalla" <email@hidden>) | |
| >Re: How to get an CGLayer from an HIView? (From: Scott Thompson <email@hidden>) | |
| >Re: How to get an CGLayer from an HIView? (From: "Olaf Krzikalla" <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.