summaryrefslogtreecommitdiffstats
path: root/src/jogl/native/macosx/ContextUpdater.m
diff options
context:
space:
mode:
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