From cc16e21c5601c3c9433b1e021addbbc9534a6e5a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 25 Feb 2012 20:09:25 +0100 Subject: Include GraphicsConfigurationFactory in lifecycle (initSingleton/shutdown) - fixes recursion on fallback GraphicsConfigurationFactory .. also validate the X11 GraphicsConfigurationFactory in X11GLXGraphicsConfigurationFactory and fail fast --- .../nativewindow/GraphicsConfigurationFactory.java | 71 +++++++++++++++------- .../media/nativewindow/NativeWindowFactory.java | 9 ++- 2 files changed, 55 insertions(+), 25 deletions(-) (limited to 'src/nativewindow/classes/javax') 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, GraphicsConfigurationFactory> registeredFactories = - Collections.synchronizedMap(new HashMap, GraphicsConfigurationFactory>()); + private static Map, 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."); + // 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, 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."); - td.printStackTrace(); + System.err.println(Thread.currentThread().getName()+" - Info: NativeWindowFactory."); + // 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"); -- cgit v1.2.3