aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/native/macosx/ContextUpdater.m
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-13 03:33:28 +0200
committerSven Gothel <[email protected]>2011-10-13 03:33:28 +0200
commit946c98fd196802755e9e13a9c5db75650a564466 (patch)
treec3aa9b62a1cea7e3a2dc8c306decbbbe273f3b4c /src/jogl/native/macosx/ContextUpdater.m
parent22f8e786219166019688ff2eea6ff9570c117544 (diff)
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.
Diffstat (limited to 'src/jogl/native/macosx/ContextUpdater.m')
-rw-r--r--src/jogl/native/macosx/ContextUpdater.m54
1 files changed, 36 insertions, 18 deletions
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