diff options
author | Sven Gothel <[email protected]> | 2012-02-25 19:21:43 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-25 19:21:43 +0100 |
commit | aee3a75ad87ef3da0652c6b917ccdfda63a1230d (patch) | |
tree | 087637968ca3e1a6bf81a92e7dfaaef2cceb9ada | |
parent | 9db2d90e5398e7b2abe45f0799a9d00729575b49 (diff) |
X11: Fix unavailable GLX (Server): Use fallback GraphicsConfigurationFactory (X11GLX -> X11)
- GraphicsConfigurationFactory.registerFactory(..) returns previous mapped GraphicsConfigurationFactory.
This allows daisy chaining of GraphicsConfigurationFactory, in case one is not suitable.
- X11GLXGraphicsConfigurationFactory:
- Store the previously mapped factory as fallback
- choose*Impl(): If GLX is not available, use fallback
4 files changed, 35 insertions, 21 deletions
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java index 8b90d6887..7d03bbb88 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/GLXUtil.java @@ -43,6 +43,20 @@ import com.jogamp.common.util.VersionNumber; public class GLXUtil { public static final boolean DEBUG = Debug.debug("GLXUtil"); + public static synchronized boolean isGLXAvailableOnServer(X11GraphicsDevice x11Device) { + if(null == x11Device) { + throw new IllegalArgumentException("null X11GraphicsDevice"); + } + if(0 == x11Device.getHandle()) { + throw new IllegalArgumentException("null X11GraphicsDevice display handle"); + } + boolean glXAvailable = false; + try { + glXAvailable = GLX.glXQueryExtension(x11Device.getHandle(), null, 0, null, 0); + } catch (Throwable t) { /* n/a */ } + return glXAvailable; + } + public static VersionNumber getGLXServerVersionNumber(long display) { int[] major = new int[1]; int[] minor = new int[1]; @@ -92,17 +106,6 @@ public class GLXUtil { return clientVersionNumber; } - public static synchronized boolean isGLXAvailable(long handle) { - if(0 == handle) { - throw new IllegalArgumentException("null X11 display handle"); - } - boolean glXAvailable = false; - try { - glXAvailable = GLX.glXQueryExtension(handle, null, 0, null, 0); - } catch (Throwable t) { /* n/a */ } - return glXAvailable; - } - public static synchronized void initGLXClientDataSingleton(X11GraphicsDevice x11Device) { if(null != clientVendorName) { return; // already initialized diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index 2ba067b02..55d0e9400 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -220,8 +220,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { // NativeWindowFactory.getNullToolkitLock(), true); // own non-shared display connection, no locking sharedDevice.lock(); try { - if(!GLXUtil.isGLXAvailable(sharedDevice.getHandle())) { - throw new GLException("GLX not available on device: "+sharedDevice); + if(!GLXUtil.isGLXAvailableOnServer(sharedDevice)) { + throw new GLException("GLX not available on device/server: "+sharedDevice); } GLXUtil.initGLXClientDataSingleton(sharedDevice); final String glXServerVendorName = GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_VENDOR); diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 344c56f64..e77cba9d0 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -52,7 +52,6 @@ import javax.media.opengl.GLProfile; import com.jogamp.common.nio.PointerBuffer; import jogamp.nativewindow.x11.X11Lib; import jogamp.nativewindow.x11.XVisualInfo; -import jogamp.opengl.Debug; import jogamp.opengl.GLGraphicsConfigurationFactory; import jogamp.opengl.GLGraphicsConfigurationUtil; @@ -67,11 +66,10 @@ import java.util.List; GraphicsDevice and GraphicsConfiguration abstractions. */ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory { - protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); static X11GLCapabilities.XVisualIDComparator XVisualIDComparator = new X11GLCapabilities.XVisualIDComparator(); - + static GraphicsConfigurationFactory fallbackX11GraphicsConfigurationFactory = null; static void registerFactory() { - GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, new X11GLXGraphicsConfigurationFactory()); + fallbackX11GraphicsConfigurationFactory = GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, new X11GLXGraphicsConfigurationFactory()); } private X11GLXGraphicsConfigurationFactory() { } @@ -93,6 +91,16 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) { throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); } + + if(!GLXUtil.isGLXAvailableOnServer((X11GraphicsDevice)absScreen.getDevice())) { + if(null != fallbackX11GraphicsConfigurationFactory) { + if(DEBUG) { + System.err.println("No GLX available, fallback to "+fallbackX11GraphicsConfigurationFactory.getClass().getSimpleName()+" for: "+absScreen); + } + return fallbackX11GraphicsConfigurationFactory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, absScreen); + } + throw new InternalError("No GLX and no fallback GraphicsConfigurationFactory available for: "+absScreen); + } return chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable)capsChosen, (GLCapabilitiesImmutable)capsRequested, (GLCapabilitiesChooser)chooser, (X11GraphicsScreen)absScreen); } @@ -187,7 +195,7 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF if (capsChosen == null) { capsChosen = new GLCapabilities(null); } - X11GraphicsDevice x11Device = (X11GraphicsDevice) x11Screen.getDevice(); + X11GraphicsDevice x11Device = (X11GraphicsDevice) x11Screen.getDevice(); X11GLXDrawableFactory factory = (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory(); capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( capsChosen, factory.canCreateGLPbuffer(x11Device) ); diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index 259644467..8570794d8 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -154,18 +154,21 @@ public abstract class GraphicsConfigurationFactory { * called by end users, only implementors of new * GraphicsConfigurationFactory subclasses. * + * @return the previous registered factory, or null if none * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice */ - protected static void registerFactory(Class<?> abstractGraphicsDeviceImplementor, GraphicsConfigurationFactory factory) + protected static GraphicsConfigurationFactory registerFactory(Class<?> abstractGraphicsDeviceImplementor, GraphicsConfigurationFactory factory) throws IllegalArgumentException { if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) { throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice"); } + GraphicsConfigurationFactory prevFactory = registeredFactories.put(abstractGraphicsDeviceImplementor, factory); if(DEBUG) { - System.err.println("GraphicsConfigurationFactory.registerFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory); + System.err.println("GraphicsConfigurationFactory.registerFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory+ + ", overridding: "+prevFactory); } - registeredFactories.put(abstractGraphicsDeviceImplementor, factory); + return prevFactory; } /** |