GUI part of the graphics context rewrite.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24966 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-04-04 14:33:39 +00:00
parent f8aac2ba14
commit 66fcff3b42
5 changed files with 147 additions and 125 deletions

View file

@ -1,3 +1,17 @@
2007-04-04 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSWindow.h: Reuse one reserved ivar as the
graphics context.
* Source/NSWindow.m (-_terminateBackendWindow,
-_initBackendWindow, -initWithWindowRef:, -graphicsContext,
-flushWindow, -_processResizeEvent): Set and use context from ivar.
* Source/NSImage.m (-drawInRect:fromRect:operation:fraction:):
make sure to use the right graphic context.
* Source/NSView.m (-releaseGState): Use context from window.
* Source/NSView.m (-_lockFocusInContext:inRect:,
-unlockFocusNeedsFlush:) Set context to current when locking focus
and pop it when unlocking.
2007-04-02 Richard Frith-Macdonald <rfm@gnu.org> 2007-04-02 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/AppKit/NSAlert.h: Tidied. * Headers/AppKit/NSAlert.h: Tidied.

View file

@ -215,9 +215,9 @@ APPKIT_EXPORT NSSize NSTokenSize;
} _f; } _f;
id _defaultButtonCell; id _defaultButtonCell;
NSGraphicsContext *_context;
void *_reserved_1; void *_reserved_1;
void *_reserved_2;
} }
/* /*

View file

@ -1051,6 +1051,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
NSPoint p; NSPoint p;
double x0, y0, x1, y1, w, h; double x0, y0, x1, y1, w, h;
int gState; int gState;
NSGraphicsContext *ctxt1;
s = [self size]; s = [self size];
@ -1098,8 +1099,9 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
alpha: YES]; alpha: YES];
[[[cache window] contentView] lockFocus]; [[[cache window] contentView] lockFocus];
// The context of the cache window
DPScompositerect(ctxt, 0, 0, w, h, NSCompositeClear); ctxt1 = GSCurrentContext();
DPScompositerect(ctxt1, 0, 0, w, h, NSCompositeClear);
/* Set up the effective transform. We also save a gState with this /* Set up the effective transform. We also save a gState with this
transform to make it easier to do the final composite. */ transform to make it easier to do the final composite. */
@ -1107,9 +1109,8 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
ts.tX = p.x; ts.tX = p.x;
ts.tY = p.y; ts.tY = p.y;
[transform setTransformStruct: ts]; [transform setTransformStruct: ts];
[ctxt GSSetCTM: transform]; [ctxt1 GSSetCTM: transform];
gState = [ctxt1 GSDefineGState];
gState = [ctxt GSDefineGState];
[self drawRepresentation: [self bestRepresentationForDevice: nil] [self drawRepresentation: [self bestRepresentationForDevice: nil]
inRect: NSMakeRect(0, 0, s.width, s.height)]; inRect: NSMakeRect(0, 0, s.width, s.height)];
@ -1118,17 +1119,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
the alpha of the pixels. */ the alpha of the pixels. */
if (delta != 1.0) if (delta != 1.0)
{ {
DPSsetalpha(ctxt, delta); DPSsetalpha(ctxt1, delta);
DPScompositerect(ctxt, 0, 0, s.width, s.height, DPScompositerect(ctxt1, 0, 0, s.width, s.height,
NSCompositeDestinationIn); NSCompositeDestinationIn);
} }
[[[cache window] contentView] unlockFocus]; [[[cache window] contentView] unlockFocus];
DPScomposite(ctxt, srcRect.origin.x, srcRect.origin.y, DPScomposite(ctxt, srcRect.origin.x, srcRect.origin.y,
srcRect.size.width, srcRect.size.height, gState, srcRect.size.width, srcRect.size.height, gState,
dstRect.origin.x, dstRect.origin.y, op); dstRect.origin.x, dstRect.origin.y, op);
[ctxt GSUndefineGState: gState]; [ctxt GSUndefineGState: gState];

View file

