From b6aa455d21fbcfc256ae8f8f4d66493c17e23f4c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 1 Dec 2011 21:40:12 +0100 Subject: New GLProfile.ShutdownType: SHARED_ONLY / COMPLETE - Enhance/Fix Lifecycle Management - Leave Platform, .. TempJarCache untouched. - GLDrawableFactoryImpl*: Leave DynamicLibraryBundle(lib-binding) untouched, for NativeLibrary, JNILibLoaderBase (JNI libs), .. consistency. - SHARED_ONLY: shutdown shared GLDrawableFactoryImpl* resources and NativeWindowFactory - COMPLETE: additionally shutdown GLContext* Clear all cached GL/GLX proc-address and device/context mappings. - Use new "GLProfile.shutdown(GLProfile.ShutdownType.SHARED_ONLY)" in Applets - X11GLXDrawableFactory Shutdown: Uncomment close/destroy of shared resources. - JAWTWindow.destroy(): Close the delegated device. In case it's X11 this closes the exclusive opened X11 Display. --- .../javax/media/opengl/GLDrawableFactory.java | 13 +++++---- src/jogl/classes/javax/media/opengl/GLProfile.java | 33 +++++++++++++++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) (limited to 'src/jogl/classes/javax/media/opengl') diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index cc71c53cf..5fff1ce02 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -54,6 +54,7 @@ import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.ProxySurface; +import javax.media.opengl.GLProfile.ShutdownType; /**

Provides a virtual machine- and operating system-independent mechanism for creating {@link GLDrawable}s.

@@ -173,21 +174,21 @@ public abstract class GLDrawableFactory { eglFactory = tmp; } - protected static void shutdown() { + protected static void shutdown(ShutdownType shutdownType) { if (isInit) { // volatile: ok synchronized (GLDrawableFactory.class) { if (isInit) { isInit=false; unregisterFactoryShutdownHook(); - shutdownImpl(); + shutdownImpl(shutdownType); } } } } - private static void shutdownImpl() { + private static void shutdownImpl(ShutdownType shutdownType) { synchronized(glDrawableFactories) { for(int i=0; i() { @@ -238,7 +239,7 @@ public abstract class GLDrawableFactory { protected void enterThreadCriticalZone() {}; protected void leaveThreadCriticalZone() {}; - protected abstract void destroy(); + protected abstract void destroy(ShutdownType shutdownType); /** * Retrieve the default device {@link AbstractGraphicsDevice#getConnection() connection}, diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 6591f4ae1..7f0c9b3d3 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -114,6 +114,10 @@ public class GLProfile { synchronized(GLProfile.class) { if(!initialized) { initialized = true; + if(DEBUG) { + System.err.println("GLProfile.initSingleton(firstUIActionOnProcess: "+firstUIActionOnProcess+") - thread "+Thread.currentThread().getName()); + Thread.dumpStack(); + } Platform.initSingleton(); // run the whole static initialization privileged to speed up, @@ -146,20 +150,41 @@ public class GLProfile { getProfileMap(device); } + /** + * Shutdown type for {@link GLProfile#shutdown(ShutdownType)}. + *

+ * {@link #SHARED_ONLY} For thread based resources only, suitable for eg. {@link java.applet.Applet Applet} restart.
+ * {@link #COMPLETE} Everything.
+ *

+ */ + public enum ShutdownType { + /* Shared thread based resources only, eg. for Applets */ + SHARED_ONLY, + /* Everything */ + COMPLETE; + } + /** * Manual shutdown method, may be called after your last JOGL use * within the running JVM.
* It releases all temporary created resources, ie issues {@link javax.media.opengl.GLDrawableFactory#shutdown()}.
* The shutdown implementation is called via the JVM shutdown hook, if not manually invoked here.
- * Invoke shutdown() manually is recommended, due to the unreliable JVM state within the shutdown hook.
+ * Invoke shutdown(type) manually is recommended, due to the unreliable JVM state within the shutdown hook.
+ * @param type the shutdown type, see {@link ShutdownType}. */ - public static void shutdown() { + public static void shutdown(ShutdownType type) { if(initialized) { // volatile: ok synchronized(GLProfile.class) { if(initialized) { initialized = false; - GLDrawableFactory.shutdown(); // may utilize static GLContext mappings - GLContext.shutdown(); // does not utilize shared resources of GLDrawableFactory + if(DEBUG) { + System.err.println("GLProfile.shutdown(type: "+type+") - thread "+Thread.currentThread().getName()); + Thread.dumpStack(); + } + GLDrawableFactory.shutdown(type); + if(ShutdownType.COMPLETE == type) { + GLContext.shutdown(); + } NativeWindowFactory.shutdown(); } } -- cgit v1.2.3