aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/javax/media
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2008-12-20 08:58:00 +0000
committerKenneth Russel <[email protected]>2008-12-20 08:58:00 +0000
commit6eda9476e8168bacdeb1854540d89bd9db0d5029 (patch)
tree692317f9924638836b16bf83a9cefe0c1047bb66 /src/classes/javax/media
parent14a94c810910f88d3b7214ae9be5027dc74df39f (diff)
Factored out the remaining toolkit, and specifically AWT, dependencies
from GLDrawableFactory implementations into NativeWindowFactory implementations. These dependencies were the up-front selection of the GraphicsConfiguration and the locking and unlocking of the toolkit, which are both currently needed only on X11 platforms due to how OpenGL and the window system interact there. Added X11GraphicsDevice and X11GraphicsConfiguration classes which are intended to be used by Newt or potentially other third-party window toolkits. Unified the separate NativeWindow and AWT GLDrawableFactory implementations in the GLDrawableFactory class. Exposed the toolkit locking mechanism through the NativeWindowFactory and introduced the concept of a default NativeWindowFactory which is used by the X11 drawable and context implementations. Removed unnecessary toolkit locking calls from Mac OS X and Windows drawable and context implementations. Added a registration mechanism for new NativeWindowFactories, allowing third parties to plug in new window toolkits orthogonally to the OpenGL drawable and context code. The public APIs for the NativeWindowFactory and the GLDrawableFactory, in particular how they are fetched, changed as a result of these refactorings. Updated all uses. Fixed bug in X11OffscreenGLXDrawable introduced during last set of changes. Tested demos on Solaris, Mac OS X and Windows. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1824 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/javax/media')
-rw-r--r--src/classes/javax/media/opengl/GLDrawableFactory.java243
-rw-r--r--src/classes/javax/media/opengl/NativeWindowFactory.java260
-rw-r--r--src/classes/javax/media/opengl/ToolkitLock.java48
-rw-r--r--src/classes/javax/media/opengl/X11GraphicsConfiguration.java53
-rw-r--r--src/classes/javax/media/opengl/X11GraphicsDevice.java53
-rw-r--r--src/classes/javax/media/opengl/awt/GLCanvas.java10
-rw-r--r--src/classes/javax/media/opengl/awt/GLJPanel.java2
7 files changed, 378 insertions, 291 deletions
diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java
index f6ada6c50..677441572 100644
--- a/src/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/classes/javax/media/opengl/GLDrawableFactory.java
@@ -59,7 +59,7 @@ import com.sun.opengl.impl.*;
passed GLCapabilitiesChooser will be ignored. </P>
<P> Because of the multithreaded nature of the Java platform's
- window system toolkit, it is typically not possible to immediately
+ Abstract Window Toolkit, it is typically not possible to immediately
reject a given {@link GLCapabilities} as being unsupportable by
either returning <code>null</code> from the creation routines or
raising a {@link GLException}. The semantics of the rejection
@@ -77,179 +77,67 @@ import com.sun.opengl.impl.*;
*/
public abstract class GLDrawableFactory {
- private static GLDrawableFactory awtFactory;
- private static GLDrawableFactory nwFactory;
+ private static GLDrawableFactory factory;
- /** Initializes the sole GLDrawableFactory instance for the given profile. */
- private static void initializeAWTFactory() throws GLException {
- if (awtFactory != null) {
- return;
- }
-
- // See if the user is requesting one of the embedded profiles,
- // and if so, try to instantiate the EGLDrawableFactory
- if (GLProfile.isGLES()) {
- try {
- awtFactory = (GLDrawableFactory) GLReflection.createInstance("com.sun.opengl.impl.egl.awt.EGLAWTDrawableFactory");
- return;
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else if (!GLProfile.isGL2() && !GLProfile.isGL2ES12()) {
- // We require that the user passes in one of the known profiles
- throw new GLException("Unknown or unsupported profile \"" + GLProfile.getProfile() + "\"");
- }
-
- // Use the desktop OpenGL as the fallback always
- try {
- String factoryClassName =
- (String) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return System.getProperty("opengl.awt.factory.class.name");
- }
- });
- String osName = System.getProperty("os.name");
- String osNameLowerCase = osName.toLowerCase();
-
- // Because there are some complications with generating all
- // platforms' Java glue code on all platforms (among them that we
- // would have to include jawt.h and jawt_md.h in the jogl
- // sources, which we currently don't have to do) we break the only
- // static dependencies with platform-specific code here using reflection.
-
- if (factoryClassName == null) {
- if (osNameLowerCase.startsWith("wind")) {
- factoryClassName = "com.sun.opengl.impl.windows.wgl.WindowsWGLDrawableFactory";
- } else if (osNameLowerCase.startsWith("mac os x")) {
- factoryClassName = "com.sun.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory";
- } else {
- // Assume Linux, Solaris, etc. Should probably test for these explicitly.
- factoryClassName = "com.sun.opengl.impl.x11.glx.awt.X11AWTGLXDrawableFactory";
- }
- }
-
- awtFactory = (GLDrawableFactory) GLReflection.createInstance(factoryClassName);
- } catch (Exception e) {
- throw new GLException(e);
- }
- }
-
- private static GLDrawableFactory getAWTFactory()
- throws GLException
- {
- if(null==GLProfile.getProfile()) {
- throw new GLException("No chosen/preset GLProfile");
- }
- initializeAWTFactory();
- if(awtFactory == null) {
- throw new GLException("Could not determine the AWT-GLDrawableFactory");
- }
- return awtFactory;
+ /** Creates a new GLDrawableFactory instance. End users do not need
+ to call this method. */
+ protected GLDrawableFactory() {
}
- /** Initializes the sole GLDrawableFactory instance for the given profile. */
- private static void initializeNWFactory() throws GLException {
- if (nwFactory != null) {
- return;
- }
+ /** Returns the sole GLDrawableFactory instance. The {@link
+ GLProfile GLProfile} must be configured before calling this
+ method. */
+ public static GLDrawableFactory getFactory() throws GLException {
+ if (null == factory) {
+ if (null == GLProfile.getProfile()) {
+ throw new GLException("GLProfile was not properly initialized");
+ }
- // See if the user is requesting one of the embedded profiles,
- // and if so, try to instantiate the EGLDrawableFactory
- if (GLProfile.isGLES()) {
- try {
- nwFactory = (GLDrawableFactory) GLReflection.createInstance("com.sun.opengl.impl.egl.EGLDrawableFactory");
- return;
- } catch (Exception e) {
+ // See if the user is requesting one of the embedded profiles,
+ // and if so, try to instantiate the EGLDrawableFactory
+ if (GLProfile.isGLES()) {
+ try {
+ factory = (GLDrawableFactory) GLReflection.createInstance("com.sun.opengl.impl.egl.EGLDrawableFactory");
+ } catch (Exception e) {
e.printStackTrace();
+ }
+ } else if (!GLProfile.isGL2() && !GLProfile.isGL2ES12()) {
+ // We require that the user passes in one of the known profiles
+ throw new GLException("Unknown or unsupported profile \"" + GLProfile.getProfile() + "\"");
}
- } else if (!GLProfile.isGL2() && !GLProfile.isGL2ES12()) {
- // We require that the user passes in one of the known profiles
- throw new GLException("Unknown or unsupported profile \"" + GLProfile.getProfile() + "\"");
- }
- // Use the desktop OpenGL as the fallback always
- try {
- String factoryClassName =
- (String) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return System.getProperty("opengl.factory.class.name");
+ if (null == factory) {
+ // Use the desktop OpenGL as the fallback always
+ try {
+ String factoryClassName =
+ (String) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty("opengl.factory.class.name");
+ }
+ });
+ String osName = System.getProperty("os.name");
+ String osNameLowerCase = osName.toLowerCase();
+
+ if (factoryClassName == null) {
+ if (osNameLowerCase.startsWith("windows")) {
+ factoryClassName = "com.sun.opengl.impl.windows.wgl.WindowsWGLDrawableFactory";
+ } else if (osNameLowerCase.startsWith("mac os x")) {
+ // FIXME: remove this residual dependence on the AWT
+ factoryClassName = "com.sun.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory";
+ } else {
+ // Assume Linux, Solaris, etc. Should probably test for these explicitly.
+ factoryClassName = "com.sun.opengl.impl.x11.glx.X11GLXDrawableFactory";
}
- });
- String osName = System.getProperty("os.name");
- String osNameLowerCase = osName.toLowerCase();
-
- if (factoryClassName == null) {
- if (osNameLowerCase.startsWith("wind")) {
- factoryClassName = "com.sun.opengl.impl.windows.wgl.WindowsWGLDrawableFactory";
- } else if (osNameLowerCase.startsWith("mac os x")) {
- factoryClassName = "com.sun.opengl.impl.macosx.cgl.MacOSXCGLDrawableFactory";
- } else {
- // Assume Linux, Solaris, etc. Should probably test for these explicitly.
- factoryClassName = "com.sun.opengl.impl.x11.glx.X11GLXDrawableFactory";
}
- }
- nwFactory = (GLDrawableFactory) GLReflection.createInstance(factoryClassName);
- return;
- } catch (Exception e) {
- throw new GLException(e);
- }
- }
-
- private static GLDrawableFactory getNWFactory()
- throws GLException
- {
- if(null==GLProfile.getProfile()) {
- throw new GLException("No chosen/preset GLProfile");
- }
- initializeNWFactory();
- if(nwFactory == null) {
- throw new GLException("Could not determine the NativeWindow GLDrawableFactory");
- }
- return nwFactory;
- }
-
- /** Creates a new GLDrawableFactory instance. End users do not need
- to call this method. */
- protected GLDrawableFactory() {
- }
-
- /** Returns a GLDrawableFactory suitable to the passed winObj.
- In case winObj is a NativeWindow, the wrapped window object will be used. */
- public static GLDrawableFactory getFactory(Object winObj)
- throws GLException
- {
- if (winObj == null) {
- throw new IllegalArgumentException("winObj is null");
- }
- if ( winObj instanceof NativeWindow ) {
- NativeWindow nw = (NativeWindow)winObj;
- if(null!=nw.getWrappedWindow()) {
- winObj = nw.getWrappedWindow();
+ factory = (GLDrawableFactory) GLReflection.createInstance(factoryClassName);
+ } catch (Exception e) {
+ throw new GLException(e);
}
+ }
}
- return getFactory(winObj.getClass());
- }
-
- /** Returns a GLDrawableFactory suitable to the passed winClazz. */
- public static GLDrawableFactory getFactory(Class winClazz)
- throws GLException
- {
- if (GLReflection.implementationOf(winClazz, NativeWindow.class.getName())) {
- return getNWFactory();
- } else if (GLReflection.isAWTComponent(winClazz)) {
- return getAWTFactory();
- }
- throw new IllegalArgumentException("Target type is unsupported. Currently supported: \n"+
- "\tjavax.media.opengl.NativeWindow\n"+
- "\tjava.awt.Component\n");
- }
- /** Returns the common GLDrawableFactory, suitable for NativeWindow. */
- public static GLDrawableFactory getFactory()
- throws GLException
- {
- return getNWFactory();
+ return factory;
}
/** Shuts down this GLDrawableFactory, releasing resources
@@ -261,38 +149,6 @@ public abstract class GLDrawableFactory {
}
/**
- * <P> Selects a graphics configuration on the specified graphics
- * device compatible with the supplied GLCapabilities. This method
- * is intended to be used by applications which do not use the
- * supplied GLCanvas class but instead wrap their own Canvas or
- * other window toolkit-specific object with a GLDrawable. Some
- * platforms (specifically X11) require the graphics configuration
- * to be specified when the window toolkit object is created. This
- * method may return null on platforms on which the OpenGL pixel
- * format selection process is performed later. </P>
- *
- * <P> The concrete data type of the passed graphics device and
- * returned graphics configuration must be specified in the
- * documentation binding this particular API to the underlying
- * window toolkit. The Reference Implementation accepts {@link
- * AWTGraphicsDevice AWTGraphicsDevice} objects and returns {@link
- * AWTGraphicsConfiguration AWTGraphicsConfiguration} objects. </P>
- *
- * @see java.awt.Canvas#Canvas(java.awt.GraphicsConfiguration)
- *
- * @throws IllegalArgumentException if the data type of the passed
- * AbstractGraphicsDevice is not supported by this
- * GLDrawableFactory.
- * @throws GLException if any window system-specific errors caused
- * the selection of the graphics configuration to fail.
- */
- public abstract AbstractGraphicsConfiguration
- chooseGraphicsConfiguration(GLCapabilities capabilities,
- GLCapabilitiesChooser chooser,
- AbstractGraphicsDevice device)
- throws IllegalArgumentException, GLException;
-
- /**
* Returns a GLDrawable that wraps a platform-specific window system
* object, such as an AWT or LCDUI Canvas. On platforms which
* support it, selects a pixel format compatible with the supplied
@@ -409,5 +265,4 @@ public abstract class GLDrawableFactory {
*/
public abstract GLDrawable createExternalGLDrawable()
throws GLException;
-
}
diff --git a/src/classes/javax/media/opengl/NativeWindowFactory.java b/src/classes/javax/media/opengl/NativeWindowFactory.java
index ee28bfea1..18ce61974 100644
--- a/src/classes/javax/media/opengl/NativeWindowFactory.java
+++ b/src/classes/javax/media/opengl/NativeWindowFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * 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
@@ -28,113 +28,191 @@
* 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.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- *
- * Sun gratefully acknowledges that this software was originally authored
- * and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package javax.media.opengl;
import java.lang.reflect.*;
import java.security.*;
+import java.util.*;
+
import com.sun.opengl.impl.*;
-public class NativeWindowFactory {
- private static Constructor awtFactory = null;
+/** Provides the link between the window toolkit and the Java binding
+ to the OpenGL API. The NativeWindowFactory, and NativeWindow
+ instances it creates, encompass all of the toolkit-specific
+ functionality, leaving the GLDrawableFactory independent of any
+ particular toolkit. */
+
+public abstract class NativeWindowFactory {
+ private static NativeWindowFactory defaultFactory;
+ private static HashMap/*<Class, NativeWindowFactory>*/ registeredFactories =
+ new HashMap();
+ private static Class nativeWindowClass;
+
+ /** Creates a new NativeWindowFactory instance. End users do not
+ need to call this method. */
+ protected NativeWindowFactory() {
+ }
+
+ static {
+ initialize();
+ }
+
+ private static void initialize() {
+ String osName = System.getProperty("os.name");
+ String osNameLowerCase = osName.toLowerCase();
+ String factoryClassName = null;
- /** Initializes the sole NativeWindowFactory instance . */
- private static void initializeAWTFactory() throws GLException {
- if (awtFactory == null) {
- // Use the desktop OpenGL as the fallback always
+ // We break compile-time dependencies on the AWT here to
+ // make it easier to run this code on mobile devices
+
+ NativeWindowFactory factory = new NativeWindowFactoryImpl();
+ nativeWindowClass = javax.media.opengl.NativeWindow.class;
+ registerFactory(nativeWindowClass, factory);
+ defaultFactory = factory;
+
+ Class componentClass = null;
try {
- String osName = System.getProperty("os.name");
- String osNameLowerCase = osName.toLowerCase();
- String factoryClassName = null;
-
- // Because there are some complications with generating all
- // platforms' Java glue code on all platforms (among them that we
- // would have to include jawt.h and jawt_md.h in the jogl
- // sources, which we currently don't have to do) we break the only
- // static dependencies with platform-specific code here using reflection.
-
- if (osNameLowerCase.startsWith("wind")) {
- factoryClassName = "com.sun.opengl.impl.jawt.windows.WindowsJAWTWindow";
- } else if (osNameLowerCase.startsWith("mac os x")) {
- factoryClassName = "com.sun.opengl.impl.jawt.macosx.MacOSXJAWTWindow";
- } else {
- // Assume Linux, Solaris, etc. Should probably test for these explicitly.
- factoryClassName = "com.sun.opengl.impl.jawt.x11.X11JAWTWindow";
- }
-
- if (factoryClassName == null) {
- throw new GLException("OS " + osName + " not yet supported");
- }
-
- awtFactory = GLReflection.getConstructor(factoryClassName, new Class[] { Object.class });
+ componentClass = Class.forName("java.awt.Component");
} catch (Exception e) {
- throw new GLException(e);
+ }
+ if (componentClass != null) {
+ if (!osNameLowerCase.startsWith("wind") &&
+ !osNameLowerCase.startsWith("mac os x")) {
+ // Assume X11 platform -- should probably test for these explicitly
+ try {
+ Constructor factoryConstructor =
+ GLReflection.getConstructor("com.sun.opengl.impl.x11.glx.awt.X11AWTGLXNativeWindowFactory", new Class[] {});
+ factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
+ } catch (Exception e) {
+ }
+ }
+ registerFactory(componentClass, factory);
+ defaultFactory = factory;
}
}
- }
-
- /**
- * Returns a NativeWindow.
- *
- * This method digest a window object 'winObj'.
- * This can be either itself a NativeWindow,
- * or any other Java-level window toolkit window object.
- *
- * In case 'winObj' is a terminal NativeWindow, where
- * {@link NativeWindow#isTerminalObject()} returns true,
- * it is passed through directly.
- *
- * Otherwise either the non NativeWindow object,
- * or the wrapped window object within the proxy NativeWindow
- * will be used to factor a terminal NativeWindow.
- *
- * @throws IllegalArgumentException if the passed winObj is null
- * @throws NativeWindowException if the passed winObj's is a proxy NativeWindow
- * and does not hold a supported wrapped window object,
- * or it is not a supported window object.
- * @throws GLException if any window system-specific errors caused
- * the creation of the GLDrawable to fail.
- */
- public static NativeWindow getNativeWindow(Object winObj)
- throws IllegalArgumentException, GLException, NativeWindowException
- {
- if(null==winObj) {
- throw new IllegalArgumentException("winObj is null");
+
+ /** Sets the default NativeWindowFactory. Certain operations on
+ X11 platforms require synchronization, and the implementation
+ of this synchronization may be specific to the window toolkit
+ in use. It is impractical to require that all of the APIs that
+ might require synchronization receive a {@link ToolkitLock
+ ToolkitLock} as argument. For this reason the concept of a
+ default NativeWindowFactory is introduced. The toolkit lock
+ provided via {@link #getToolkitLock getToolkitLock} from this
+ default NativeWindowFactory will be used for synchronization
+ within the Java binding to OpenGL. By default, if the AWT is
+ available, the default toolkit will support the AWT. */
+ public static void setDefaultFactory(NativeWindowFactory factory) {
+ defaultFactory = factory;
}
- if(winObj instanceof NativeWindow) {
- NativeWindow nw = (NativeWindow) winObj;
- if(nw.isTerminalObject()) {
- return nw; // use the terminal NativeWindow object directly
+
+ /** Gets the default NativeWindowFactory. Certain operations on
+ X11 platforms require synchronization, and the implementation
+ of this synchronization may be specific to the window toolkit
+ in use. It is impractical to require that all of the APIs that
+ might require synchronization receive a {@link ToolkitLock
+ ToolkitLock} as argument. For this reason the concept of a
+ default NativeWindowFactory is introduced. The toolkit lock
+ provided via {@link #getToolkitLock getToolkitLock} from this
+ default NativeWindowFactory will be used for synchronization
+ within the Java binding to OpenGL. By default, if the AWT is
+ available, the default toolkit will support the AWT. */
+ public static NativeWindowFactory getDefaultFactory() {
+ return defaultFactory;
+ }
+
+ /** Returns the appropriate NativeWindowFactory to handle window
+ objects of the given type. The windowClass might be {@link
+ NativeWindow NativeWindow}, in which case the client has
+ already assumed the responsibility of creating a compatible
+ NativeWindow implementation, or it might be that of a toolkit
+ class like {@link java.awt.Component Component}. */
+ public static NativeWindowFactory getFactory(Class windowClass) throws IllegalArgumentException {
+ if (nativeWindowClass.isAssignableFrom(windowClass)) {
+ return (NativeWindowFactory) registeredFactories.get(nativeWindowClass);
}
- Object wrappedWindow = nw.getWrappedWindow();
- if(null==wrappedWindow) {
- throw new NativeWindowException("Proxy NativeWindow holds no wrapped window: "+nw);
+ Class clazz = windowClass;
+ while (clazz != null) {
+ NativeWindowFactory factory = (NativeWindowFactory) registeredFactories.get(clazz);
+ if (factory != null) {
+ return factory;
+ }
+ clazz = clazz.getSuperclass();
}
- winObj = wrappedWindow;
+ throw new IllegalArgumentException("No registered NativeWindowFactory for class " + windowClass.getName());
}
- if (GLReflection.isAWTComponent(winObj)) {
- initializeAWTFactory();
- if(awtFactory == null) {
- throw new GLException("Could not determine an AWT-NativeWindow constructor");
- }
- try {
- return (NativeWindow) awtFactory.newInstance(new Object[] { winObj });
- } catch (Exception ie) {
- ie.printStackTrace();
- }
+ /** Registers a NativeWindowFactory handling window objects of the
+ given class. This does not need to be called by end users,
+ only implementors of new NativeWindowFactory subclasses.. */
+ protected static void registerFactory(Class windowClass, NativeWindowFactory factory) {
+ registeredFactories.put(windowClass, factory);
}
- throw new NativeWindowException("Target type is unsupported. Currently supported: \n"+
- "\tjavax.media.opengl.NativeWindow\n"+
- "\tjava.awt.Component\n");
- }
-}
+ /** Converts the given window object into a {@link NativeWindow
+ NativeWindow} which can be operated upon by the {@link
+ GLDrawableFactory GLDrawableFactory}. The object may be a
+ component for a particular window toolkit, such as an AWT
+ Canvas. It may also be a NativeWindow object, in which no
+ conversion is necessary. The particular implementation of the
+ NativeWindowFactory is responsible for handling objects from a
+ particular window toolkit. The built-in NativeWindowFactory
+ handles NativeWindow instances as well as AWT Components.
+
+ @throws IllegalArgumentException if the given window object
+ could not be handled by any of the registered
+ NativeWindowFactory instances
+ */
+ public static NativeWindow getNativeWindow(Object winObj) throws IllegalArgumentException, NativeWindowException {
+ if (winObj == null) {
+ throw new IllegalArgumentException("Null window object");
+ }
+
+ return getFactory(winObj.getClass()).getNativeWindowImpl(winObj);
+ }
+
+ /**
+ * <P> Selects a graphics configuration on the specified graphics
+ * device compatible with the supplied GLCapabilities. This method
+ * is intended to be used by applications which do not use the
+ * supplied GLCanvas class but instead wrap their own Canvas or
+ * other window toolkit-specific object with a GLDrawable. Some
+ * platforms (specifically X11) require the graphics configuration
+ * to be specified when the window toolkit object is created. This
+ * method may return null on platforms on which the OpenGL pixel
+ * format selection process is performed later. </P>
+ *
+ * <P> The concrete data type of the passed graphics device and
+ * returned graphics configuration must be specified in the
+ * documentation binding this particular API to the underlying
+ * window toolkit. The Reference Implementation accepts {@link
+ * AWTGraphicsDevice AWTGraphicsDevice} objects and returns {@link
+ * AWTGraphicsConfiguration AWTGraphicsConfiguration} objects. </P>
+ *
+ * @see java.awt.Canvas#Canvas(java.awt.GraphicsConfiguration)
+ *
+ * @throws IllegalArgumentException if the data type of the passed
+ * AbstractGraphicsDevice is not supported by this
+ * NativeWindowFactory.
+ * @throws GLException if any window system-specific errors caused
+ * the selection of the graphics configuration to fail.
+ */
+ public abstract AbstractGraphicsConfiguration
+ chooseGraphicsConfiguration(GLCapabilities capabilities,
+ GLCapabilitiesChooser chooser,
+ AbstractGraphicsDevice device)
+ throws IllegalArgumentException, GLException;
+
+ /** Performs the conversion from a toolkit's window object to a
+ NativeWindow. Implementors of concrete NativeWindowFactory
+ subclasses should override this method. */
+ protected abstract NativeWindow getNativeWindowImpl(Object winObj) throws IllegalArgumentException;
+
+ /** Returns the object which provides support for synchronizing
+ with the underlying window toolkit. On most platforms the
+ returned object does nothing; currently it only has effects on
+ X11 platforms. */
+ public abstract ToolkitLock getToolkitLock();
+}
diff --git a/src/classes/javax/media/opengl/ToolkitLock.java b/src/classes/javax/media/opengl/ToolkitLock.java
new file mode 100644
index 000000000..9574de77c
--- /dev/null
+++ b/src/classes/javax/media/opengl/ToolkitLock.java
@@ -0,0 +1,48 @@
+/*
+ * 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 javax.media.opengl;
+
+/** Provides an interface for locking and unlocking the underlying
+ window toolkit, where this is necessary in the OpenGL
+ implementation. This mechanism is generally only needed on X11
+ platforms. Currently it is only used when the AWT is in use.
+ Implementations of this lock, if they are not no-ops, must support
+ reentrant locking and unlocking. */
+
+public interface ToolkitLock {
+ /** Locks the toolkit. */
+ public void lock();
+
+ /** Unlocks the toolkit. */
+ public void unlock();
+}
diff --git a/src/classes/javax/media/opengl/X11GraphicsConfiguration.java b/src/classes/javax/media/opengl/X11GraphicsConfiguration.java
new file mode 100644
index 000000000..95127f2c1
--- /dev/null
+++ b/src/classes/javax/media/opengl/X11GraphicsConfiguration.java
@@ -0,0 +1,53 @@
+/*
+ * 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 javax.media.opengl;
+
+/** Encapsulates a graphics configuration, or OpenGL pixel format, on
+ X11 platforms. Objects of this type are returned from {@link
+ NativeWindowFactory#chooseGraphicsConfiguration
+ NativeWindowFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsConfiguration implements AbstractGraphicsConfiguration {
+ private long visualID;
+
+ /** Constructs a new X11GraphicsConfiguration corresponding to the given visual ID. */
+ public X11GraphicsConfiguration(long visualID) {
+ this.visualID = visualID;
+ }
+
+ /** Returns the visual ID that this graphics configuration object represents. */
+ public long getVisualID() {
+ return visualID;
+ }
+}
diff --git a/src/classes/javax/media/opengl/X11GraphicsDevice.java b/src/classes/javax/media/opengl/X11GraphicsDevice.java
new file mode 100644
index 000000000..1a8900f31
--- /dev/null
+++ b/src/classes/javax/media/opengl/X11GraphicsDevice.java
@@ -0,0 +1,53 @@
+/*
+ * 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 javax.media.opengl;
+
+/** Encapsulates a graphics device, or screen, on X11
+ platforms. Objects of this type are passed to {@link
+ NativeWindowFactory#chooseGraphicsConfiguration
+ NativeWindowFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsDevice implements AbstractGraphicsDevice {
+ private int screen;
+
+ /** Constructs a new X11GraphicsDevice corresponding to the given screen. */
+ public X11GraphicsDevice(int screen) {
+ this.screen = screen;
+ }
+
+ /** Returns the screen that this graphics device object represents. */
+ public int getScreen() {
+ return screen;
+ }
+}
diff --git a/src/classes/javax/media/opengl/awt/GLCanvas.java b/src/classes/javax/media/opengl/awt/GLCanvas.java
index 8d4a1df86..9391b566d 100644
--- a/src/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/classes/javax/media/opengl/awt/GLCanvas.java
@@ -149,8 +149,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
this.glCaps = capabilities;
}
if (!Beans.isDesignTime()) {
- drawable = GLDrawableFactory.getFactory(this.getClass()).createGLDrawable(NativeWindowFactory.getNativeWindow(this),
- capabilities, chooser);
+ drawable = GLDrawableFactory.getFactory().createGLDrawable(NativeWindowFactory.getFactory(getClass()).getNativeWindow(this),
+ capabilities, chooser);
context = (GLContextImpl) drawable.createContext(shareWith);
context.setSynchronized(true);
}
@@ -553,9 +553,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
}
AWTGraphicsConfiguration config = (AWTGraphicsConfiguration)
- GLDrawableFactory.getFactory(Component.class).chooseGraphicsConfiguration(capabilities,
- chooser,
- new AWTGraphicsDevice(device));
+ NativeWindowFactory.getFactory(Component.class).chooseGraphicsConfiguration(capabilities,
+ chooser,
+ new AWTGraphicsDevice(device));
if (config == null) {
return null;
}
diff --git a/src/classes/javax/media/opengl/awt/GLJPanel.java b/src/classes/javax/media/opengl/awt/GLJPanel.java
index 48a2c7cd9..7c38cefe7 100644
--- a/src/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/classes/javax/media/opengl/awt/GLJPanel.java
@@ -145,7 +145,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
getDefaultConfiguration());
}
GLProfile.setProfile(GLProfile.GL2);
- factory = GLDrawableFactoryImpl.getFactoryImpl(Component.class);
+ factory = GLDrawableFactoryImpl.getFactoryImpl();
}
/** Creates a new GLJPanel component with a default set of OpenGL