diff options
author | Sven Gothel <[email protected]> | 2012-08-18 14:52:32 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-08-18 14:52:32 +0200 |
commit | c5835a2e19a84cb08957d6c742e4334d578c3c66 (patch) | |
tree | 2d7b50355cbbf3a4e19ab5922f8d478316e75110 /src/nativewindow | |
parent | a694cadca4ab72481e777222f412f006f973f77e (diff) |
NativeWindowFactory.getNativeWindowType(..): Return canonical string representation allowing proper use of ref. comparison '==', instead of 'String.equals()'
Also make NativeWindowFactory's instances of nativeWindowingTypePure and nativeWindowingTypeCustom static final.
Diffstat (limited to 'src/nativewindow')
5 files changed, 65 insertions, 58 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java index ba07d97dc..1cc796086 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java @@ -83,7 +83,9 @@ public class SWTAccessor { static { Field f = null; - if(NativeWindowFactory.TYPE_MACOSX != NativeWindowFactory.getNativeWindowType(false) ) { + final String nwt = NativeWindowFactory.getNativeWindowType(false); + + if(NativeWindowFactory.TYPE_MACOSX != nwt ) { try { f = Control.class.getField(str_handle); } catch (Exception ex) { @@ -124,7 +126,7 @@ public class SWTAccessor { Class<?> c=null; Method m1=null, m2=null, m3=null, m4=null, m5=null; Class<?> handleType = swt_uses_long_handles ? long.class : int.class ; - if( NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(false) ) { + if( NativeWindowFactory.TYPE_X11 == nwt ) { try { c = ReflectionUtil.getClass(str_OS_gtk_class, false, SWTAccessor.class.getClassLoader()); m1 = c.getDeclaredMethod(str_gtk_widget_realize, handleType); @@ -210,33 +212,36 @@ public class SWTAccessor { long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle); return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false); } - if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) { + final String nwt = NativeWindowFactory.getNativeWindowType(false); + if( NativeWindowFactory.TYPE_WINDOWS == nwt ) { return new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); } - if( NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + if( NativeWindowFactory.TYPE_MACOSX == nwt ) { return new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); } - throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); + throw new UnsupportedOperationException("n/a for this windowing system: "+nwt); } public static AbstractGraphicsScreen getScreen(AbstractGraphicsDevice device, int screen) { if( null != OS_gtk_class ) { return new X11GraphicsScreen((X11GraphicsDevice)device, screen); - } - if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) || - NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + } + final String nwt = NativeWindowFactory.getNativeWindowType(false); + if( NativeWindowFactory.TYPE_WINDOWS == nwt || + NativeWindowFactory.TYPE_MACOSX == nwt ) { return new DefaultGraphicsScreen(device, screen); } - throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); + throw new UnsupportedOperationException("n/a for this windowing system: "+nwt); } public static int getNativeVisualID(AbstractGraphicsDevice device, long windowHandle) { if( null != OS_gtk_class ) { return X11Lib.GetVisualIDFromWindow(device.getHandle(), windowHandle); } - if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) || - NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + final String nwt = NativeWindowFactory.getNativeWindowType(false); + if( NativeWindowFactory.TYPE_WINDOWS == nwt || + NativeWindowFactory.TYPE_MACOSX == nwt ) { return VisualIDHolder.VID_UNDEFINED; } - throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); + throw new UnsupportedOperationException("n/a for this windowing system: "+nwt); } public static long getWindowHandle(Control swtControl) { @@ -245,11 +250,12 @@ public class SWTAccessor { long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle); return callStaticMethodL2L(OS_gdk_x11_drawable_get_xid, widgedHandle); } - if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) || - NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) { + final String nwt = NativeWindowFactory.getNativeWindowType(false); + if( NativeWindowFactory.TYPE_WINDOWS == nwt || + NativeWindowFactory.TYPE_MACOSX == nwt ) { return handle; } - throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false)); + throw new UnsupportedOperationException("n/a for this windowing system: "+nwt); } public static long newGC(final Control swtControl, final GCData gcData) { diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index c3fdc6798..9694f2491 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -129,7 +129,7 @@ public abstract class GraphicsConfigurationFactory { // well as X11GraphicsDevices in non-AWT situations) registerFactory(defaultDeviceCapsType.deviceType, defaultDeviceCapsType.capsType, new DefaultGraphicsConfigurationFactoryImpl()); - if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { + if (NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(true)) { try { ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.X11GraphicsConfigurationFactory", "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader()); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 867d0733b..afcd0a008 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -56,33 +56,34 @@ import com.jogamp.common.util.ReflectionUtil; public abstract class NativeWindowFactory { protected static final boolean DEBUG; - /** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}*/ - public static final String TYPE_EGL = "jogamp.newt.driver.kd"; + /** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/ + public static final String TYPE_EGL = "jogamp.newt.driver.kd".intern(); - /** Microsoft Windows type, as retrieved with {@link #getNativeWindowType(boolean)} */ - public static final String TYPE_WINDOWS = "jogamp.newt.driver.windows"; + /** Microsoft Windows type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */ + public static final String TYPE_WINDOWS = "jogamp.newt.driver.windows".intern(); - /** X11 type, as retrieved with {@link #getNativeWindowType(boolean)} */ - public static final String TYPE_X11 = "jogamp.newt.driver.x11"; + /** X11 type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */ + public static final String TYPE_X11 = "jogamp.newt.driver.x11".intern(); - /** Android/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}*/ - public static final String TYPE_ANDROID = "jogamp.newt.driver.android"; + /** Android/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/ + public static final String TYPE_ANDROID = "jogamp.newt.driver.android".intern(); - /** Mac OS X type, as retrieved with {@link #getNativeWindowType(boolean)} */ - public static final String TYPE_MACOSX = "jogamp.newt.driver.macosx"; + /** Mac OS X type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */ + public static final String TYPE_MACOSX = "jogamp.newt.driver.macosx".intern(); - /** Generic AWT type, as retrieved with {@link #getNativeWindowType(boolean)} */ - public static final String TYPE_AWT = "jogamp.newt.driver.awt"; + /** Generic AWT type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */ + public static final String TYPE_AWT = "jogamp.newt.driver.awt".intern(); - /** Generic DEFAULT type, where platform implementation don't care, as retrieved with {@link #getNativeWindowType(boolean)} */ - public static final String TYPE_DEFAULT = "default"; + /** Generic DEFAULT type, where platform implementation don't care, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */ + public static final String TYPE_DEFAULT = "default".intern(); + private static final String nativeWindowingTypePure; // canonical String via String.intern() + private static final String nativeWindowingTypeCustom; // canonical String via String.intern() + private static NativeWindowFactory defaultFactory; private static Map<Class<?>, NativeWindowFactory> registeredFactories; private static Class<?> nativeWindowClass; - private static String nativeWindowingTypePure; - private static String nativeWindowingTypeCustom; private static boolean isAWTAvailable; private static final String JAWTUtilClassName = "jogamp.nativewindow.jawt.JAWTUtil" ; @@ -133,17 +134,26 @@ public abstract class NativeWindowFactory { System.err.println(Thread.currentThread().getName()+" - Info: NativeWindowFactory.<init>"); // Thread.dumpStack(); } + + // Gather the windowing TK first + nativeWindowingTypePure = _getNativeWindowingType(); + final String tmp = Debug.getProperty("nativewindow.ws.name", true); + if(null==tmp || tmp.length()==0) { + nativeWindowingTypeCustom = nativeWindowingTypePure; + } else { + nativeWindowingTypeCustom = tmp.intern(); // canonical representation + } } static boolean initialized = false; private static void initSingletonNativeImpl(final ClassLoader cl) { final String clazzName; - if( TYPE_X11.equals(nativeWindowingTypePure) ) { + if( TYPE_X11 == nativeWindowingTypePure ) { clazzName = X11UtilClassName; - } else if( TYPE_WINDOWS.equals(nativeWindowingTypePure) ) { + } else if( TYPE_WINDOWS == nativeWindowingTypePure ) { clazzName = GDIClassName; - } else if( TYPE_MACOSX.equals(nativeWindowingTypePure) ) { + } else if( TYPE_MACOSX == nativeWindowingTypePure ) { clazzName = OSXUtilClassName; } else { clazzName = null; @@ -172,15 +182,6 @@ public abstract class NativeWindowFactory { final ClassLoader cl = NativeWindowFactory.class.getClassLoader(); - // Gather the windowing OS first - nativeWindowingTypePure = _getNativeWindowingType(); - String tmp = Debug.getProperty("nativewindow.ws.name", true); - if(null==tmp || tmp.length()==0) { - nativeWindowingTypeCustom = nativeWindowingTypePure; - } else { - nativeWindowingTypeCustom = tmp; - } - isAWTAvailable = false; // may be set to true below if( Platform.AWT_AVAILABLE && @@ -293,7 +294,8 @@ public abstract class NativeWindowFactory { /** * @param useCustom if false return the native value, if true return a custom value if set, otherwise fallback to the native value. - * @return a define native window type, like {@link #TYPE_X11}, .. + * @return the native window type, e.g. {@link #TYPE_X11}, which is canonical via {@link String#intern()}. + * Hence {@link String#equals(Object)} and <code>==</code> produce the same result. */ public static String getNativeWindowType(boolean useCustom) { return useCustom?nativeWindowingTypeCustom:nativeWindowingTypePure; @@ -301,13 +303,13 @@ public abstract class NativeWindowFactory { /** Don't know if we shall add this factory here .. public static AbstractGraphicsDevice createGraphicsDevice(String type, String connection, int unitID, long handle, ToolkitLock locker) { - if(type.equals(TYPE_EGL)) { + if(TYPE_EGL == type) { return new - } else if(type.equals(TYPE_X11)) { - } else if(type.equals(TYPE_WINDOWS)) { - } else if(type.equals(TYPE_MACOSX)) { - } else if(type.equals(TYPE_AWT)) { - } else if(type.equals(TYPE_DEFAULT)) { + } else if(TYPE_X11 == type) { + } else if(TYPE_WINDOWS == type) { + } else if(TYPE_MACOSX == type)) { + } else if(TYPE_AWT == type) { + } else if(TYPE_DEFAULT == type) { } } */ diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java index 2c2a627a4..29564da3b 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java +++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java @@ -39,7 +39,6 @@ import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.ToolkitLock; -import com.jogamp.common.os.Platform; import com.jogamp.common.util.ReflectionUtil; import com.jogamp.common.util.ReflectionUtil.AWTNames; @@ -76,17 +75,17 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory { private NativeWindow getAWTNativeWindow(Object winObj, AbstractGraphicsConfiguration config) { if (nativeWindowConstructor == null) { try { - String windowingType = getNativeWindowType(true); - String windowClassName = null; + final String windowingType = getNativeWindowType(true); + final String windowClassName; // We break compile-time dependencies on the AWT here to // make it easier to run this code on mobile devices - if (windowingType.equals(TYPE_WINDOWS)) { + if (TYPE_WINDOWS == windowingType) { windowClassName = "jogamp.nativewindow.jawt.windows.WindowsJAWTWindow"; - } else if (windowingType.equals(TYPE_MACOSX)) { + } else if (TYPE_MACOSX == windowingType) { windowClassName = "jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow"; - } else if (windowingType.equals(TYPE_X11)) { + } else if (TYPE_X11 == windowingType) { // Assume Linux, Solaris, etc. Should probably test for these explicitly. windowClassName = "jogamp.nativewindow.jawt.x11.X11JAWTWindow"; } else { diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java index 2377c2be6..f579da217 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java @@ -60,7 +60,7 @@ public class JAWTJNILibLoader extends NWJNILibLoader { // ensure references from jogl_awt shared object // will succeed since JAWT shared object isn't in // default library path - if ( ! NativeWindowFactory.TYPE_MACOSX.equals( NativeWindowFactory.getNativeWindowType(false) ) ) { + if ( NativeWindowFactory.TYPE_MACOSX != NativeWindowFactory.getNativeWindowType(false) ) { try { loadLibrary("jawt", null, true, JAWTJNILibLoader.class.getClassLoader()); } catch (Throwable t) { |