From 1ad8c39df6b097c80ba7a85badf555e7f669cc3f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 24 Apr 2010 05:11:29 +0200 Subject: NEWT/AWT Interoperability - Moved all event classes to com.jogamp.newt.event and the new AWT event helper to com.jogamp.newt.awt.event - Added NewtAdapter for convenience - Added AWTAdapter for - Using AWT agnostic NEWT event listener see com.jogamp.test.junit.jogl.demos.gl2.gears.TestGearsNEWT even for AWT see com.jogamp.test.junit.jogl.demos.gl2.gears.TestGearsAWT (Nice idea by mbien) - Forwarding AWT events to NEWT (refactoring) Misc - GLDrawableFactory.shutdown() is now protected and called by the JVM shutdown hook. Hence removing the validate(). --- .../jogamp/opengl/impl/GLDrawableFactoryImpl.java | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java') 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"); } -- cgit v1.2.3