Some more optimisation

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4235 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-05-10 08:30:14 +00:00
parent 977ca1a87e
commit 7b54630f98
8 changed files with 59 additions and 22 deletions

View file

@ -1,3 +1,15 @@
Mon May 10 9:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Headers/AppKit/NSGraphicsContext.h: Added GSCurrentContext() for
optimised access to current context for thread.
* Source/NSView.m: Minor optimisation of graphics context access.
* Source/NSApplication.m: ditto
* Source/NSScrollView.m: ditto
* Source/NSSplitView.m: ditto
* Source/NSStringDrawing.m: ditto
* Source/NSGraphicsContext.m: Added GSCurrentContext() to return the
current graphics context for the thread.
Sun May 9 9:13:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Sun May 9 9:13:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSView.m: Further optimisations, plus bugfix to ensure that * Source/NSView.m: Further optimisations, plus bugfix to ensure that

View file

@ -112,6 +112,8 @@ typedef enum _NSWindowOrderingMode
@end @end
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP
NSGraphicsContext *GSCurrentContext();
@interface NSGraphicsContext (GNUstep) @interface NSGraphicsContext (GNUstep)
+ (void) setDefaultContextClass: (Class)defaultContextClass; + (void) setDefaultContextClass: (Class)defaultContextClass;
+ (NSGraphicsContext*) defaultContextWithInfo: (NSDictionary *)info; + (NSGraphicsContext*) defaultContextWithInfo: (NSDictionary *)info;

View file

@ -1660,9 +1660,9 @@ NSApplication *NSApp = nil;
return nil; return nil;
} }
- (NSGraphicsContext *) context // return the current draw - (NSGraphicsContext *) context
{ // context (drawing dest) {
return [NSGraphicsContext currentContext]; return GSCurrentContext();
} }
- (void) reportException: (NSException *)anException - (void) reportException: (NSException *)anException

View file

@ -55,7 +55,29 @@ static NSMutableDictionary *classMethodTable;
/* Lock for use when creating contexts */ /* Lock for use when creating contexts */
static NSRecursiveLock *contextLock = nil; static NSRecursiveLock *contextLock = nil;
static NSString *NSGraphicsContextThredKey = @"NSGraphicsContextThredKey"; #ifndef GNUSTEP_BASE_LIBRARY
static NSString *NSGraphicsContextThreadKey = @"NSGraphicsContextThreadKey";
#endif
/*
* Function for rapid access to current graphics context.
*/
NSGraphicsContext *GSCurrentContext()
{
#ifdef GNUSTEP_BASE_LIBRARY
/*
* gstep-base has a faster mechanism to get the current thread.
*/
NSThread *th = GSCurrentThread();
return (NSGraphicsContext*) th->_gcontext;
#else
NSMutableDictionary *dict [[NSThread currentThread] threadDictionary];
return (NSGraphicsContext*) [dict objectForKey: NSGraphicsContextThreadKey];
#endif
}
@interface NSGraphicsContext (Private) @interface NSGraphicsContext (Private)
+ (gsMethodTable *) _initializeMethodTable; + (gsMethodTable *) _initializeMethodTable;
@ -103,29 +125,31 @@ struct NSWindow_struct
return ctxt; return ctxt;
} }
+ (void) setCurrentContext: (NSGraphicsContext *)context
{
#ifdef GNUSTEP_BASE_LIBRARY
/* /*
* gstep-base has a faster mechanism to get the current thread. * gstep-base has a faster mechanism to get the current thread.
*/ */
#ifndef GNUSTEP_BASE_LIBRARY NSThread *th = GSCurrentThread();
#define GSCurrentThreadDictionary() [[NSThread currentThread] threadDictionary]
th->_gcontext = context;
#else
NSMutableDictionary *dict [[NSThread currentThread] threadDictionary];
[dict setObject: context forKey: NSGraphicsContextThreadKey];
#endif #endif
+ (void) setCurrentContext: (NSGraphicsContext *)context
{
NSMutableDictionary *dict = GSCurrentThreadDictionary();
[dict setObject: context forKey: NSGraphicsContextThredKey];
} }
+ (NSGraphicsContext *) currentContext + (NSGraphicsContext *) currentContext
{ {
NSMutableDictionary *dict = GSCurrentThreadDictionary(); return GSCurrentContext();
return (NSGraphicsContext*) [dict objectForKey: NSGraphicsContextThredKey];
} }
- (void) dealloc - (void) dealloc
{ {
if (GSCurrentContext() == self)
[NSGraphicsContext setCurrentContext: nil];
DESTROY(focus_stack); DESTROY(focus_stack);
DESTROY(context_data); DESTROY(context_data);
DESTROY(context_info); DESTROY(context_info);

View file

@ -506,7 +506,7 @@ static Class rulerViewClass = nil;
- (void) drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
NSGraphicsContext *ctxt = [NSGraphicsContext currentContext]; NSGraphicsContext *ctxt = GSCurrentContext();
float scrollerWidth = [NSScroller scrollerWidth]; float scrollerWidth = [NSScroller scrollerWidth];
float horizLinePosition, horizLineLength = [self bounds].size.width; float horizLinePosition, horizLineLength = [self bounds].size.width;
float borderThickness = 0; float borderThickness = 0;

View file

@ -210,7 +210,6 @@
(int)NSHeight(r)); (int)NSHeight(r));
[dividerColor set]; [dividerColor set];
NSHighlightRect(r); NSHighlightRect(r);
// [[NSDrawContext currentContext] flush];
oldRect = r; oldRect = r;
e = [app nextEventMatchingMask: eventMask e = [app nextEventMatchingMask: eventMask
untilDate: farAway untilDate: farAway

View file

@ -1140,7 +1140,7 @@ setupLine(GSTextLine *line, NSAttributedString *str, NSRange range,
- (void) drawAtPoint: (NSPoint)point - (void) drawAtPoint: (NSPoint)point
{ {
NSGraphicsContext *ctxt = [NSGraphicsContext currentContext]; NSGraphicsContext *ctxt = GSCurrentContext();
BOOL isFlipped = [[ctxt focusView] isFlipped]; BOOL isFlipped = [[ctxt focusView] isFlipped];
NSString *allText = [self string]; NSString *allText = [self string];
unsigned length = [allText length]; unsigned length = [allText length];

View file

@ -94,7 +94,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
*/ */
+ (NSView*) focusView + (NSView*) focusView
{ {
return [[NSGraphicsContext currentContext] focusView]; return [GSCurrentContext() focusView];
} }
// //
@ -1067,13 +1067,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) lockFocus - (void) lockFocus
{ {
[[NSGraphicsContext currentContext] lockFocusView: self [GSCurrentContext() lockFocusView: self
inRect: [self visibleRect]]; inRect: [self visibleRect]];
} }
- (void) unlockFocus - (void) unlockFocus
{ {
[[NSGraphicsContext currentContext] unlockFocusView: self needsFlush: YES ]; [GSCurrentContext() unlockFocusView: self needsFlush: YES ];
} }
- (BOOL) canDraw - (BOOL) canDraw