diff options
Diffstat (limited to 'src/jogl')
48 files changed, 651 insertions, 332 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java index 9d1235e13..75c4a6a73 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/ExtensionAvailabilityCache.java @@ -51,8 +51,8 @@ import java.lang.reflect.*; * and display. */ public final class ExtensionAvailabilityCache { - private static final boolean DEBUG = Debug.debug("ExtensionAvailabilityCache"); - private static final boolean DEBUG_AVAILABILITY = Debug.isPropertyDefined("ExtensionAvailabilityCache", true); + private static final boolean DEBUG = GLContextImpl.DEBUG; + private static final boolean DEBUG_AVAILABILITY = Debug.isPropertyDefined("jogl.debug.ExtensionAvailabilityCache", true); ExtensionAvailabilityCache(GLContextImpl context) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLBufferSizeTracker.java b/src/jogl/classes/com/jogamp/opengl/impl/GLBufferSizeTracker.java index b4237501e..ceabd3910 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLBufferSizeTracker.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLBufferSizeTracker.java @@ -95,7 +95,7 @@ public class GLBufferSizeTracker { // never shrinks is probably not that bad. private IntIntHashMap bufferSizeMap; - private static final boolean DEBUG = Debug.debug("GLBufferSizeTracker"); + protected static final boolean DEBUG = Debug.debug("GLStatusTracker"); public GLBufferSizeTracker() { bufferSizeMap = new IntIntHashMap(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLBufferStateTracker.java b/src/jogl/classes/com/jogamp/opengl/impl/GLBufferStateTracker.java index 05b2a2fa9..c3ed7b6b1 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLBufferStateTracker.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLBufferStateTracker.java @@ -75,7 +75,7 @@ import com.jogamp.common.util.IntIntHashMap; */ public class GLBufferStateTracker { - private static final boolean DEBUG = Debug.debug("GLBufferStateTracker"); + protected static final boolean DEBUG = GLBufferSizeTracker.DEBUG; // Maps binding targets to buffer objects. A null value indicates // that the binding is unknown. A zero value indicates that it is diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java index 219d9f4dd..3d4c601fe 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java @@ -122,7 +122,7 @@ public abstract class GLContextImpl extends GLContext { if(DEBUG) { String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():"<null>"; String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():"<null>"; - Exception e = new Exception("setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); + Exception e = new Exception("Info: setGL (OpenGL "+getGLVersion()+"): "+Thread.currentThread()+", "+sgl1+" -> "+sgl2); e.printStackTrace(); } this.gl = gl; @@ -1053,7 +1053,7 @@ public abstract class GLContextImpl extends GLContext { e.printStackTrace(); // FIXME: refactor desktop OpenGL dependencies and make this // class work properly for OpenGL ES - System.err.println("ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.<init>: "+e); + System.err.println("Info: ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.<init>: "+e); major = 1; minor = 0; /* diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextLock.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextLock.java index 565ec967e..ea78f5209 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextLock.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextLock.java @@ -50,11 +50,13 @@ import javax.media.opengl.*; be raised. */ public class GLContextLock { + protected static final boolean DEBUG = GLContextImpl.DEBUG; + static class SyncData { boolean failFastMode = true; Thread owner = null; int waiters = 0; - Exception lockedStack = null; + Exception lockedStack = null; // only enabled if DEBUG } private SyncData sdata = new SyncData(); // synchronized (flow/mem) mutable access @@ -66,12 +68,16 @@ public class GLContextLock { Thread current = Thread.currentThread(); if (sdata.owner == null) { sdata.owner = current; - sdata.lockedStack = new Exception("Previously made current (1) by "+sdata.owner+", lock: "+this); + if(DEBUG) { + sdata.lockedStack = new Exception("Error: Previously made current (1) by "+sdata.owner+", lock: "+this); + } } else if (sdata.owner != current) { while (sdata.owner != null) { if (sdata.failFastMode) { - sdata.lockedStack.printStackTrace(); - throw new GLException("Attempt to make context current on thread " + current + + if(null!=sdata.lockedStack) { + sdata.lockedStack.printStackTrace(); + } + throw new GLException("Error: Attempt to make context current on thread " + current + " which is already current on thread " + sdata.owner); } else { try { @@ -85,7 +91,9 @@ public class GLContextLock { } } sdata.owner = current; - sdata.lockedStack = new Exception("Previously made current (2) by "+sdata.owner+", lock: "+this); + if(DEBUG) { + sdata.lockedStack = new Exception("Previously made current (2) by "+sdata.owner+", lock: "+this); + } } else { throw new GLException("Attempt to make the same context current twice on thread " + current); } @@ -139,6 +147,7 @@ public class GLContextLock { } } + /** holding the owners stack trace when lock is acquired and DEBUG is true */ public final Exception getLockedStack() { synchronized(sdata) { return sdata.lockedStack; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextShareSet.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextShareSet.java index abeb231f4..7be06b698 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextShareSet.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextShareSet.java @@ -54,7 +54,7 @@ import javax.media.opengl.*; public class GLContextShareSet { // FIXME: refactor Java SE dependencies // private static boolean forceTracking = Debug.isPropertyDefined("jogl.glcontext.forcetracking"); - private static final boolean DEBUG = Debug.debug("GLContextShareSet"); + private static final boolean DEBUG = Debug.debug("GLContext"); // This class is implemented with a WeakHashMap that goes from the // contexts as keys to a complex data structure as value that tracks diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index 6cf326949..c0e554889 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -51,7 +51,7 @@ import java.security.*; these GLDrawables is not supplied directly to end users, though they may be instantiated by the GLJPanel implementation. */ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { - protected static final boolean DEBUG = Debug.debug("GLDrawableFactory"); + protected static final boolean DEBUG = GLDrawableImpl.DEBUG; /** * Returns the GLDynamicLookupHelper @@ -69,28 +69,34 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { } AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); GLCapabilities caps = (GLCapabilities) config.getChosenCapabilities(); + AbstractGraphicsDevice adevice = config.getScreen().getDevice(); GLDrawable result = null; - if(caps.isOnscreen()) { - if(DEBUG) { - System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OnscreenDrawable: "+target); - } - result = createOnscreenDrawable(target); - } else { - if( ! ( target instanceof SurfaceChangeable ) ) { - throw new IllegalArgumentException("Passed NativeSurface must implement SurfaceChangeable for offscreen: "+target); - } - if(caps.isPBuffer()) { + adevice.lock(); + try { + if(caps.isOnscreen()) { if(DEBUG) { - System.err.println("GLDrawableFactoryImpl.createGLDrawable -> PbufferDrawable: "+target); + System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OnscreenDrawable: "+target); } - result = createGLPbufferDrawable(target); - } - if(null==result) { - if(DEBUG) { - System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable: "+target); + result = createOnscreenDrawableImpl(target); + } else { + if( ! ( target instanceof SurfaceChangeable ) ) { + throw new IllegalArgumentException("Passed NativeSurface must implement SurfaceChangeable for offscreen: "+target); + } + if(caps.isPBuffer() && canCreateGLPbuffer(adevice)) { + if(DEBUG) { + System.err.println("GLDrawableFactoryImpl.createGLDrawable -> PbufferDrawable: "+target); + } + result = createGLPbufferDrawable(target); + } + if(null==result) { + if(DEBUG) { + System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable: "+target); + } + result = createOffscreenDrawableImpl(target); } - result = createOffscreenDrawable(target); } + } finally { + adevice.unlock(); } if(DEBUG) { System.err.println("GLDrawableFactoryImpl.createGLDrawable: "+result); @@ -103,23 +109,25 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { // Onscreen GLDrawable construction // - protected abstract GLDrawableImpl createOnscreenDrawable(NativeSurface target); + protected abstract GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target); //--------------------------------------------------------------------------- // // PBuffer GLDrawable construction // + public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device); + /** Target must implement SurfaceChangeable */ protected abstract GLDrawableImpl createGLPbufferDrawableImpl(NativeSurface target); - protected GLDrawableImpl createGLPbufferDrawable(NativeSurface target) { + private GLDrawableImpl createGLPbufferDrawable(NativeSurface target) { if (!canCreateGLPbuffer(target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice())) { throw new GLException("Pbuffer support not available with current graphics card"); } return createGLPbufferDrawableImpl(target); } - + public GLDrawable createGLPbufferDrawable(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, @@ -131,7 +139,12 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { capabilities.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN capabilities.setOnscreen(false); capabilities.setPBuffer(true); - return createGLPbufferDrawable( createOffscreenSurface(capabilities, chooser, height, height) ); + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return createGLPbufferDrawable( createOffscreenSurfaceImpl(capabilities, chooser, height, height) ); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } } public GLPbuffer createGLPbuffer(GLCapabilities capabilities, @@ -149,7 +162,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { // Offscreen GLDrawable construction // - protected abstract GLDrawableImpl createOffscreenDrawable(NativeSurface target) ; + protected abstract GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) ; public GLDrawable createOffscreenDrawable(GLCapabilities capabilities, GLCapabilitiesChooser chooser, @@ -162,16 +175,53 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { capabilities.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN capabilities.setOnscreen(false); capabilities.setPBuffer(false); - return createOffscreenDrawable( createOffscreenSurface(capabilities, chooser, width, height) ); + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return createOffscreenDrawableImpl( createOffscreenSurfaceImpl(capabilities, chooser, width, height) ); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } } /** * creates an offscreen NativeSurface, which must implement SurfaceChangeable as well, * so the windowing system related implementation is able to set the surface handle. */ - protected abstract NativeSurface createOffscreenSurface(GLCapabilities capabilities, GLCapabilitiesChooser chooser, + protected abstract NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height); + //--------------------------------------------------------------------------- + // + // External GLDrawable construction + // + + protected abstract GLContext createExternalGLContextImpl(); + + public GLContext createExternalGLContext() { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return createExternalGLContextImpl(); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + protected abstract GLDrawable createExternalGLDrawableImpl(); + + public GLDrawable createExternalGLDrawable() { + NativeWindowFactory.getDefaultToolkitLock().lock(); + try { + return createExternalGLDrawableImpl(); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); + } + } + + + //--------------------------------------------------------------------------- + // + // GLDrawableFactoryImpl details + // protected abstract GLDrawableImpl getSharedDrawable(); protected abstract GLContextImpl getSharedContext(); protected abstract void shutdown(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableHelper.java index 1596f0baf..4ad0dd4c3 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableHelper.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableHelper.java @@ -47,17 +47,32 @@ import javax.media.opengl.*; methods to be able to share it between GLCanvas and GLJPanel. */ public class GLDrawableHelper { - private static final boolean DEBUG = Debug.debug("GLDrawableHelper"); + protected static final boolean DEBUG = GLDrawableImpl.DEBUG; private static final boolean VERBOSE = Debug.verbose(); private Object listenersLock = new Object(); - private List listeners = new ArrayList(); - private Set listenersToBeInit = new HashSet(); - private boolean autoSwapBufferMode = true; + private List listeners; + private volatile boolean listenersIter; // avoid java.util.ConcurrentModificationException + private Set listenersToBeInit; + private boolean autoSwapBufferMode; private Object glRunnablesLock = new Object(); - private ArrayList glRunnables = new ArrayList(); // one shot GL tasks - private GLAnimatorControl animatorCtrl = null; // default + private ArrayList glRunnables; + private GLAnimatorControl animatorCtrl; public GLDrawableHelper() { + reset(); + } + + public void reset() { + synchronized(listenersLock) { + listeners = new ArrayList(); + listenersIter = false; + listenersToBeInit = new HashSet(); + } + autoSwapBufferMode = true; + synchronized(glRunnablesLock) { + glRunnables = new ArrayList(); + } + animatorCtrl = null; } public String toString() { @@ -65,13 +80,15 @@ public class GLDrawableHelper { sb.append("GLAnimatorControl: "+animatorCtrl+", "); synchronized(listenersLock) { sb.append("GLEventListeners num "+listeners.size()+" ["); - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - Object l = iter.next(); + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + Object l = listeners.get(i); sb.append(l); sb.append("[init "); sb.append( !listenersToBeInit.contains(l) ); sb.append("], "); } + listenersIter = false; } sb.append("]"); return sb.toString(); @@ -87,24 +104,42 @@ public class GLDrawableHelper { index = listeners.size(); } listenersToBeInit.add(listener); - listeners.add(index, listener); + if(!listenersIter) { + // fast path + listeners.add(index, listener); + } else { + // copy mode in case this is issued while iterating, eg via init, display, .. + List newListeners = (List) ((ArrayList) listeners).clone(); + newListeners.add(index, listener); + listeners = newListeners; + } } } public void removeGLEventListener(GLEventListener listener) { synchronized(listenersLock) { - listeners.remove(listener); + if(!listenersIter) { + // fast path + listeners.remove(listener); + } else { + // copy mode in case this is issued while iterating, eg via init, display, .. + List newListeners = (List) ((ArrayList) listeners).clone(); + newListeners.remove(listener); + listeners = newListeners; + } listenersToBeInit.remove(listener); } } public void dispose(GLAutoDrawable drawable) { synchronized(listenersLock) { - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - GLEventListener listener = (GLEventListener) iter.next() ; + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + GLEventListener listener = (GLEventListener) listeners.get(i) ; listener.dispose(drawable); listenersToBeInit.add(listener); } + listenersIter = false; } } @@ -121,24 +156,28 @@ public class GLDrawableHelper { public void init(GLAutoDrawable drawable) { synchronized(listenersLock) { - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - GLEventListener listener = (GLEventListener) iter.next() ; + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + GLEventListener listener = (GLEventListener) listeners.get(i) ; if ( ! init( listener, drawable, false ) ) { throw new GLException("GLEventListener "+listener+" already initialized: "+drawable); } } + listenersIter = false; } } public void display(GLAutoDrawable drawable) { synchronized(listenersLock) { - for (Iterator iter = listeners.iterator(); iter.hasNext(); ) { - GLEventListener listener = (GLEventListener) iter.next() ; + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + GLEventListener listener = (GLEventListener) listeners.get(i) ; // GLEventListener may need to be init, // in case this one is added after the realization of the GLAutoDrawable init( listener, drawable, true ) ; listener.display(drawable); } + listenersIter = false; } execGLRunnables(drawable); } @@ -153,10 +192,11 @@ public class GLDrawableHelper { public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { synchronized(listenersLock) { - int i=0; - for (Iterator iter = listeners.iterator(); iter.hasNext(); i++) { - reshape((GLEventListener) iter.next(), drawable, x, y, width, height, 0==i); + listenersIter = true; + for (int i=0; i < listeners.size(); i++) { + reshape((GLEventListener) listeners.get(i), drawable, x, y, width, height, 0==i); } + listenersIter = false; } } @@ -171,8 +211,8 @@ public class GLDrawableHelper { } } if(null!=_glRunnables) { - for (Iterator iter = _glRunnables.iterator(); iter.hasNext(); ) { - ((GLRunnable) iter.next()).run(drawable); + for (int i=0; i < _glRunnables.size(); i++) { + ((GLRunnable) _glRunnables.get(i)).run(drawable); } } } @@ -255,7 +295,7 @@ public class GLDrawableHelper { Runnable initAction) { if(null==context) { if (DEBUG) { - Exception e = new GLException(Thread.currentThread().getName()+" GLDrawableHelper " + this + ".invokeGL(): NULL GLContext"); + Exception e = new GLException(Thread.currentThread().getName()+"Info: GLDrawableHelper " + this + ".invokeGL(): NULL GLContext"); e.printStackTrace(); } return; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java index 19e637cab..e68ee3644 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableImpl.java @@ -67,6 +67,14 @@ public abstract class GLDrawableImpl implements GLDrawable { /** For offscreen GLDrawables (pbuffers and "pixmap" drawables), indicates that native resources should be reclaimed. */ public void destroy() { + surface.getGraphicsConfiguration().getScreen().getDevice().lock(); + try { + destroyImpl(); + } finally { + surface.getGraphicsConfiguration().getScreen().getDevice().unlock(); + } + } + protected void destroyImpl() { throw new GLException("Should not call this (should only be called for offscreen GLDrawables)"); } @@ -129,35 +137,41 @@ public abstract class GLDrawableImpl implements GLDrawable { return factory; } - public final void setRealized(boolean realized) { - if ( this.realized != realized ) { + public final synchronized void setRealized(boolean realizedArg) { + if ( realized != realizedArg ) { if(DEBUG) { - System.err.println("setRealized: "+getClass().getName()+" "+this.realized+" -> "+realized); + System.err.println("setRealized: "+getClass().getName()+" "+realized+" -> "+realizedArg); } - this.realized = realized; - if(realized && NativeSurface.LOCK_SURFACE_NOT_READY == lockSurface()) { - throw new GLException("X11GLXDrawable.setRealized(true): lockSurface - surface not ready"); - } - try { - AbstractGraphicsDevice aDevice = getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); - if(!realized) { - destroyHandle(); + realized = realizedArg; + AbstractGraphicsDevice aDevice = surface.getGraphicsConfiguration().getScreen().getDevice(); + if(realizedArg) { + if(NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) { + throw new GLException("X11GLXDrawable.setRealized(true): already realized, but surface not ready (lockSurface)"); } + } else { + aDevice.lock(); + } + try { setRealizedImpl(); - if(realized) { + if(realizedArg) { updateHandle(); + } else { + destroyHandle(); } } finally { - if(realized) { + if(realizedArg) { unlockSurface(); + } else { + aDevice.unlock(); } } } else if(DEBUG) { - System.err.println("setRealized: "+getClass().getName()+" "+this.realized+" == "+realized); + System.err.println("setRealized: "+getClass().getName()+" "+this.realized+" == "+realizedArg); } } protected abstract void setRealizedImpl(); - public boolean isRealized() { + + public synchronized boolean isRealized() { return realized; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLPbufferImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLPbufferImpl.java index e2c217ac0..7a30f9a6f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLPbufferImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLPbufferImpl.java @@ -49,7 +49,7 @@ import java.beans.PropertyChangeListener; import javax.media.nativewindow.*; import javax.media.opengl.*; -import com.jogamp.common.util.RecursiveToolkitLock; +import com.jogamp.common.util.locks.RecursiveLock; /** Platform-independent class exposing pbuffer functionality to applications. This class is not exposed in the public API as it @@ -216,7 +216,7 @@ public class GLPbufferImpl implements GLPbuffer { return pbufferDrawable.getGLProfile(); } - private RecursiveToolkitLock recurLock = new RecursiveToolkitLock(); + private RecursiveLock recurLock = new RecursiveLock(); public int lockSurface() throws GLException { recurLock.lock(); @@ -231,7 +231,7 @@ public class GLPbufferImpl implements GLPbuffer { return recurLock.isLocked(); } - public Exception getLockedStack() { + public Throwable getLockedStack() { return recurLock.getLockedStack(); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLWorkerThread.java b/src/jogl/classes/com/jogamp/opengl/impl/GLWorkerThread.java index 768eea3f7..c292de778 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLWorkerThread.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLWorkerThread.java @@ -254,7 +254,7 @@ public class GLWorkerThread { Runnable curAsync = (Runnable) queue.remove(0); curAsync.run(); } catch (Throwable t) { - System.out.println("Exception occurred on JOGL OpenGL worker thread:"); + System.err.println("Exception occurred on JOGL OpenGL worker thread:"); t.printStackTrace(); } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java b/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java index e5570a8ee..36c0a3250 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/awt/AWTUtil.java @@ -117,9 +117,4 @@ public class AWTUtil { } } } - - public static boolean isToolkitLocked() { - return JAWTUtil.isToolkitLocked(); - } - } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/awt/Java2D.java b/src/jogl/classes/com/jogamp/opengl/impl/awt/Java2D.java index b871c66a7..d8f83a5f7 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/awt/Java2D.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/awt/Java2D.java @@ -178,7 +178,7 @@ public class Java2D { fbObjectSupportInitialized = false; if (DEBUG && VERBOSE) { e.printStackTrace(); - System.err.println("Disabling Java2D/JOGL FBO support"); + System.err.println("Info: Disabling Java2D/JOGL FBO support"); } } @@ -192,7 +192,7 @@ public class Java2D { } catch (Exception e) { if (DEBUG && VERBOSE) { e.printStackTrace(); - System.err.println("GL_ARB_texture_rectangle FBO support disabled"); + System.err.println("Info: GL_ARB_texture_rectangle FBO support disabled"); } } @@ -205,7 +205,7 @@ public class Java2D { } catch (Exception e) { if (DEBUG && VERBOSE) { e.printStackTrace(); - System.err.println("Unable to find class sun.java2d.opengl.CGLSurfaceData for OS X"); + System.err.println("Info: Unable to find class sun.java2d.opengl.CGLSurfaceData for OS X"); } } if (cglSurfaceData != null) { @@ -236,7 +236,7 @@ public class Java2D { } catch (Exception e) { if (DEBUG && VERBOSE) { e.printStackTrace(); - System.err.println("Disabling Java2D/JOGL integration"); + System.err.println("Info: Disabling Java2D/JOGL integration"); } isOGLPipelineActive = false; } @@ -265,7 +265,7 @@ public class Java2D { checkActive(); try { - return ((Boolean) isQueueFlusherThreadMethod.invoke(null, new Object[] {})).booleanValue(); + return ((Boolean) isQueueFlusherThreadMethod.invoke(null, null)).booleanValue(); } catch (InvocationTargetException e) { throw new GLException(e.getTargetException()); } catch (Exception e) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index b1084dd8f..83e85b922 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -115,14 +115,14 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { protected final GLDrawableImpl getSharedDrawable() { return null; } protected final GLContextImpl getSharedContext() { return null; } - public GLDrawableImpl createOnscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new EGLOnscreenDrawable(this, target); } - protected GLDrawableImpl createOffscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { throw new GLException("Not yet implemented"); } @@ -134,13 +134,13 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { return new EGLPbufferDrawable(this, target); } - protected NativeSurface createOffscreenSurface(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + protected NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { ProxySurface ns = new ProxySurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(capabilities, chooser)); ns.setSize(width, height); return ns; } - public GLContext createExternalGLContext() { + protected GLContext createExternalGLContextImpl() { AbstractGraphicsScreen absScreen = DefaultGraphicsScreen.createScreenDevice(0); return new EGLExternalContext(absScreen); } @@ -149,7 +149,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { return false; } - public GLDrawable createExternalGLDrawable() { + protected GLDrawable createExternalGLDrawableImpl() { throw new GLException("Not yet implemented"); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java index 33e301ee9..88e8a9ed1 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java @@ -53,9 +53,8 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.egl.EGLGraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl ( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { if (absScreen == null) { throw new IllegalArgumentException("This NativeWindowFactory accepts only AbstractGraphicsDevice objects"); } @@ -75,7 +74,7 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor absScreen); } - public static EGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilities capabilities, + private static EGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilities capabilities, GLCapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { if (capabilities == null) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/gl2/fixme/GLObjectTracker.java b/src/jogl/classes/com/jogamp/opengl/impl/gl2/fixme/GLObjectTracker.java index 3e3b6ae87..6ee29b876 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/gl2/fixme/GLObjectTracker.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/gl2/fixme/GLObjectTracker.java @@ -69,7 +69,7 @@ import javax.media.opengl.*; */ public class GLObjectTracker { - private static final boolean DEBUG = Debug.debug("GLObjectTracker"); + private static final boolean DEBUG = Debug.debug("GLStatusTracker"); //---------------------------------------------------------------------- // Adders diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index 396d6aefc..47e0e656f 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -80,7 +80,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { try { ReflectionUtil.createInstance("com.jogamp.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory", - new Object[] {}, getClass().getClassLoader()); + null, getClass().getClassLoader()); } catch (JogampRuntimeException jre) { /* n/a .. */ } } @@ -88,14 +88,14 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { protected final GLDrawableImpl getSharedDrawable() { return null; } protected final GLContextImpl getSharedContext() { return null; } - public GLDrawableImpl createOnscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new MacOSXOnscreenCGLDrawable(this, target); } - protected GLDrawableImpl createOffscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { return new MacOSXOffscreenCGLDrawable(this, target); } @@ -120,14 +120,14 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return new MacOSXPbufferCGLDrawable(this, target); } - protected NativeSurface createOffscreenSurface(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + protected NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); ProxySurface ns = new ProxySurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, screen, true)); ns.setSize(width, height); return ns; } - public GLContext createExternalGLContext() { + protected GLContext createExternalGLContextImpl() { return MacOSXExternalCGLContext.create(this, null); } @@ -135,7 +135,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return false; } - public GLDrawable createExternalGLDrawable() { + protected GLDrawable createExternalGLDrawableImpl() { // FIXME throw new GLException("Not yet implemented"); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java index ada5fb1a7..69bb245e1 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLGraphicsConfigurationFactory.java @@ -51,9 +51,8 @@ public class MacOSXCGLGraphicsConfigurationFactory extends GraphicsConfiguration GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.macosx.MacOSXGraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { return chooseGraphicsConfigurationStatic(capabilities, chooser, absScreen, false); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java index bc470383f..14ed02918 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -77,7 +77,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { if(realized) { createPbuffer(); } else { - destroy(); + destroyImpl(); } } @@ -85,7 +85,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { return new MacOSXPbufferCGLContext(this, shareWith); } - public void destroy() { + protected void destroyImpl() { if (this.pBuffer != 0) { NativeSurface ns = getNativeSurface(); impl.destroy(pBuffer); @@ -185,7 +185,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { if (haveSetOpenGLMode) { throw new GLException("Can't switch between using NSOpenGLPixelBuffer and CGLPBufferObj more than once"); } - destroy(); + destroyImpl(); openGLMode = mode; haveSetOpenGLMode = true; if (DEBUG) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java index 0d59da32e..6a9617d27 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java @@ -53,9 +53,8 @@ public class MacOSXAWTCGLGraphicsConfigurationFactory extends GraphicsConfigurat GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { GraphicsDevice device = null; if (absScreen != null && !(absScreen instanceof AWTGraphicsScreen)) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java index 299adec50..9a86f7d08 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java @@ -89,7 +89,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { return new WindowsWGLContext(this, shareWith); } - public void destroy() { + protected void destroyImpl() { if (hdc != 0) { GDI.ReleaseDC(hwnd, hdc); hdc = 0; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java index ea02a4919..f58d2f4bc 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java @@ -48,7 +48,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { private long origbitmap; private long hbitmap; - public WindowsOffscreenWGLDrawable(GLDrawableFactory factory, NativeSurface target) { + protected WindowsOffscreenWGLDrawable(GLDrawableFactory factory, NativeSurface target) { super(factory, target, true); create(); } @@ -57,7 +57,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { if(realized) { create(); } else { - destroy(); + destroyImpl(); } } @@ -113,11 +113,10 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { hdc = 0; throw new GLException("Error selecting bitmap into new device context"); } - config.updateGraphicsConfiguration(getFactory(), ns); } - public void destroy() { + protected void destroyImpl() { NativeSurface ns = getNativeSurface(); if (ns.getSurfaceHandle() != 0) { // Must destroy bitmap and device context diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java index 66953289b..abbaf5004 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java @@ -43,8 +43,6 @@ import javax.media.opengl.*; import com.jogamp.opengl.impl.*; public class WindowsPbufferWGLContext extends WindowsWGLContext { - private static final boolean DEBUG = Debug.debug("WindowsPbufferWGLContext"); - // State for render-to-texture and render-to-texture-rectangle support private boolean rtt; // render-to-texture? private boolean hasRTT; // render-to-texture extension available? diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java index 5708aa6bb..0198f334c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -72,7 +72,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { if(realized) { throw new GLException("Recreation via setRealized not supported."); } else { - destroy(); + destroyImpl(); } } @@ -80,7 +80,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { return new WindowsPbufferWGLContext(this, shareWith); } - public void destroy() { + protected void destroyImpl() { NativeSurface ns = getNativeSurface(); if(0!=buffer) { WGLExt wglExt = cachedWGLExt; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index c80e46cc2..65a8e8ac3 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -298,7 +298,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { throw new GLException("Error making context current: 0x" + toHexString(contextHandle) + ", werr: 0x" + Integer.toHexString(GDI.GetLastError()) + ", " + this); } else { - if (DEBUG && VERBOSE) { + if (DEBUG && (VERBOSE || newCreated)) { System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + toHexString(drawable.getHandle()) + ", contextHandle " + toHexString(contextHandle) + ") succeeded"); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java index 9fef457db..984708f52 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java @@ -43,10 +43,11 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; +import java.security.*; public abstract class WindowsWGLDrawable extends GLDrawableImpl { private static final int MAX_SET_PIXEL_FORMAT_FAIL_COUNT = 5; - private static final boolean PROFILING = Debug.debug("WindowsWGLDrawable.profiling"); + private static final boolean PROFILING = Debug.isPropertyDefined("jogl.debug.GLDrawable.profiling", true, AccessController.getContext()); private static final int PROFILING_TICKS = 200; private int profilingLockSurfaceTicks; private long profilingLockSurfaceTime; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index aafea36fd..409e914b0 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -82,9 +82,10 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { new WindowsWGLGraphicsConfigurationFactory(); try { ReflectionUtil.createInstance("com.jogamp.opengl.impl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", - new Object[] {}, getClass().getClassLoader()); + null, getClass().getClassLoader()); } catch (JogampRuntimeException jre) { /* n/a .. */ } + NativeWindowFactory.getDefaultToolkitLock().lock(); // OK try { sharedDrawable = new WindowsDummyWGLDrawable(this, null); WindowsWGLContext ctx = (WindowsWGLContext) sharedDrawable.createContext(null); @@ -94,6 +95,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { sharedContext = ctx; } catch (Throwable t) { throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources", t); + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); // OK } if(null==sharedContext) { throw new GLException("WindowsWGLDrawableFactory - Shared Context is null"); @@ -135,14 +138,14 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } } - public GLDrawableImpl createOnscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new WindowsOnscreenWGLDrawable(this, target); } - protected GLDrawableImpl createOffscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } @@ -185,7 +188,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return (GLDrawableImpl) returnList.get(0); } - protected NativeSurface createOffscreenSurface(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + protected NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); ProxySurface ns = new ProxySurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capabilities, chooser, screen) ); @@ -193,7 +196,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return ns; } - public GLContext createExternalGLContext() { + protected GLContext createExternalGLContextImpl() { return WindowsExternalWGLContext.create(this, null); } @@ -201,7 +204,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return true; } - public GLDrawable createExternalGLDrawable() { + protected GLDrawable createExternalGLDrawableImpl() { return WindowsExternalWGLDrawable.create(this, null); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index ae12d254a..c8ecb2b72 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -52,9 +52,8 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.windows.WindowsGraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { GLCapabilities caps = (GLCapabilities)capabilities; return chooseGraphicsConfigurationStatic(caps, chooser, absScreen); } @@ -107,10 +106,12 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio GLProfile glProfile = capabilities.getGLProfile(); long hdc = ns.getSurfaceHandle(); - if (DEBUG) { - Exception ex = new Exception("WindowsWGLGraphicsConfigurationFactory got HDC "+toHexString(hdc)); + if(0==hdc) { + throw new GLException("Error: HDC is null "+toHexString(hdc)); + } + if(DEBUG) { + Exception ex = new Exception("Info: WindowsWGLGraphicsConfigurationFactory got HDC "+toHexString(hdc)); ex.printStackTrace(); - System.err.println("WindowsWGLGraphicsConfigurationFactory got NW "+ns); } PIXELFORMATDESCRIPTOR pfd = null; @@ -120,7 +121,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio if (onscreen) { if ((pixelFormat = GDI.GetPixelFormat(hdc)) != 0) { - // Pixelformat already set by either + // Pixelformat already set by either // - a previous updateGraphicsConfiguration() call on the same HDC, // - the graphics driver, copying the HDC's pixelformat to the new one, // - or the Java2D/OpenGL pipeline's configuration diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java index 02cfd14c3..26704acf3 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java @@ -53,9 +53,8 @@ public class WindowsAWTWGLGraphicsConfigurationFactory extends GraphicsConfigura GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { GraphicsDevice device = null; if (absScreen != null && !(absScreen instanceof AWTGraphicsScreen)) { @@ -107,8 +106,7 @@ public class WindowsAWTWGLGraphicsConfigurationFactory extends GraphicsConfigura if(DEBUG) { System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: chosen "+winConfig); } - - // FIXME: we have nothing to match .. so choose the default + return new AWTGraphicsConfiguration(awtScreen, winConfig.getChosenCapabilities(), winConfig.getRequestedCapabilities(), gc, winConfig); } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java index 690bc4b52..e77735637 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java @@ -57,7 +57,7 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { int scrn = screen.getIndex(); long visualID = config.getVisualID(); - dummyWindow = X11Lib.CreateDummyWindow(dpy, scrn, visualID); + dummyWindow = X11Util.CreateDummyWindow(dpy, scrn, visualID); ns.setSurfaceHandle( dummyWindow ); updateHandle(); @@ -74,11 +74,11 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { return 1; } - public void destroy() { + protected void destroyImpl() { if(0!=dummyWindow) { destroyHandle(); X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - X11Lib.DestroyDummyWindow(config.getScreen().getDevice().getHandle(), dummyWindow); + X11Util.DestroyDummyWindow(config.getScreen().getDevice().getHandle(), dummyWindow); } } } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java index 494860c5b..21de61ff8 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java @@ -119,7 +119,7 @@ public abstract class X11GLXContext extends GLContextImpl { } } catch (RuntimeException re) { if(DEBUG) { - System.err.println("X11GLXContext.glXMakeContextCurrent failed: "+re+", with "+ + System.err.println("Warning: X11GLXContext.glXMakeContextCurrent failed: "+re+", with "+ "dpy "+toHexString(dpy)+ ", write "+toHexString(writeDrawable)+ ", read "+toHexString(readDrawable)+ @@ -191,7 +191,7 @@ public abstract class X11GLXContext extends GLContextImpl { ctx = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0); } catch (RuntimeException re) { if(DEBUG) { - System.err.println("X11GLXContext.createContextARB glXCreateContextAttribsARB failed: "+re+", with "+getGLVersion(major, minor, ctp, "@creation")); + System.err.println("Warning: X11GLXContext.createContextARB glXCreateContextAttribsARB failed: "+re+", with "+getGLVersion(major, minor, ctp, "@creation")); re.printStackTrace(); } } @@ -335,7 +335,7 @@ public abstract class X11GLXContext extends GLContextImpl { if (!glXMakeContextCurrent(dpy, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { throw new GLException("Error making context current: "+this); } - if (DEBUG && (VERBOSE || isCreated())) { + if (DEBUG && (VERBOSE || newCreated)) { System.err.println(getThreadName() + ": glXMakeCurrent(display " + toHexString(dpy)+ ", drawable " + toHexString(drawable.getHandle()) + diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 4b84227c3..adf4d8e0d 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -53,8 +53,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { private static final DesktopGLDynamicLookupHelper x11GLXDynamicLookupHelper; static { - X11Util.initSingleton(); // ensure it's loaded and setup - DesktopGLDynamicLookupHelper tmp = null; try { tmp = new DesktopGLDynamicLookupHelper(new X11GLXDynamicLibraryBundleInfo()); @@ -80,35 +78,45 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { new X11GLXGraphicsConfigurationFactory(); try { ReflectionUtil.createInstance("com.jogamp.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", - new Object[] {}, getClass().getClassLoader()); + null, getClass().getClassLoader()); } catch (JogampRuntimeException jre) { /* n/a .. */ } // init shared resources .. - long tlsDisplay = X11Util.createThreadLocalDisplay(null); - X11GraphicsDevice sharedDevice = new X11GraphicsDevice(tlsDisplay); - vendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); - isVendorATI = GLXUtil.isVendorATI(vendorName); - isVendorNVIDIA = GLXUtil.isVendorNVIDIA(vendorName); - sharedScreen = new X11GraphicsScreen(sharedDevice, 0); - sharedDrawable = new X11DummyGLXDrawable(sharedScreen, X11GLXDrawableFactory.this, GLProfile.getDefault()); - if(isVendorATI() && GLProfile.isAWTAvailable()) { - X11Util.markThreadLocalDisplayUncloseable(tlsDisplay); // failure to close with ATI and AWT usage - } - if(null==sharedScreen || null==sharedDrawable) { - throw new GLException("Couldn't init shared screen("+sharedScreen+")/drawable("+sharedDrawable+")"); - } - // We have to keep this within this thread, - // since we have a 'chicken-and-egg' problem otherwise on the <init> lock of this thread. - try{ - X11GLXContext ctx = (X11GLXContext) sharedDrawable.createContext(null); - ctx.makeCurrent(); - ctx.release(); - sharedContext = ctx; - } catch (Throwable t) { - throw new GLException("X11GLXDrawableFactory - Could not initialize shared resources", t); - } - if(null==sharedContext) { - throw new GLException("X11GLXDrawableFactory - Shared Context is null"); + NativeWindowFactory.getDefaultToolkitLock().lock(); // OK + try { + long tlsDisplay = X11Util.createThreadLocalDisplay(null); + X11Util.XLockDisplay(tlsDisplay); + try { + X11GraphicsDevice sharedDevice = new X11GraphicsDevice(tlsDisplay); + vendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); + isVendorATI = GLXUtil.isVendorATI(vendorName); + isVendorNVIDIA = GLXUtil.isVendorNVIDIA(vendorName); + sharedScreen = new X11GraphicsScreen(sharedDevice, 0); + sharedDrawable = new X11DummyGLXDrawable(sharedScreen, X11GLXDrawableFactory.this, GLProfile.getDefault()); + if(isVendorATI() && GLProfile.isAWTAvailable()) { + X11Util.markThreadLocalDisplayUncloseable(tlsDisplay); // failure to close with ATI and AWT usage + } + if(null==sharedScreen || null==sharedDrawable) { + throw new GLException("Couldn't init shared screen("+sharedScreen+")/drawable("+sharedDrawable+")"); + } + // We have to keep this within this thread, + // since we have a 'chicken-and-egg' problem otherwise on the <init> lock of this thread. + try{ + X11GLXContext ctx = (X11GLXContext) sharedDrawable.createContext(null); + ctx.makeCurrent(); + ctx.release(); + sharedContext = ctx; + } catch (Throwable t) { + throw new GLException("X11GLXDrawableFactory - Could not initialize shared resources", t); + } + if(null==sharedContext) { + throw new GLException("X11GLXDrawableFactory - Shared Context is null"); + } + } finally { + X11Util.XUnlockDisplay(tlsDisplay); + } + } finally { + NativeWindowFactory.getDefaultToolkitLock().unlock(); // OK } if (DEBUG) { System.err.println("!!! Vendor: "+vendorName+", ATI: "+isVendorATI+", NV: "+isVendorNVIDIA); @@ -122,9 +130,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { private boolean isVendorATI; private boolean isVendorNVIDIA; - public String getVendorName() { return vendorName; } - public boolean isVendorATI() { return isVendorATI; } - public boolean isVendorNVIDIA() { return isVendorNVIDIA; } + protected String getVendorName() { return vendorName; } + protected boolean isVendorATI() { return isVendorATI; } + protected boolean isVendorNVIDIA() { return isVendorNVIDIA; } private X11DummyGLXDrawable sharedDrawable=null; private X11GLXContext sharedContext=null; @@ -165,14 +173,14 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { X11Util.shutdown( false, DEBUG ); } - public GLDrawableImpl createOnscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new X11OnscreenGLXDrawable(this, target); } - protected GLDrawableImpl createOffscreenDrawable(NativeSurface target) { + protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } @@ -185,7 +193,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { private boolean glxVersionsQueried = false; private int glxVersionMajor=0, glxVersionMinor=0; - public boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) { + protected final boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) { if (!glxVersionsQueried) { if(null == device) { device = (X11GraphicsDevice) sharedScreen.getDevice(); @@ -193,19 +201,24 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { if(null == device) { throw new GLException("FIXME: No AbstractGraphicsDevice (passed or shared-device"); } - long display = device.getHandle(); - int[] major = new int[1]; - int[] minor = new int[1]; - - GLXUtil.getGLXVersion(display, major, minor); - if (DEBUG) { - System.err.println("!!! GLX version: major " + major[0] + - ", minor " + minor[0]); - } + device.lock(); // OK + try { + long display = device.getHandle(); + int[] major = new int[1]; + int[] minor = new int[1]; + + GLXUtil.getGLXVersion(display, major, minor); + if (DEBUG) { + System.err.println("!!! GLX version: major " + major[0] + + ", minor " + minor[0]); + } - glxVersionMajor = major[0]; - glxVersionMinor = minor[0]; - glxVersionsQueried = true; + glxVersionMajor = major[0]; + glxVersionMinor = minor[0]; + glxVersionsQueried = true; + } finally { + device.unlock(); // OK + } } return ( glxVersionMajor > majorReq ) || ( glxVersionMajor == majorReq && glxVersionMinor >= minorReq ) ; } @@ -239,7 +252,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } - protected NativeSurface createOffscreenSurface(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + protected NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { ProxySurface ns = new ProxySurface(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, sharedScreen)); if(ns != null) { ns.setSize(width, height); @@ -247,7 +260,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return ns; } - public GLContext createExternalGLContext() { + protected GLContext createExternalGLContextImpl() { return X11ExternalGLXContext.create(this, null); } @@ -255,7 +268,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return canCreateGLPbuffer(device); } - public GLDrawable createExternalGLDrawable() { + protected GLDrawable createExternalGLDrawableImpl() { return X11ExternalGLXDrawable.create(this, null); } @@ -282,9 +295,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { long display = sharedScreen.getDevice().getHandle(); int[] size = new int[1]; - boolean res = X11Lib.XF86VidModeGetGammaRampSize(display, - X11Lib.DefaultScreen(display), - size, 0); + boolean res = X11Util.XF86VidModeGetGammaRampSize(display, + X11Util.DefaultScreen(display), + size, 0); if (!res) { return 0; } @@ -301,8 +314,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } long display = sharedScreen.getDevice().getHandle(); - boolean res = X11Lib.XF86VidModeSetGammaRamp(display, - X11Lib.DefaultScreen(display), + boolean res = X11Util.XF86VidModeSetGammaRamp(display, + X11Util.DefaultScreen(display), rampData.length, rampData, 0, rampData, 0, @@ -323,8 +336,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); long display = sharedScreen.getDevice().getHandle(); - boolean res = X11Lib.XF86VidModeGetGammaRamp(display, - X11Lib.DefaultScreen(display), + boolean res = X11Util.XF86VidModeGetGammaRamp(display, + X11Util.DefaultScreen(display), size, redRampData, greenRampData, @@ -354,8 +367,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); long display = sharedScreen.getDevice().getHandle(); - X11Lib.XF86VidModeSetGammaRamp(display, - X11Lib.DefaultScreen(display), + X11Util.XF86VidModeSetGammaRamp(display, + X11Util.DefaultScreen(display), size, redRampData, greenRampData, diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java index 589d7b2db..3df9ee541 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfiguration.java @@ -339,7 +339,7 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem int[] count = new int[1]; XVisualInfo template = XVisualInfo.create(); template.setVisualid(visualID); - XVisualInfo[] infos = X11Lib.XGetVisualInfo(display, X11Lib.VisualIDMask, template, count, 0); + XVisualInfo[] infos = X11Util.XGetVisualInfo(display, X11Lib.VisualIDMask, template, count, 0); if (infos == null || infos.length == 0) { return null; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 9884db288..8dbd69dce 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -53,9 +53,8 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { if (!(absScreen instanceof X11GraphicsScreen)) { throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here"); } @@ -95,7 +94,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); - long visID = X11Lib.DefaultVisualID(display, x11Screen.getIndex()); + long visID = X11Util.DefaultVisualID(display, x11Screen.getIndex()); xvis = X11GLXGraphicsConfiguration.XVisualID2XVisualInfo(display, visID); caps = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(glProfile, display, xvis, onscreen, usePBuffer, isMultisampleAvailable); @@ -140,7 +139,8 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac caps2.setDoubleBuffered(false); } - X11GLXGraphicsConfiguration res = chooseGraphicsConfigurationFBConfig(caps2, chooser, x11Screen); + X11GLXGraphicsConfiguration res; + res = chooseGraphicsConfigurationFBConfig(caps2, chooser, x11Screen); if(null==res) { if(usePBuffer) { throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for "+caps2); @@ -156,7 +156,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac return res; } - protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(GLCapabilities capabilities, + private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { long recommendedFBConfig = 0; @@ -277,7 +277,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac return new X11GLXGraphicsConfiguration(x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, fbcfgsL.get(chosen), retFBID); } - protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual(GLCapabilities capabilities, + private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual(GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { if (chooser == null) { @@ -315,7 +315,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac int[] count = new int[1]; XVisualInfo template = XVisualInfo.create(); template.setScreen(screen); - infos = X11Lib.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0); + infos = X11Util.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0); if (infos == null || infos.length<1) { throw new GLException("Error while enumerating available XVisualInfos"); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 3be34eb6a..f46bdbb75 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -56,7 +56,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { if(realized) { create(); } else { - destroy(); + destroyImpl(); } } @@ -74,14 +74,14 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { long dpy = aDevice.getHandle(); int screen = aScreen.getIndex(); - pixmap = X11Lib.XCreatePixmap(dpy, X11Lib.RootWindow(dpy, screen), + pixmap = X11Util.XCreatePixmap(dpy, X11Util.RootWindow(dpy, screen), surface.getWidth(), surface.getHeight(), bitsPerPixel); if (pixmap == 0) { throw new GLException("XCreatePixmap failed"); } long drawable = GLX.glXCreateGLXPixmap(dpy, vis, pixmap); if (drawable == 0) { - X11Lib.XFreePixmap(dpy, pixmap); + X11Util.XFreePixmap(dpy, pixmap); pixmap = 0; throw new GLException("glXCreateGLXPixmap failed"); } @@ -93,7 +93,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { } } - public void destroy() { + protected void destroyImpl() { if (pixmap == 0) return; NativeSurface ns = getNativeSurface(); @@ -122,7 +122,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { GLX.glXMakeCurrent(display, 0, 0); GLX.glXDestroyGLXPixmap(display, drawable); - X11Lib.XFreePixmap(display, pixmap); + X11Util.XFreePixmap(display, pixmap); drawable = 0; pixmap = 0; ((SurfaceChangeable)ns).setSurfaceHandle(0); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java index ce9e6d75d..b86394cc6 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PbufferGLXDrawable.java @@ -65,7 +65,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { if(realized) { createPbuffer(); } else { - destroy(); + destroyImpl(); } } @@ -73,7 +73,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { return new X11PbufferGLXContext(this, shareWith); } - public void destroy() { + protected void destroyImpl() { NativeSurface ns = getNativeSurface(); if (ns.getSurfaceHandle() != 0) { GLX.glXDestroyPbuffer(ns.getDisplayHandle(), ns.getSurfaceHandle()); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index de55a3148..99791b43e 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -32,6 +32,7 @@ package com.jogamp.opengl.impl.x11.glx.awt; +import com.jogamp.nativewindow.impl.jawt.JAWTUtil; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import javax.media.nativewindow.*; @@ -50,9 +51,8 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, - CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen) { + protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl( + Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { GraphicsDevice device = null; if (absScreen != null && !(absScreen instanceof AWTGraphicsScreen)) { @@ -93,7 +93,7 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration System.err.println("X11AWTGLXGraphicsConfigurationFactory: using AWT X11 display 0x"+Long.toHexString(displayHandle)); } } - ((AWTGraphicsDevice)awtScreen.getDevice()).setHandle(displayHandle); + ((AWTGraphicsDevice)awtScreen.getDevice()).setSubType(NativeWindowFactory.TYPE_X11, displayHandle); X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle); X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex()); diff --git a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java index e3aff61c6..9dd58bb57 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java @@ -55,29 +55,36 @@ class AWTAnimatorImpl extends AnimatorImpl { public void display(AnimatorBase animator, boolean ignoreExceptions, boolean printExceptions) { - Iterator iter = animator.drawableIterator(); - while (animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && iter.hasNext()) { - GLAutoDrawable drawable = (GLAutoDrawable) iter.next(); - if (drawable instanceof JComponent) { - // Lightweight components need a more efficient drawing - // scheme than simply forcing repainting of each one in - // turn since drawing one can force another one to be - // drawn in turn - lightweights.add(drawable); - } else { - try { - drawable.display(); - } catch (RuntimeException e) { - if (ignoreExceptions) { - if (printExceptions) { - e.printStackTrace(); + List drawables = animator.acquireDrawables(); + try { + for (int i=0; + animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && i<drawables.size(); + i++) { + GLAutoDrawable drawable = (GLAutoDrawable) drawables.get(i); + if (drawable instanceof JComponent) { + // Lightweight components need a more efficient drawing + // scheme than simply forcing repainting of each one in + // turn since drawing one can force another one to be + // drawn in turn + lightweights.add(drawable); + } else { + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); } - } else { - throw(e); } } } + } finally { + animator.releaseDrawables(); } + if (lightweights.size() > 0) { try { SwingUtilities.invokeAndWait(drawWithRepaintManagerRunnable); diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java index a54f6be57..24eee1875 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java @@ -28,9 +28,11 @@ package com.jogamp.opengl.util; +import com.jogamp.common.util.locks.RecursiveLock; import com.jogamp.opengl.impl.Debug; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLProfile; @@ -43,7 +45,8 @@ public abstract class AnimatorBase implements GLAnimatorControl { private static int animatorCount = 0; - protected volatile ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); + protected ArrayList/*<GLAutoDrawable>*/ drawables = new ArrayList(); + protected RecursiveLock drawablesLock = new RecursiveLock(); protected AnimatorImpl impl; protected String baseName; protected Thread thread; @@ -75,18 +78,24 @@ public abstract class AnimatorBase implements GLAnimatorControl { protected abstract String getBaseName(String prefix); public synchronized void add(GLAutoDrawable drawable) { - ArrayList newList = (ArrayList) drawables.clone(); - newList.add(drawable); - drawables = newList; - drawable.setAnimator(this); + drawablesLock.lock(); + try { + drawables.add(drawable); + drawable.setAnimator(this); + } finally { + drawablesLock.unlock(); + } notifyAll(); } public synchronized void remove(GLAutoDrawable drawable) { - ArrayList newList = (ArrayList) drawables.clone(); - newList.remove(drawable); - drawables = newList; - drawable.setAnimator(null); + drawablesLock.lock(); + try { + drawables.remove(drawable); + drawable.setAnimator(null); + } finally { + drawablesLock.unlock(); + } notifyAll(); } @@ -101,8 +110,13 @@ public abstract class AnimatorBase implements GLAnimatorControl { totalFrames++; } - public Iterator drawableIterator() { - return drawables.iterator(); + public List acquireDrawables() { + drawablesLock.lock(); + return drawables; + } + + public void releaseDrawables() { + drawablesLock.unlock(); } public long getCurrentTime() { diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java index e4bf8d711..8f2715e0a 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorImpl.java @@ -44,20 +44,26 @@ class AnimatorImpl { public void display(AnimatorBase animator, boolean ignoreExceptions, boolean printExceptions) { - Iterator iter = animator.drawableIterator(); - while (animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && iter.hasNext()) { - GLAutoDrawable drawable = (GLAutoDrawable) iter.next(); - try { - drawable.display(); - } catch (RuntimeException e) { - if (ignoreExceptions) { - if (printExceptions) { - e.printStackTrace(); + List drawables = animator.acquireDrawables(); + try { + for (int i=0; + animator.isAnimating() && !animator.getShouldStop() && !animator.getShouldPause() && i<drawables.size(); + i++) { + GLAutoDrawable drawable = (GLAutoDrawable) drawables.get(i); + try { + drawable.display(); + } catch (RuntimeException e) { + if (ignoreExceptions) { + if (printExceptions) { + e.printStackTrace(); + } + } else { + throw(e); } - } else { - throw(e); } } + } finally { + animator.releaseDrawables(); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index 04b994198..d9fce6e6a 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -85,7 +85,7 @@ public class ImmModeSink { public void draw(GL gl, boolean disableBufferAfterDraw) { if(DEBUG_DRAW) { - Exception e = new Exception("ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + Exception e = new Exception("Info: ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); e.printStackTrace(); } int n=0; @@ -96,7 +96,7 @@ public class ImmModeSink { public void draw(GL gl, Buffer indices, boolean disableBufferAfterDraw) { if(DEBUG_DRAW) { - Exception e = new Exception("ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + Exception e = new Exception("Info: ImmModeSink.draw(disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); e.printStackTrace(); } int n=0; @@ -107,7 +107,7 @@ public class ImmModeSink { public void glBegin(int mode) { if(DEBUG_BEGIN_END) { - Exception e = new Exception("ImmModeSink.glBegin("+vboSet.mode+"):\n\t"+this); + Exception e = new Exception("Info: ImmModeSink.glBegin("+vboSet.mode+"):\n\t"+this); e.printStackTrace(); } vboSet.modeOrig = mode; @@ -141,7 +141,7 @@ public class ImmModeSink { private void glEnd(GL gl, Buffer indices, boolean immediateDraw) { if(DEBUG_BEGIN_END) { - Exception e = new Exception("ImmModeSink START glEnd(immediate: "+immediateDraw+"):\n\t"+this); + Exception e = new Exception("Info: ImmModeSink START glEnd(immediate: "+immediateDraw+"):\n\t"+this); e.printStackTrace(); } if(immediateDraw) { @@ -328,7 +328,7 @@ public class ImmModeSink { protected void draw(GL gl, Buffer indices, boolean disableBufferAfterDraw, int i) { if(DEBUG_DRAW) { - Exception e = new Exception("ImmModeSink.draw["+i+"](disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); + Exception e = new Exception("Info: ImmModeSink.draw["+i+"](disableBufferAfterDraw: "+disableBufferAfterDraw+"):\n\t"+this); e.printStackTrace(); } enableBuffer(gl, true); diff --git a/src/jogl/classes/com/jogamp/opengl/util/VersionInfo.java b/src/jogl/classes/com/jogamp/opengl/util/VersionInfo.java new file mode 100644 index 000000000..0359ef492 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/VersionInfo.java @@ -0,0 +1,135 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.util; + +import javax.media.opengl.*; +import com.jogamp.common.os.Platform; + +import java.io.IOException; + +public class VersionInfo { + + public static StringBuffer getInfo(StringBuffer sb, String prefix, GL gl) { + if(null==sb) { + sb = new StringBuffer(); + } + + sb.append(Platform.getNewline()); + sb.append("-----------------------------------------------------------------------------------------------------"); + sb.append(Platform.getNewline()); + getPackageInfo(sb, prefix, "javax.media.opengl", "GL"); + sb.append(Platform.getNewline()); + sb.append(Platform.getNewline()); + getPlatformInfo(sb, prefix); + sb.append(Platform.getNewline()); + sb.append(Platform.getNewline()); + getOpenGLInfo(sb, prefix, gl); + sb.append(Platform.getNewline()); + sb.append(Platform.getNewline()); + sb.append("-----------------------------------------------------------------------------------------------------"); + sb.append(Platform.getNewline()); + + return sb; + } + + public static StringBuffer getPlatformInfo(StringBuffer sb, String prefix) { + if(null==sb) { + sb = new StringBuffer(); + } + + sb.append(prefix+" Platform: " + Platform.getOS() + " " + Platform.getOSVersion() + " (os), " + Platform.getArch() + " (arch)"); + sb.append(Platform.getNewline()); + sb.append(prefix+" Platform: littleEndian " + Platform.isLittleEndian() + ", 32Bit "+Platform.is32Bit() + ", a-ptr bit-size "+Platform.getPointerSizeInBits()); + sb.append(Platform.getNewline()); + sb.append(prefix+" Platform: Java " + Platform.getJavaVersion()+", " + +Platform.getJavaVendor()+", "+Platform.getJavaVendorURL()+", is JavaSE: "+Platform.isJavaSE()); + + return sb; + } + + public static StringBuffer getOpenGLInfo(StringBuffer sb, String prefix, GL gl) { + if(null==sb) { + sb = new StringBuffer(); + } + + sb.append(prefix+" Swap Interval " + gl.getSwapInterval()); + sb.append(Platform.getNewline()); + sb.append(prefix+" GL Profile " + gl.getGLProfile()); + sb.append(Platform.getNewline()); + sb.append(prefix+" CTX VERSION " + gl.getContext().getGLVersion()); + sb.append(Platform.getNewline()); + sb.append(prefix+" GL " + gl); + sb.append(Platform.getNewline()); + sb.append(prefix+" GL_VERSION " + gl.glGetString(gl.GL_VERSION)); + sb.append(Platform.getNewline()); + sb.append(prefix+" GL_EXTENSIONS "); + sb.append(Platform.getNewline()); + sb.append(prefix+" " + gl.glGetString(gl.GL_EXTENSIONS)); + + return sb; + } + + public static StringBuffer getPackageInfo(StringBuffer sb, String prefix, + String pkgName, String className) { + try { + ClassLoader classLoader = VersionInfo.class.getClassLoader(); + classLoader.loadClass(pkgName + "." + className); + + if(null==sb) { + sb = new StringBuffer(); + } + + Package p = Package.getPackage(pkgName); + if (p == null) { + sb.append(prefix+" WARNING: Package.getPackage(" + pkgName + ") is null"); + sb.append(Platform.getNewline()); + } + else { + sb.append(prefix+" "+p); + sb.append(Platform.getNewline()); + sb.append(prefix+" Specification Title = " + p.getSpecificationTitle()); + sb.append(Platform.getNewline()); + sb.append(prefix+" Specification Vendor = " + p.getSpecificationVendor()); + sb.append(Platform.getNewline()); + sb.append(prefix+" Specification Version = " + p.getSpecificationVersion()); + sb.append(Platform.getNewline()); + + sb.append(prefix+" Implementation Vendor = " + p.getImplementationVendor()); + sb.append(Platform.getNewline()); + sb.append(prefix+" Implementation Version = " + p.getImplementationVersion()); + } + } + catch (ClassNotFoundException e) { + sb.append(Platform.getNewline()); + sb.append(prefix+" Unable to load " + pkgName); + } + return sb; + } +} + diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java index 5bff710ae..f22e11cb7 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java @@ -67,6 +67,8 @@ import java.text.*; import java.util.*; +import java.security.*; + import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.opengl.glu.gl2.*; @@ -127,7 +129,7 @@ import javax.media.opengl.awt.*; @author Kenneth Russell */ public class TextRenderer { - private static final boolean DEBUG = Debug.debug("TextRenderer"); + private static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.TextRenderer", true, AccessController.getContext()); // These are occasionally useful for more in-depth debugging private static final boolean DISABLE_GLYPH_CACHE = false; diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index a85993c8e..f9f5f8324 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -127,7 +127,7 @@ public abstract class GLDrawableFactory { tmp = (GLDrawableFactory) ReflectionUtil.createInstance(factoryClassName, cl); } catch (JogampRuntimeException jre) { if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); + System.err.println("Info: GLDrawableFactory.static - Native Platform: "+nativeOSType+" - not available: "+factoryClassName); jre.printStackTrace(); } } @@ -139,7 +139,7 @@ public abstract class GLDrawableFactory { tmp = (GLDrawableFactory) ReflectionUtil.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory", cl); } catch (JogampRuntimeException jre) { if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - EGLDrawableFactory - not available"); + System.err.println("Info: GLDrawableFactory.static - EGLDrawableFactory - not available"); jre.printStackTrace(); } } diff --git a/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java index 352545849..590e88ab7 100644 --- a/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java @@ -152,11 +152,11 @@ public class GLPipelineFactory { instance = cstr.newInstance( cstrArgs ) ; } catch (Throwable t) { t.printStackTrace(); } if(null==instance) { - throw new GLException("Couldn't create instance of pipeline: "+upstreamClazz.getName()+ + throw new GLException("Error: Couldn't create instance of pipeline: "+upstreamClazz.getName()+ " ( "+getArgsClassNameList(downstreamClazz, additionalArgs) +" )"); } if( ! (instance instanceof GL) ) { - throw new GLException(upstreamClazz.getName()+" not an instance of GL"); + throw new GLException("Error: "+upstreamClazz.getName()+" not an instance of GL"); } return (GL) instance; } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 287e7a5a9..be5968409 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -37,7 +37,9 @@ package javax.media.opengl; +import com.jogamp.common.jvm.JVMUtil; import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.opengl.util.VersionInfo; import com.jogamp.opengl.impl.Debug; import com.jogamp.opengl.impl.GLDrawableFactoryImpl; import com.jogamp.opengl.impl.GLDynamicLookupHelper; @@ -281,6 +283,7 @@ public class GLProfile { * @see #GL_PROFILE_LIST_ALL */ public static final GLProfile getDefault() { + validateInitialization(); if(null==defaultGLProfile) { throw new GLException("No default profile available"); // should never be reached } @@ -349,6 +352,7 @@ public class GLProfile { public static final GLProfile get(String profile) throws GLException { + validateInitialization(); if(null==profile || profile.equals("GL")) return getDefault(); GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); if(null==glProfile) { @@ -366,6 +370,7 @@ public class GLProfile { public static final GLProfile get(String[] profiles) throws GLException { + validateInitialization(); for(int i=0; i<profiles.length; i++) { String profile = profiles[i]; GLProfile glProfile = (GLProfile) mappedProfiles.get(profile); @@ -851,9 +856,9 @@ public class GLProfile { * Tries the profiles implementation and native libraries. * Throws an GLException if no profile could be found at all. */ - private static void initProfiles() { + private static void initProfiles(boolean firstUIActionOnProcess) { - NativeWindowFactory.initSingleton(); + NativeWindowFactory.initSingleton(firstUIActionOnProcess); ClassLoader classloader = GLProfile.class.getClassLoader(); @@ -898,13 +903,15 @@ public class GLProfile { t=le; } catch (RuntimeException re) { t=re; + } catch (Throwable tt) { + t=tt; } if(DEBUG) { if(null!=t) { t.printStackTrace(); } if(!hasNativeOSFactory) { - System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); + System.err.println("Info: GLProfile.init - Native platform GLDrawable factory not available"); } } @@ -969,41 +976,80 @@ public class GLProfile { mappedProfiles = computeProfileMap(); if (DEBUG) { - System.err.println("GLProfile.static isAWTAvailable "+isAWTAvailable); - System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); - System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); - System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); - System.err.println("GLProfile.static hasGL234Impl "+hasGL234Impl); - System.err.println("GLProfile.static "+glAvailabilityToString()); + System.err.println(VersionInfo.getPackageInfo(null, "GLProfile.init", "javax.media.opengl", "GL")); + System.err.println(VersionInfo.getPlatformInfo(null, "GLProfile.init")); + System.err.println("GLProfile.init firstUIActionOnProcess "+firstUIActionOnProcess); + System.err.println("GLProfile.init isAWTAvailable "+isAWTAvailable); + System.err.println("GLProfile.init hasNativeOSFactory "+hasNativeOSFactory); + System.err.println("GLProfile.init hasDesktopGL "+hasDesktopGL); + System.err.println("GLProfile.init hasDesktopGLES12 "+hasDesktopGLES12); + System.err.println("GLProfile.init hasGL234Impl "+hasGL234Impl); + System.err.println("GLProfile.init "+glAvailabilityToString()); } + } + static { + JVMUtil.initSingleton(); } + static boolean initialized = false; + /** - * Initializes available profiles eagerly. + * Static one time initialization of JOGL. + * <p> + * Applications shall call this methods <b>ASAP</b>, before any other UI invocation.<br> + * You may issue the call in your main function.<br> + * In case applications are able to initialize JOGL before any other UI action,<br> + * they shall invoke this method with <code>firstUIActionOnProcess=true</code> and benefit from fast native multithreading support on all platforms if possible.</P> + * <P> + * RCP Application (Applet's, Webstart, Netbeans, ..) using JOGL may not be able to initialize JOGL + * before the first UI action.<br> + * In such case you shall invoke this method with <code>firstUIActionOnProcess=false</code>.<br> + * On some platforms, notably X11 with AWT usage, JOGL will utilize special locking mechanisms which may slow down your + * application.</P> + * <P> + * Remark: NEWT is currently not affected by this behavior, ie always uses native multithreading.</P> + * <P> + * However, in case this method is not invoked, hence GLProfile is not initialized explicitly by the user,<br> + * the first call to {@link #getDefault()}, {@link #get(java.lang.String)}, etc, will initialize with <code>firstUIActionOnProcess=false</code>,<br> + * hence without the possibility to enable native multithreading.<br> + * This is not the recommended way, since it may has a performance impact, but it allows you to run code without explicit initialization.</P> + * <P> + * In case no explicit initialization was invoked and the implicit initialization didn't happen,<br> + * you may encounter the following exception: + * <pre> + * javax.media.opengl.GLException: No default profile available + * </pre></P> + * + * @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program, + * otherwise <code>false</code>. */ - static { - // run the whole static initialization privileged to speed up, - // since this skips checking further access - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - initProfiles(); - return null; - } - }); + public static synchronized void initSingleton(final boolean firstUIActionOnProcess) { + if(!initialized) { + initialized = true; + // run the whole static initialization privileged to speed up, + // since this skips checking further access + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + initProfiles(firstUIActionOnProcess); + return null; + } + }); - if(null==defaultGLProfile) { - throw new GLException("No profile available: "+array2String(GL_PROFILE_LIST_ALL)+", "+glAvailabilityToString()); + if(null==defaultGLProfile) { + throw new GLException("No profile available: "+array2String(GL_PROFILE_LIST_ALL)+", "+glAvailabilityToString()); + } } } - /** - * It is mandatory to call this methods ASAP, before anything else.<br> - * You may issue the call in your main class static initializer block, or in the static main function.<br> - * This will kick off JOGL's static initialization.<br> - * It is essential to do this at the very beginning, so JOGL has a chance to initialize multithreading support.<br> - */ - public static void initSingleton() { + private static void validateInitialization() { + if(!initialized) { + synchronized(GLProfile.class) { + if(!initialized) { + initSingleton(false); + } + } + } } private static final String array2String(String[] list) { @@ -1028,17 +1074,17 @@ public class GLProfile { GLProfile glProfile = new GLProfile(profile, profileImpl); _mappedProfiles.put(profile, glProfile); if (DEBUG) { - System.err.println("GLProfile.static map "+glProfile); + System.err.println("GLProfile.init map "+glProfile); } if(null==defaultGLProfile) { defaultGLProfile=glProfile; if (DEBUG) { - System.err.println("GLProfile.static default "+glProfile); + System.err.println("GLProfile.init default "+glProfile); } } } else { if (DEBUG) { - System.err.println("GLProfile.static map *** no mapping for "+profile); + System.err.println("GLProfile.init map *** no mapping for "+profile); } } } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 60ed731f1..4ac21204f 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -45,7 +45,6 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.awt.*; import com.jogamp.opengl.impl.*; -import com.jogamp.nativewindow.impl.jawt.JAWTUtil; import java.awt.Canvas; import java.awt.Color; @@ -54,7 +53,6 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; -import java.awt.Container; import java.awt.Window; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; @@ -79,9 +77,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { private static final GLProfile defaultGLProfile; static { - NativeWindowFactory.initSingleton(); - defaultGLProfile = GLProfile.getDefault(); DEBUG = Debug.debug("GLCanvas"); + defaultGLProfile = GLProfile.getDefault(); } private GLProfile glProfile; @@ -234,7 +231,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; boolean equalCaps = config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities()); if(DEBUG) { - Exception e = new Exception("Call Stack: "+Thread.currentThread().getName()); + Exception e = new Exception("Info: Call Stack: "+Thread.currentThread().getName()); e.printStackTrace(); System.err.println("!!! Created Config (n): HAVE GC "+chosen); System.err.println("!!! Created Config (n): THIS GC "+gc); @@ -313,7 +310,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { protected void dispose(boolean regenerate) { if(DEBUG) { - Exception ex1 = new Exception("dispose("+regenerate+") - start"); + Exception ex1 = new Exception("Info: dispose("+regenerate+") - start"); ex1.printStackTrace(); } @@ -381,7 +378,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { (int) ((getHeight() + bounds.getHeight()) / 2)); return; } - if( this.drawableHelper.isExternalAnimatorAnimating() ) { + if( ! this.drawableHelper.isExternalAnimatorAnimating() ) { display(); } } @@ -408,11 +405,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { /* * Save the chosen capabilities for use in getGraphicsConfiguration(). */ - JAWTUtil.lockToolkit(); + NativeWindowFactory.getDefaultToolkitLock().lock(); try { awtConfig = chooseGraphicsConfiguration(capabilities, chooser, device); if(DEBUG) { - Exception e = new Exception("Created Config: "+awtConfig); + Exception e = new Exception("Info: Created Config: "+awtConfig); e.printStackTrace(); } if(null!=awtConfig) { @@ -427,7 +424,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { context = (GLContextImpl) drawable.createContext(shareWith); context.setSynchronized(true); } finally { - JAWTUtil.unlockToolkit(); + NativeWindowFactory.getDefaultToolkitLock().unlock(); } if(DEBUG) { @@ -446,7 +443,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { <DL><DD><CODE>removeNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ public void removeNotify() { if(DEBUG) { - Exception ex1 = new Exception("removeNotify - start"); + Exception ex1 = new Exception("Info: removeNotify - start"); ex1.printStackTrace(); } @@ -461,7 +458,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { } } if(DEBUG) { - System.out.println("removeNotify - end"); + System.err.println("Info: removeNotify - end"); } } @@ -580,7 +577,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { } public String toString() { - return "AWT-GLCanvas[ "+awtConfig+", "+((null!=drawable)?drawable.getClass().getName():"null-drawable")+", "+drawableHelper+"]"; + return "AWT-GLCanvas[ "+awtConfig+", "+((null!=drawable)?drawable.getClass().getName():"null-drawable")+"]"; } //---------------------------------------------------------------------- diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index e4a295ba3..192695955 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -138,8 +138,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { private int viewportY; static { - NativeWindowFactory.initSingleton(); - // Force eager initialization of part of the Java2D class since // otherwise it's likely it will try to be initialized while on // the Queue Flusher Thread, which is not allowed @@ -212,7 +210,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { protected void dispose(boolean regenerate) { if(DEBUG) { - Exception ex1 = new Exception("dispose("+regenerate+") - start"); + Exception ex1 = new Exception("Info: dispose("+regenerate+") - start"); ex1.printStackTrace(); } if (backend != null) { @@ -287,10 +285,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return; } - if ( drawableHelper.isExternalAnimatorAnimating() ) { - return; - } - if (backend == null || !isInitialized) { createAndInitializeBackend(); } @@ -334,7 +328,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { <DL><DD><CODE>removeNotify</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ public void removeNotify() { if(DEBUG) { - Exception ex1 = new Exception("removeNotify - start"); + Exception ex1 = new Exception("Info: removeNotify - start"); ex1.printStackTrace(); } dispose(false); @@ -345,7 +339,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { isInitialized = false; super.removeNotify(); if(DEBUG) { - System.out.println("removeNotify - end"); + System.err.println("Info: removeNotify - end"); } } @@ -617,7 +611,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { } public String toString() { - return "AWT-GLJPanel[ "+((null!=backend)?backend.getDrawable().getClass().getName():"null-drawable")+", "+drawableHelper+"]"; + return "AWT-GLJPanel[ "+((null!=backend)?backend.getDrawable().getClass().getName():"null-drawable")+"]"; } private boolean disposeRegenerate; @@ -1034,7 +1028,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { } catch (GLException e) { if (DEBUG) { e.printStackTrace(); - System.err.println("GLJPanel: Falling back on software rendering because of problems creating pbuffer"); + System.err.println("Info: GLJPanel: Falling back on software rendering because of problems creating pbuffer"); } hardwareAccelerationDisabled = true; backend = null; @@ -1111,7 +1105,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { readBackWidthInPixels = Math.max(1, panelWidth); readBackHeightInPixels = Math.max(1, panelHeight); if (DEBUG) { - System.err.println("WARNING: falling back to software rendering due to bugs in OpenGL drivers"); + System.err.println("Warning: falling back to software rendering due to bugs in OpenGL drivers"); e.printStackTrace(); } createAndInitializeBackend(); |