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/nativewindow/classes/com/sun | |
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/nativewindow/classes/com/sun')
14 files changed, 221 insertions, 33 deletions
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java new file mode 100644 index 000000000..eb39b9f59 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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 of Sun Microsystems, Inc. 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 + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nativewindow.impl; + +import javax.media.nativewindow.*; + +public class GraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory { + // By default we just return null; X11 is the only window system requiring eager visual selection + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, + AbstractGraphicsDevice device) { + return null; + } +} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java index aec6e3175..89b620161 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java @@ -64,19 +64,19 @@ public final class NWReflection { try { factoryClass = Class.forName(clazzName); if (factoryClass == null) { - throw new NWException(clazzName + " not available"); + throw new NativeWindowException(clazzName + " not available"); } try { factory = factoryClass.getDeclaredConstructor( cstrArgTypes ); } catch(NoSuchMethodException nsme) { - throw new NWException("Constructor: '" + clazzName + "("+cstrArgTypes+")' not found"); + throw new NativeWindowException("Constructor: '" + clazzName + "("+cstrArgTypes+")' not found"); } return factory; } catch (Throwable e) { if (DEBUG) { e.printStackTrace(); } - throw new NWException(e); + throw new NativeWindowException(e); } } @@ -91,7 +91,7 @@ public final class NWReflection { factory = getConstructor(clazzName, cstrArgTypes); return factory.newInstance( cstrArgs ) ; } catch (Exception e) { - throw new NWException(e); + throw new NativeWindowException(e); } } diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java index 6e8542181..8a865733a 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java @@ -98,14 +98,6 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory { } } - // All platforms except for X11 perform the OpenGL pixel format - // selection lazily - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, - AbstractGraphicsDevice device) { - return null; - } - // On most platforms the toolkit lock is a no-op private ToolkitLock toolkitLock = new ToolkitLock() { public void lock() { diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java index fe07b0f16..b4124a375 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java @@ -101,8 +101,8 @@ public class NullWindow implements NativeWindow { public void setSurfaceHandle(long handle) { surfaceHandle=handle; } - public long getVisualID() { - return 0; + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return null; } public Object getWrappedWindow() { diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java index a996f9ea9..e6aa3ca74 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java @@ -57,9 +57,9 @@ public class JAWTUtil { private static boolean lockedToolkit; - public static synchronized void lockToolkit() throws NWException { + public static synchronized void lockToolkit() throws NativeWindowException { if (lockedToolkit) { - throw new NWException("Toolkit already locked"); + throw new NativeWindowException("Toolkit already locked"); } lockedToolkit = true; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java index c710a67bf..cccf911bd 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java @@ -61,7 +61,7 @@ public abstract class JAWTWindow implements NativeWindow { protected long display; protected long screen; protected long drawable; - protected long visualID; + protected AbstractGraphicsConfiguration config; protected int screenIndex; public JAWTWindow(Object comp) { @@ -83,7 +83,7 @@ public abstract class JAWTWindow implements NativeWindow { screen= 0; screenIndex = -1; drawable= 0; - visualID = 0; + config = null; } public synchronized int lockSurface() throws NativeWindowException { @@ -119,8 +119,8 @@ public abstract class JAWTWindow implements NativeWindow { public long getSurfaceHandle() { return drawable; } - public long getVisualID() { - return visualID; + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; } public Object getWrappedWindow() { @@ -147,7 +147,7 @@ public abstract class JAWTWindow implements NativeWindow { ", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+ ", visible "+component.isVisible()+ ", wrappedWindow "+getWrappedWindow()+ - ", visualID "+visualID+ + ", config "+config+ ", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() + ", display handle "+getDisplayHandle()+"]"); diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java index 310f17f64..e627b18f4 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java @@ -69,7 +69,7 @@ public class MacOSXJAWTWindow extends JAWTWindow { } int res = ds.Lock(); if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - throw new NWException("Unable to lock surface"); + throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old // OpenGL context so it will be recreated (NOTE: removeNotify @@ -110,7 +110,7 @@ public class MacOSXJAWTWindow extends JAWTWindow { drawable = macosxdsi.cocoaViewRef(); // FIXME: Are the followup abstractions available ? would it be usefull ? display = 0; - visualID = 0; + config = null; screen= 0; screenIndex = 0; @@ -127,7 +127,7 @@ public class MacOSXJAWTWindow extends JAWTWindow { return ret; } - public void unlockSurface() throws NWException { + public void unlockSurface() throws NativeWindowException { if(!isSurfaceLocked()) return; ds.FreeDrawingSurfaceInfo(dsi); ds.Unlock(); diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java index 364ee9d32..122ee3f8d 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java @@ -73,7 +73,7 @@ public class WindowsJAWTWindow extends JAWTWindow { } int res = ds.Lock(); if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - throw new NWException("Unable to lock surface"); + throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old // OpenGL context so it will be recreated (NOTE: removeNotify @@ -95,7 +95,7 @@ public class WindowsJAWTWindow extends JAWTWindow { drawable = win32dsi.hdc(); // FIXME: Are the followup abstractions available ? would it be usefull ? display = 0; - visualID = 0; + config = null; screen= 0; screenIndex = 0; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java index 60b68c0e8..e8d955b21 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java @@ -36,12 +36,13 @@ package com.sun.nativewindow.impl.jawt.x11; +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + import com.sun.nativewindow.impl.x11.*; import com.sun.nativewindow.impl.jawt.*; import com.sun.nativewindow.impl.*; -import javax.media.nativewindow.*; - import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; @@ -87,7 +88,8 @@ public class X11JAWTWindow extends JAWTWindow { x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); display = x11dsi.display(); drawable = x11dsi.drawable(); - visualID = x11dsi.visualID(); + long visualID = x11dsi.visualID(); + config = new X11GraphicsConfiguration(visualID); screen= 0; if (X11Lib.XineramaEnabled(display)) { screenIndex = 0; @@ -105,7 +107,7 @@ public class X11JAWTWindow extends JAWTWindow { x11dsi = null; display = 0; drawable = 0; - visualID = 0; + config = null; screen= 0; screenIndex = -1; return LOCK_SURFACE_NOT_READY; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java index f8c1624df..a4160033d 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java @@ -46,6 +46,9 @@ import java.awt.GraphicsDevice; import java.lang.reflect.*; import java.security.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; + /** This class encapsulates the reflection routines necessary to peek inside a few data structures in the AWT implementation on X11 for the purposes of correctly enumerating the available visuals. */ @@ -89,6 +92,17 @@ public class X11SunJDKReflection { } } + public static int graphicsConfigurationGetVisualID(AbstractGraphicsConfiguration config) { + try { + if (config instanceof AWTGraphicsConfiguration) { + return graphicsConfigurationGetVisualID(((AWTGraphicsConfiguration) config).getGraphicsConfiguration()); + } + return 0; + } catch (Exception e) { + return 0; + } + } + public static int graphicsConfigurationGetVisualID(GraphicsConfiguration config) { if (!initted) { return 0; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java new file mode 100644 index 000000000..5250e251b --- /dev/null +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. 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 of Sun Microsystems, Inc. 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 + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nativewindow.impl.x11; + +import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; + +public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory { + // FIXME: there is a "quality of implementation" issue here. We + // want to allow the use of the GraphicsConfigurationFactory in + // conjunction with OpenGL as well as other rendering mechanisms. + // On X11 platforms the OpenGL pixel format is associated with the + // window's visual. On other platforms, the OpenGL pixel format is + // chosen lazily. As in the OpenGL binding, the default + // X11GraphicsConfigurationFactory would need to provide a default + // mechanism for selecting a visual based on a set of + // capabilities. Here we always return 0 for the visual ID, which + // presumably corresponds to the default visual (which may be a + // bad assumption). When using OpenGL, the OpenGL binding is + // responsible for registering a GraphicsConfigurationFactory + // which actually performs visual selection, though based on + // GLCapabilities. + public AbstractGraphicsConfiguration + chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, + AbstractGraphicsDevice device) + throws IllegalArgumentException, NativeWindowException { + return new X11GraphicsConfiguration(0); + } +} diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11NativeWindowFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11NativeWindowFactory.java new file mode 100644 index 000000000..1643c30d8 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11NativeWindowFactory.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. 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 of Sun Microsystems, Inc. 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 + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nativewindow.impl.x11; + +import javax.media.nativewindow.*; +import com.sun.nativewindow.impl.*; + +public class X11NativeWindowFactory extends NativeWindowFactoryImpl { + // 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/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java index af3300ec8..703f8baf3 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java @@ -60,7 +60,7 @@ public class X11Util { NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } if (staticDisplay == 0) { - throw new NWException("Unable to open default display"); + throw new NativeWindowException("Unable to open default display"); } } return staticDisplay; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java index e3bf428cc..4102715ce 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2008-2009 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -42,7 +42,7 @@ import com.sun.nativewindow.impl.jawt.*; import com.sun.nativewindow.impl.jawt.x11.*; import com.sun.nativewindow.impl.x11.*; -public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl { +public class X11AWTNativeWindowFactory extends X11NativeWindowFactory { // When running the AWT on X11 platforms, we use the AWT native // interface (JAWT) to lock and unlock the toolkit |