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 ?



> 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?

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

> All in all, if I compare the speed of my app with the speed of the
> Dock at resizing the icons, the Dock is blazing fast. Some people told
> me it uses OpenGL to achive that. Is it true ? Is it what I should try
> to implement ?
>
> Can anybody enlighten me please ?

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>

In Tiger you will have another option which may be even more
attractive. You can use a CGLayer (as was recently discussed on the
quartz-dev list) and cache your icons off to those layers. Then when
redraw the CGLayer the OS will be able to put your graphics on the
fastest pipe it can find.

--
Macintosh Software Engineering Consulting Services
Visit my resume at <http://homepage.mac.com/easco/RSTResume.html>

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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>)



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.