aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/GLDrawableFactory.java')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDrawableFactory.java62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
index f6dce1c9c..ab23e18f8 100644
--- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
@@ -97,10 +97,21 @@ public abstract class GLDrawableFactory {
protected static ArrayList/*<GLDrawableFactoryImpl>*/ glDrawableFactories = new ArrayList();
+ // Shutdown hook mechanism for the factory
+ private static boolean factoryShutdownHookRegistered = false;
+ private static Thread factoryShutdownHook = null;
+
/**
* Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones.
*/
static {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ registerFactoryShutdownHook();
+ return null;
+ }
+ });
+
nativeOSType = NativeWindowFactory.getNativeWindowType(true);
GLDrawableFactory tmp = null;
@@ -151,15 +162,38 @@ public abstract class GLDrawableFactory {
eglFactory = tmp;
}
- private AbstractGraphicsDevice defaultSharedDevice = null;
+ private static synchronized void registerFactoryShutdownHook() {
+ if (factoryShutdownHookRegistered) {
+ return;
+ }
+ factoryShutdownHook = new Thread(new Runnable() {
+ public void run() {
+ GLDrawableFactory.shutdownImpl();
+ }
+ });
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ Runtime.getRuntime().addShutdownHook(factoryShutdownHook);
+ return null;
+ }
+ });
+ factoryShutdownHookRegistered = true;
+ }
- protected GLDrawableFactory() {
- synchronized(glDrawableFactories) {
- glDrawableFactories.add(this);
+ private static synchronized void unregisterFactoryShutdownHook() {
+ if (!factoryShutdownHookRegistered) {
+ return;
}
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ Runtime.getRuntime().removeShutdownHook(factoryShutdownHook);
+ return null;
+ }
+ });
+ factoryShutdownHookRegistered = false;
}
- protected static void shutdown() {
+ private static void shutdownImpl() {
synchronized(glDrawableFactories) {
for(int i=0; i<glDrawableFactories.size(); i++) {
GLDrawableFactory factory = (GLDrawableFactory) glDrawableFactories.get(i);
@@ -169,6 +203,24 @@ public abstract class GLDrawableFactory {
}
}
+ protected static void shutdown() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ unregisterFactoryShutdownHook();
+ return null;
+ }
+ });
+ shutdownImpl();
+ }
+
+ private AbstractGraphicsDevice defaultSharedDevice = null;
+
+ protected GLDrawableFactory() {
+ synchronized(glDrawableFactories) {
+ glDrawableFactories.add(this);
+ }
+ }
+
protected abstract void shutdownInstance();
/**