summaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java23
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface.m34
2 files changed, 27 insertions, 30 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 8e944c2ef..cf9924b26 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -383,16 +383,7 @@ public class MacOSXCGLContext extends GLContextImpl
isIncompleteView = false;
}
if( !isIncompleteView ) {
- if( useAppKit ) {
- OSXUtil.RunOnMainThread(true, false, new Runnable() {
- @Override
- public void run() {
- updateHandle = CGL.updateContextRegister(contextHandle, drawable.getHandle());
- }
- });
- } else {
- updateHandle = CGL.updateContextRegister(contextHandle, drawable.getHandle());
- }
+ updateHandle = CGL.updateContextRegister(contextHandle, drawable.getHandle(), false /* useAppKit .. onMain */);
if(0 == updateHandle) {
throw new InternalError("XXX2");
}
@@ -409,7 +400,6 @@ public class MacOSXCGLContext extends GLContextImpl
}
}
- private static boolean useAppKit = false;
@Override
protected void drawableUpdatedNotify() throws GLException {
if( drawable.getChosenGLCapabilities().isOnscreen() ) {
@@ -424,16 +414,7 @@ public class MacOSXCGLContext extends GLContextImpl
if (contextHandle == 0) {
throw new GLException("Context not created");
}
- if( useAppKit ) {
- OSXUtil.RunOnMainThread(true, false, new Runnable() {
- @Override
- public void run() {
- CGL.updateContext(contextHandle);
- }
- });
- } else {
- CGL.updateContext(contextHandle);
- }
+ CGL.updateContext(contextHandle, true /* useAppKit .. onMain */);
}
}
}
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
index 16b85974e..78b0b1854 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
@@ -643,12 +643,17 @@ void setContextOpacity(NSOpenGLContext* ctx, int opacity) {
[ctx setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
}
-void updateContext(NSOpenGLContext* ctx) {
+void updateContext(NSOpenGLContext* ctx, Bool onMainThread) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSView *nsView = [ctx view];
if(NULL != nsView) {
- DBG_PRINT("updateContext.0: ctx %p, ctx.view %p\n", ctx, nsView);
- [ctx update];
+ Bool isMainThread = [NSThread isMainThread];
+ DBG_PRINT("updateContext.0: ctx %p, ctx.view %p, onMain %d, isMain %d\n", ctx, nsView, onMainThread, isMainThread);
+ if(onMainThread && NO == isMainThread) {
+ [ctx performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:NO];
+ } else {
+ [ctx update];
+ }
DBG_PRINT("updateContext.X\n");
}
[pool release];
@@ -658,14 +663,25 @@ void copyContext(NSOpenGLContext* dest, NSOpenGLContext* src, int mask) {
[dest copyAttributesFromContext: src withMask: mask];
}
-void* updateContextRegister(NSOpenGLContext* ctx, NSView* view) {
+void* updateContextRegister(NSOpenGLContext* ctx, NSView* view, Bool onMainThread) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- DBG_PRINT("updateContextRegister.0: ctx %p, view %p\n", ctx, view);
- ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view];
- DBG_PRINT("updateContextRegister.X: ctxupd %p\n", contextUpdater);
- [pool release];
- return contextUpdater;
+ Bool isMainThread = [NSThread isMainThread];
+ DBG_PRINT("updateContextRegister.0: ctx %p, view %p, onMain %d, isMain %d\n", ctx, view, onMainThread, isMainThread);
+ if(onMainThread && NO == isMainThread) {
+ __block ContextUpdater *contextUpdater = NULL;
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view];
+ });
+ DBG_PRINT("updateContextRegister.XM: ctxupd %p\n", contextUpdater);
+ [pool release];
+ return contextUpdater;
+ } else {
+ ContextUpdater *contextUpdater = [[ContextUpdater alloc] initWithContext: ctx view: view];
+ DBG_PRINT("updateContextRegister.X_: ctxupd %p\n", contextUpdater);
+ [pool release];
+ return contextUpdater;
+ }
}
Bool updateContextNeedsUpdate(void* updater) {