Re: Invalidating Rects for redraw
Re: Invalidating Rects for redraw
- Subject: Re: Invalidating Rects for redraw
- From: Ondra Cada <email@hidden>
- Date: Fri, 26 Jul 2002 14:37:53 +0200
On Friday, July 26, 2002, at 10:02 , David Martin wrote:
The problem is that Cocoa appears to be unioning these rects, meaning
that much more is being redrawn than needs to be. If you roll over a
link near the top of a page, almost the entire page needs to be redrawn.
I've found indeed that sending a [self setNeedsDisplayInRect:aRect] to a
NSView, and then a [self setNeedsDisplayInRect:anotherRect] will actually
redraw a single rectangle containing the two smaller rectangles.
That's a very very bad practice. Read on, though!
My workaround was to call [self displayRect:aRect], then [self
displayRect:anotherRect]. The documentation seems to want people to call
-setNeedsDisplayInRect: and let the view redraw itself when it wants it,
but the thing looks terribly inefficient
Triple alas, this is well-known Apple bug, which makes the terrible
nonsense of calling display... instead of just invalidating sometimes
necessary :(((
It might be worth checking archives; this was spoken about in details,
like below:
(Incidentally, as for current workaround, I'd recommend considering Erik's
(4) below: at the very least, it'd allow you not to pollute the entire
source with very ugly workarounds.)
From: "Erik M. Buck" <email@hidden>
Date: Mon Dec 17, 2001 05:03:36 Europe/Prague
To: <email@hidden>
Subject: Ways Apple COULD optimize -setNeedsDisplay
Apple could optimize the implementation of Cocoa window content display
and
backing store flushing in conjunction with -setNeedsDisplay:
and -setNeedsDisplayInRect:.
Rather than simply storing the union of all invalid rectangles pending the
next trip through the event loop, Apple could do one or more of the
following:
1) Use a micro-tile array to efficiently keep track of invalid rectangles
2) Only union intersecting rectangles. Keep non-intersecting rectangles
in
a data structure for pending display. A small fixed number of rectangles
could be used and unioning could be the fall back when running out of
space
in the invalid rectangles data structure. Micro-tile arrays would be
better
though.
3) Store a flag when -setNeedsDisplay: is called and then iterate over all
views in a window calling -display exactly once per event loop cycle for
each marked view. As it is now, many large expensive views that do not
need
display are being displayed anyway.
4) Simply re-implement -setNeedsDisplay: to call -display immediately. As
stupid and counter productive as that sounds, it will probably improve
performance of most applications. Just for fun, I did this in a category
of
NSView. The results are so far inconclusive but promising.
5) Quit breaking things that used to work!
I would be happy to implement any or all of the suggestions and donate the
code to Apple so that they don't have to divert any engineering resources.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.