aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java2
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java10
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m13
3 files changed, 14 insertions, 11 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index e6334150b..0828d1dc3 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -745,7 +745,7 @@ public class MacOSXCGLContext extends GLContextImpl
if (DEBUG) {
System.err.println("NSOpenGLLayer.Attach: Re-Queue, drawableHandle "+toHexString(drawable.getHandle())+" - "+getThreadName());
}
- OSXUtil.RunLater(this, 1);
+ OSXUtil.RunLater(true /* onMain */, this, 1);
}
}
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index b27affa7e..dc32bd58c 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -263,13 +263,13 @@ public class OSXUtil implements ToolkitProperties {
}
/**
- * Run later on current OSX thread.
- *
+ * Run later on ..
+ * @param onMain if true, run on main-thread, otherwise on the current OSX thread.
* @param runnable
* @param delay delay to run the runnable in milliseconds
*/
- public static void RunLater(Runnable runnable, int delay) {
- RunLater0(new RunnableTask( runnable, null, true, System.err ), delay);
+ public static void RunLater(boolean onMain, Runnable runnable, int delay) {
+ RunLater0(onMain, new RunnableTask( runnable, null, true, System.err ), delay);
}
private static Runnable _nop = new Runnable() { public void run() {}; };
@@ -363,7 +363,7 @@ public class OSXUtil implements ToolkitProperties {
private static native void RemoveCASublayer0(long rootCALayer, long subCALayer);
private static native void DestroyCALayer0(long caLayer);
private static native void RunOnMainThread0(Runnable runnable);
- private static native void RunLater0(Runnable runnable, int delay);
+ private static native void RunLater0(boolean onMain, Runnable runnable, int delay);
private static native boolean IsMainThread0();
private static native int GetScreenRefreshRate0(int scrn_idx);
}
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index 3b19440d7..6a7952eaf 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -852,10 +852,13 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_jawt_macosx_MacOSXJAWTWindow_Uns
static void RunOnThread (JNIEnv *env, jobject runnable, BOOL onMain, jint delayInMS)
{
- DBG_PRINT2( "RunOnThread0: isMainThread %d, NSApp %d, NSApp-isRunning %d, onMain %d, delay %dms\n",
- (int)([NSThread isMainThread]), (int)(NULL!=NSApp), (int)([NSApp isRunning]), (int)onMain, (int)delayInMS);
+ BOOL isMainThread = [NSThread isMainThread];
+ BOOL forkOnMain = onMain && ( NO == isMainThread || 0 < delayInMS );
- if ( !onMain || NO == [NSThread isMainThread] ) {
+ DBG_PRINT2( "RunOnThread0: forkOnMain %d [onMain %d, delay %dms, isMainThread %d], NSApp %d, NSApp-isRunning %d\n",
+ (int)forkOnMain, (int)onMain, (int)delayInMS, (int)isMainThread, (int)(NULL!=NSApp), (int)([NSApp isRunning]));
+
+ if ( forkOnMain ) {
jobject runnableObj = (*env)->NewGlobalRef(env, runnable);
JavaVM *jvmHandle = NULL;
@@ -907,10 +910,10 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunOnMainThread0
* Signature: (ZLjava/lang/Runnable;I)V
*/
JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunLater0
- (JNIEnv *env, jclass unused, jobject runnable, jint delay)
+ (JNIEnv *env, jclass unused, jboolean onMain, jobject runnable, jint delay)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- RunOnThread (env, runnable, NO, delay);
+ RunOnThread (env, runnable, onMain ? YES : NO, delay);
[pool release];
}