Optimise display

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4389 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-06-10 21:12:10 +00:00
parent 827af8bf22
commit 8bfdcdce8c
4 changed files with 115 additions and 92 deletions

View file

@ -1,7 +1,10 @@
Thu Jun 10 19:45:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Thu Jun 10 22:25:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSView.m: Optimise display routines - avoid unneeded * Source/NSView.m: Optimise display routines - avoid unneeded
re-displays. re-displays. Use flag to tell if a view is opaque. Optimise
'opaqueAncestor'
* Model/GMAppKit.m: Set flag to say if a view is opaque on decoding.
* Headers/AppKit/NSResponder.h: Add 'opaque_view' flag.
Wed Jun 9 8:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Wed Jun 9 8:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>

View file

@ -50,12 +50,14 @@
* This caching assumes that the value returned by [-isFlipped] will * This caching assumes that the value returned by [-isFlipped] will
* not change during the views lifetime - if it does, the view must * not change during the views lifetime - if it does, the view must
* be sure to change the flag accordingly. * be sure to change the flag accordingly.
* 'opaque_view' is similar.
*/ */
unsigned flipped_view:1; unsigned flipped_view:1;
unsigned has_subviews:1; /* This view has subviews */ unsigned has_subviews:1; /* This view has subviews */
unsigned has_currects:1; /* This view has cursor rects */ unsigned has_currects:1; /* This view has cursor rects */
unsigned has_trkrects:1; /* This view has tracking rects */ unsigned has_trkrects:1; /* This view has tracking rects */
unsigned has_draginfo:1; /* View/window has drag types */ unsigned has_draginfo:1; /* View/window has drag types */
unsigned opaque_view:1;
} _rFlags; } _rFlags;
} }

View file

@ -979,6 +979,7 @@ void __dummy_GMAppKit_functionForLinking() {}
[unarchiver decodeUnsignedIntWithName:@"autoresizingMask"]]; [unarchiver decodeUnsignedIntWithName:@"autoresizingMask"]];
_rFlags.flipped_view = [self isFlipped]; _rFlags.flipped_view = [self isFlipped];
_rFlags.opaque_view = [self isOpaque];
if ([sub_views count]) if ([sub_views count])
_rFlags.has_subviews = 1; _rFlags.has_subviews = 1;

View file

