diff options
author | Kenneth Russel <[email protected]> | 2009-03-19 00:32:21 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2009-03-19 00:32:21 +0000 |
commit | c4cd0db6b9865c97245921d2824bcc4c1541e615 (patch) | |
tree | 6f9df4a383767992fa9ec36d820630bfabedf75a /src/jogl/classes/com/sun/opengl/impl/x11 | |
parent | 23d13ee00ebdf7052299fc65af6f50e43d673e67 (diff) |
Movement of Capabilities class and chooseCapabilities functionality
into NativeWindowFactory introduced an undesirable dependence between
the windowing toolkit, which can be replaced via NativeWindowFactory,
and the library which implements the selection algorithm, for example
OpenGL. This would prevent, for example, an easy SWT port of JOGL.
To fix this, refactored chooseCapabilities into new
GraphicsConfigurationFactory, the default implementation of which is
currently a no-op on X11 platforms, and which is provided by JOGL in a
toolkit-agnostic manner via GLX. Refactored OpenGL portions of
Capabilities class back into GLCapabilities. Reintroduced
GLCapabilitiesChooser interface for compatibility and to avoid having
to import javax.media.nativewindow classes in most user code.
Fixed problem in GLProfile where failures to load native libraries
were being squelched. Reorganized build to have all outputs under
build/ directory.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1884 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/impl/x11')
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java | 27 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java | 70 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java (renamed from src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXNativeWindowFactory.java) | 109 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java | 8 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java | 6 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java | 8 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java | 8 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java (renamed from src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXNativeWindowFactory.java) | 106 |
8 files changed, 166 insertions, 176 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java index 2f1f777c9..0b916213c 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java @@ -47,11 +47,11 @@ import com.sun.nativewindow.impl.x11.*; public abstract class X11GLXDrawable extends GLDrawableImpl { protected static final boolean DEBUG = Debug.debug("X11GLXDrawable"); - protected NWCapabilitiesChooser chooser; + protected GLCapabilitiesChooser chooser; protected X11GLXDrawable(GLDrawableFactory factory, NativeWindow comp, boolean realized, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser) { super(factory, comp, requestedCapabilities, realized); this.chooser = chooser; } @@ -62,7 +62,7 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { protected XVisualInfo chooseVisual(boolean onscreen) { long display = getNativeWindow().getDisplayHandle(); - long visualID = getNativeWindow().getVisualID(); + long visualID = ((X11GLXDrawableFactory) getFactory()).getVisualID(getNativeWindow().getGraphicsConfiguration()); if (display == 0) { throw new GLException("null display"); } @@ -105,24 +105,29 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { XVisualInfo template = XVisualInfo.create(); template.screen(screen); XVisualInfo[] infos = null; - NWCapabilities[] caps = null; + GLCapabilities[] caps = null; getFactoryImpl().lockToolkit(); try { infos = X11Lib.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0); if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } - caps = new NWCapabilities[infos.length]; + caps = new GLCapabilities[infos.length]; for (int i = 0; i < infos.length; i++) { - caps[i] = ((X11GLXDrawableFactory)getFactory()).xvi2NWCapabilities(display, infos[i]); + caps[i] = ((X11GLXDrawableFactory)getFactory()).xvi2GLCapabilities(display, infos[i]); } } finally { getFactoryImpl().unlockToolkit(); } - NWCapabilities capabilities = getRequestedNWCapabilities(); - int chosen = chooser.chooseCapabilities(capabilities, caps, -1); + GLCapabilities capabilities = getRequestedGLCapabilities(); + int chosen; + try { + chosen = chooser.chooseCapabilities(capabilities, caps, -1); + } catch (NativeWindowException e) { + throw new GLException(e); + } if (chosen < 0 || chosen >= caps.length) { - throw new GLException("NWCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } if (DEBUG) { System.err.println("Chosen visual (" + chosen + "):"); @@ -130,7 +135,7 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { } vis = infos[chosen]; if (vis == null) { - throw new GLException("NWCapabilitiesChooser chose an invalid visual"); + throw new GLException("GLCapabilitiesChooser chose an invalid visual"); } // FIXME: the storage for the infos array is leaked (should // clean it up somehow when we're done with the visual we're diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java index a0c3a7758..3ca1396d2 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -40,18 +40,21 @@ import java.nio.*; import java.security.*; import java.util.*; import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import com.sun.gluegen.runtime.*; import com.sun.gluegen.runtime.opengl.*; import com.sun.opengl.impl.*; import com.sun.opengl.impl.x11.glx.*; import com.sun.nativewindow.impl.NullWindow; +import com.sun.nativewindow.impl.NWReflection; import com.sun.nativewindow.impl.x11.*; +import com.sun.nativewindow.impl.jawt.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { protected static final boolean DEBUG = Debug.debug("X11GLXDrawableFactory"); - // Map for rediscovering the NWCapabilities associated with a + // Map for rediscovering the GLCapabilities associated with a // particular screen and visualID after the fact protected static Map visualToGLCapsMap = Collections.synchronizedMap(new HashMap()); // The screens for which we've already initialized it @@ -90,19 +93,27 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { // Must initialize GLX support eagerly in case a pbuffer is the // first thing instantiated GLProcAddressHelper.resetProcAddressTable(GLX.getGLXProcAddressTable(), this); + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + new X11GLXGraphicsConfigurationFactory(); + try { + NWReflection.createInstance("com.sun.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", + new Object[] {}); + } catch (Exception e) { + } } private static final int MAX_ATTRIBS = 128; - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, AbstractGraphicsDevice absDevice) { return null; } public GLDrawable createGLDrawable(NativeWindow target, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { if (target == null) { throw new IllegalArgumentException("Null target"); } @@ -110,9 +121,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return new X11OnscreenGLXDrawable(this, target); } - public void initializeVisualToNWCapabilitiesMap(int screen, + public void initializeVisualToGLCapabilitiesMap(int screen, XVisualInfo[] infos, - NWCapabilities[] caps) { + GLCapabilities[] caps) { Integer key = new Integer(screen); if (!initializedScreenSet.contains(key)) { for (int i = 0; i < infos.length; i++) { @@ -125,13 +136,32 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } - public NWCapabilities lookupCapabilitiesByScreenAndVisualID(int screenIndex, - long visualID) { - return (NWCapabilities) visualToGLCapsMap.get(new ScreenAndVisualIDKey(screenIndex, visualID)); + public GLCapabilities lookupCapabilitiesByScreenAndConfig(int screenIndex, + AbstractGraphicsConfiguration config) { + return (GLCapabilities) visualToGLCapsMap.get(new ScreenAndVisualIDKey(screenIndex, getVisualID(config))); + } + + public long getVisualID(AbstractGraphicsConfiguration config) { + if (config == null) { + return 0; + } + // FIXME: this is hopefully the last remaining place in this + // implementation that is over-specialized; third-party toolkits + // would need to use the X11GraphicsConfiguration in order to + // interoperate with this code + if (config instanceof X11GraphicsConfiguration) { + return ((X11GraphicsConfiguration) config).getVisualID(); + } + try { + // The AWT-specific code and casts have been moved to the X11SunJDKReflection helper class + return X11SunJDKReflection.graphicsConfigurationGetVisualID(config); + } catch (Throwable t) { + return 0; + } } - public GLDrawableImpl createOffscreenDrawable(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int width, int height) { return new X11OffscreenGLXDrawable(this, capabilities, chooser, width, height); @@ -181,8 +211,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return canCreateGLPbuffer; } - public GLPbuffer createGLPbuffer(final NWCapabilities capabilities, - final NWCapabilitiesChooser chooser, + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final GLCapabilitiesChooser chooser, final int initialWidth, final int initialHeight, final GLContext shareWith) { @@ -230,7 +260,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - public NWCapabilities xvi2NWCapabilities(long display, XVisualInfo info) { + public GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) { int[] tmp = new int[1]; int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); if (val == 0) { @@ -242,12 +272,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { // Visual does not support RGBA return null; } - NWCapabilities res = new NWCapabilities(); + GLCapabilities res = new GLCapabilities(); res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp, 0) != 0); // Note: use of hardware acceleration is determined by // glXCreateContext, not by the XVisualInfo. Optimistically claim - // that all NWCapabilities have the capability to be hardware + // that all GLCapabilities have the capability to be hardware // accelerated. res.setHardwareAccelerated(true); res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp, 0)); @@ -267,7 +297,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - public static int[] glCapabilities2AttribList(NWCapabilities caps, + public static int[] glCapabilities2AttribList(GLCapabilities caps, boolean isMultisampleAvailable, boolean pbuffer, long display, @@ -357,11 +387,11 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - public static NWCapabilities attribList2NWCapabilities(int[] iattribs, + public static GLCapabilities attribList2GLCapabilities(int[] iattribs, int niattribs, int[] ivalues, boolean pbuffer) { - NWCapabilities caps = new NWCapabilities(); + GLCapabilities caps = new GLCapabilities(); for (int i = 0; i < niattribs; i++) { int attr = iattribs[i]; diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXNativeWindowFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 3944f4180..8120dca52 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXNativeWindowFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -43,44 +43,58 @@ import javax.media.opengl.*; import com.sun.opengl.impl.*; import com.sun.opengl.impl.x11.glx.*; -/** Subclass of NativeWindowFactory used when non-AWT tookits are used - on X11 platforms. Toolkits will likely need to subclass this one - to add synchronization in certain places and change the accepted - and returned types of the GraphicsDevice and GraphicsConfiguration - abstractions. */ - -public class X11GLXNativeWindowFactory extends NativeWindowFactoryImpl { - - public X11GLXNativeWindowFactory() { - NativeWindowFactory.registerFactory(javax.media.nativewindow.NativeWindow.class, this); +/** Subclass of GraphicsConfigurationFactory used when non-AWT tookits + are used on X11 platforms. Toolkits will likely need to delegate + to this one to change the accepted and returned types of the + GraphicsDevice and GraphicsConfiguration abstractions. */ + +public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFactory { + // Keep this under the same debug flag as the drawable factory for convenience + protected static final boolean DEBUG = Debug.debug("X11GLXDrawableFactory"); + + public X11GLXGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, + this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, AbstractGraphicsDevice absDevice) { if (absDevice != null && !(absDevice instanceof X11GraphicsDevice)) { throw new IllegalArgumentException("This NativeWindowFactory accepts only X11GraphicsDevice objects"); } + if (capabilities != null && + !(capabilities instanceof GLCapabilities)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + int screen = 0; if (absDevice != null) { screen = ((X11GraphicsDevice) absDevice).getScreen(); } - long visualID = chooseGraphicsConfigurationImpl(capabilities, chooser, screen); + long visualID = chooseGraphicsConfigurationImpl((GLCapabilities) capabilities, + (GLCapabilitiesChooser) chooser, + screen); return new X11GraphicsConfiguration(visualID); } /** Returns the visual ID of the chosen GraphicsConfiguration. */ - protected long chooseGraphicsConfigurationImpl(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + protected long chooseGraphicsConfigurationImpl(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int screen) { if (capabilities == null) { - capabilities = new NWCapabilities(); + capabilities = new GLCapabilities(); } if (chooser == null) { - chooser = new DefaultNWCapabilitiesChooser(); + chooser = new DefaultGLCapabilitiesChooser(); } if (X11Util.isXineramaEnabled()) { @@ -93,9 +107,9 @@ public class X11GLXNativeWindowFactory extends NativeWindowFactoryImpl { int[] attribs = X11GLXDrawableFactory.glCapabilities2AttribList(capabilities, GLXUtil.isMultisampleAvailable(), false, 0, 0); XVisualInfo[] infos = null; - NWCapabilities[] caps = null; + GLCapabilities[] caps = null; int recommendedIndex = -1; - getDefaultFactory().getToolkitLock().lock(); + NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); try { long display = X11Util.getDisplayConnection(); XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0); @@ -114,66 +128,33 @@ public class X11GLXNativeWindowFactory extends NativeWindowFactoryImpl { if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } - caps = new NWCapabilities[infos.length]; + caps = new GLCapabilities[infos.length]; for (int i = 0; i < infos.length; i++) { - caps[i] = ((X11GLXDrawableFactory) GLDrawableFactory.getFactory()).xvi2NWCapabilities(display, infos[i]); + caps[i] = ((X11GLXDrawableFactory) GLDrawableFactory.getFactory()).xvi2GLCapabilities(display, infos[i]); // Attempt to find the visual chosen by glXChooseVisual if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) { recommendedIndex = i; } } } finally { - getDefaultFactory().getToolkitLock().unlock(); + NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } // Store these away for later ((X11GLXDrawableFactory) GLDrawableFactory.getFactory()). - initializeVisualToNWCapabilitiesMap(screen, infos, caps); - int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); + initializeVisualToGLCapabilitiesMap(screen, infos, caps); + int chosen; + try { + chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); + } catch (NativeWindowException e) { + throw new GLException(e); + } if (chosen < 0 || chosen >= caps.length) { - throw new GLException("NWCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } XVisualInfo vis = infos[chosen]; if (vis == null) { - throw new GLException("NWCapabilitiesChooser chose an invalid visual"); + throw new GLException("GLCapabilitiesChooser chose an invalid visual"); } return vis.visualid(); } - - // On X11 platforms we need to do some locking; this basic - // implementation should suffice for some simple window toolkits - private ToolkitLock toolkitLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - } - }; - - public ToolkitLock getToolkitLock() { - return toolkitLock; - } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 46712bced..63dcca80e 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -50,8 +50,8 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { private boolean isDoubleBuffered; protected X11OffscreenGLXDrawable(GLDrawableFactory factory, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser, + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser, int width, int height) { super(factory, new NullWindow(), true, requestedCapabilities, chooser); @@ -92,7 +92,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { ", GLXPixmap " + toHexString(drawable) + ", display " + toHexString(dpy)); } - setChosenNWCapabilities(((X11GLXDrawableFactory)getFactory()).xvi2NWCapabilities(dpy, vis)); + setChosenGLCapabilities(((X11GLXDrawableFactory)getFactory()).xvi2GLCapabilities(dpy, vis)); } finally { getFactoryImpl().unlockToolkit(); } @@ -131,7 +131,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { drawable = 0; pixmap = 0; display = 0; - setChosenNWCapabilities(null); + setChosenGLCapabilities(null); } finally { getFactoryImpl().unlockToolkit(); } 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 9da86205d..b4370e142 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 @@ -61,11 +61,11 @@ public class X11OnscreenGLXContext extends X11GLXContext { protected int makeCurrentImpl() throws GLException { int lockRes = drawable.lockSurface(); - if (drawable.getChosenNWCapabilities() == null) { + if (drawable.getChosenGLCapabilities() == null) { X11GLXDrawableFactory factory = (X11GLXDrawableFactory) drawable.getFactory(); NativeWindow window = drawable.getNativeWindow(); - drawable.setChosenNWCapabilities(factory.lookupCapabilitiesByScreenAndVisualID(window.getScreenIndex(), - window.getVisualID())); + drawable.setChosenGLCapabilities(factory.lookupCapabilitiesByScreenAndConfig(window.getScreenIndex(), + window.getGraphicsConfiguration())); } boolean exceptionOccurred = false; try { diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java index 5c1a5071c..4a22940b6 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java @@ -79,16 +79,16 @@ public class X11OnscreenGLXDrawable extends X11GLXDrawable { } // This is public to allow access from the DrawableFactory - protected void setChosenNWCapabilities(NWCapabilities caps) { - super.setChosenNWCapabilities(caps); + protected void setChosenGLCapabilities(GLCapabilities caps) { + super.setChosenGLCapabilities(caps); } public void setRealized(boolean realized) { if (realized) { X11GLXDrawableFactory factory = (X11GLXDrawableFactory) getFactory(); NativeWindow window = getNativeWindow(); - setChosenNWCapabilities(factory.lookupCapabilitiesByScreenAndVisualID(window.getScreenIndex(), - window.getVisualID())); + setChosenGLCapabilities(factory.lookupCapabilitiesByScreenAndConfig(window.getScreenIndex(), + window.getGraphicsConfiguration())); } super.setRealized(realized); } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java index 99aebb4ed..91be786dd 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java @@ -56,7 +56,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { protected static final int MAX_ATTRIBS = 256; protected X11PbufferGLXDrawable(GLDrawableFactory factory, - NWCapabilities requestedCapabilities, + GLCapabilities requestedCapabilities, int width, int height) { super(factory, new NullWindow(), true, requestedCapabilities, null); if (width <= 0 || height <= 0) { @@ -106,7 +106,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { int screen = X11Lib.DefaultScreen(display); nw.setScreenIndex(screen); - NWCapabilities capabilities = getRequestedNWCapabilities(); + GLCapabilities capabilities = getRequestedGLCapabilities(); if (capabilities.getPbufferRenderToTexture()) { throw new GLException("Render-to-texture pbuffers not supported yet on X11"); @@ -174,7 +174,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { int samplesAttrib = GLXUtil.isMultisampleAvailable() ? GLX.GLX_SAMPLES: GLX.GLX_RED_SIZE; int floatNV = capabilities.getPbufferFloatingPointBuffers() ? GLXExt.GLX_FLOAT_COMPONENTS_NV : GLX.GLX_RED_SIZE; - // Query the fbconfig to determine its NWCapabilities + // Query the fbconfig to determine its GLCapabilities int[] iattribs = { GLX.GLX_DOUBLEBUFFER, GLX.GLX_STEREO, @@ -195,7 +195,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { int[] ivalues = new int[iattribs.length]; queryFBConfig(display, fbConfig, iattribs, iattribs.length, ivalues); - setChosenNWCapabilities(X11GLXDrawableFactory.attribList2NWCapabilities(iattribs, iattribs.length, ivalues, true)); + setChosenGLCapabilities(X11GLXDrawableFactory.attribList2GLCapabilities(iattribs, iattribs.length, ivalues, true)); // Determine the actual width and height we were able to create. int[] tmp = new int[1]; diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXNativeWindowFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index 4029d90bd..0d75056c4 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXNativeWindowFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -36,8 +36,10 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.x11.X11GraphicsConfiguration; +import javax.media.nativewindow.x11.X11GraphicsDevice; import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; import javax.media.opengl.*; import javax.media.opengl.awt.*; @@ -47,26 +49,19 @@ import com.sun.nativewindow.impl.jawt.x11.*; import com.sun.opengl.impl.x11.*; import com.sun.opengl.impl.x11.glx.*; -public class X11AWTGLXNativeWindowFactory extends X11GLXNativeWindowFactory { - - public X11AWTGLXNativeWindowFactory() { - Class componentClass = null; - try { - componentClass = Class.forName("java.awt.Component"); - } catch (Exception e) { - throw new GLException(e); - } - - NativeWindowFactory.registerFactory(componentClass, this); +public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfigurationFactory { + public X11AWTGLXGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, + this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, AbstractGraphicsDevice absDevice) { GraphicsDevice device = null; if (absDevice != null && !(absDevice instanceof AWTGraphicsDevice)) { - throw new IllegalArgumentException("This NativeWindowFactory accepts only AWTGraphicsDevice objects"); + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only AWTGraphicsDevice objects"); } if ((absDevice == null) || @@ -76,21 +71,40 @@ public class X11AWTGLXNativeWindowFactory extends X11GLXNativeWindowFactory { device = ((AWTGraphicsDevice) absDevice).getGraphicsDevice(); } - long visualID = chooseGraphicsConfigurationImpl(capabilities, chooser, - X11SunJDKReflection.graphicsDeviceGetScreen(device)); + if (capabilities != null && + !(capabilities instanceof GLCapabilities)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects"); + } - // Now figure out which GraphicsConfiguration corresponds to this - // visual by matching the visual ID - GraphicsConfiguration[] configs = device.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - GraphicsConfiguration config = configs[i]; - if (config != null) { - if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { - return new AWTGraphicsConfiguration(config); + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects"); + } + + // Fabricate an X11GraphicsDevice and delegate to the GraphicsConfigurationFactory for those + // + // Note that we could derive from X11GLXGraphicsConfigurationFactory, but that would + // limit the ability of third parties to plug in new visual selection algorithms + X11GraphicsDevice x11Device = new X11GraphicsDevice(X11SunJDKReflection.graphicsDeviceGetScreen(device)); + X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(x11Device).chooseGraphicsConfiguration(capabilities, + chooser, + x11Device); + if (x11Config != null) { + long visualID = x11Config.getVisualID(); + // Now figure out which GraphicsConfiguration corresponds to this + // visual by matching the visual ID + GraphicsConfiguration[] configs = device.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + GraphicsConfiguration config = configs[i]; + if (config != null) { + if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { + return new AWTGraphicsConfiguration(config); + } } } } - + // Either we weren't able to reflectively introspect on the // X11GraphicsConfig or something went wrong in the steps above; // we're going to return null without signaling an error condition @@ -98,44 +112,4 @@ public class X11AWTGLXNativeWindowFactory extends X11GLXNativeWindowFactory { // and possibly report more of an error in the latter case) return null; } - - // When running the AWT on X11 platforms, we use the AWT native - // interface (JAWT) to lock and unlock the toolkit - private ToolkitLock toolkitLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - JAWTUtil.lockToolkit(); - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - JAWTUtil.unlockToolkit(); - } - }; - - public ToolkitLock getToolkitLock() { - return toolkitLock; - } } |