aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-12-25 03:50:40 +0100
committerSven Gothel <[email protected]>2012-12-25 03:50:40 +0100
commitb0be3d764fc6ff90457fcb96ea81d53ba04cd420 (patch)
tree098336cb932eb91af2a77b25a150cea67fa32547 /src/nativewindow/classes/jogamp
parenta35beb22d712b6da85a794115b19d484a12c8643 (diff)
Misc OSX/SWT: OSXUtil.RunOnMainThread(..) refinement; Fix Test*NewtEventModifiers for SWT (TestNewtEventModifiersNewtCanvasSWT)
- Misc OSX/SWT: OSXUtil.RunOnMainThread(..) refinement - 'waitUntilDone' is implemented on Java site via lock/wait on RunnableTask to not freeze OSX main thread. - Fix Test*NewtEventModifiers for SWT (TestNewtEventModifiersNewtCanvasSWT) - Deal with SWT's requirement to run the SWT event dispatch on the TK thread, which must be the main thread on OSX. We spawn off the actual test-action into another thread, while dispatching the events until the test-action is completed. - AWTRobot: Add 'void requestFocus(Robot robot, Object obj, int x, int y)' - Use waitForIdle() only if programmed in Robot (Deadlock w/ OSX SWT) - Required for SWT usage (see above)
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index a195f137e..f06f97064 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -32,6 +32,8 @@ import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.Point;
+import com.jogamp.common.util.RunnableTask;
+
import jogamp.nativewindow.Debug;
import jogamp.nativewindow.NWJNILibLoader;
import jogamp.nativewindow.ToolkitProperties;
@@ -154,11 +156,42 @@ public class OSXUtil implements ToolkitProperties {
DestroyCALayer0(caLayer);
}
+ /**
+ * Run on OSX UI main thread.
+ * <p>
+ * 'waitUntilDone' is implemented on Java site via lock/wait on {@link RunnableTask} to not freeze OSX main thread.
+ * </p>
+ *
+ * @param waitUntilDone
+ * @param runnable
+ */
public static void RunOnMainThread(boolean waitUntilDone, Runnable runnable) {
- if(IsMainThread0()) {
+ if( IsMainThread0() ) {
runnable.run(); // don't leave the JVM
} else {
- RunOnMainThread0(waitUntilDone, runnable);
+ if( waitUntilDone ) {
+ // Utilize Java side lock/wait and simply pass the Runnable async to OSX main thread,
+ // otherwise we may freeze the OSX main thread.
+ Throwable throwable = null;
+ final Object sync = new Object();
+ final RunnableTask rt = new RunnableTask( runnable, sync, true );
+ synchronized(sync) {
+ RunOnMainThread0(rt);
+ try {
+ sync.wait();
+ } catch (InterruptedException ie) {
+ throwable = ie;
+ }
+ if(null==throwable) {
+ throwable = rt.getThrowable();
+ }
+ if(null!=throwable) {
+ throw new RuntimeException(throwable);
+ }
+ }
+ } else {
+ RunOnMainThread0(runnable);
+ }
}
}
@@ -205,7 +238,7 @@ public class OSXUtil implements ToolkitProperties {
private static native void AddCASublayer0(long rootCALayer, long subCALayer);
private static native void RemoveCASublayer0(long rootCALayer, long subCALayer);
private static native void DestroyCALayer0(long caLayer);
- private static native void RunOnMainThread0(boolean waitUntilDone, Runnable runnable);
+ private static native void RunOnMainThread0(Runnable runnable);
private static native boolean IsMainThread0();
private static native int GetScreenRefreshRate0(int scrn_idx);
}