@ -138,10 +138,8 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
autoresizingMask = NSViewNotSizable; autoresizingMask = NSViewNotSizable;
coordinates_valid = NO; coordinates_valid = NO;
/*
* Keep a note of whether this is a flipped view or not.
*/
_rFlags.flipped_view = [self isFlipped]; _rFlags.flipped_view = [self isFlipped];
_rFlags.opaque_view = [self isOpaque];
return self; return self;
} }
@ -259,10 +257,17 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (NSView*) opaqueAncestor - (NSView*) opaqueAncestor
{ {
if ([self isOpaque] || !super_view) NSView *next = super_view;
return self; NSView *current = self;
else
return [super_view opaqueAncestor]; while (next != nil)
{
if (current->_rFlags.opaque_view)
break;
current = next;
next = current->super_view;
}
return current;
} }
- (void) removeFromSuperviewWithoutNeedingDisplay - (void) removeFromSuperviewWithoutNeedingDisplay
@ -1090,21 +1095,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
if (window) if (window)
{ {
NSRect rect; [self displayRect: visibleRect];
/*
* Display the entire view - if there is nothing marked as needing
* display, that's just the visible rect. If there is an area needing
* display, do the entire area so that the view will no longer need
* be marked as needing display.
*/
if (coordinates_valid == NO)
[self _rebuildCoordinates];
if (needs_display)
rect = NSUnionRect(invalidRect, visibleRect);
else
rect = visibleRect;
[self displayRect: rect];
} }
} }
@ -1112,7 +1103,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
if (needs_display) if (needs_display)
{ {
if ([self isOpaque]) if (_rFlags.opaque_view)
{ {
[self displayIfNeededIgnoringOpacity]; [self displayIfNeededIgnoringOpacity];
} }
@ -1123,7 +1114,19 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (coordinates_valid == NO) if (coordinates_valid == NO)
[self _rebuildCoordinates]; [self _rebuildCoordinates];
rect = NSUnionRect(invalidRect, visibleRect); /*
* If this view is higher in the view hierarchy than one that
* actually needs display, it's invalidRect will be empty, so
* we need to set it to the visibleRect.
*/
if (NSIsEmptyRect(invalidRect) == YES)
{
rect = visibleRect;
}
else
{
rect = invalidRect;
}
rect = [firstOpaque convertRect: rect fromView: self]; rect = [firstOpaque convertRect: rect fromView: self];
[firstOpaque displayIfNeededInRectIgnoringOpacity: rect]; [firstOpaque displayIfNeededInRectIgnoringOpacity: rect];
} }
@ -1138,7 +1141,19 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (coordinates_valid == NO) if (coordinates_valid == NO)
[self _rebuildCoordinates]; [self _rebuildCoordinates];
rect = NSUnionRect(invalidRect, visibleRect); /*
* If this view is higher in the view hierarchy than one that
* actually needs display, it's invalidRect will be empty, so
* we need to set it to the visibleRect.
*/
if (NSIsEmptyRect(invalidRect) == YES)
{
rect = visibleRect;
}
else
{
rect = invalidRect;
}
[self displayIfNeededInRectIgnoringOpacity: rect]; [self displayIfNeededInRectIgnoringOpacity: rect];
} }
} }
@ -1147,7 +1162,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
if (needs_display) if (needs_display)
{ {
if ([self isOpaque]) if (_rFlags.opaque_view)
{ {
[self displayIfNeededInRectIgnoringOpacity: aRect]; [self displayIfNeededInRectIgnoringOpacity: aRect];
} }
@ -1169,17 +1184,14 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (needs_display) if (needs_display)
{ {
unsigned i, count;
BOOL stillNeedsDisplay = NO;
NSRect redrawRect; NSRect redrawRect;
if (coordinates_valid == NO) if (coordinates_valid == NO)
[self _rebuildCoordinates]; [self _rebuildCoordinates];
invalidRect = NSIntersectionRect(invalidRect, visibleRect);
aRect = NSIntersectionRect(aRect, visibleRect); aRect = NSIntersectionRect(aRect, visibleRect);
redrawRect = NSIntersectionRect(aRect, invalidRect); redrawRect = NSIntersectionRect(aRect, invalidRect);
if (NSIsEmptyRect(redrawRect) == NO) if (NSIsEmptyRect(redrawRect) == NO)
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
@ -1191,18 +1203,21 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (_rFlags.has_subviews) if (_rFlags.has_subviews)
{ {
count = [sub_views count]; unsigned count = [sub_views count];
if (count > 0) if (count > 0)
{ {
NSView* array[count]; NSView *array[count];
unsigned i;
[sub_views getObjects: array]; [sub_views getObjects: array];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
NSRect isect; NSRect isect;
NSView *subview = array[i]; NSView *subview = array[i];
NSRect subviewFrame = subview->frame; NSRect subviewFrame = subview->frame;
BOOL intersectCalculated = NO;
if ([subview->frameMatrix isRotated]) if ([subview->frameMatrix isRotated])
{ {
@ -1219,6 +1234,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
isect = [subview convertRect: isect isect = [subview convertRect: isect
fromView: self]; fromView: self];
intersectCalculated = YES;
/* /*
* hack the ivars of the subview directly for speed. * hack the ivars of the subview directly for speed.
*/ */
@ -1229,45 +1245,37 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if (subview->needs_display) if (subview->needs_display)
{ {
isect = NSIntersectionRect(aRect, subviewFrame); if (intersectCalculated == NO
if (NSIsEmptyRect(isect) == NO) || NSEqualRects(aRect, redrawRect) == NO)
{ {
isect = NSIntersectionRect(aRect, subviewFrame);
isect = [subview convertRect: isect isect = [subview convertRect: isect
fromView: self]; fromView: self];
[subview displayIfNeededInRectIgnoringOpacity: isect];
}
if (subview->needs_display)
{
stillNeedsDisplay = YES;
} }
[subview displayIfNeededInRectIgnoringOpacity: isect];
} }
} }
} }
} }
/* /*
* If the rect we displayed contains the invalidRect for the view * If the rect we displayed contains the invalidRect or visibleRect
* then we can empty invalidRect. All subviews will have been * then we can empty invalidRect. All subviews will have been
* fully displayed, so the 'stillNeedsDisplay' flag will be NO. * fully displayed, so this view no longer needs to be displayed.
*/ */
redrawRect = NSUnionRect(invalidRect, aRect); if (NSEqualRects(aRect, NSUnionRect(invalidRect, aRect)) == YES
if (NSEqualRects(aRect, redrawRect) == YES) || NSEqualRects(aRect, NSUnionRect(visibleRect, aRect)) == YES)
{ {
invalidRect = NSZeroRect; invalidRect = NSZeroRect;
needs_display = NO;
} }
else
{
stillNeedsDisplay = YES;
}
needs_display = stillNeedsDisplay;
[window flushWindow]; [window flushWindow];
} }
} }
- (void) displayRect: (NSRect)rect - (void) displayRect: (NSRect)rect
{ {
if ([self isOpaque]) if (_rFlags.opaque_view)
{ {
[self displayRectIgnoringOpacity: rect]; [self displayRectIgnoringOpacity: rect];
} }
@ -1282,39 +1290,34 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) displayRectIgnoringOpacity: (NSRect)aRect - (void) displayRectIgnoringOpacity: (NSRect)aRect
{ {
unsigned i, count;
NSRect rect;
BOOL stillNeedsDisplay = NO;
NSGraphicsContext *ctxt;
if (!window) if (!window)
return; return;
if (coordinates_valid == NO) if (coordinates_valid == NO)
[self _rebuildCoordinates]; [self _rebuildCoordinates];
/* aRect = NSIntersectionRect(aRect, visibleRect);
* we limit the invalid rect to the visible area - since we can't
* display beyond that anyway.
*/
if (needs_display)
invalidRect = NSIntersectionRect(invalidRect, visibleRect);
/* if (NSIsEmptyRect(aRect) == NO)
* Now we draw this view. {
*/ NSGraphicsContext *ctxt = GSCurrentContext();
ctxt = GSCurrentContext();
[ctxt lockFocusView: self inRect: aRect]; /*
[self drawRect: aRect]; * Now we draw this view.
[ctxt unlockFocusView: self needsFlush: YES]; */
[ctxt lockFocusView: self inRect: aRect];
[self drawRect: aRect];
[ctxt unlockFocusView: self needsFlush: YES];
}
if (_rFlags.has_subviews) if (_rFlags.has_subviews)
{ {
count = [sub_views count]; unsigned count = [sub_views count];
if (count > 0) if (count > 0)
{ {
NSView* array[count]; NSView *array[count];
unsigned i;
[sub_views getObjects: array]; [sub_views getObjects: array];
@ -1322,42 +1325,55 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
{ {
NSView *subview = array[i]; NSView *subview = array[i];
NSRect subviewFrame = subview->frame; NSRect subviewFrame = subview->frame;
NSRect intersection; NSRect isect;
BOOL intersectCalculated = NO;
if ([subview->frameMatrix isRotated]) if ([subview->frameMatrix isRotated])
[subview->frameMatrix boundingRectFor: subviewFrame [subview->frameMatrix boundingRectFor: subviewFrame
result: &subviewFrame]; result: &subviewFrame];
intersection = NSIntersectionRect(aRect, subviewFrame); /*
if (NSIsEmptyRect(intersection) == NO) * Having drawn ourself into the rect, we must make sure that
* subviews overlapping the area are redrawn.
*/
isect = NSIntersectionRect(aRect, subviewFrame);
if (NSIsEmptyRect(isect) == NO)
{ {
intersection = [subview convertRect: intersection isect = [subview convertRect: isect
fromView: self]; fromView: self];
[subview displayRectIgnoringOpacity: intersection]; intersectCalculated = YES;
/*
* hack the ivars of the subview directly for speed.
*/
subview->needs_display = YES;
subview->invalidRect = NSUnionRect(subview->invalidRect,
isect);
} }
if (subview->needs_display) if (subview->needs_display)
{ {
stillNeedsDisplay = YES; if (intersectCalculated == NO)
{
isect = [subview convertRect: isect
fromView: self];
}
[subview displayIfNeededInRectIgnoringOpacity: isect];
} }
} }
} }
} }
/* /*
* If the rect we displayed contains the invalidRect for the view * If the rect we displayed contains the invalidRect or visibleRect
* then we can empty invalidRect. All subviews will have been * then we can empty invalidRect. All subviews will have been
* fully displayed, so the 'stillNeedsDisplay' flag will be NO. * fully displayed, so this view no longer needs to be displayed.
*/ */
rect = NSUnionRect(invalidRect, aRect); if (NSEqualRects(aRect, NSUnionRect(invalidRect, aRect)) == YES
if (NSEqualRects(rect, aRect) == YES) || NSEqualRects(aRect, NSUnionRect(visibleRect, aRect)) == YES)
{ {
invalidRect = NSZeroRect; invalidRect = NSZeroRect;
needs_display = NO;
} }
else
{
stillNeedsDisplay = YES;
}
needs_display = stillNeedsDisplay;
[window flushWindow]; [window flushWindow];
} }
@ -1933,6 +1949,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
* Keep a note of whether this is a flipped view or not. * Keep a note of whether this is a flipped view or not.
*/ */
_rFlags.flipped_view = [self isFlipped]; _rFlags.flipped_view = [self isFlipped];
_rFlags.opaque_view = [self isOpaque];
if ([sub_views count]) if ([sub_views count])
_rFlags.has_subviews = 1; _rFlags.has_subviews = 1;