aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-12-01 21:40:12 +0100
committerSven Gothel <[email protected]>2011-12-01 21:40:12 +0100
commitb6aa455d21fbcfc256ae8f8f4d66493c17e23f4c (patch)
tree373c8a31d6ce9ac98cd290e8c6872ec6145f0c7e /src/jogl/classes/jogamp
parent919aabb77250cb0e272dac228388592d08bf98f5 (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/classes/jogamp')
-rw-r--r--src/jogl/classes/jogamp/opengl/awt/VersionApplet.java12
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java77
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java39
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java40
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java49
5 files changed, 135 insertions, 82 deletions
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;
}
}