diff options
author | Sven Gothel <[email protected]> | 2012-02-25 20:09:25 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-25 20:09:25 +0100 |
commit | cc16e21c5601c3c9433b1e021addbbc9534a6e5a (patch) | |
tree | ec94403aa8fc66647e7e654395460f26baec6e64 /src/nativewindow | |
parent | aee3a75ad87ef3da0652c6b917ccdfda63a1230d (diff) |
Include GraphicsConfigurationFactory in lifecycle (initSingleton/shutdown) - fixes recursion on fallback GraphicsConfigurationFactory
.. also validate the X11 GraphicsConfigurationFactory in X11GLXGraphicsConfigurationFactory and fail fast
Diffstat (limited to 'src/nativewindow')
-rw-r--r-- | src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java | 71 | ||||
-rw-r--r-- | src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java | 9 |
2 files changed, 55 insertions, 25 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index 8570794d8..fb8bf2764 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -57,38 +57,65 @@ import java.util.Map; */ public abstract class GraphicsConfigurationFactory { - protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + protected static final boolean DEBUG; - private static Map<Class<?>, GraphicsConfigurationFactory> registeredFactories = - Collections.synchronizedMap(new HashMap<Class<?>, GraphicsConfigurationFactory>()); + private static Map<Class<?>, GraphicsConfigurationFactory> registeredFactories; private static Class<?> abstractGraphicsDeviceClass; - + static boolean initialized = false; + static { - abstractGraphicsDeviceClass = javax.media.nativewindow.AbstractGraphicsDevice.class; - - // Register the default no-op factory for arbitrary - // AbstractGraphicsDevice implementations, including - // AWTGraphicsDevice instances -- the OpenGL binding will take - // care of handling AWTGraphicsDevices on X11 platforms (as - // well as X11GraphicsDevices in non-AWT situations) - registerFactory(abstractGraphicsDeviceClass, new DefaultGraphicsConfigurationFactoryImpl()); + DEBUG = Debug.debug("GraphicsConfiguration"); + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - Info: GraphicsConfigurationFactory.<init>"); + // Thread.dumpStack(); + } + abstractGraphicsDeviceClass = javax.media.nativewindow.AbstractGraphicsDevice.class; + } - if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { - try { - ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.X11GraphicsConfigurationFactory", - "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader()); - } catch (Exception e) { - throw new RuntimeException(e); + public static synchronized void initSingleton() { + if(!initialized) { + initialized = true; + + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - GraphicsConfigurationFactory.initSingleton()"); } - if(NativeWindowFactory.isAWTAvailable()) { + registeredFactories = Collections.synchronizedMap(new HashMap<Class<?>, GraphicsConfigurationFactory>()); + + // Register the default no-op factory for arbitrary + // AbstractGraphicsDevice implementations, including + // AWTGraphicsDevice instances -- the OpenGL binding will take + // care of handling AWTGraphicsDevices on X11 platforms (as + // well as X11GraphicsDevices in non-AWT situations) + registerFactory(abstractGraphicsDeviceClass, new DefaultGraphicsConfigurationFactoryImpl()); + + if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { try { - ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.awt.X11AWTGraphicsConfigurationFactory", + ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.X11GraphicsConfigurationFactory", "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader()); - } catch (Exception e) { /* n/a */ } + } catch (Exception e) { + throw new RuntimeException(e); + } + if(NativeWindowFactory.isAWTAvailable()) { + try { + ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.awt.X11AWTGraphicsConfigurationFactory", + "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader()); + } catch (Exception e) { /* n/a */ } + } } } } - + + public static synchronized void shutdown() { + if(initialized) { + initialized = false; + if(DEBUG) { + System.err.println(Thread.currentThread().getName()+" - GraphicsConfigurationFactory.shutdown()"); + } + registeredFactories.clear(); + registeredFactories = null; + } + } + protected static String getThreadName() { return Thread.currentThread().getName(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index c69b18b30..683fb4847 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -135,8 +135,8 @@ public abstract class NativeWindowFactory { Platform.initSingleton(); DEBUG = Debug.debug("NativeWindow"); if(DEBUG) { - Throwable td = new Throwable(Thread.currentThread().getName()+" - Info: NativeWindowFactory.<init>"); - td.printStackTrace(); + System.err.println(Thread.currentThread().getName()+" - Info: NativeWindowFactory.<init>"); + // Thread.dumpStack(); } } @@ -263,12 +263,14 @@ public abstract class NativeWindowFactory { x11JAWTToolkitLockConstructor = ReflectionUtil.getConstructor(x11JAWTToolkitLockClass, new Class[] { long.class } ); } } - + if(DEBUG) { System.err.println("NativeWindowFactory firstUIActionOnProcess "+firstUIActionOnProcess); System.err.println("NativeWindowFactory requiresToolkitLock "+requiresToolkitLock); System.err.println("NativeWindowFactory isAWTAvailable "+isAWTAvailable+", defaultFactory "+factory); } + + GraphicsConfigurationFactory.initSingleton(); } } @@ -280,6 +282,7 @@ public abstract class NativeWindowFactory { } registeredFactories.clear(); registeredFactories = null; + GraphicsConfigurationFactory.shutdown(); // X11Util.shutdown(..) already called via GLDrawableFactory.shutdown() .. if(DEBUG) { System.err.println(Thread.currentThread().getName()+" - NativeWindowFactory.shutdown() END"); |