summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-13 17:04:17 +0200
committerSven Gothel <[email protected]>2011-10-13 17:04:17 +0200
commitd186f6e945fd157b219231fb3861b3b0ce10ee75 (patch)
treeb3851f97222cf224251956cb8ad06508c7a9d090 /src/nativewindow/classes/jogamp
parent3fd89ccc138eddb915372cff4843f69f764048a7 (diff)
OSX/SWT: Adding OSXUtil: RunOnMainThread(), IsMainThread() / Utilizing those for SWT access/calls
Adding OSXUtil: RunOnMainThread(), IsMainThread() - Issuing a native call where the user Runnable is to be performed on the main thread - Enable query if we are on the main thread. Utilizing those for SWT access/calls - Using the above to call all SWT functions on the main thread if required (incomplete) TODO/Issues: - JOGL OSX CGL Context fails, ie expecting NS, but having CGL
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java10
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java65
2 files changed, 54 insertions, 21 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index ffd23fef7..ca303e6bc 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -34,6 +34,16 @@ public class OSXUtil {
return (Point) GetLocationOnScreen0(windowOrView, src_x, src_y);
}
+ public static void RunOnMainThread(boolean waitUntilDone, Runnable runnable) {
+ RunOnMainThread0(waitUntilDone, runnable);
+ }
+
+ public static boolean IsMainThread() {
+ return IsMainThread0();
+ }
+
private static native boolean initIDs0();
private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y);
+ private static native void RunOnMainThread0(boolean waitUntilDone, Runnable runnable);
+ private static native boolean IsMainThread0();
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java
index d1f5efc88..1ad909897 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java
@@ -42,6 +42,8 @@ import javax.media.nativewindow.x11.X11GraphicsDevice;
import com.jogamp.common.util.ReflectionUtil;
import javax.media.nativewindow.macosx.MacOSXGraphicsDevice;
+import jogamp.nativewindow.macosx.OSXUtil;
+
public class SWTAccessor {
static final Field swt_control_handle;
static final boolean swt_uses_long_handles;
@@ -60,7 +62,7 @@ public class SWTAccessor {
static final String str_internal_dispose_GC = "internal_dispose_GC";
static final String str_OS_gtk_class = "org.eclipse.swt.internal.gtk.OS";
- static final Class OS_gtk_class;
+ static final Class<?> OS_gtk_class;
static final Method OS_gtk_widget_realize;
static final Method OS_gtk_widget_unrealize;
static final Method OS_GTK_WIDGET_WINDOW;
@@ -113,9 +115,9 @@ public class SWTAccessor {
}
swt_control_internal_dispose_GC = m;
- Class c=null;
+ Class<?> c=null;
Method m1=null, m2=null, m3=null, m4=null, m5=null;
- Class handleType = swt_uses_long_handles ? long.class : int.class ;
+ Class<?> handleType = swt_uses_long_handles ? long.class : int.class ;
if( NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(false) ) {
try {
c = ReflectionUtil.getClass(str_OS_gtk_class, false, SWTAccessor.class.getClassLoader());
@@ -179,15 +181,19 @@ public class SWTAccessor {
return h;
}
- public static void setRealized(Control swtControl, boolean realize) {
- long handle = getHandle(swtControl);
+ public static void setRealized(final Control swtControl, final boolean realize) {
+ final long handle = getHandle(swtControl);
if(null != OS_gtk_class) {
- if(realize) {
- callStaticMethodL2V(OS_gtk_widget_realize, handle);
- } else {
- callStaticMethodL2V(OS_gtk_widget_unrealize, handle);
- }
+ invoke(true, new Runnable() {
+ public void run() {
+ if(realize) {
+ callStaticMethodL2V(OS_gtk_widget_realize, handle);
+ } else {
+ callStaticMethodL2V(OS_gtk_widget_unrealize, handle);
+ }
+ }
+ });
}
}
@@ -220,21 +226,38 @@ public class SWTAccessor {
throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false));
}
- public static long newGC(Control swtControl, GCData gcData) {
- Object o = ReflectionUtil.callMethod(swtControl, swt_control_internal_new_GC, new Object[] { gcData });
- if(o instanceof Number) {
- return ((Number)o).longValue();
+ public static long newGC(final Control swtControl, final GCData gcData) {
+ final Object[] o = new Object[1];
+ invoke(true, new Runnable() {
+ public void run() {
+ o[0] = ReflectionUtil.callMethod(swtControl, swt_control_internal_new_GC, new Object[] { gcData });
+ }
+ });
+ if(o[0] instanceof Number) {
+ return ((Number)o[0]).longValue();
} else {
- throw new InternalError("SWT internal_new_GC did not return int or long but "+o.getClass());
+ throw new InternalError("SWT internal_new_GC did not return int or long but "+o[0].getClass());
}
}
- public static void disposeGC(Control swtControl, long gc, GCData gcData) {
- if(swt_uses_long_handles) {
- ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Long(gc), gcData });
- } else {
- ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Integer((int)gc), gcData });
- }
+ public static void disposeGC(final Control swtControl, final long gc, final GCData gcData) {
+ invoke(true, new Runnable() {
+ public void run() {
+ if(swt_uses_long_handles) {
+ ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Long(gc), gcData });
+ } else {
+ ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Integer((int)gc), gcData });
+ }
+ }
+ });
+ }
+
+ public static void invoke(boolean wait, Runnable runnable) {
+ if(Platform.OS_TYPE == Platform.OSType.MACOS) {
+ OSXUtil.RunOnMainThread(wait, runnable);
+ } else {
+ runnable.run();
+ }
}
}