Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing icons fast : CGImageRef or IconRef ?



On 30 juil. 04, at 14:52, Scott Thompson wrote:

However, while profiling my app, I noticed that PlotIconRefInContext calls private APIs to draw CGImages... so I was wondering if drawing CGImageRefs myself wouldn't be faster.

So I converted all my .icns files into .png ones, modified my code to handle CGImageRefs..
The result is odd : it's slower, and the icons don't look as anti-aliased as with IconRefs.

Are you recreating the CGImages every time you want to draw the icons or do you keep the images around and reuse them?

Don't worry, I keep my CGImages around. But it's slow slow slow anyway....


You might try profiling and see if you can determine which step is taking the longest.

Already done. The only public API that is taking the longest is definitely PlotIconRefInContext. Itself, it calls some private APIs including some CGImagexxxx ones, but I don't see how I could improve that....


Well the Dock does use a separate window for each icon that it presents. How the icons are drawn into that window is not clear but it very well could be going through OpenGL.

Nevertheless, I've had good luck using OpenGL to quickly blit 2D images on the screen. Essentially what is involved is creating an OpenGL texture from your image data and then drawing a rectangle on the screen that uses that texture. The technique has some caveats, particularly if your working with images that are not a power of two. If you are using standard icon sizes (128x128 for example) then I don't think this will be a problem for you. There's also quite a bit of setup what with getting the OpenGL contexts created, the textures enabled and things like that. Nevertheless, once your graphic is in the texture you can get it to the screen screamingly quickly.

There is sample code in the OpenGL sample at Apple's site. The two in particular that I am thinking of are:

<http://developer.apple.com/samplecode/OpenGL_Image/OpenGL_Image.html>
and
<http://developer.apple.com/samplecode/Red_Rocket/Red_Rocket.html>

Thanks. I think I'll have a look at that.

Jirome
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Drawing icons fast : CGImageRef or IconRef ? (From: Jérome Foucher <email@hidden>)
 >Re: Drawing icons fast : CGImageRef or IconRef ? (From: Scott Thompson <email@hidden>)



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.