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 Frith-MacDonald 1999-05-10 08:30:14 +00:00
parent 0644a7dfeb
commit 0c507ab2d0
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>
* Source/NSView.m: Further optimisations, plus bugfix to ensure that

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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