aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDrawableFactory.java56
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java43
2 files changed, 29 insertions, 70 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
index 55ad85c9c..f1d8ff95e 100644
--- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
@@ -40,8 +40,6 @@
package javax.media.opengl;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
@@ -118,13 +116,8 @@ public abstract class GLDrawableFactory {
private static GLDrawableFactory eglFactory;
private static GLDrawableFactory nativeOSFactory;
- protected static ArrayList<GLDrawableFactory> glDrawableFactories = new ArrayList<GLDrawableFactory>();
-
- // Shutdown hook mechanism for the factory
- private static boolean factoryShutdownHookRegistered = false;
- private static Thread factoryShutdownHook = null;
- private static volatile boolean isJVMShuttingDown = false;
-
+ private static ArrayList<GLDrawableFactory> glDrawableFactories = new ArrayList<GLDrawableFactory>();
+
/**
* Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones.
*/
@@ -139,7 +132,12 @@ public abstract class GLDrawableFactory {
}
}
private static final void initSingletonImpl() {
- registerFactoryShutdownHook();
+ NativeWindowFactory.initSingleton();
+ NativeWindowFactory.addCustomShutdownHook(false /* head */, new Runnable() {
+ public void run() {
+ shutdown0();
+ }
+ });
final String nwt = NativeWindowFactory.getNativeWindowType(true);
GLDrawableFactory tmp = null;
@@ -199,23 +197,31 @@ public abstract class GLDrawableFactory {
synchronized (GLDrawableFactory.class) {
if (isInit) {
isInit=false;
- shutdownImpl();
+ shutdown0();
}
}
}
}
- private static void shutdownImpl() {
+ private static void shutdown0() {
// Following code will _always_ remain in shutdown hook
// due to special semantics of native utils, i.e. X11Utils.
// The latter requires shutdown at JVM-Shutdown only.
synchronized(glDrawableFactories) {
- for(int i=0; i<glDrawableFactories.size(); i++) {
+ final int gldfCount = glDrawableFactories.size();
+ if( DEBUG ) {
+ System.err.println("GLDrawableFactory.shutdownAll "+gldfCount+" instances, on thread "+getThreadName());
+ }
+ for(int i=0; i<gldfCount; i++) {
final GLDrawableFactory gldf = glDrawableFactories.get(i);
+ if( DEBUG ) {
+ System.err.println("GLDrawableFactory.shutdownAll["+(i+1)+"/"+gldfCount+"]: "+gldf.getClass().getName());
+ }
try {
+ gldf.resetDisplayGamma();
gldf.destroy();
} catch (Throwable t) {
- System.err.println("GLDrawableFactory.shutdownImpl: Catched Exception during shutdown of "+gldf.getClass().getName());
+ System.err.println("GLDrawableFactory.shutdownImpl: Catched "+t.getClass().getName()+" during factory shutdown #"+(i+1)+"/"+gldfCount+" "+gldf.getClass().getName());
if( DEBUG ) {
t.printStackTrace();
}
@@ -228,28 +234,8 @@ public abstract class GLDrawableFactory {
eglFactory = null;
}
GLContext.shutdown();
- NativeWindowFactory.shutdown(isJVMShuttingDown);
}
- private static synchronized void registerFactoryShutdownHook() {
- if (factoryShutdownHookRegistered) {
- return;
- }
- factoryShutdownHook = new Thread(new Runnable() {
- public void run() {
- isJVMShuttingDown = true;
- GLDrawableFactory.shutdownImpl();
- }
- });
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- Runtime.getRuntime().addShutdownHook(factoryShutdownHook);
- return null;
- }
- });
- factoryShutdownHookRegistered = true;
- }
-
protected GLDrawableFactory() {
synchronized(glDrawableFactories) {
glDrawableFactories.add(this);
@@ -266,6 +252,8 @@ public abstract class GLDrawableFactory {
protected abstract void destroy();
+ public abstract void resetDisplayGamma();
+
/**
* Retrieve the default <code>device</code> {@link AbstractGraphicsDevice#getConnection() connection},
* {@link AbstractGraphicsDevice#getUnitID() unit ID} and {@link AbstractGraphicsDevice#getUniqueID() unique ID name}. for this factory<br>
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
index 06e856d41..4ac413545 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
@@ -575,16 +575,16 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
rampEntry = 0.0f;
gammaRamp[i] = rampEntry;
}
- registerGammaShutdownHook();
+ needsGammaRampReset = true;
return setGammaRamp(gammaRamp);
}
+ @Override
public synchronized void resetDisplayGamma() {
- if (gammaShutdownHook == null) {
- throw new IllegalArgumentException("Should not call this unless setDisplayGamma called first");
+ if( needsGammaRampReset ) {
+ resetGammaRamp(originalGammaRamp);
+ needsGammaRampReset = false;
}
- resetGammaRamp(originalGammaRamp);
- unregisterGammaShutdownHook();
}
//------------------------------------------------------
@@ -616,35 +616,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
// Shutdown hook mechanism for resetting gamma
- private boolean gammaShutdownHookRegistered;
- private Thread gammaShutdownHook;
- private Buffer originalGammaRamp;
- private synchronized void registerGammaShutdownHook() {
- if (gammaShutdownHookRegistered)
- return;
- if (gammaShutdownHook == null) {
- gammaShutdownHook = new Thread(new Runnable() {
- @Override
- public void run() {
- synchronized (GLDrawableFactoryImpl.this) {
- resetGammaRamp(originalGammaRamp);
- }
- }
- });
- originalGammaRamp = getGammaRamp();
- }
- Runtime.getRuntime().addShutdownHook(gammaShutdownHook);
- gammaShutdownHookRegistered = true;
- }
-
- private synchronized void unregisterGammaShutdownHook() {
- if (!gammaShutdownHookRegistered)
- return;
- if (gammaShutdownHook == null) {
- throw new InternalError("Error in gamma shutdown hook logic");
- }
- Runtime.getRuntime().removeShutdownHook(gammaShutdownHook);
- gammaShutdownHookRegistered = false;
- // Leave the original gamma ramp data alone
- }
+ private volatile Buffer originalGammaRamp;
+ private volatile boolean needsGammaRampReset = false;
}