From 8f76db4364f66c36780e762e086a18d5cc315363 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 11 Oct 2009 07:41:31 -0700 Subject: NEWT X11 Display Lock: Integrate Display.lock/unlock, so the generic Window will call it. Specialized for X11Display, the only real impl of it. Fixes offscreen EDT usage .. GLProfile: Add isAWTAvailable() and isAWTJOGLAvailable() TextureIO: - Add NetPbmTextureWriter - Only use IIOTexture* if !isAWTJOGLAvailable() - Add write (TextureData, File) --- .../com/sun/opengl/impl/x11/glx/X11GLXContext.java | 33 ++++++++++++- .../opengl/impl/x11/glx/X11OnscreenGLXContext.java | 31 ------------ src/jogl/classes/com/sun/opengl/util/Animator.java | 15 ++++-- .../util/texture/TextureIO.java.javame_cdc_fp | 51 +++++++++++--------- .../sun/opengl/util/texture/TextureIO.java.javase | 55 +++++++++++++--------- .../util/texture/spi/NetPbmTextureWriter.java | 24 ++++++---- src/jogl/classes/javax/media/opengl/GLProfile.java | 17 +++++++ .../media/nativewindow/NativeWindowFactory.java | 2 +- src/newt/classes/com/sun/javafx/newt/Display.java | 6 +++ src/newt/classes/com/sun/javafx/newt/Window.java | 2 + .../com/sun/javafx/newt/x11/X11Display.java | 7 +-- .../classes/com/sun/javafx/newt/x11/X11Window.java | 21 +-------- 12 files changed, 151 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java index 42b0f2a5f..84f32d43e 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java @@ -296,7 +296,38 @@ public abstract class X11GLXContext extends GLContextImpl { GLContextShareSet.contextCreated(this); } + // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] protected int makeCurrentImpl() throws GLException { + int lockRes = drawable.lockSurface(); + boolean exceptionOccurred = false; + try { + if (lockRes == NativeWindow.LOCK_SURFACE_NOT_READY) { + return CONTEXT_NOT_CURRENT; + } + return makeCurrentImplAfterLock(); + } catch (RuntimeException e) { + exceptionOccurred = true; + throw e; + } finally { + if (exceptionOccurred || + (isOptimizable() && lockRes != NativeWindow.LOCK_SURFACE_NOT_READY) && drawable.isSurfaceLocked()) { + drawable.unlockSurface(); + } + } + } + + // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] + protected void releaseImpl() throws GLException { + try { + releaseImplAfterLock(); + } finally { + if (!isOptimizable() && drawable.isSurfaceLocked()) { + drawable.unlockSurface(); + } + } + } + + protected int makeCurrentImplAfterLock() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { if (drawable.getNativeWindow().getSurfaceHandle() == 0) { @@ -341,7 +372,7 @@ public abstract class X11GLXContext extends GLContextImpl { } } - protected void releaseImpl() throws GLException { + protected void releaseImplAfterLock() throws GLException { getDrawableImpl().getFactoryImpl().lockToolkit(); try { if (!GLX.glXMakeContextCurrent(drawable.getNativeWindow().getDisplayHandle(), 0, 0, 0)) { diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java index c37ddd49c..a73b41146 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java @@ -57,37 +57,6 @@ public class X11OnscreenGLXContext extends X11GLXContext { super(drawable, shareWith); } - // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] - protected int makeCurrentImpl() throws GLException { - int lockRes = drawable.lockSurface(); - boolean exceptionOccurred = false; - try { - if (lockRes == NativeWindow.LOCK_SURFACE_NOT_READY) { - return CONTEXT_NOT_CURRENT; - } - return super.makeCurrentImpl(); - } catch (RuntimeException e) { - exceptionOccurred = true; - throw e; - } finally { - if (exceptionOccurred || - (isOptimizable() && lockRes != NativeWindow.LOCK_SURFACE_NOT_READY) && drawable.isSurfaceLocked()) { - drawable.unlockSurface(); - } - } - } - - // Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] - protected void releaseImpl() throws GLException { - try { - super.releaseImpl(); - } finally { - if (!isOptimizable() && drawable.isSurfaceLocked()) { - drawable.unlockSurface(); - } - } - } - public boolean isOptimizable() { return super.isOptimizable() && !isIndirect; } diff --git a/src/jogl/classes/com/sun/opengl/util/Animator.java b/src/jogl/classes/com/sun/opengl/util/Animator.java index a10717881..1d4b832e8 100755 --- a/src/jogl/classes/com/sun/opengl/util/Animator.java +++ b/src/jogl/classes/com/sun/opengl/util/Animator.java @@ -43,6 +43,8 @@ import java.util.*; import javax.media.opengl.*; +import com.sun.opengl.impl.Debug; + /**

