diff options
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java index 055b608c3..4a5260155 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java +++ b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java @@ -27,6 +27,7 @@ */ package jogamp.nativewindow.swt; +import com.jogamp.common.os.Platform; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -39,16 +40,17 @@ import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.windows.WindowsGraphicsDevice; import javax.media.nativewindow.x11.X11GraphicsDevice; import com.jogamp.common.util.ReflectionUtil; +import javax.media.nativewindow.macosx.MacOSXGraphicsDevice; public class SWTAccessor { + static final Field swt_control_handle; + static final boolean swt_uses_long_handles; + static final String str_handle = "handle"; + static final Method swt_control_internal_new_GC; static final Method swt_control_internal_dispose_GC; - static final boolean swt_uses_long_handles; - static final Field swt_control_handle; - static final String str_internal_new_GC = "internal_new_GC"; static final String str_internal_dispose_GC = "internal_dispose_GC"; - static final String str_handle = "handle"; static final String str_OS_gtk_class = "org.eclipse.swt.internal.gtk.OS"; static final Class OS_gtk_class; @@ -64,6 +66,17 @@ public class SWTAccessor { static final String str_gdk_x11_drawable_get_xid = "gdk_x11_drawable_get_xid"; static { + Field f = null; + try { + f = Control.class.getField(str_handle); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + swt_control_handle = f; + swt_uses_long_handles = swt_control_handle.getGenericType().toString().equals(long.class.toString()); + // System.err.println("SWT long handles: " + swt_uses_long_handles); + // System.err.println("Platform 64bit: "+Platform.is64Bit()); + Method m=null; try { m = ReflectionUtil.getMethod(Control.class, str_internal_new_GC, new Class[] { GCData.class }); @@ -71,33 +84,21 @@ public class SWTAccessor { throw new NativeWindowException(ex); } swt_control_internal_new_GC = m; - - boolean swt_uses_long_tmp = false; + try { - m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { int.class, GCData.class }); - swt_uses_long_tmp = false; - } catch (NoSuchMethodException ex1) { - try { - m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { long.class, GCData.class }); - swt_uses_long_tmp = true; - } catch (NoSuchMethodException ex2) { - throw new NativeWindowException("Neither 'int' nor 'long' variant of '"+str_internal_dispose_GC+"' exist", ex2); + if(swt_uses_long_handles) { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { long.class, GCData.class }); + } else { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { int.class, GCData.class }); } + } catch (NoSuchMethodException ex) { + throw new NativeWindowException(ex); } - swt_uses_long_handles = swt_uses_long_tmp; swt_control_internal_dispose_GC = m; - Field f = null; - try { - f = Control.class.getField(str_handle); - } catch (Exception ex) { - throw new NativeWindowException(ex); - } - swt_control_handle = f; - Class c=null; Method m1=null, m2=null, m3=null, m4=null, m5=null; - Class handleType = swt_uses_long_tmp ? 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()); @@ -116,18 +117,23 @@ public class SWTAccessor { OS_gdk_x11_drawable_get_xid = m5; } - static void callMethodL2V(Class c, Method m, long arg) { - Object argObj = swt_uses_long_handles ? new Long(arg) : new Integer((int)arg); - ReflectionUtil.callMethod(c, m, new Object[] { argObj }); + static Object getIntOrLong(long arg) { + if(swt_uses_long_handles) { + return new Long(arg); + } + return new Integer((int) arg); } - static long callMethodL2L(Class c, Method m, long arg) { - Object argObj = swt_uses_long_handles ? new Long(arg) : new Integer((int)arg); - Object o = ReflectionUtil.callMethod(c, m, new Object[] { argObj }); + static void callStaticMethodL2V(Method m, long arg) { + ReflectionUtil.callMethod(null, m, new Object[] { getIntOrLong(arg) }); + } + + static long callStaticMethodL2L(Method m, long arg) { + Object o = ReflectionUtil.callMethod(null, m, new Object[] { getIntOrLong(arg) }); if(o instanceof Number) { return ((Number)o).longValue(); } else { - throw new InternalError("SWT method "+c.getSimpleName()+"."+m.getName()+" didn't return int or long but "+o.getClass()); + throw new InternalError("SWT method "+m.getName()+" didn't return int or long but "+o.getClass()); } } @@ -150,9 +156,9 @@ public class SWTAccessor { if(null != OS_gtk_class) { if(realize) { - callMethodL2V(OS_gtk_class, OS_gtk_widget_realize, handle); + callStaticMethodL2V(OS_gtk_widget_realize, handle); } else { - callMethodL2V(OS_gtk_class, OS_gtk_widget_unrealize, handle); + callStaticMethodL2V(OS_gtk_widget_unrealize, handle); } } } @@ -160,23 +166,27 @@ public class SWTAccessor { public static AbstractGraphicsDevice getDevice(Control swtControl) { long handle = getHandle(swtControl); if( null != OS_gtk_class ) { - long widgedHandle = callMethodL2L(OS_gtk_class, OS_GTK_WIDGET_WINDOW, handle); - long displayHandle = callMethodL2L(OS_gtk_class, OS_gdk_x11_drawable_get_xdisplay, widgedHandle); + long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle); + long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle); return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT); } if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) { return new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); } + if( NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + return new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + } throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); } public static long getWindowHandle(Control swtControl) { long handle = getHandle(swtControl); if( null != OS_gtk_class ) { - long widgedHandle = callMethodL2L(OS_gtk_class, OS_GTK_WIDGET_WINDOW, handle); - return callMethodL2L(OS_gtk_class, OS_gdk_x11_drawable_get_xid, widgedHandle); + long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle); + return callStaticMethodL2L(OS_gdk_x11_drawable_get_xid, widgedHandle); } - if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) { + if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) || + NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { return handle; } throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); |