diff options
author | Sven Gothel <[email protected]> | 2010-04-13 21:24:44 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-04-13 21:24:44 +0200 |
commit | 2df3bea10859ee2f2c4b3622f3b610b17a5749d6 (patch) | |
tree | 9bb948241aef06fdaf1dd4d09f1b31989c76f858 /src/jogl/classes/com/jogamp/opengl/impl/x11/glx | |
parent | 1c1053c6a8b669c067ae1316b9770871e213ea05 (diff) |
ATI (fglrx) PBuffer/X11Display bug workaround/cleanup
- See https://bugzilla.mozilla.org/show_bug.cgi?id=486277
- Description:
- To use PBuffer, a context must be current
- X11Display cannot be switched while using the PBuffer
[within one thread]. Hence we shall try harder to reuse
_the_ user configured X11Display - whenever possible.
This is actually a good thing, ie cleanup up our
code again.
- Changes to workaround/cleanup:
- GLDrawableFactory* methods 'canCreate*()'
are changed to 'canCreate*(AbstractGraphicsDevice)'
to allow pipelining the X11Display.
This reduces the overhead of using a local TLS X11Display.
- WindowsDummyWGLDrawable cstr gets the GLProfile as a parameter now,
this is done while adding X11DummyGLXDrawable - forseeing the
usecase to query available GLProfiles at startup.
- X11DummyGLXDrawable added, following the WindowsDummyWGLDrawable path
to have a dummy GLContext current to fix the ATI bug.
NativeWindow X11:
- Add XIOErrorHandler to identify the fatal failure
of closing a Display (-> ATI bug).
Build:
- Adding ant.jar and ant-junit.jar to the junit compile/run classpath
-
Misc:
- Fix: CreateDummyWindow(..) returns a HWND, not a HDC
- mapToRealGLFunctionName: Added mapping for X11/GLX.
- X11GLXGraphicsConfigurationFactory: Uncommented dead code 'createDefaultGraphicsConfigurationFBConfig'
Tests: Passed (Linux64bit: NVidia/ATI)
Todo: More tests on ATI, especially multithreading/X11Display usage.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/x11/glx')
4 files changed, 158 insertions, 42 deletions
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 new file mode 100644 index 000000000..097689967 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11DummyGLXDrawable.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010 Sven Gothel. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name Sven Gothel or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.opengl.impl.x11.glx; + +import javax.media.opengl.*; +import com.jogamp.opengl.impl.*; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; +import com.jogamp.nativewindow.impl.*; +import com.jogamp.nativewindow.impl.x11.*; + +public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable { + + /** + * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, + * we cannot switch the Display as we please, + * hence we reuse the target's screen configuration. + */ + public X11DummyGLXDrawable(X11GraphicsScreen screen, GLDrawableFactory factory, GLProfile glp) { + super(factory, + new NullWindow(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + new GLCapabilities(glp), null, screen))); + this.realized = true; + + NullWindow nw = (NullWindow) getNativeWindow(); + X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)nw.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilities caps = (GLCapabilities) config.getChosenCapabilities(); + + long dpy = config.getScreen().getDevice().getHandle(); + int scrn = config.getScreen().getIndex(); + // System.out.println("X11DummyGLXDrawable: dpy "+toHexString(dpy)+", scrn "+scrn); + X11Lib.XLockDisplay(dpy); + try{ + nw.setSurfaceHandle( X11Lib.RootWindow(dpy, scrn) ); + } finally { + X11Lib.XUnlockDisplay(dpy); + } + } + + public void setSize(int width, int height) { + } + + public int getWidth() { + return 1; + } + + public int getHeight() { + return 1; + } + + public void destroy() { + // nothing to do, but allowed + } +} 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 ce846c0a4..055e7236c 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 @@ -54,6 +54,7 @@ public abstract class X11GLXContext extends GLContextImpl { private boolean glXQueryExtensionsStringInitialized; private boolean glXQueryExtensionsStringAvailable; private static final Map/*<String, String>*/ functionNameMap; + private static final Map/*<String, String>*/ extensionNameMap; private GLXExt glXExt; // Table that holds the addresses of the native C-language entry points for // GLX extension functions. @@ -63,6 +64,10 @@ public abstract class X11GLXContext extends GLContextImpl { functionNameMap = new HashMap(); functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV"); functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV"); + + extensionNameMap = new HashMap(); + extensionNameMap.put("GL_ARB_pbuffer", "GLX_SGIX_pbuffer"); + extensionNameMap.put("GL_ARB_pixel_format", "GLX_SGIX_pbuffer"); // good enough } public X11GLXContext(GLDrawableImpl drawable, GLDrawableImpl drawableRead, @@ -94,17 +99,9 @@ public abstract class X11GLXContext extends GLContextImpl { return glXExt; } - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } + protected Map/*<String, String>*/ getFunctionNameMap() { return functionNameMap; } - protected String mapToRealGLExtensionName(String glExtensionName) { - return glExtensionName; - } + protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; } /** Helper routine which usually just turns around and calls * createContext (except for pbuffers, which use a different context @@ -363,7 +360,7 @@ public abstract class X11GLXContext extends GLContextImpl { drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), context)) { - throw new GLException("Error making context current"); + throw new GLException("Error making context current: "+this); } if (DEBUG && (VERBOSE || created)) { System.err.println(getThreadName() + ": glXMakeCurrent(display " + @@ -485,7 +482,8 @@ public abstract class X11GLXContext extends GLContextImpl { public boolean isExtensionAvailable(String glExtensionName) { if (glExtensionName.equals("GL_ARB_pbuffer") || glExtensionName.equals("GL_ARB_pixel_format")) { - return getGLDrawable().getFactory().canCreateGLPbuffer(); + return getGLDrawable().getFactory().canCreateGLPbuffer( + drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice() ); } return super.isExtensionAvailable(glExtensionName); } 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 1a254843e..60ee431dc 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 @@ -73,14 +73,29 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return new X11OffscreenGLXDrawable(this, target); } - private boolean pbufferSupportInitialized = false; - private boolean canCreateGLPbuffer = false; - public boolean canCreateGLPbuffer() { - if (!pbufferSupportInitialized) { - long display = X11Util.getThreadLocalDefaultDisplay(); + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + return glxVersionGreaterEqualThan(device, 1, 3); + } + + private boolean glxVersionsQueried = false; + private int glxVersionMajor=0, glxVersionMinor=0; + public boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) { + if (!glxVersionsQueried) { + if(null == device) { + GLContext ctx = GLContext.getCurrent(); + if( null != ctx) { + device = ctx.getGLDrawable().getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + } + } + if(null == device) { + GLException gle = new GLException("FIXME: No AbstractGraphicsDevice (passed or queried via current context - Fallback to ThreadLocal Display .."); + gle.printStackTrace(); + + device = new X11GraphicsDevice(X11Util.getThreadLocalDisplay(null)); + } + long display = device.getHandle(); int[] major = new int[1]; int[] minor = new int[1]; - int screen = 0; // FIXME: provide way to specify this? if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) { throw new GLException("glXQueryVersion failed"); @@ -94,34 +109,51 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna // only implement GLX version 1.2 on the server side if (major[0] == 1 && minor[0] == 2) { String str = GLX.glXGetClientString(display, GLX.GLX_VERSION); - if (str != null && str.startsWith("1.") && - (str.charAt(2) >= '3')) { - canCreateGLPbuffer = true; + try { + major[0] = Integer.valueOf(str.substring(0, 1)).intValue(); + minor[0] = Integer.valueOf(str.substring(2, 3)).intValue(); + } catch (NumberFormatException nfe) { + major[0] = 1; + minor[0] = 2; } - } else { - canCreateGLPbuffer = ((major[0] > 1) || (minor[0] > 2)); } - pbufferSupportInitialized = true; + glxVersionMajor = major[0]; + glxVersionMinor = minor[0]; + glxVersionsQueried = true; } - return canCreateGLPbuffer; + return ( glxVersionMajor > majorReq ) || ( glxVersionMajor == majorReq && glxVersionMinor >= minorReq ) ; } protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { + GLDrawableImpl pbufferDrawable; + X11DummyGLXDrawable dummyDrawable=null; + GLContext dummyContext=null; + /** - * FIXME: Think about this .. - * should not be necessary ? .. - final List returnList = new ArrayList(); - final GLDrawableFactory factory = this; - Runnable r = new Runnable() { - public void run() { - returnList.add(new X11PbufferGLXDrawable(factory, target)); + * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, + * we need to have a context current on the same Display to create a PBuffer. + * The dummy context shall also use the same Display, + * since switching Display in this regard is another ATI bug. + */ + if( null == GLContext.getCurrent() ) { + X11GraphicsScreen screen = (X11GraphicsScreen) target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen(); + dummyDrawable = new X11DummyGLXDrawable(screen, this, null); + dummyContext = dummyDrawable.createContext(null); + dummyContext.makeCurrent(); + } + try { + pbufferDrawable = new X11PbufferGLXDrawable(this, target); + } finally { + if(null!=dummyContext) { + dummyContext.release(); + dummyContext.destroy(); } - }; - maybeDoSingleThreadedWorkaround(r); - return (GLDrawableImpl) returnList.get(0); - */ - return new X11PbufferGLXDrawable(this, target); + if(null!=dummyDrawable) { + dummyDrawable.destroy(); + } + } + return pbufferDrawable; } @@ -136,8 +168,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return X11ExternalGLXContext.create(this, null); } - public boolean canCreateExternalGLDrawable() { - return canCreateGLPbuffer(); + public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + return canCreateGLPbuffer(device); } public GLDrawable createExternalGLDrawable() { @@ -158,7 +190,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl implements Dyna return res; } - public boolean canCreateContextOnJava2DSurface() { + public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } 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 16e341652..72551f928 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 @@ -59,7 +59,8 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac return chooseGraphicsConfigurationStatic(capabilities, chooser, absScreen); } - protected static X11GLXGraphicsConfiguration createDefaultGraphicsConfiguration(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { + /** + protected static X11GLXGraphicsConfiguration createDefaultGraphicsConfigurationFBConfig(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { if (absScreen == null) { throw new IllegalArgumentException("AbstractGraphicsScreen is null"); } @@ -110,7 +111,7 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac } return new X11GLXGraphicsConfiguration(x11Screen, (null!=capsFB)?capsFB:caps, caps, null, xvis, fbcfg, fbid); - } + } */ protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationStatic(Capabilities capabilities, CapabilitiesChooser chooser, |