@ -1691,26 +1691,28 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
NSAssert(_window != nil, NSInternalInconsistencyException); NSAssert(_window != nil, NSInternalInconsistencyException);
/* Check for deferred window */ /* Check for deferred window */
if ((window_gstate = [_window gState]) == 0) if ((window_gstate = [_window gState]) == 0)
{ {
return; return;
} }
} }
if (ctxt == nil) if (ctxt == nil)
{ {
if (viewIsPrinting != nil) if (viewIsPrinting != nil)
{ {
NSPrintOperation *printOp = [NSPrintOperation currentOperation]; NSPrintOperation *printOp = [NSPrintOperation currentOperation];
ctxt = [printOp context]; ctxt = [printOp context];
} }
else else
{ {
ctxt = [_window graphicsContext]; ctxt = [_window graphicsContext];
} }
} }
// FIXME: Set current context
// Set current context
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: ctxt];
[ctxt lockFocusView: self inRect: rect]; [ctxt lockFocusView: self inRect: rect];
wrect = [self convertRect: rect toView: nil]; wrect = [self convertRect: rect toView: nil];
@ -1732,16 +1734,16 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
if (viewIsPrinting != nil) if (viewIsPrinting != nil)
{ {
if (viewIsPrinting == self) if (viewIsPrinting == self)
{ {
/* Make sure coordinates are valid, then fake that we don't have /* Make sure coordinates are valid, then fake that we don't have
a superview so we get printed correctly */ a superview so we get printed correctly */
[self _matrixToWindow]; [self _matrixToWindow];
[_matrixToWindow makeIdentityMatrix]; [_matrixToWindow makeIdentityMatrix];
} }
else else
{ {
[[self _matrixToWindow] concat]; [[self _matrixToWindow] concat];
} }
/* Allow subclases to make other modifications */ /* Allow subclases to make other modifications */
[self setUpGState]; [self setUpGState];
@ -1752,34 +1754,35 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
matrix = [self _matrixToWindow]; matrix = [self _matrixToWindow];
if (_gstate) if (_gstate)
{ {
DPSsetgstate(ctxt, _gstate); DPSsetgstate(ctxt, _gstate);
if (_renew_gstate) if (_renew_gstate)
{ {
[self setUpGState]; [self setUpGState];
_renew_gstate = NO; _renew_gstate = NO;
} }
DPSgsave(ctxt); DPSgsave(ctxt);
} }
else else
{ {
DPSsetgstate(ctxt, window_gstate); // This only works, when the context comes from the window
DPSgsave(ctxt); DPSsetgstate(ctxt, window_gstate);
[matrix concat]; DPSgsave(ctxt);
[matrix concat];
/* Allow subclases to make other modifications */
[self setUpGState]; /* Allow subclases to make other modifications */
_renew_gstate = NO; [self setUpGState];
if (_allocate_gstate) _renew_gstate = NO;
{ if (_allocate_gstate)
_gstate = GSDefineGState(ctxt); {
/* Balance the previous gsave and install our own gstate */ _gstate = GSDefineGState(ctxt);
DPSgrestore(ctxt); /* Balance the previous gsave and install our own gstate */
DPSsetgstate(ctxt, _gstate); DPSgrestore(ctxt);
DPSgsave(ctxt); DPSsetgstate(ctxt, _gstate);
} DPSgsave(ctxt);
}
}
}
} }
if ([self wantsDefaultClipping]) if ([self wantsDefaultClipping])
@ -1790,25 +1793,25 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
* our bounds. * our bounds.
*/ */
if (_is_rotated_from_base) if (_is_rotated_from_base)
{ {
// When the view is rotated, more complex clipping is needed. // When the view is rotated, more complex clipping is needed.
NSAffineTransform *matrix; NSAffineTransform *matrix;
NSBezierPath *bp = [NSBezierPath bezierPathWithRect: _frame]; NSBezierPath *bp = [NSBezierPath bezierPathWithRect: _frame];
matrix = [_boundsMatrix copy]; matrix = [_boundsMatrix copy];
[matrix invert]; [matrix invert];
[bp transformUsingAffineTransform: matrix]; [bp transformUsingAffineTransform: matrix];
[bp addClip]; [bp addClip];
RELEASE(matrix); RELEASE(matrix);
} }
else else
{ {
DPSrectclip(ctxt, NSMinX(rect), NSMinY(rect), DPSrectclip(ctxt, NSMinX(rect), NSMinY(rect),
NSWidth(rect), NSHeight(rect)); NSWidth(rect), NSHeight(rect));
} }
} }
/* Tell backends that images are drawn upside down. /* Tell backends that images are drawn upside down. Obsolete?
This is needed when a backend is able to handle full image transformation. */ This is needed when a backend is able to handle full image transformation. */
GSWSetViewIsFlipped(ctxt, _rFlags.flipped_view); GSWSetViewIsFlipped(ctxt, _rFlags.flipped_view);
} }
@ -1825,7 +1828,7 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
NSAssert(_window != nil, NSInternalInconsistencyException); NSAssert(_window != nil, NSInternalInconsistencyException);
/* Check for deferred window */ /* Check for deferred window */
if ([_window gState] == 0) if ([_window gState] == 0)
return; return;
/* Restore our original gstate */ /* Restore our original gstate */
DPSgrestore(ctxt); DPSgrestore(ctxt);
@ -1842,15 +1845,16 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
struct NSWindow_struct *window_t; struct NSWindow_struct *window_t;
window_t = (struct NSWindow_struct *)_window; window_t = (struct NSWindow_struct *)_window;
if (flush) if (flush)
{ {
rect = [[window_t->_rectsBeingDrawn lastObject] rectValue]; rect = [[window_t->_rectsBeingDrawn lastObject] rectValue];
window_t->_rectNeedingFlush = window_t->_rectNeedingFlush =
NSUnionRect(window_t->_rectNeedingFlush, rect); NSUnionRect(window_t->_rectNeedingFlush, rect);
window_t->_f.needs_flush = YES; window_t->_f.needs_flush = YES;
} }
[window_t->_rectsBeingDrawn removeLastObject]; [window_t->_rectsBeingDrawn removeLastObject];
} }
[ctxt unlockFocusView: self needsFlush: YES ]; [ctxt unlockFocusView: self needsFlush: YES ];
[NSGraphicsContext restoreGraphicsState];
} }
/** /**
@ -1878,7 +1882,7 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
- (void) releaseGState - (void) releaseGState
{ {
if (_allocate_gstate && _gstate) if (_allocate_gstate && _gstate)
GSUndefineGState(GSCurrentContext(), _gstate); GSUndefineGState([_window graphicsContext], _gstate);
_gstate = 0; _gstate = 0;
_allocate_gstate = NO; _allocate_gstate = NO;
} }
@ -1977,9 +1981,9 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
if (_rFlags.needs_display == YES) if (_rFlags.needs_display == YES)
{ {
if ([self isOpaque] == YES) if ([self isOpaque] == YES)
{ {
[self displayIfNeededIgnoringOpacity]; [self displayIfNeededIgnoringOpacity];
} }
else else
{ {
NSView *firstOpaque = [self opaqueAncestor]; NSView *firstOpaque = [self opaqueAncestor];
@ -2024,32 +2028,32 @@ static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matri
NSRect rect; NSRect rect;
if (_coordinates_valid == NO) if (_coordinates_valid == NO)
{ {
[self _rebuildCoordinates]; [self _rebuildCoordinates];
} }
rect = NSIntersectionRect(_invalidRect, _visibleRect); rect = NSIntersectionRect(_invalidRect, _visibleRect);
if (NSIsEmptyRect(rect) == NO) if (NSIsEmptyRect(rect) == NO)
{ {
[self displayIfNeededInRectIgnoringOpacity: rect]; [self displayIfNeededInRectIgnoringOpacity: rect];
} }
/* /*
* If we still need display after displaying the invalid rectangle, * If we still need display after displaying the invalid rectangle,
* display any subviews that need display. * display any subviews that need display.
*/ */
if (_rFlags.needs_display == YES) if (_rFlags.needs_display == YES)
{ {
NSEnumerator *enumerator = [_sub_views objectEnumerator]; NSEnumerator *enumerator = [_sub_views objectEnumerator];
NSView *sub; NSView *sub;
while ((sub = [enumerator nextObject]) != nil) while ((sub = [enumerator nextObject]) != nil)
{ {
if (sub->_rFlags.needs_display) if (sub->_rFlags.needs_display)
{ {
[sub displayIfNeededIgnoringOpacity]; [sub displayIfNeededIgnoringOpacity];
} }
} }
_rFlags.needs_display = NO; _rFlags.needs_display = NO;
} }
} }
} }

