From 946c98fd196802755e9e13a9c5db75650a564466 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 13 Oct 2011 03:33:28 +0200 Subject: JOGL/OSX: Properly utilize NSOpenGLContext update() via ContextUpdater, which only holds the 'update' state now. Avoid calling updater() for every makeCurrent(), but if view's frame has changed only. This solves the pixel flickering experienced on OSX. - GLContextImpl:update() -> drawableUpdatedNotify() w/ comments - ContextUpdater holds context, view, old view frame and the update state. It doesn't issue NSOpenGLContext update() by itself, but allows querying and clearing the update flag. - MacOSXOnscreenCGLContext impl drawableUpdatedNotify() - register via ContextUpdater, and use it if available. --- src/jogl/native/macosx/ContextUpdater.m | 54 ++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'src/jogl/native/macosx/ContextUpdater.m') 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 -- cgit v1.2.3