• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Optimizing drawing by caching
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optimizing drawing by caching


  • Subject: Re: Optimizing drawing by caching
  • From: Marco Binder <email@hidden>
  • Date: Sun, 29 Sep 2002 18:02:55 +0200

Your idea is good and will work nicley. I4ve done the same thing. Putting your "rendering" function in the display method however doesnt make too much sense to me- display is called basically as frequently as drawRect.

Why dont you just cache your image whenever it changes?! Thats what I do. Since only your own program-code CAN change the image4s content, you also should know best, when to call the "cache" method.

In this caching method, simply have the content draw into an NSImage (btw, there is no subclass to NSImage in Cocoa) and have this image draw itself in your view4s drawRect method.

You should not need to use a PDF or EPS NSImageRep or anything, even if your content is "Quartz", since the NSImage will cache its contents anyway in an NSCachedImageRep in order to draw it to screen. As long as you dont need to scale, this should work fine. If you wanna scale the whole thing however, just call your caching method again and draw it into a larger NSImage.

marco

PS: sample code should not be neccessary, it4s all very str8forward. Lock focus on your NSImage, do your drawing, unlockFocus, thats it.


Am Sonntag, 29.09.02 um 17:18 Uhr schrieb Drew McCormack:

I have some drawing which is expensive to perform, but only needs to be performed occasionally. If I use it in a scrollview as is, resizing and scrolling performance is worse than it was under Mac OS X public beta ;-) In other words, it isn't good enough.

Since what is drawn changes infrequently, I thought I should cache the drawing in an NSImage or something like that. Rather than draw to screen, I would draw to the image, and then draw the image on the screen whenever needed. I thought the best place to do the caching would be the "display" method: this could rebuild the image if necessary, and then call the super's display, which in turn would call "drawRect:" where the image would actually be drawn on the screen.

Is this approach a good idea, or am I missing something? Are there any pitfalls? Does anyone know any sample code for this? Can anyone give me any idea what NSImage or NSBitmapImageRep classes I should use for this purpose?

One more thing: All my drawn makes use of Quartz, so a postscript format may be my best bet. Could I/Should I use a PDF image rep for this caching, or a bitmap image rep?

Drew


--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________


--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________


--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________


--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Optimizing drawing by caching (From: Drew McCormack <email@hidden>)

  • Prev by Date: Re: Optimizing drawing by caching
  • Next by Date: Re: DateFormatter in a table?
  • Previous by thread: Re: Optimizing drawing by caching
  • Next by thread: NSView not initialized and unusable
  • Index(es):
    • Date
    • Thread