diff options
author | Sven Gothel <[email protected]> | 2011-12-01 21:40:12 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-12-01 21:40:12 +0100 |
commit | b6aa455d21fbcfc256ae8f8f4d66493c17e23f4c (patch) | |
tree | 373c8a31d6ce9ac98cd290e8c6872ec6145f0c7e /src/jogl | |
parent | 919aabb77250cb0e272dac228388592d08bf98f5 (diff) |
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.
Diffstat (limited to 'src/jogl')
7 files changed, 171 insertions, 92 deletions
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; /** <P> Provides a virtual machine- and operating system-independent mechanism for creating {@link GLDrawable}s. </P> @@ -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<glDrawableFactories.size(); i++) { - glDrawableFactories.get(i).destroy(); + glDrawableFactories.get(i).destroy(shutdownType); } glDrawableFactories.clear(); @@ -203,7 +204,7 @@ public abstract class GLDrawableFactory { } factoryShutdownHook = new Thread(new Runnable() { public void run() { - GLDrawableFactory.shutdownImpl(); + GLDrawableFactory.shutdownImpl(GLProfile.ShutdownType.COMPLETE); } }); AccessController.doPrivileged(new PrivilegedAction<Object>() { @@ -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 <code>device</code> {@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)}. + * <p> + * {@link #SHARED_ONLY} For thread based resources only, suitable for eg. {@link java.applet.Applet Applet} restart.<br> + * {@link #COMPLETE} Everything.<br> + * </p> + */ + 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.<br> * It releases all temporary created resources, ie issues {@link javax.media.opengl.GLDrawableFactory#shutdown()}.<br> * The shutdown implementation is called via the JVM shutdown hook, if not manually invoked here.<br> - * Invoke <code>shutdown()</code> manually is recommended, due to the unreliable JVM state within the shutdown hook.<br> + * Invoke <code>shutdown(type)</code> manually is recommended, due to the unreliable JVM state within the shutdown hook.<br> + * @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(); } } diff --git a/src/jogl/classes/jogamp/opengl/awt/VersionApplet.java b/src/jogl/classes/jogamp/opengl/awt/VersionApplet.java index 5856bf3a0..b7c90a18b 100644 --- a/src/jogl/classes/jogamp/opengl/awt/VersionApplet.java +++ b/src/jogl/classes/jogamp/opengl/awt/VersionApplet.java @@ -67,6 +67,8 @@ public class VersionApplet extends Applet { private synchronized void my_init() { if(null != canvas) { return; } + setEnabled(true); + GLProfile glp = GLProfile.getDefault(); GLCapabilities glcaps = new GLCapabilities(glp); @@ -120,30 +122,36 @@ public class VersionApplet extends Applet { remove(canvas); canvas.destroy(); canvas = null; - remove(tareaVersion); - tareaVersion=null; + remove(tareaVersion.getParent()); // remove the grid + tareaVersion = null; + tareaCaps = null; + setEnabled(false); } } public void init() { System.err.println("VersionApplet: init() - begin"); + GLProfile.initSingleton(false); my_init(); System.err.println("VersionApplet: init() - end"); } public void start() { System.err.println("VersionApplet: start() - begin"); + canvas.setVisible(true); System.err.println("VersionApplet: start() - end"); } public void stop() { System.err.println("VersionApplet: stop() - begin"); + canvas.setVisible(false); System.err.println("VersionApplet: stop() - end"); } public void destroy() { System.err.println("VersionApplet: destroy() - start"); my_release(); + GLProfile.shutdown(GLProfile.ShutdownType.SHARED_ONLY); System.err.println("VersionApplet: destroy() - end"); } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java index fe4adb564..f6988a73f 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -39,6 +39,7 @@ package jogamp.opengl.egl; import javax.media.nativewindow.*; import javax.media.nativewindow.egl.EGLGraphicsDevice; import javax.media.opengl.*; +import javax.media.opengl.GLProfile.ShutdownType; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.*; @@ -50,6 +51,9 @@ import java.util.HashMap; import java.util.List; public class EGLDrawableFactory extends GLDrawableFactoryImpl { + private static GLDynamicLookupHelper eglES1DynamicLookupHelper = null; + private static GLDynamicLookupHelper eglES2DynamicLookupHelper = null; + public EGLDrawableFactory() { super(); @@ -68,55 +72,66 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { // to a dynamic one, where there can be 2 instances // for each ES profile with their own ProcAddressTable. - GLDynamicLookupHelper tmp=null; - try { - tmp = new GLDynamicLookupHelper(new EGLES1DynamicLibraryBundleInfo()); - } catch (GLException gle) { - if(DEBUG) { - gle.printStackTrace(); + synchronized(EGLDrawableFactory.class) { + if(null==eglES1DynamicLookupHelper) { + GLDynamicLookupHelper tmp=null; + try { + tmp = new GLDynamicLookupHelper(new EGLES1DynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + eglES1DynamicLookupHelper = tmp; + if(null!=eglES1DynamicLookupHelper && eglES1DynamicLookupHelper.isLibComplete()) { + EGL.resetProcAddressTable(eglES1DynamicLookupHelper); + } } } - eglES1DynamicLookupHelper = tmp; - if(null!=eglES1DynamicLookupHelper && eglES1DynamicLookupHelper.isLibComplete()) { - EGL.resetProcAddressTable(eglES1DynamicLookupHelper); - } - tmp=null; - try { - tmp = new GLDynamicLookupHelper(new EGLES2DynamicLibraryBundleInfo()); - } catch (GLException gle) { - if(DEBUG) { - gle.printStackTrace(); + synchronized(EGLDrawableFactory.class) { + if(null==eglES2DynamicLookupHelper) { + GLDynamicLookupHelper tmp=null; + try { + tmp = new GLDynamicLookupHelper(new EGLES2DynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + eglES2DynamicLookupHelper = tmp; + if(null!=eglES2DynamicLookupHelper && eglES2DynamicLookupHelper.isLibComplete()) { + EGL.resetProcAddressTable(eglES2DynamicLookupHelper); + } } } - eglES2DynamicLookupHelper = tmp; - if(null!=eglES2DynamicLookupHelper && eglES2DynamicLookupHelper.isLibComplete()) { - EGL.resetProcAddressTable(eglES2DynamicLookupHelper); - } if(null != eglES1DynamicLookupHelper || null != eglES2DynamicLookupHelper) { defaultDevice = new EGLGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); sharedMap = new HashMap(); } } - protected final void destroy() { + protected final void destroy(ShutdownType shutdownType) { if(null != sharedMap) { sharedMap.clear(); sharedMap = null; } defaultDevice = null; - if(null != eglES1DynamicLookupHelper) { - eglES1DynamicLookupHelper.destroy(); - eglES1DynamicLookupHelper = null; - } - if(null != eglES2DynamicLookupHelper) { - eglES2DynamicLookupHelper.destroy(); - eglES2DynamicLookupHelper = null; - } + /** + * Pulling away the native library may cause havoc .. + * + if(ShutdownType.COMPLETE == shutdownType) { + if(null != eglES1DynamicLookupHelper) { + eglES1DynamicLookupHelper.destroy(); + eglES1DynamicLookupHelper = null; + } + if(null != eglES2DynamicLookupHelper) { + eglES2DynamicLookupHelper.destroy(); + eglES2DynamicLookupHelper = null; + } + } */ } - private GLDynamicLookupHelper eglES1DynamicLookupHelper; - private GLDynamicLookupHelper eglES2DynamicLookupHelper; private HashMap/*<connection, SharedResource>*/ sharedMap; private EGLGraphicsDevice defaultDevice; diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java index 4543424a6..45445067e 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -61,6 +61,7 @@ import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawable; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import javax.media.opengl.GLProfile.ShutdownType; import jogamp.nativewindow.WrappedSurface; import jogamp.opengl.DesktopGLDynamicLookupHelper; @@ -72,24 +73,30 @@ import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.ReflectionUtil; public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { + private static DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper = null; + public MacOSXCGLDrawableFactory() { super(); - DesktopGLDynamicLookupHelper tmp = null; - try { - tmp = new DesktopGLDynamicLookupHelper(new MacOSXCGLDynamicLibraryBundleInfo()); - } catch (GLException gle) { - if(DEBUG) { - gle.printStackTrace(); + synchronized(MacOSXCGLDrawableFactory.class) { + if(null==macOSXCGLDynamicLookupHelper) { + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new MacOSXCGLDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + macOSXCGLDynamicLookupHelper = tmp; + /** FIXME ?? + if(null!=macOSXCGLDynamicLookupHelper) { + CGL.getCGLProcAddressTable().reset(macOSXCGLDynamicLookupHelper); + } */ } } - macOSXCGLDynamicLookupHelper = tmp; if(null!=macOSXCGLDynamicLookupHelper) { - /** FIXME ?? - CGL.getCGLProcAddressTable().reset(macOSXCGLDynamicLookupHelper); - */ - // Register our GraphicsConfigurationFactory implementations // The act of constructing them causes them to be registered MacOSXCGLGraphicsConfigurationFactory.registerFactory(); @@ -105,23 +112,25 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { } } - protected final void destroy() { + protected final void destroy(ShutdownType shutdownType) { if(null != sharedMap) { sharedMap.clear(); sharedMap = null; } defaultDevice = null; - if(null != macOSXCGLDynamicLookupHelper) { + /** + * Pulling away the native library may cause havoc .. + * + if(ShutdownType.COMPLETE == shutdownType && null != macOSXCGLDynamicLookupHelper) { macOSXCGLDynamicLookupHelper.destroy(); macOSXCGLDynamicLookupHelper = null; - } + } */ } public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { return macOSXCGLDynamicLookupHelper; } - private DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper; private HashMap<String, SharedResource> sharedMap = new HashMap<String, SharedResource>(); private MacOSXGraphicsDevice defaultDevice; diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index 8e9bf553b..917402b0a 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -61,6 +61,7 @@ import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawable; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import javax.media.opengl.GLProfile.ShutdownType; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.nio.PointerBuffer; @@ -80,22 +81,29 @@ import jogamp.opengl.GLDynamicLookupHelper; import jogamp.opengl.SharedResourceRunner; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { + private static DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper = null; + public WindowsWGLDrawableFactory() { super(); - DesktopGLDynamicLookupHelper tmp = null; - try { - tmp = new DesktopGLDynamicLookupHelper(new WindowsWGLDynamicLibraryBundleInfo()); - } catch (GLException gle) { - if(DEBUG) { - gle.printStackTrace(); + synchronized(WindowsWGLDrawableFactory.class) { + if(null==windowsWGLDynamicLookupHelper) { + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new WindowsWGLDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + windowsWGLDynamicLookupHelper = tmp; + if(null!=windowsWGLDynamicLookupHelper) { + WGL.getWGLProcAddressTable().reset(windowsWGLDynamicLookupHelper); + } } } - windowsWGLDynamicLookupHelper = tmp; if(null!=windowsWGLDynamicLookupHelper) { - WGL.getWGLProcAddressTable().reset(windowsWGLDynamicLookupHelper); - // Register our GraphicsConfigurationFactory implementations // The act of constructing them causes them to be registered WindowsWGLGraphicsConfigurationFactory.registerFactory(); @@ -119,7 +127,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } } - protected final void destroy() { + protected final void destroy(ShutdownType shutdownType) { if(null != sharedResourceRunner) { sharedResourceRunner.releaseAndWait(); sharedResourceRunner = null; @@ -129,12 +137,13 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { sharedMap = null; } defaultDevice = null; - if(null != windowsWGLDynamicLookupHelper) { - // FIXME: If closing the native library NativeLibrary.close(), - // reload of Applets doesn't work. Dunno why. - // windowsWGLDynamicLookupHelper.destroy(); + /** + * Pulling away the native library may cause havoc .. + * + if(ShutdownType.COMPLETE == shutdownType && null != windowsWGLDynamicLookupHelper) { + windowsWGLDynamicLookupHelper.destroy(); windowsWGLDynamicLookupHelper = null; - } + } */ RegisteredClassFactory.shutdownSharedClasses(); } @@ -143,7 +152,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return windowsWGLDynamicLookupHelper; } - private DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper; private WindowsGraphicsDevice defaultDevice; private SharedResourceImplementation sharedResourceImpl; private SharedResourceRunner sharedResourceRunner; diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index d2b9242be..96153dd27 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -57,6 +57,7 @@ import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawable; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import javax.media.opengl.GLProfile.ShutdownType; import jogamp.nativewindow.WrappedSurface; import jogamp.nativewindow.x11.X11Lib; @@ -78,22 +79,29 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { public static final VersionNumber versionOneThree = new VersionNumber(1, 3, 0); public static final VersionNumber versionOneFour = new VersionNumber(1, 4, 0); + private static DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper = null; + public X11GLXDrawableFactory() { super(); - DesktopGLDynamicLookupHelper tmp = null; - try { - tmp = new DesktopGLDynamicLookupHelper(new X11GLXDynamicLibraryBundleInfo()); - } catch (GLException gle) { - if(DEBUG) { - gle.printStackTrace(); + synchronized(X11GLXDrawableFactory.class) { + if(null==x11GLXDynamicLookupHelper) { + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new X11GLXDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + x11GLXDynamicLookupHelper = tmp; + if(null!=x11GLXDynamicLookupHelper) { + GLX.getGLXProcAddressTable().reset(x11GLXDynamicLookupHelper); + } } } - x11GLXDynamicLookupHelper = tmp; - if(null!=x11GLXDynamicLookupHelper) { - GLX.getGLXProcAddressTable().reset(x11GLXDynamicLookupHelper); - + if(null!=x11GLXDynamicLookupHelper) { // Register our GraphicsConfigurationFactory implementations // The act of constructing them causes them to be registered X11GLXGraphicsConfigurationFactory.registerFactory(); @@ -111,7 +119,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } - protected final void destroy() { + protected final void destroy(ShutdownType shutdownType) { if(null != sharedResourceRunner) { sharedResourceRunner.releaseAndWait(); sharedResourceRunner = null; @@ -121,10 +129,13 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { sharedMap = null; } defaultDevice = null; - if(null != x11GLXDynamicLookupHelper) { + /** + * Pulling away the native library may cause havoc .. + * + if(ShutdownType.COMPLETE == shutdownType && null != x11GLXDynamicLookupHelper) { x11GLXDynamicLookupHelper.destroy(); x11GLXDynamicLookupHelper = null; - } + } */ // Don't really close pending Display connections, // since this may trigger a JVM exception @@ -135,7 +146,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return x11GLXDynamicLookupHelper; } - private DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper; private X11GraphicsDevice defaultDevice; private SharedResourceImplementation sharedResourceImpl; private SharedResourceRunner sharedResourceRunner; @@ -273,17 +283,19 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { System.err.println("!!! Screen : " + sr.screen); System.err.println("!!! Drawable: " + sr.drawable); System.err.println("!!! CTX : " + sr.context); + Thread.dumpStack(); } if (null != sr.context) { // may cause JVM SIGSEGV: - // sr.context.makeCurrent(); - // sr.context.destroy(); + sr.context.makeCurrent(); + sr.context.destroy(); sr.context = null; } if (null != sr.drawable) { - // may cause JVM SIGSEGV: sr.drawable.destroy(); + // may cause JVM SIGSEGV: + sr.drawable.destroy(); sr.drawable = null; } @@ -292,7 +304,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } if (null != sr.device) { - // may cause JVM SIGSEGV: sr.device.close(); + // may cause JVM SIGSEGV: + sr.device.close(); sr.device = null; } } |