From 53ba4a2b3639a3746218693ea588159e5c6d07c7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 1 Dec 2011 16:48:45 +0100 Subject: GLDrawableFactory: Implementations lifecycle is handled via constructor/destroy() --- .../jogamp/opengl/egl/EGLDrawableFactory.java | 37 ++++++--- .../macosx/cgl/MacOSXCGLDrawableFactory.java | 77 ++++++++++-------- .../windows/wgl/WindowsWGLDrawableFactory.java | 92 +++++++++++++--------- .../opengl/x11/glx/X11GLXDrawableFactory.java | 78 ++++++++++-------- 4 files changed, 168 insertions(+), 116 deletions(-) (limited to 'src/jogl/classes/jogamp') diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java index 4a1a4ccf5..fe4adb564 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java @@ -50,10 +50,9 @@ import java.util.HashMap; import java.util.List; public class EGLDrawableFactory extends GLDrawableFactoryImpl { - private static final GLDynamicLookupHelper eglES1DynamicLookupHelper; - private static final GLDynamicLookupHelper eglES2DynamicLookupHelper; - - static { + public EGLDrawableFactory() { + super(); + // Register our GraphicsConfigurationFactory implementations // The act of constructing them causes them to be registered EGLGraphicsConfigurationFactory.registerFactory(); @@ -94,13 +93,33 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { 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(); + } } - public EGLDrawableFactory() { - super(); - defaultDevice = new EGLGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); + protected final void destroy() { + if(null != sharedMap) { + sharedMap.clear(); + sharedMap = null; + } + defaultDevice = null; + if(null != eglES1DynamicLookupHelper) { + eglES1DynamicLookupHelper.destroy(); + eglES1DynamicLookupHelper = null; + } + if(null != eglES2DynamicLookupHelper) { + eglES2DynamicLookupHelper.destroy(); + eglES2DynamicLookupHelper = null; + } } + private GLDynamicLookupHelper eglES1DynamicLookupHelper; + private GLDynamicLookupHelper eglES2DynamicLookupHelper; + private HashMap/**/ sharedMap; + private EGLGraphicsDevice defaultDevice; + static class SharedResource { private EGLGraphicsDevice device; // private EGLDrawable drawable; @@ -125,8 +144,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { final boolean wasES1ContextAvailable() { return wasES1ContextCreated; } final boolean wasES2ContextAvailable() { return wasES2ContextCreated; } } - HashMap/**/ sharedMap = new HashMap(); - EGLGraphicsDevice defaultDevice; public final AbstractGraphicsDevice getDefaultDevice() { return defaultDevice; @@ -243,8 +260,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } } - protected final void shutdownInstance() {} - protected List getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { return EGLGraphicsConfigurationFactory.getAvailableCapabilities(this, device); } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java index ed7959ae8..4543424a6 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -72,43 +72,58 @@ import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.util.ReflectionUtil; public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { - private static final DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper; - - static { - DesktopGLDynamicLookupHelper tmp = null; - try { - tmp = new DesktopGLDynamicLookupHelper(new MacOSXCGLDynamicLibraryBundleInfo()); - } catch (GLException gle) { - if(DEBUG) { - gle.printStackTrace(); - } + public MacOSXCGLDrawableFactory() { + super(); + + DesktopGLDynamicLookupHelper tmp = null; + try { + tmp = new DesktopGLDynamicLookupHelper(new MacOSXCGLDynamicLibraryBundleInfo()); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); } - macOSXCGLDynamicLookupHelper = tmp; + } + macOSXCGLDynamicLookupHelper = tmp; + + if(null!=macOSXCGLDynamicLookupHelper) { /** FIXME ?? - if(null!=macOSXCGLDynamicLookupHelper) { - CGL.getCGLProcAddressTable().reset(macOSXCGLDynamicLookupHelper); - } */ + CGL.getCGLProcAddressTable().reset(macOSXCGLDynamicLookupHelper); + */ + + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + MacOSXCGLGraphicsConfigurationFactory.registerFactory(); + if(GLProfile.isAWTAvailable()) { + try { + ReflectionUtil.callStaticMethod("jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", + "registerFactory", null, null, getClass().getClassLoader()); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + } + + defaultDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + sharedMap = new HashMap(); + } + } + + protected final void destroy() { + if(null != sharedMap) { + sharedMap.clear(); + sharedMap = null; + } + defaultDevice = null; + if(null != macOSXCGLDynamicLookupHelper) { + macOSXCGLDynamicLookupHelper.destroy(); + macOSXCGLDynamicLookupHelper = null; + } } public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { return macOSXCGLDynamicLookupHelper; } - public MacOSXCGLDrawableFactory() { - super(); - - // Register our GraphicsConfigurationFactory implementations - // The act of constructing them causes them to be registered - MacOSXCGLGraphicsConfigurationFactory.registerFactory(); - if(GLProfile.isAWTAvailable()) { - try { - ReflectionUtil.callStaticMethod("jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", - "registerFactory", null, null, getClass().getClassLoader()); - } catch (JogampRuntimeException jre) { /* n/a .. */ } - } - - defaultDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); - } + private DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper; + private HashMap sharedMap = new HashMap(); + private MacOSXGraphicsDevice defaultDevice; static class SharedResource { // private MacOSXCGLDrawable drawable; @@ -136,8 +151,6 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { final boolean isRECTTextureAvailable() { return hasRECTTextures; } final boolean isAppletFloatPixelsAvailable() { return hasAppletFloatPixels; } } - HashMap sharedMap = new HashMap(); - MacOSXGraphicsDevice defaultDevice; public final AbstractGraphicsDevice getDefaultDevice() { return defaultDevice; @@ -259,8 +272,6 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return null; } - protected final void shutdownInstance() {} - protected List getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { return MacOSXCGLGraphicsConfiguration.getAvailableCapabilities(this, device); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index 1b2b0fa4f..8e9bf553b 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -80,9 +80,9 @@ import jogamp.opengl.GLDynamicLookupHelper; import jogamp.opengl.SharedResourceRunner; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { - private static final DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper; + public WindowsWGLDrawableFactory() { + super(); - static { DesktopGLDynamicLookupHelper tmp = null; try { tmp = new DesktopGLDynamicLookupHelper(new WindowsWGLDynamicLibraryBundleInfo()); @@ -92,48 +92,67 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } } 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(); + if(GLProfile.isAWTAvailable()) { + try { + ReflectionUtil.callStaticMethod("jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", + "registerFactory", null, null, getClass().getClassLoader()); + } catch (JogampRuntimeException jre) { /* n/a .. */ } + } + + defaultDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + sharedMap = new HashMap(); + + // Init shared resources off thread + // Will be released via ShutdownHook + sharedResourceImpl = new SharedResourceImplementation(); + sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl); + sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner"); + sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running + sharedResourceThread.start(); } } - public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { - return windowsWGLDynamicLookupHelper; - } - - public WindowsWGLDrawableFactory() { - super(); - - // Register our GraphicsConfigurationFactory implementations - // The act of constructing them causes them to be registered - WindowsWGLGraphicsConfigurationFactory.registerFactory(); - if(GLProfile.isAWTAvailable()) { - try { - ReflectionUtil.callStaticMethod("jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", - "registerFactory", null, null, getClass().getClassLoader()); - } catch (JogampRuntimeException jre) { /* n/a .. */ } + protected final void destroy() { + if(null != sharedResourceRunner) { + sharedResourceRunner.releaseAndWait(); + sharedResourceRunner = null; } + if(null != sharedMap) { + sharedMap.clear(); + 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(); + windowsWGLDynamicLookupHelper = null; + } + + RegisteredClassFactory.shutdownSharedClasses(); + } - defaultDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); - - // Init shared resources off thread - // Will be released via ShutdownHook - sharedResourceImpl = new SharedResourceImplementation(); - sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl); - sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner"); - sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running - sharedResourceThread.start(); + public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { + return windowsWGLDynamicLookupHelper; } - WindowsGraphicsDevice defaultDevice; - SharedResourceImplementation sharedResourceImpl; - SharedResourceRunner sharedResourceRunner; - Thread sharedResourceThread; - HashMap sharedMap = new HashMap(); + private DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper; + private WindowsGraphicsDevice defaultDevice; + private SharedResourceImplementation sharedResourceImpl; + private SharedResourceRunner sharedResourceRunner; + private Thread sharedResourceThread; + private HashMap sharedMap; - long processAffinityChanges = 0; - PointerBuffer procMask = PointerBuffer.allocateDirect(1); - PointerBuffer sysMask = PointerBuffer.allocateDirect(1); + private long processAffinityChanges = 0; + private PointerBuffer procMask = PointerBuffer.allocateDirect(1); + private PointerBuffer sysMask = PointerBuffer.allocateDirect(1); protected void enterThreadCriticalZone() { synchronized (sysMask) { @@ -413,11 +432,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return (SharedResource) sharedResourceRunner.getOrCreateShared(device); } - protected final void shutdownInstance() { - sharedResourceRunner.releaseAndWait(); - RegisteredClassFactory.shutdownSharedClasses(); - } - protected List getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { return WindowsWGLGraphicsConfigurationFactory.getAvailableCapabilities(this, device); } diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index a68b039ce..d2b9242be 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -72,15 +72,15 @@ import com.jogamp.common.util.VersionNumber; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { - private static final DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper; - public static final VersionNumber versionOneZero = new VersionNumber(1, 0, 0); public static final VersionNumber versionOneOne = new VersionNumber(1, 1, 0); public static final VersionNumber versionOneTwo = new VersionNumber(1, 2, 0); public static final VersionNumber versionOneThree = new VersionNumber(1, 3, 0); public static final VersionNumber versionOneFour = new VersionNumber(1, 4, 0); - static { + public X11GLXDrawableFactory() { + super(); + DesktopGLDynamicLookupHelper tmp = null; try { tmp = new DesktopGLDynamicLookupHelper(new X11GLXDynamicLibraryBundleInfo()); @@ -90,37 +90,57 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } x11GLXDynamicLookupHelper = tmp; + if(null!=x11GLXDynamicLookupHelper) { GLX.getGLXProcAddressTable().reset(x11GLXDynamicLookupHelper); + + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + X11GLXGraphicsConfigurationFactory.registerFactory(); + + defaultDevice = new X11GraphicsDevice(X11Util.getNullDisplayName(), AbstractGraphicsDevice.DEFAULT_UNIT); + sharedMap = new HashMap(); + + // Init shared resources off thread + // Will be released via ShutdownHook + sharedResourceImpl = new SharedResourceImplementation(); + sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl); + sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner"); + sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running + sharedResourceThread.start(); + } + } + + protected final void destroy() { + if(null != sharedResourceRunner) { + sharedResourceRunner.releaseAndWait(); + sharedResourceRunner = null; + } + if(null != sharedMap) { + sharedMap.clear(); + sharedMap = null; } + defaultDevice = null; + if(null != x11GLXDynamicLookupHelper) { + x11GLXDynamicLookupHelper.destroy(); + x11GLXDynamicLookupHelper = null; + } + + // Don't really close pending Display connections, + // since this may trigger a JVM exception + X11Util.shutdown( false, DEBUG ); } public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { return x11GLXDynamicLookupHelper; } - public X11GLXDrawableFactory() { - super(); - // Register our GraphicsConfigurationFactory implementations - // The act of constructing them causes them to be registered - X11GLXGraphicsConfigurationFactory.registerFactory(); - - defaultDevice = new X11GraphicsDevice(X11Util.getNullDisplayName(), AbstractGraphicsDevice.DEFAULT_UNIT); - - // Init shared resources off thread - // Will be released via ShutdownHook - sharedResourceImpl = new SharedResourceImplementation(); - sharedResourceRunner = new SharedResourceRunner(sharedResourceImpl); - sharedResourceThread = new Thread(sharedResourceRunner, Thread.currentThread().getName()+"-SharedResourceRunner"); - sharedResourceThread.setDaemon(true); // Allow JVM to exit, even if this one is running - sharedResourceThread.start(); - } - - X11GraphicsDevice defaultDevice; - SharedResourceImplementation sharedResourceImpl; - SharedResourceRunner sharedResourceRunner; - Thread sharedResourceThread; - HashMap sharedMap = new HashMap(); + private DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper; + private X11GraphicsDevice defaultDevice; + private SharedResourceImplementation sharedResourceImpl; + private SharedResourceRunner sharedResourceRunner; + private Thread sharedResourceThread; + private HashMap sharedMap; static class SharedResource implements SharedResourceRunner.Resource { X11GraphicsDevice device; @@ -332,14 +352,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return (SharedResource) sharedResourceRunner.getOrCreateShared(device); } - protected final void shutdownInstance() { - sharedResourceRunner.releaseAndWait(); - - // Don't really close pending Display connections, - // since this may trigger a JVM exception - X11Util.shutdown( false, DEBUG ); - } - protected List getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { return X11GLXGraphicsConfigurationFactory.getAvailableCapabilities(this, device); } -- cgit v1.2.3