View file

@ -664,17 +664,16 @@ many times.
*/ */
- (void) _terminateBackendWindow - (void) _terminateBackendWindow
{ {
NSGraphicsContext *context = GSCurrentContext();
/* Check for context also as it might have disappeared before us */ /* Check for context also as it might have disappeared before us */
if (context && _gstate) if (_context && _gstate)
{ {
GSUndefineGState(context, _gstate); GSUndefineGState(_context, _gstate);
_gstate = 0; _gstate = 0;
} }
if (_windowNum) if (_windowNum)
{ {
DESTROY(_context);
[_wv setWindowNumber: 0]; [_wv setWindowNumber: 0];
[GSServerForWindow(self) termwindow: _windowNum]; [GSServerForWindow(self) termwindow: _windowNum];
NSMapRemove(windowmaps, (void*)(intptr_t)_windowNum); NSMapRemove(windowmaps, (void*)(intptr_t)_windowNum);
@ -749,7 +748,6 @@ many times.
{ {
int screenNumber; int screenNumber;
NSCountedSet *dragTypes; NSCountedSet *dragTypes;
NSGraphicsContext *context = GSCurrentContext();
GSDisplayServer *srv = GSCurrentServer(); GSDisplayServer *srv = GSCurrentServer();
/* If we were deferred or one shot, our drag types may not have /* If we were deferred or one shot, our drag types may not have
@ -776,11 +774,15 @@ many times.
[srv setwindowlevel: [self level] : _windowNum]; [srv setwindowlevel: [self level] : _windowNum];
NSMapInsert (windowmaps, (void*)(intptr_t)_windowNum, self); NSMapInsert (windowmaps, (void*)(intptr_t)_windowNum, self);
// Set window in new _gstate ASSIGN(_context, [NSGraphicsContext graphicsContextWithWindow: self]);
DPSgsave(context); // FIXME: This belongs into NSGraphicsContext
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: _context];
[srv windowdevice: _windowNum]; [srv windowdevice: _windowNum];
_gstate = GSDefineGState(context); [NSGraphicsContext restoreGraphicsState];
DPSgrestore(context);
// Set window in new _gstate
_gstate = GSDefineGState(_context);
{ {
NSRect frame = _frame; NSRect frame = _frame;
@ -974,7 +976,6 @@ many times.
NSScreen* aScreen; NSScreen* aScreen;
int screen; int screen;
int winNum; int winNum;
NSGraphicsContext *context = GSCurrentContext();
GSDisplayServer *srv = GSCurrentServer(); GSDisplayServer *srv = GSCurrentServer();
// Get the properties for the underlying window // Get the properties for the underlying window
@ -994,11 +995,15 @@ many times.
_windowNum = winNum; _windowNum = winNum;
NSMapInsert (windowmaps, (void*)(intptr_t)_windowNum, self); NSMapInsert (windowmaps, (void*)(intptr_t)_windowNum, self);
// Set window in new _gstate ASSIGN(_context, [NSGraphicsContext graphicsContextWithWindow: self]);
DPSgsave(context); // FIXME: This belongs into NSGraphicsContext
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: _context];
[srv windowdevice: _windowNum]; [srv windowdevice: _windowNum];
_gstate = GSDefineGState(context); [NSGraphicsContext restoreGraphicsState];
DPSgrestore(context);
// Set window in new _gstate
_gstate = GSDefineGState(_context);
{ {
NSRect frame = _frame; NSRect frame = _frame;
@ -1173,8 +1178,7 @@ many times.
- (NSGraphicsContext*) graphicsContext - (NSGraphicsContext*) graphicsContext
{ {
// FIXME return _context;
return GSCurrentContext();
} }
- (int) gState - (int) gState
@ -2118,9 +2122,7 @@ many times.
*/ */
if (_backingType == NSBackingStoreNonretained) if (_backingType == NSBackingStoreNonretained)
{ {
NSGraphicsContext *context = GSCurrentContext(); [_context flushGraphics];
[context flushGraphics];
return; return;
} }
@ -3167,12 +3169,13 @@ resetCursorRectsForView(NSView *theView)
{ {
if (_windowNum && _gstate) if (_windowNum && _gstate)
{ {
NSGraphicsContext *context = GSCurrentContext(); // FIXME: move this into NSGraphicsContext
DPSgsave(context); [NSGraphicsContext saveGraphicsState];
DPSsetgstate(context, _gstate); [NSGraphicsContext setCurrentContext: _context];
DPSsetgstate(_context, _gstate);
[GSServerForWindow(self) windowdevice: _windowNum]; [GSServerForWindow(self) windowdevice: _windowNum];
GSReplaceGState(context, _gstate); GSReplaceGState(_context, _gstate);
DPSgrestore(context); [NSGraphicsContext restoreGraphicsState];
} }
[self update]; [self update];