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. --- .../jogamp/opengl/egl/EGLDrawableFactory.java | 77 +++++++++++++--------- 1 file changed, 46 insertions(+), 31 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/egl') 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/**/ sharedMap; private EGLGraphicsDevice defaultDevice; -- cgit v1.2.3