aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
index cdf5beb24..8f0299c1c 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java
@@ -54,24 +54,10 @@ import java.lang.reflect.*;
public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
protected static final boolean DEBUG = Debug.debug("GLDrawableFactory");
- private boolean isValid = false;
-
- public void shutdown() {
- validate();
- isValid = false;
- }
-
- protected final void validate() {
- if(!isValid) {
- throw new GLException("GLDrawableFactory is already shutdown!");
- }
- }
-
//---------------------------------------------------------------------------
// Dispatching GLDrawable construction in respect to the NativeWindow Capabilities
//
public GLDrawable createGLDrawable(NativeWindow target) {
- validate();
if (target == null) {
throw new IllegalArgumentException("Null target");
}
@@ -132,7 +118,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
GLCapabilitiesChooser chooser,
int width,
int height) {
- validate();
if(height<=0 || height<=0) {
throw new GLException("Width and height of pbuffer must be positive (were (" +
width + ", " + height + "))");
@@ -148,7 +133,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
int width,
int height,
GLContext shareWith) {
- validate();
return new GLPbufferImpl( (GLDrawableImpl) createGLPbufferDrawable(capabilities, chooser, height, height),
shareWith);
}
@@ -165,7 +149,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
GLCapabilitiesChooser chooser,
int width,
int height) {
- validate();
if(width<=0 || height<=0) {
throw new GLException("Width and height of pbuffer must be positive (were (" +
width + ", " + height + "))");
@@ -185,10 +168,30 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
protected abstract GLDrawableImpl getSharedDrawable();
protected abstract GLContextImpl getSharedContext();
+ protected abstract void shutdown();
+
+ // Shutdown hook mechanism for the factory
+ private boolean factoryShutdownHookRegistered;
+ private Thread factoryShutdownHook;
+ private synchronized void registerFactoryShutdownHook() {
+ if (factoryShutdownHookRegistered)
+ return;
+ if (factoryShutdownHook == null) {
+ factoryShutdownHook = new Thread(new Runnable() {
+ public void run() {
+ synchronized (GLDrawableFactoryImpl.this) {
+ shutdown();
+ }
+ }
+ });
+ }
+ Runtime.getRuntime().addShutdownHook(factoryShutdownHook);
+ factoryShutdownHookRegistered = true;
+ }
protected GLDrawableFactoryImpl() {
super();
- isValid = true;
+ registerFactoryShutdownHook();
}
protected void maybeDoSingleThreadedWorkaround(Runnable action) {
@@ -294,7 +297,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
* out-of-bounds
*/
public boolean setDisplayGamma(float gamma, float brightness, float contrast) throws IllegalArgumentException {
- validate();
if ((brightness < -1.0f) || (brightness > 1.0f)) {
throw new IllegalArgumentException("Brightness must be between -1.0 and 1.0");
}
@@ -327,7 +329,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
public synchronized void resetDisplayGamma() {
- validate();
if (gammaShutdownHook == null) {
throw new IllegalArgumentException("Should not call this unless setDisplayGamma called first");
}