An Animator can be attached to one or more {@link GLAutoDrawable}s to drive their display() methods in a loop.

@@ -53,7 +55,7 @@ import javax.media.opengl.*; */ public class Animator { - protected static final boolean DEBUG = com.sun.opengl.impl.Debug.debug("Animator"); + protected static final boolean DEBUG = Debug.debug("Animator"); private volatile ArrayList/**/ drawables = new ArrayList(); private AnimatorImpl impl; @@ -67,10 +69,13 @@ public class Animator { /** Creates a new, empty Animator. */ public Animator(ThreadGroup tg) { - try { - // Try to use the AWT-capable Animator implementation by default - impl = (AnimatorImpl) Class.forName("com.sun.opengl.util.awt.AWTAnimatorImpl").newInstance(); - } catch (Exception e) { + + if(GLProfile.isAWTJOGLAvailable()) { + try { + impl = (AnimatorImpl) Class.forName("com.sun.opengl.util.awt.AWTAnimatorImpl").newInstance(); + } catch (Exception e) { } + } + if(null==impl) { impl = new AnimatorImpl(); } threadGroup = tg; diff --git a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp index 1f6b89c7e..e7c80678f 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp +++ b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javame_cdc_fp @@ -640,6 +640,10 @@ public class TextureIO { } } + write(data, file); + } + + public static void write(TextureData data, File file) throws IOException, GLException { for (Iterator iter = textureWriters.iterator(); iter.hasNext(); ) { TextureWriter writer = (TextureWriter) iter.next(); if (writer.write(file, data)) { @@ -647,9 +651,9 @@ public class TextureIO { } } - throw new IOException("No suitable texture writer found"); + throw new IOException("No suitable texture writer found for "+file.getAbsolutePath()); } - + //---------------------------------------------------------------------- // SPI support // @@ -710,15 +714,17 @@ public class TextureIO { static { /* - // ImageIO provider, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureProvider provider = (TextureProvider) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); - addTextureProvider(provider); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + // ImageIO provider, the fall-back, must be the first one added + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureProvider provider = (TextureProvider) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); + addTextureProvider(provider); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } } } */ @@ -730,14 +736,16 @@ public class TextureIO { /* // ImageIO writer, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureWriter writer = (TextureWriter) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); - addTextureWriter(writer); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureWriter writer = (TextureWriter) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); + addTextureWriter(writer); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } } } */ @@ -746,6 +754,7 @@ public class TextureIO { addTextureWriter(new DDSTextureWriter()); addTextureWriter(new SGITextureWriter()); addTextureWriter(new TGATextureWriter()); + addTextureWriter(new NetPbmTextureWriter()); } // Implementation methods @@ -772,7 +781,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given file"); + throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); } private static TextureData newTextureDataImpl(InputStream stream, @@ -829,7 +838,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given URL"); + throw new IOException("No suitable reader for given URL "+url); } //---------------------------------------------------------------------- diff --git a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase index 2b2f123a0..556d51343 100755 --- a/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase +++ b/src/jogl/classes/com/sun/opengl/util/texture/TextureIO.java.javase @@ -640,6 +640,10 @@ public class TextureIO { } } + write(data, file); + } + + public static void write(TextureData data, File file) throws IOException, GLException { for (Iterator iter = textureWriters.iterator(); iter.hasNext(); ) { TextureWriter writer = (TextureWriter) iter.next(); if (writer.write(file, data)) { @@ -647,7 +651,7 @@ public class TextureIO { } } - throw new IOException("No suitable texture writer found"); + throw new IOException("No suitable texture writer found for "+file.getAbsolutePath()); } //---------------------------------------------------------------------- @@ -710,14 +714,16 @@ public class TextureIO { static { // ImageIO provider, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureProvider provider = (TextureProvider) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); - addTextureProvider(provider); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureProvider provider = (TextureProvider) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); + addTextureProvider(provider); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } } } @@ -727,18 +733,20 @@ public class TextureIO { addTextureProvider(new TGATextureProvider()); // ImageIO writer, the fall-back, must be the first one added - try { - // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureWriter writer = (TextureWriter) - Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); - addTextureWriter(writer); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); - } - } catch (Error e) { - if (DEBUG) { - e.printStackTrace(); + if(GLProfile.isAWTJOGLAvailable()) { + try { + // Use reflection to avoid compile-time dependencies on AWT-related classes + TextureWriter writer = (TextureWriter) + Class.forName("com.sun.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); + addTextureWriter(writer); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } + } catch (Error e) { + if (DEBUG) { + e.printStackTrace(); + } } } @@ -746,6 +754,7 @@ public class TextureIO { addTextureWriter(new DDSTextureWriter()); addTextureWriter(new SGITextureWriter()); addTextureWriter(new TGATextureWriter()); + addTextureWriter(new NetPbmTextureWriter()); } // Implementation methods @@ -772,7 +781,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given file"); + throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); } private static TextureData newTextureDataImpl(InputStream stream, @@ -829,7 +838,7 @@ public class TextureIO { } } - throw new IOException("No suitable reader for given URL"); + throw new IOException("No suitable reader for given URL "+url); } //---------------------------------------------------------------------- diff --git a/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java b/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java index f771e0a3d..18df1dc55 100644 --- a/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java +++ b/src/jogl/classes/com/sun/opengl/util/texture/spi/NetPbmTextureWriter.java @@ -58,7 +58,7 @@ public class NetPbmTextureWriter implements TextureWriter { /** * supported magic values are:
*
-     *   magic 0 - auto
+     *   magic 0 - detect by file suffix (TextureIO compliant)
      *   magic 6 - PPM binary RGB
      *   magic 7 - PAM binary RGB or RGBA
      * 
@@ -77,13 +77,25 @@ public class NetPbmTextureWriter implements TextureWriter { public int getMagic() { return magic; } - public static String getPPMSuffix() { return "ppm"; } - public static String getPAMSuffix() { return "pam"; } + public static final String PPM = "ppm"; + public static final String PAM = "pam"; - public String getSuffix() { return (magic==6)?getPPMSuffix():getPAMSuffix(); } + public String getSuffix() { return (magic==6)?PPM:PAM; } public boolean write(File file, TextureData data) throws IOException { + + // file suffix selection + if (0==magic) { + if (PPM.equals(FileUtil.getFileSuffix(file))) { + magic = 6; + } else if (PAM.equals(FileUtil.getFileSuffix(file))) { + magic = 7; + } else { + return false; + } + } + int pixelFormat = data.getPixelFormat(); int pixelType = data.getPixelType(); if ((pixelFormat == GL.GL_RGB || @@ -93,10 +105,6 @@ public class NetPbmTextureWriter implements TextureWriter { int comps = ( pixelFormat == GL.GL_RGBA ) ? 4 : 3 ; - if(0==magic) { - magic = ( comps == 4 ) ? 7 : 6 ; - } - if(magic==6 && comps==4) { throw new IOException("NetPbmTextureWriter magic 6 (PPM) doesn't RGBA pixel format, use magic 7 (PAM)"); } diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 756c80009..abb6ca4f3 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -605,6 +605,9 @@ public class GLProfile implements Cloneable { // This is here only to avoid having separate GL2ES1Impl and GL2ES2Impl classes private static final String GL2ES12 = "GL2ES12"; + private static final boolean isAWTAvailable; + private static final boolean isAWTJOGLAvailable; + private static final boolean hasGL3Impl; private static final boolean hasGL2Impl; private static final boolean hasGL2ES12Impl; @@ -624,6 +627,15 @@ public class GLProfile implements Cloneable { static { JVMUtil.initSingleton(); + AccessControlContext acc = AccessController.getContext(); + + isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) && + NWReflection.isClassAvailable("java.awt.Component") ; + + isAWTJOGLAvailable = isAWTAvailable && + NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") && // NativeWindow + NWReflection.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL + boolean hasDesktopGL = false; boolean hasDesktopGLES12 = false; boolean hasNativeOSFactory = false; @@ -711,6 +723,8 @@ public class GLProfile implements Cloneable { hasGLES1Impl = btest; if (DEBUG) { + System.err.println("GLProfile.static isAWTAvailable "+isAWTAvailable); + System.err.println("GLProfile.static isAWTJOGLAvailable "+isAWTJOGLAvailable); System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); @@ -799,6 +813,9 @@ public class GLProfile implements Cloneable { return null; } + public static boolean isAWTAvailable() { return isAWTAvailable; } + public static boolean isAWTJOGLAvailable() { return isAWTJOGLAvailable; } + public static String getGLTypeName(int type) { switch (type) { case GL.GL_UNSIGNED_BYTE: diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 0710bc24c..cd89e2164 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -131,7 +131,7 @@ public abstract class NativeWindowFactory { } boolean toolkitLockForced = Debug.getBooleanProperty("nativewindow.locking", true, acc); - boolean awtToolkitLockDisabled = Debug.getBooleanProperty("java.awt.headless", false, acc) || + boolean awtToolkitLockDisabled = Debug.getBooleanProperty("java.awt.headless", true, acc) || Debug.getBooleanProperty("nativewindow.nolocking", true, acc) ; NativeWindowFactory _factory = null; diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java index ad4664ac8..97d5465c9 100755 --- a/src/newt/classes/com/sun/javafx/newt/Display.java +++ b/src/newt/classes/com/sun/javafx/newt/Display.java @@ -261,6 +261,12 @@ public abstract class Display { protected abstract void dispatchMessages(); + /** Default impl. nop - Currently only X11 needs a Display lock */ + protected void lockDisplay() { } + + /** Default impl. nop - Currently only X11 needs a Display lock */ + protected void unlockDisplay() { } + protected EventDispatchThread eventDispatchThread = null; protected String name; protected int refCount; diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java index b9d8bde42..8260b1a16 100755 --- a/src/newt/classes/com/sun/javafx/newt/Window.java +++ b/src/newt/classes/com/sun/javafx/newt/Window.java @@ -286,6 +286,7 @@ public abstract class Window implements NativeWindow } owner = cur; lockedStack = new Exception("NEWT Surface previously locked by "+Thread.currentThread()); + screen.getDisplay().lockDisplay(); return LOCK_SUCCESS; } @@ -302,6 +303,7 @@ public abstract class Window implements NativeWindow } owner = null; lockedStack = null; + screen.getDisplay().unlockDisplay(); notifyAll(); // We leave the ToolkitLock unlock to the specializtion's discretion, // ie the implicit JAWTWindow in case of AWTWindow diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java index 297f98edb..ae23c4423 100755 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java @@ -84,17 +84,18 @@ public class X11Display extends Display { DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); } - protected long getJavaObjectAtom() { return javaObjectAtom; } - protected long getWindowDeleteAtom() { return windowDeleteAtom; } - protected void lockDisplay() { + super.lockDisplay(); LockDisplay(getHandle()); } protected void unlockDisplay() { UnlockDisplay(getHandle()); + super.unlockDisplay(); } + protected long getJavaObjectAtom() { return javaObjectAtom; } + protected long getWindowDeleteAtom() { return windowDeleteAtom; } //---------------------------------------------------------------------- // Internals only diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java index 94eb98299..f46ae9564 100755 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java @@ -71,7 +71,7 @@ public class X11Window extends Window { } protected void closeNative() { - if(0!=displayHandleClose && 0!=windowHandleClose) { + if(0!=displayHandleClose && 0!=windowHandleClose && null!=getScreen() ) { X11Display display = (X11Display) getScreen().getDisplay(); CloseWindow(displayHandleClose, windowHandleClose, display.getJavaObjectAtom()); windowHandleClose = 0; @@ -85,25 +85,6 @@ public class X11Window extends Window { super.windowDestroyed(); } - public synchronized int lockSurface() throws NativeWindowException { - int res = super.lockSurface(); - if(LOCK_SUCCESS == res) { - ((X11Display)(screen.getDisplay())).lockDisplay(); - } - return res; - } - - public synchronized void unlockSurface() { - // prevalidate, before we change data .. - Thread cur = Thread.currentThread(); - if ( getSurfaceLockOwner() != cur ) { - getLockedStack().printStackTrace(); - throw new NativeWindowException(cur+": Not owner, owner is "+getSurfaceLockOwner()); - } - ((X11Display)(screen.getDisplay())).unlockDisplay(); - super.unlockSurface(); - } - public void setVisible(boolean visible) { if(0!=windowHandle && this.visible!=visible) { this.visible=visible; -- cgit v1.2.3