Re: Dirty rects getting merged together makes for inefficient drawing
Re: Dirty rects getting merged together makes for inefficient drawing
- Subject: Re: Dirty rects getting merged together makes for inefficient drawing
- From: Ben Haller <email@hidden>
- Date: Tue, 20 Oct 2009 07:42:22 -0400
On 20-Oct-09, at 6:54 AM, Uli Kusterer wrote:
On 19.10.2009, at 23:58, Ben Haller wrote:
On 19-Oct-09, at 5:27 PM, Dave Keck wrote:
Would NSView's -getRectsBeingDrawn:count: help?
Well, I'm already using it in my own code where appropriate. (Or
actually I'm using -needsToDrawRect:). But the problem is that a
whole bunch of NSTableView cells are getting drawn that never got
invalidated.
That's like saying: "I'm using the setter, why would I need to use
the getter?"
The dirtyRect parameter passed to drawRect: is the union of all
redraw rectangles. So, it's the smallest rect that encloses all the
dirty rects. drawRect: does not get called for each redraw rect. If
you want the individual sub-rects, use getRectsBeingDrawn:count: and
loop over all those rects and draw the individual parts.
Uh, Uli, reread what I typed. I did not say "or actually I'm using
setNeedsDisplayInRect:". -needsToDrawRect is a shorthand for exactly
what you propose: calling -getRectsBeingDrawn:count: and looping over
those rects. From the docs for -needsToDrawRect:
It gives you a convenient way to determine whether any part of a given
graphical entity might need to be drawn. It is optimized to
efficiently reject any rectangle that lies outside the bounding box of
the area the receiver is being asked to draw in drawRect:.
So whether -needsToDrawRect or -getRectsBeingDrawn:count: is a
better solution depends mostly upon taste, and a little bit on how
many tests you intend to do in your draw method (i.e. efficiency to
testing). For my purposes, doing a total of two tests, -
needsToDrawRect is fine.
Ben Haller
Stick Software
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden