From b6aa455d21fbcfc256ae8f8f4d66493c17e23f4c Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
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.
---
 .../macosx/cgl/MacOSXCGLDrawableFactory.java       | 39 +++++++++++++---------
 1 file changed, 24 insertions(+), 15 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/macosx/cgl')

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;
 
-- 
cgit v1.2.3