diff options
Diffstat (limited to 'src/jogl/native')
-rw-r--r-- | src/jogl/native/macosx/ContextUpdater.h | 11 | ||||
-rw-r--r-- | src/jogl/native/macosx/ContextUpdater.m | 54 | ||||
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface.m | 23 |
3 files changed, 61 insertions, 27 deletions
diff --git a/src/jogl/native/macosx/ContextUpdater.h b/src/jogl/native/macosx/ContextUpdater.h index f8ce93def..2483ec403 100644 --- a/src/jogl/native/macosx/ContextUpdater.h +++ b/src/jogl/native/macosx/ContextUpdater.h @@ -22,10 +22,13 @@ This notification is sent whenever an NSView that has an attached NSSurface chan #define UNLOCK_GL(func, line) [ContextUpdater unlock]; #endif -// gznote: OpenGL NOT thread safe - need to sync on update and paints - @interface ContextUpdater : NSObject { +@protected + NSView * view; + NSRect viewRect; + NSOpenGLContext *ctx; + BOOL viewUpdated; } + (void) lock; @@ -33,8 +36,10 @@ This notification is sent whenever an NSView that has an attached NSSurface chan + (void) unlock; + (void) unlockInFunction:(char *)func atLine:(int)line; -- (void) registerFor:(NSOpenGLContext *)context with: (NSView *)window; +- (id) initWithContext:(NSOpenGLContext *)context view: (NSView *)nsView; - (void) update:(NSNotification *)notification; +- (BOOL) needsUpdate; + @end diff --git a/src/jogl/native/macosx/ContextUpdater.m b/src/jogl/native/macosx/ContextUpdater.m index 859697722..64d5ef1f9 100644 --- a/src/jogl/native/macosx/ContextUpdater.m +++ b/src/jogl/native/macosx/ContextUpdater.m @@ -5,18 +5,17 @@ { } -static NSOpenGLContext *theContext; static pthread_mutex_t resourceLock = PTHREAD_MUTEX_INITIALIZER; static void printLockDebugInfo(char *message, char *func, int line) { fprintf(stderr, "%s in function: \"%s\" at line: %d\n", message, func, line); - fflush(stderr); + fflush(NULL); } + (void) lock { - if (theContext != NULL) + if (ctx != NULL) { pthread_mutex_lock(&resourceLock); } @@ -24,7 +23,7 @@ static void printLockDebugInfo(char *message, char *func, int line) + (void) lockInFunction:(char *)func atLine:(int)line { - if (theContext != NULL) + if (ctx != NULL) { printLockDebugInfo("locked ", func, line); [self lock]; @@ -33,7 +32,7 @@ static void printLockDebugInfo(char *message, char *func, int line) + (void) unlock { - if (theContext != NULL) + if (ctx != NULL) { pthread_mutex_unlock(&resourceLock); } @@ -41,43 +40,62 @@ static void printLockDebugInfo(char *message, char *func, int line) + (void) unlockInFunction:(char *)func atLine:(int)line { - if (theContext != NULL) + if (ctx != NULL) { printLockDebugInfo("unlocked", func, line); [self unlock]; } } -- (void) registerFor:(NSOpenGLContext *)context with: (NSView *)view +- (void) update:(NSNotification *)notification { - if (view != NULL) - { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:NSViewGlobalFrameDidChangeNotification object: view]; - theContext = context; + [ContextUpdater lock]; + + NSRect r = [view frame]; + if(viewRect.origin.x != r.origin.x || + viewRect.origin.y != r.origin.y || + viewRect.size.width != r.size.width || + viewRect.size.height != r.size.height) { + viewUpdated = TRUE; + viewRect = r; } + + [ContextUpdater unlock]; } -- (void) update:(NSNotification *)notification +- (BOOL) needsUpdate { + BOOL r; [ContextUpdater lock]; - [theContext update]; + r = viewUpdated; + viewUpdated = FALSE; [ContextUpdater unlock]; + + return r; } -- (id) init -{ - theContext = NULL; - +- (id) initWithContext:(NSOpenGLContext *)context view: (NSView *)nsView +{ + ctx = context; + view = nsView; + [ctx retain]; + [view retain]; + viewRect = [view frame]; + viewUpdated = FALSE; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:NSViewGlobalFrameDidChangeNotification object: view]; + return [super init]; } - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + [view release]; + [ctx release]; [super dealloc]; } -@end
\ No newline at end of file +@end diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m index 86d875502..aab70791c 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -590,7 +590,8 @@ Bool deleteContext(void* nsJContext) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; [nsContext clearDrawable]; - [nsContext release]; // freezes for a few seconds if ctx is shared + // [nsContext release]; // FIXME: JAU: freezes for a few seconds if ctx is shared + // [nsContext dealloc]; [pool release]; return true; } @@ -624,15 +625,25 @@ void copyContext(void* destContext, void* srcContext, int mask) { [dst copyAttributesFromContext: src withMask: mask]; } -void* updateContextRegister(void* nsJContext, void* view) { +void* updateContextRegister(void* nsJContext, void* nsJView) { NSOpenGLContext *nsContext = (NSOpenGLContext*)nsJContext; - NSView *nsView = (NSView*)view; + NSView *nsView = (NSView*)nsJView; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - ContextUpdater *contextUpdater = [[ContextUpdater alloc] init]; - [contextUpdater registerFor:nsContext with:nsView]; + ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: nsContext view: nsView]; [pool release]; - return NULL; + return contextUpdater; +} + +Bool updateContextNeedsUpdate(void* updater) { + ContextUpdater *contextUpdater = (ContextUpdater *)updater; + BOOL res; + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + res = [contextUpdater needsUpdate]; + [pool release]; + + return ( res == TRUE ) ? true : false; } void updateContextUnregister(void* updater) { |