summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java93
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java43
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java124
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java149
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java138
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java114
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java131
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java71
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java100
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java168
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java47
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java152
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java170
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java136
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java132
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java105
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11NativeWindowFactory.java77
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java125
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java87
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java77
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java58
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java55
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/Capabilities.java259
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java68
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java153
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java103
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java68
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java71
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java208
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java176
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java68
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java352
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java73
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java132
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java86
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java95
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java50
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java50
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/package.html111
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java50
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java76
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java55
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java91
-rw-r--r--src/nativewindow/native/JAWT_DrawingSurfaceInfo.c65
-rw-r--r--src/nativewindow/native/x11/Xinerama.c316
-rw-r--r--src/nativewindow/native/x11/Xinerama.h76
-rw-r--r--src/nativewindow/native/x11/XineramaHelper.c126
-rw-r--r--src/nativewindow/native/x11/extutil.h222
-rw-r--r--src/nativewindow/native/x11/panoramiXext.h54
-rw-r--r--src/nativewindow/native/x11/panoramiXproto.h196
50 files changed, 5802 insertions, 0 deletions
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java b/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java
new file mode 100644
index 000000000..5d53f88fd
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2003-2005 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.
+ *
+ * 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 com.sun.nativewindow.impl;
+
+import java.security.*;
+
+/** Helper routines for logging and debugging. */
+
+public class Debug {
+ // Some common properties
+ private static boolean verbose;
+ private static boolean debugAll;
+
+ static {
+ verbose = isPropertyDefined("nativewindow.verbose");
+ debugAll = isPropertyDefined("nativewindow.debug");
+ if (verbose) {
+ Package p = Package.getPackage("javax.media.nativewindow");
+ System.err.println("NativeWindow specification version " + p.getSpecificationVersion());
+ System.err.println("NativeWindow implementation version " + p.getImplementationVersion());
+ System.err.println("NativeWindow implementation vendor " + p.getImplementationVendor());
+ }
+ }
+
+ public static boolean getBooleanProperty(final String property) {
+ Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ boolean val = Boolean.getBoolean(property);
+ return (val ? Boolean.TRUE : Boolean.FALSE);
+ }
+ });
+ return b.booleanValue();
+ }
+
+ public static boolean isPropertyDefined(final String property) {
+ Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ String val = System.getProperty(property);
+ return (val != null ? Boolean.TRUE : Boolean.FALSE);
+ }
+ });
+ return b.booleanValue();
+ }
+
+ public static boolean verbose() {
+ return verbose;
+ }
+
+ public static boolean debugAll() {
+ return debugAll;
+ }
+
+ public static boolean debug(String subcomponent) {
+ return debugAll() || isPropertyDefined("nativewindow.debug." + subcomponent);
+ }
+}
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..4e8e281a8
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
@@ -0,0 +1,43 @@
+/*
+ * 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 {
+ public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities,
+ CapabilitiesChooser chooser,
+ AbstractGraphicsScreen screen) {
+ return new DefaultGraphicsConfiguration(screen, capabilities, capabilities);
+ }
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java
new file mode 100644
index 000000000..0425014df
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java
@@ -0,0 +1,124 @@
+/*
+ * 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 java.lang.reflect.*;
+import java.nio.*;
+
+/** Internal copy of selected routines from BufferUtil to avoid
+ outward dependencies on com.sun.opengl.util package. */
+public class InternalBufferUtil {
+ public static final int SIZEOF_BYTE = 1;
+ public static final int SIZEOF_SHORT = 2;
+ public static final int SIZEOF_INT = 4;
+ public static final int SIZEOF_FLOAT = 4;
+
+ //----------------------------------------------------------------------
+ // Allocation routines
+ //
+
+ /** Allocates a new direct ByteBuffer with the specified number of
+ elements. The returned buffer will have its byte order set to
+ the host platform's native byte order. */
+ public static ByteBuffer newByteBuffer(int numElements) {
+ ByteBuffer bb = ByteBuffer.allocateDirect(numElements);
+ nativeOrder(bb);
+ return bb;
+ }
+
+ /** Allocates a new direct IntBuffer with the specified number of
+ elements. The returned buffer will have its byte order set to
+ the host platform's native byte order. */
+ public static IntBuffer newIntBuffer(int numElements) {
+ ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT);
+ return bb.asIntBuffer();
+ }
+
+ //----------------------------------------------------------------------
+ // Copy routines (type-to-type)
+ //
+
+ /** Copies the <i>remaining</i> elements (as defined by
+ <code>limit() - position()</code>) in the passed ByteBuffer into
+ a newly-allocated direct ByteBuffer. The returned buffer will
+ have its byte order set to the host platform's native byte
+ order. The position of the newly-allocated buffer will be zero,
+ and the position of the passed buffer is unchanged (though its
+ mark is changed). */
+ public static ByteBuffer copyByteBuffer(ByteBuffer orig) {
+ ByteBuffer dest = newByteBuffer(orig.remaining());
+ dest.put(orig);
+ dest.rewind();
+ return dest;
+ }
+
+ //----------------------------------------------------------------------
+ // Conversion routines
+ //
+
+ public static ByteBuffer nativeOrder(ByteBuffer buf) {
+ if (!isCDCFP) {
+ try {
+ if (byteOrderClass == null) {
+ byteOrderClass = Class.forName("java.nio.ByteOrder");
+ orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass });
+ Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null);
+ nativeOrderObject = nativeOrderMethod.invoke(null, null);
+ }
+ } catch (Throwable t) {
+ // Must be running on CDC / FP
+ isCDCFP = true;
+ }
+
+ if (!isCDCFP) {
+ try {
+ orderMethod.invoke(buf, new Object[] { nativeOrderObject });
+ } catch (Throwable t) {
+ }
+ }
+ }
+ return buf;
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ // NOTE that this work must be done reflectively at the present time
+ // because this code must compile and run correctly on both CDC/FP and J2SE
+ private static boolean isCDCFP;
+ private static Class byteOrderClass;
+ private static Object nativeOrderObject;
+ private static Method orderMethod;
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java
new file mode 100644
index 000000000..b13cf4317
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package com.sun.nativewindow.impl;
+
+import java.lang.reflect.*;
+import javax.media.nativewindow.*;
+
+public final class NWReflection {
+ public static final boolean DEBUG = Debug.debug("NWReflection");
+
+ public static final boolean isClassAvailable(String clazzName) {
+ try {
+ Class clazz = Class.forName(clazzName, false, NWReflection.class.getClassLoader());
+ return null!=clazz;
+ } catch (Throwable e) { }
+ return false;
+ }
+
+ public static final Class getClass(String clazzName, boolean initialize) {
+ try {
+ return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader());
+ } catch (Throwable e) { }
+ return null;
+ }
+
+ public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) {
+ Class factoryClass = null;
+ Constructor factory = null;
+
+ try {
+ factoryClass = getClass(clazzName, true);
+ if (factoryClass == null) {
+ throw new NativeWindowException(clazzName + " not available");
+ }
+ try {
+ factory = factoryClass.getDeclaredConstructor( cstrArgTypes );
+ } catch(NoSuchMethodException nsme) {
+ throw new NativeWindowException("Constructor: '" + clazzName + "("+cstrArgTypes+")' not found");
+ }
+ return factory;
+ } catch (Throwable e) {
+ if (DEBUG) {
+ e.printStackTrace();
+ }
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public static final Constructor getConstructor(String clazzName) {
+ return getConstructor(clazzName, new Class[0]);
+ }
+
+ public static final Object createInstance(String clazzName, Class[] cstrArgTypes, Object[] cstrArgs) {
+ Constructor factory = null;
+
+ try {
+ factory = getConstructor(clazzName, cstrArgTypes);
+ return factory.newInstance( cstrArgs ) ;
+ } catch (Exception e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public static final Object createInstance(String clazzName, Object[] cstrArgs) {
+ Class[] cstrArgTypes = new Class[cstrArgs.length];
+ for(int i=0; i<cstrArgs.length; i++) {
+ cstrArgTypes[i] = cstrArgs[i].getClass();
+ }
+ return createInstance(clazzName, cstrArgTypes, cstrArgs);
+ }
+
+ public static final Object createInstance(String clazzName) {
+ return createInstance(clazzName, new Class[0], null);
+ }
+
+ public static final boolean instanceOf(Object obj, String clazzName) {
+ return instanceOf(obj.getClass(), clazzName);
+ }
+ public static final boolean instanceOf(Class clazz, String clazzName) {
+ do {
+ if(clazz.getName().equals(clazzName)) {
+ return true;
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz!=null);
+ return false;
+ }
+
+ public static final boolean implementationOf(Object obj, String faceName) {
+ return implementationOf(obj.getClass(), faceName);
+ }
+ public static final boolean implementationOf(Class clazz, String faceName) {
+ do {
+ Class[] clazzes = clazz.getInterfaces();
+ for(int i=clazzes.length-1; i>=0; i--) {
+ Class face = clazzes[i];
+ if(face.getName().equals(faceName)) {
+ return true;
+ }
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz!=null);
+ return false;
+ }
+
+ public static boolean isAWTComponent(Object target) {
+ return instanceOf(target, "java.awt.Component");
+ }
+
+ public static boolean isAWTComponent(Class clazz) {
+ return instanceOf(clazz, "java.awt.Component");
+ }
+
+}
+
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
new file mode 100644
index 000000000..e1427d7be
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.sun.nativewindow.impl;
+
+// FIXME: refactor Java SE dependencies
+//import java.awt.Toolkit;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashSet;
+
+public class NativeLibLoaderBase {
+ public static final boolean DEBUG = Debug.debug("NativeLibLoader");
+
+ public interface LoaderAction {
+ /**
+ * Loads the library specified by libname. Optionally preloads the libraries specified by
+ * preload. The implementation should ignore, if the preload-libraries have already been
+ * loaded.
+ * @param libname the library to load
+ * @param preload the libraries to load before loading the main library if not null
+ * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored
+ */
+ void loadLibrary(String libname, String[] preload,
+ boolean preloadIgnoreError);
+ }
+
+ private static class DefaultAction implements LoaderAction {
+ public void loadLibrary(String libname, String[] preload,
+ boolean preloadIgnoreError) {
+ if (null!=preload) {
+ for (int i=0; i<preload.length; i++) {
+ if(!isLoaded(preload[i])) {
+ try {
+ System.loadLibrary(preload[i]);
+ addLoaded(preload[i]);
+ if(DEBUG) {
+ System.err.println("NativeLibLoaderBase preloaded "+preload[i]);
+ }
+ }
+ catch (UnsatisfiedLinkError e) {
+ if(DEBUG) e.printStackTrace();
+ if (!preloadIgnoreError && e.getMessage().indexOf("already loaded") < 0) {
+ throw e;
+ }
+ }
+ }
+ }
+ }
+ System.loadLibrary(libname);
+ addLoaded(libname);
+ if(DEBUG) {
+ System.err.println("NativeLibLoaderBase loaded "+libname);
+ }
+ }
+ }
+
+ private static final HashSet loaded = new HashSet();
+ private static LoaderAction loaderAction = new DefaultAction();
+
+ public static boolean isLoaded(String libName) {
+ return loaded.contains(libName);
+ }
+
+ public static void addLoaded(String libName) {
+ loaded.add(libName);
+ if(DEBUG) {
+ System.err.println("NativeLibLoaderBase Loaded Native Library: "+libName);
+ }
+ }
+
+ public static void disableLoading() {
+ setLoadingAction(null);
+ }
+
+ public static void enableLoading() {
+ setLoadingAction(new DefaultAction());
+ }
+
+ public static synchronized void setLoadingAction(LoaderAction action) {
+ loaderAction = action;
+ }
+
+ protected static synchronized void loadLibrary(String libname, String[] preload,
+ boolean preloadIgnoreError) {
+ if (loaderAction != null && !isLoaded(libname))
+ {
+ loaderAction.loadLibrary(libname, preload, preloadIgnoreError);
+ }
+ }
+
+ public static void loadNativeWindow(final String ossuffix) {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ loadLibrary("nativewindow_"+ossuffix, null, false);
+ return null;
+ }
+ });
+ }
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java
new file mode 100644
index 000000000..424b44c8c
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java
@@ -0,0 +1,114 @@
+/*
+ * 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;
+
+import java.lang.reflect.*;
+import java.security.*;
+
+import javax.media.nativewindow.*;
+
+public class NativeWindowFactoryImpl extends NativeWindowFactory {
+ protected static final boolean DEBUG = Debug.debug("NativeWindowFactoryImpl");
+
+ // This subclass of NativeWindowFactory handles the case of
+ // NativeWindows being passed in
+ protected NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException {
+ if (null == winObj) {
+ throw new IllegalArgumentException("winObj is null");
+ }
+ if (winObj instanceof NativeWindow) {
+ // Use the NativeWindow directly
+ return (NativeWindow) winObj;
+ }
+
+ if (null == config) {
+ throw new IllegalArgumentException("AbstractGraphicsConfiguration is null with a non NativeWindow object");
+ }
+
+ if (NWReflection.isAWTComponent(winObj)) {
+ return getAWTNativeWindow(winObj, config);
+ }
+
+ throw new IllegalArgumentException("Target window object type " +
+ winObj.getClass().getName() + " is unsupported; expected " +
+ "javax.media.nativewindow.NativeWindow or java.awt.Component");
+ }
+
+ private Constructor nativeWindowConstructor = null;
+
+ private NativeWindow getAWTNativeWindow(Object winObj, AbstractGraphicsConfiguration config) {
+ if (nativeWindowConstructor == null) {
+ try {
+ String osType = getNativeWindowType(false);
+ String windowClassName = null;
+
+ // We break compile-time dependencies on the AWT here to
+ // make it easier to run this code on mobile devices
+
+ if (osType.equals(TYPE_WINDOWS)) {
+ windowClassName = "com.sun.nativewindow.impl.jawt.windows.WindowsJAWTWindow";
+ } else if (osType.equals(TYPE_MACOSX)) {
+ windowClassName = "com.sun.nativewindow.impl.jawt.macosx.MacOSXJAWTWindow";
+ } else if (osType.equals(TYPE_X11)) {
+ // Assume Linux, Solaris, etc. Should probably test for these explicitly.
+ windowClassName = "com.sun.nativewindow.impl.jawt.x11.X11JAWTWindow";
+ } else {
+ throw new IllegalArgumentException("OS " + getNativeOSName(false) + " not yet supported");
+ }
+
+ nativeWindowConstructor = NWReflection.getConstructor(windowClassName, new Class[] { Object.class, AbstractGraphicsConfiguration.class });
+ } catch (Exception e) {
+ throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);
+ }
+ }
+
+ try {
+ return (NativeWindow) nativeWindowConstructor.newInstance(new Object[] { winObj, config });
+ } catch (Exception ie) {
+ throw (IllegalArgumentException) new IllegalArgumentException().initCause(ie);
+ }
+ }
+
+ // On most platforms the toolkit lock is a no-op
+ private ToolkitLock toolkitLock = new ToolkitLock() {
+ public void lock() {
+ }
+
+ public void unlock() {
+ }
+ };
+
+ public ToolkitLock getToolkitLock() {
+ return toolkitLock;
+ }
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java
new file mode 100644
index 000000000..46128b227
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package com.sun.nativewindow.impl;
+
+import javax.media.nativewindow.*;
+
+public class NullWindow implements NativeWindow {
+ private Exception lockedStack = null;
+ protected int width, height, scrnIndex;
+ protected long surfaceHandle, displayHandle;
+ protected AbstractGraphicsConfiguration config;
+
+
+ public NullWindow(AbstractGraphicsConfiguration cfg) {
+ invalidate();
+ config = cfg;
+ displayHandle=cfg.getScreen().getDevice().getHandle();
+ scrnIndex=cfg.getScreen().getIndex();
+ }
+
+ protected void init(Object windowObject) throws NativeWindowException {
+ }
+
+ protected void initNative() throws NativeWindowException {
+ }
+
+ public synchronized void invalidate() {
+ displayHandle=0;
+ scrnIndex=-1;
+ surfaceHandle=0;
+ }
+
+ public synchronized int lockSurface() throws NativeWindowException {
+ if (null!=lockedStack) {
+ lockedStack.printStackTrace();
+ throw new NativeWindowException("Surface already locked - "+this);
+ }
+ lockedStack = new Exception("NullWindow previously locked by "+Thread.currentThread().getName());
+ return LOCK_SUCCESS;
+ }
+
+ public synchronized void unlockSurface() {
+ if (null!=lockedStack) {
+ lockedStack = null;
+ } else {
+ throw new NativeWindowException("NullWindow not locked");
+ }
+ }
+
+ public synchronized boolean isSurfaceLocked() {
+ return null!=lockedStack;
+ }
+
+ public Exception getLockedStack() {
+ return lockedStack;
+ }
+
+ public long getDisplayHandle() {
+ return displayHandle;
+ }
+ public int getScreenIndex() {
+ return scrnIndex;
+ }
+ public long getWindowHandle() {
+ return 0;
+ }
+ public long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+ public void setSurfaceHandle(long handle) {
+ surfaceHandle=handle;
+ }
+ public AbstractGraphicsConfiguration getGraphicsConfiguration() {
+ return config;
+ }
+
+ public Object getWrappedWindow() {
+ return null;
+ }
+
+ public final boolean isTerminalObject() {
+ return true;
+ }
+
+ public void setSize(int width, int height) {
+ this.width=width;
+ this.height=height;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java
new file mode 100644
index 000000000..f0f2ac8c3
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.sun.nativewindow.impl.jawt;
+
+import javax.media.nativewindow.NativeWindowFactory;
+import com.sun.nativewindow.impl.NativeLibLoaderBase;
+
+import java.awt.Toolkit;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class JAWTNativeLibLoader extends NativeLibLoaderBase {
+ public static void loadAWTImpl() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ // Make sure that awt.dll is loaded before loading jawt.dll. Otherwise
+ // a Dialog with "awt.dll not found" might pop up.
+ // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4481947.
+ Toolkit.getDefaultToolkit();
+
+ // Must pre-load JAWT on all non-Mac platforms to
+ // ensure references from jogl_awt shared object
+ // will succeed since JAWT shared object isn't in
+ // default library path
+ if ( ! NativeWindowFactory.TYPE_MACOSX.equals( NativeWindowFactory.getNativeWindowType(false) ) ) {
+ loadLibrary("jawt", null, true);
+ }
+ return null;
+ }
+ });
+ }
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
new file mode 100644
index 000000000..ae606a790
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package com.sun.nativewindow.impl.jawt;
+
+import com.sun.nativewindow.impl.*;
+
+import javax.media.nativewindow.*;
+
+import java.awt.GraphicsEnvironment;
+
+public class JAWTUtil {
+ static {
+ JAWTNativeLibLoader.loadAWTImpl();
+ NativeLibLoaderBase.loadNativeWindow("awt");
+ }
+
+ // See whether we're running in headless mode
+ private static boolean headlessMode;
+
+ static {
+ lockedStack = null;
+ headlessMode = GraphicsEnvironment.isHeadless();
+ }
+
+ private static Exception lockedStack;
+
+ public static synchronized void lockToolkit() throws NativeWindowException {
+ if (null!=lockedStack) {
+ lockedStack.printStackTrace();
+ throw new NativeWindowException("JAWT Toolkit already locked - "+Thread.currentThread().getName());
+ }
+ lockedStack = new Exception("JAWT Toolkit already locked by: "+Thread.currentThread().getName());
+
+ if (headlessMode) {
+ // Workaround for running (to some degree) in headless
+ // environments but still supporting rendering via pbuffers
+ // For full correctness, would need to implement a Lock class
+ return;
+ }
+
+ JAWT.getJAWT().Lock();
+ }
+
+ public static synchronized void unlockToolkit() {
+ if (null!=lockedStack) {
+ lockedStack = null;
+ if (headlessMode) {
+ // Workaround for running (to some degree) in headless
+ // environments but still supporting rendering via pbuffers
+ // For full correctness, would need to implement a Lock class
+ return;
+ }
+
+ JAWT.getJAWT().Unlock();
+ }
+ }
+
+ public static boolean isToolkitLocked() {
+ return null!=lockedStack;
+ }
+
+ public static Exception getLockedStack() {
+ return lockedStack;
+ }
+}
+
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java
new file mode 100644
index 000000000..a4a529c54
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package com.sun.nativewindow.impl.jawt;
+
+import com.sun.nativewindow.impl.*;
+
+import java.awt.Component;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+import com.sun.nativewindow.impl.*;
+
+public abstract class JAWTWindow implements NativeWindow {
+ protected static final boolean DEBUG = Debug.debug("JAWT");
+
+ // See whether we're running in headless mode
+ private static boolean headlessMode;
+
+ static {
+ headlessMode = GraphicsEnvironment.isHeadless();
+ }
+
+ // lifetime: forever
+ protected Component component;
+ protected AbstractGraphicsConfiguration config;
+
+ // lifetime: valid after lock, forever until invalidate
+ protected long drawable;
+
+ public JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ if (config == null) {
+ throw new NativeWindowException("Error: AbstractGraphicsConfiguration is null");
+ }
+ this.config = config;
+ init((Component)comp);
+ }
+
+ protected void init(Component windowObject) throws NativeWindowException {
+ invalidate();
+ this.component = windowObject;
+ initNative();
+ }
+
+ protected abstract void initNative() throws NativeWindowException;
+
+ public synchronized void invalidate() {
+ component = null;
+ drawable= 0;
+ }
+
+ private volatile Exception lockedStack = null;
+
+ public synchronized int lockSurface() throws NativeWindowException {
+ // We have to be the owner of the JAWT ToolkitLock 'lock' to benefit from the
+ // recursive lock capabitlites. Otherwise a followup ToolkitLock would
+ // deadlock, since we already have locked JAWT with the surface lock.
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+
+ if (null!=lockedStack) {
+ lockedStack.printStackTrace();
+ throw new NativeWindowException("JAWT Surface already locked - "+Thread.currentThread().getName()+" "+this);
+ }
+ lockedStack = new Exception("JAWT Surface previously locked by "+Thread.currentThread().getName());
+
+ return LOCK_SUCCESS;
+ }
+
+ public synchronized void unlockSurface() {
+ if (null!=lockedStack) {
+ lockedStack = null;
+ } else {
+ throw new NativeWindowException("JAWT Surface not locked");
+ }
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
+ }
+
+ public synchronized boolean isSurfaceLocked() {
+ return null!=lockedStack;
+ }
+
+ public Exception getLockedStack() {
+ return lockedStack;
+ }
+
+ public long getDisplayHandle() {
+ return config.getScreen().getDevice().getHandle();
+ }
+ public int getScreenIndex() {
+ return config.getScreen().getIndex();
+ }
+ public long getWindowHandle() {
+ return drawable;
+ }
+ public long getSurfaceHandle() {
+ return drawable;
+ }
+ public AbstractGraphicsConfiguration getGraphicsConfiguration() {
+ return config;
+ }
+
+ public Object getWrappedWindow() {
+ return component;
+ }
+
+ public void setSize(int width, int height) {
+ component.setSize(width, height);
+ }
+
+ public int getWidth() {
+ return component.getWidth();
+ }
+
+ public int getHeight() {
+ return component.getHeight();
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("JAWT-Window["+
+ "windowHandle 0x"+Long.toHexString(getWindowHandle())+
+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle()));
+ if(null!=component) {
+ sb.append(", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+
+ ", visible "+component.isVisible());
+ } else {
+ sb.append(", component NULL");
+ }
+ sb.append(", locked "+isSurfaceLocked()+
+ ",\n\tconfig "+config+
+ ",\n\twrappedWindow "+getWrappedWindow()+"]");
+
+ return sb.toString();
+ }
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java
new file mode 100644
index 000000000..cc6af7ea4
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.sun.nativewindow.impl.jawt;
+
+import com.sun.nativewindow.impl.*;
+
+/** Marker class for all window system-specific JAWT data structures. */
+
+public interface JAWT_PlatformInfo {
+}
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
new file mode 100644
index 000000000..2d85f1d4d
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.sun.nativewindow.impl.jawt.macosx;
+
+import com.sun.nativewindow.impl.jawt.*;
+import com.sun.nativewindow.impl.*;
+
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+
+import javax.media.nativewindow.*;
+import java.security.*;
+
+public class MacOSXJAWTWindow extends JAWTWindow {
+
+ public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
+ }
+
+ protected void initNative() throws NativeWindowException {
+ }
+
+ public int lockSurface() throws NativeWindowException {
+ int ret = super.lockSurface();
+ if(NativeWindow.LOCK_SUCCESS != ret) {
+ return ret;
+ }
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ super.unlockSurface();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
+ super.unlockSurface();
+ 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
+ // should handle this case, but it may be possible that race
+ // conditions can cause this code to be triggered -- should test
+ // more)
+ if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
+ ret = NativeWindow.LOCK_SURFACE_CHANGED;
+ }
+ if (firstLock) {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ dsi = ds.GetDrawingSurfaceInfo();
+ return null;
+ }
+ });
+ } else {
+ dsi = ds.GetDrawingSurfaceInfo();
+ }
+ if (dsi == null) {
+ // Widget not yet realized
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ super.unlockSurface();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ firstLock = false;
+ macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo();
+ if (macosxdsi == null) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ super.unlockSurface();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ drawable = macosxdsi.cocoaViewRef();
+
+ if (drawable == 0) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ macosxdsi = null;
+ super.unlockSurface();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ return ret;
+ }
+
+ public void unlockSurface() throws NativeWindowException {
+ if(!isSurfaceLocked()) {
+ throw new RuntimeException("JAWTWindow not locked");
+ }
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ macosxdsi = null;
+ super.unlockSurface();
+ }
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
+
+ // Workaround for instance of 4796548
+ private boolean firstLock = true;
+
+}
+
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
new file mode 100644
index 000000000..591213038
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.sun.nativewindow.impl.jawt.windows;
+
+import com.sun.nativewindow.impl.*;
+import com.sun.nativewindow.impl.jawt.*;
+
+import javax.media.nativewindow.*;
+
+public class WindowsJAWTWindow extends JAWTWindow {
+
+ public static final boolean PROFILING = false; // FIXME
+ public static final int PROFILING_TICKS = 600; // FIXME
+
+ public WindowsJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
+ }
+
+ protected void initNative() throws NativeWindowException {
+ }
+
+ public int lockSurface() throws NativeWindowException {
+ int ret = super.lockSurface();
+ if(LOCK_SUCCESS != ret) {
+ return ret;
+ }
+
+ long startTime;
+ if (PROFILING) {
+ startTime = System.currentTimeMillis();
+ }
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
+ super.unlockSurface();
+ 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
+ // should handle this case, but it may be possible that race
+ // conditions can cause this code to be triggered -- should test
+ // more)
+ if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
+ ret = LOCK_SURFACE_CHANGED;
+ }
+ dsi = ds.GetDrawingSurfaceInfo();
+ if (dsi == null) {
+ // Widget not yet realized
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo();
+ if (win32dsi == null) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ drawable = win32dsi.hdc();
+ if (drawable == 0) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ win32dsi = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ if (PROFILING) {
+ long endTime = System.currentTimeMillis();
+ profilingLockSurfaceTime += (endTime - startTime);
+ if (++profilingLockSurfaceTicks == PROFILING_TICKS) {
+ System.err.println("LockSurface calls: " + profilingLockSurfaceTime + " ms / " + PROFILING_TICKS + " calls (" +
+ ((float) profilingLockSurfaceTime / (float) PROFILING_TICKS) + " ms/call)");
+ profilingLockSurfaceTime = 0;
+ profilingLockSurfaceTicks = 0;
+ }
+ }
+ return ret;
+ }
+
+ public void unlockSurface() {
+ if(!isSurfaceLocked()) {
+ throw new RuntimeException("JAWTWindow not locked");
+ }
+ long startTime = 0;
+ if (PROFILING) {
+ startTime = System.currentTimeMillis();
+ }
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ win32dsi = null;
+ super.unlockSurface();
+ if (PROFILING) {
+ long endTime = System.currentTimeMillis();
+ profilingUnlockSurfaceTime += (endTime - startTime);
+ if (++profilingUnlockSurfaceTicks == PROFILING_TICKS) {
+ System.err.println("UnlockSurface calls: " + profilingUnlockSurfaceTime + " ms / " + PROFILING_TICKS + " calls (" +
+ ((float) profilingUnlockSurfaceTime / (float) PROFILING_TICKS) + " ms/call)");
+ profilingUnlockSurfaceTime = 0;
+ profilingUnlockSurfaceTicks = 0;
+ }
+ }
+ }
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_Win32DrawingSurfaceInfo win32dsi;
+ private long profilingLockSurfaceTime = 0;
+ private int profilingLockSurfaceTicks = 0;
+ private long profilingUnlockSurfaceTime = 0;
+ private int profilingUnlockSurfaceTicks = 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
new file mode 100644
index 000000000..75133488f
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+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 java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+
+public class X11JAWTWindow extends JAWTWindow {
+
+ public X11JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
+ }
+
+ protected void initNative() throws NativeWindowException {
+ }
+
+ public synchronized int lockSurface() throws NativeWindowException {
+ int ret = super.lockSurface();
+ if(LOCK_SUCCESS != ret) {
+ return ret;
+ }
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
+ super.unlockSurface();
+ 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
+ // should handle this case, but it may be possible that race
+ // conditions can cause this code to be triggered -- should test
+ // more)
+ if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
+ ret = LOCK_SURFACE_CHANGED;
+ }
+ dsi = ds.GetDrawingSurfaceInfo();
+ if (dsi == null) {
+ // Widget not yet realized
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo();
+ if (x11dsi == null) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ drawable = x11dsi.drawable();
+ if (drawable == 0) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ x11dsi = null;
+ drawable = 0;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ return ret;
+ }
+
+ public synchronized void unlockSurface() {
+ if(!isSurfaceLocked()) {
+ throw new RuntimeException("JAWTWindow not locked");
+ }
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ x11dsi = null;
+ super.unlockSurface();
+ }
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_X11DrawingSurfaceInfo x11dsi;
+
+}
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
new file mode 100644
index 000000000..ef1f82cee
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.sun.nativewindow.impl.jawt.x11;
+
+import com.sun.nativewindow.impl.x11.*;
+
+import java.awt.GraphicsConfiguration;
+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. */
+
+public class X11SunJDKReflection {
+ private static Class x11GraphicsDeviceClass;
+ private static Method x11GraphicsDeviceGetScreenMethod;
+ private static Method x11GraphicsDeviceGetDisplayMethod;
+ private static Class x11GraphicsConfigClass;
+ private static Method x11GraphicsConfigGetVisualMethod;
+ private static boolean initted;
+
+ static {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ try {
+ x11GraphicsDeviceClass = Class.forName("sun.awt.X11GraphicsDevice");
+ x11GraphicsDeviceGetScreenMethod = x11GraphicsDeviceClass.getDeclaredMethod("getScreen", new Class[] {});
+ x11GraphicsDeviceGetScreenMethod.setAccessible(true);
+ x11GraphicsDeviceGetDisplayMethod = x11GraphicsDeviceClass.getDeclaredMethod("getDisplay", new Class[] {});
+ x11GraphicsDeviceGetDisplayMethod.setAccessible(true);
+
+ x11GraphicsConfigClass = Class.forName("sun.awt.X11GraphicsConfig");
+ x11GraphicsConfigGetVisualMethod = x11GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {});
+ x11GraphicsConfigGetVisualMethod.setAccessible(true);
+ initted = true;
+ } catch (Exception e) {
+ // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
+ }
+ return null;
+ }
+ });
+ }
+
+ public static int graphicsDeviceGetScreen(GraphicsDevice device) {
+ if (!initted) {
+ return 0;
+ }
+
+ try {
+ return ((Integer) x11GraphicsDeviceGetScreenMethod.invoke(device, new Object[] {})).intValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static long graphicsDeviceGetDisplay(GraphicsDevice device) {
+ if (!initted) {
+ return 0;
+ }
+
+ try {
+ return ((Long) x11GraphicsDeviceGetDisplayMethod.invoke(device, new Object[] {})).longValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ 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;
+ }
+
+ try {
+ return ((Integer) x11GraphicsConfigGetVisualMethod.invoke(config, new Object[] {})).intValue();
+ } catch (Exception e) {
+ 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..890f017ab
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
@@ -0,0 +1,105 @@
+/*
+ * 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.*;
+import com.sun.nativewindow.impl.x11.XVisualInfo;
+import com.sun.nativewindow.impl.x11.X11Lib;
+
+public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory {
+ public AbstractGraphicsConfiguration
+ chooseGraphicsConfiguration(Capabilities capabilities,
+ CapabilitiesChooser chooser,
+ AbstractGraphicsScreen screen)
+ throws IllegalArgumentException, NativeWindowException {
+
+ if(null==screen || !(screen instanceof X11GraphicsScreen)) {
+ throw new NativeWindowException("Only valid X11GraphicsScreen are allowed");
+ }
+ return new X11GraphicsConfiguration((X11GraphicsScreen)screen, capabilities, capabilities, getXVisualInfo(screen, capabilities));
+ }
+
+ public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, long visualID)
+ {
+ XVisualInfo xvi_temp = XVisualInfo.create();
+ xvi_temp.visualid(visualID);
+ xvi_temp.screen(screen.getIndex());
+ int num[] = { -1 };
+
+ XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(screen.getDevice().getHandle(), X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0);
+
+ if(xvis==null || num[0]<1) {
+ return null;
+ }
+
+ return XVisualInfo.create(xvis[0]);
+ }
+
+ public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, Capabilities capabilities)
+ {
+ XVisualInfo xv = getXVisualInfoImpl(screen, capabilities, 4 /* TrueColor */);
+ if(null!=xv) return xv;
+ return getXVisualInfoImpl(screen, capabilities, 5 /* DirectColor */);
+ }
+
+ private static XVisualInfo getXVisualInfoImpl(AbstractGraphicsScreen screen, Capabilities capabilities, int c_class)
+ {
+ XVisualInfo ret = null;
+ int[] num = { -1 };
+
+ XVisualInfo vinfo_template = XVisualInfo.create();
+ vinfo_template.screen(screen.getIndex());
+ vinfo_template.c_class(c_class);
+
+ XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(screen.getDevice().getHandle(), X11Lib.VisualScreenMask, vinfo_template, num, 0);
+ XVisualInfo best=null;
+ int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits();
+ for (int i = 0; vinfos!=null && i < num[0]; i++) {
+ if ( best == null ||
+ best.depth() < vinfos[i].depth() )
+ {
+ best = vinfos[i];
+ if(rdepth <= best.depth())
+ break;
+ }
+ }
+ if ( null!=best && ( rdepth <= best.depth() || 24 == best.depth()) ) {
+ ret = XVisualInfo.create(best);
+ }
+ best = null;
+
+ return ret;
+ }
+}
+
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..1c67d6184
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11NativeWindowFactory.java
@@ -0,0 +1,77 @@
+/*
+ * 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;
+ notifyAll();
+ }
+ };
+
+ 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
new file mode 100644
index 000000000..731bd3caf
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
@@ -0,0 +1,125 @@
+/*
+ * 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 java.util.HashMap;
+
+import javax.media.nativewindow.*;
+
+import com.sun.nativewindow.impl.*;
+
+/**
+ * Contains a thread safe X11 utility to retrieve tread local display connection,<br>
+ * as well as the static global discplay connection.<br>
+ *
+ * The TLS variant is thread safe per se, but has the memory leak risk on applications
+ * heavily utilizing runnables on a new thread.<br>
+ *
+ * The static variant is more nice to resources, but involves the default toolkit
+ * locking mechanism, which invocation you have to provide as shown below.<br>
+ * <PRE>
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ try {
+ long displayHandle = X11Util.getStaticDefaultDisplay();
+ ...
+ } finally {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
+ }
+ * </PRE><br>
+ *
+ * We will use the TLS variant, where a long term display connection is being used,
+ * ie in JOGL's <code>X11AWTGLXGraphicsConfigurationFactory</code>,
+ * on all other situations where we just query some X11 attributes,
+ * the locked static variant shall be used instead.<br>
+ */
+public class X11Util {
+ private static final boolean DEBUG = Debug.debug("X11Util");
+
+ static {
+ NativeLibLoaderBase.loadNativeWindow("x11");
+ }
+
+ private X11Util() {}
+
+ private static ThreadLocal currentDisplayAssociation = new ThreadLocal();
+
+ private static long staticDefaultDisplay=0;
+ private static boolean staticDefaultDisplayXineramaEnable=false;
+
+ private static long fetchStaticDefaultDisplay() {
+ if(0==staticDefaultDisplay) {
+ synchronized (X11Util.class) {
+ if(0==staticDefaultDisplay) {
+ staticDefaultDisplay = X11Lib.XOpenDisplay(null);
+ if(0==staticDefaultDisplay) {
+ throw new NativeWindowException("Unable to create a static default display connection");
+ }
+ staticDefaultDisplayXineramaEnable = X11Lib.XineramaEnabled(staticDefaultDisplay);
+ }
+ }
+ }
+ return staticDefaultDisplay;
+ }
+
+ /** Returns the global static default display connection, read the toolkit lock/unlock
+ * requirements {@link X11Util above} for synchronization. */
+ public static long getStaticDefaultDisplay() {
+ return fetchStaticDefaultDisplay();
+ }
+
+ /** Returns the global static default display connection, read the toolkit lock/unlock
+ * requirements {@link X11Util above} for synchronization. */
+ public static boolean isXineramaEnabledOnStaticDefaultDisplay() {
+ fetchStaticDefaultDisplay();
+ return staticDefaultDisplayXineramaEnable;
+ }
+
+
+ /** Returns this thread current default display. */
+ public static long getThreadLocalDefaultDisplay() {
+ Long dpyL = (Long) currentDisplayAssociation.get();
+ if(null==dpyL) {
+ long dpy = X11Lib.XOpenDisplay(null);
+ if(0==dpy) {
+ throw new NativeWindowException("Unable to create a default display connection on Thread "+Thread.currentThread().getName());
+ }
+ dpyL = new Long(dpy);
+ currentDisplayAssociation.set( dpyL );
+ if(DEBUG) {
+ Exception e = new Exception("Created new TLS display connection 0x"+Long.toHexString(dpy)+" for thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ }
+ return dpyL.longValue();
+ }
+}
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
new file mode 100644
index 000000000..53b82ce08
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java
@@ -0,0 +1,87 @@
+/*
+ * 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
+ * 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.awt;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+
+import com.sun.nativewindow.impl.*;
+import com.sun.nativewindow.impl.jawt.*;
+import com.sun.nativewindow.impl.jawt.x11.*;
+import com.sun.nativewindow.impl.x11.*;
+
+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
+ 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();
+ notifyAll();
+ }
+ };
+
+ public ToolkitLock getToolkitLock() {
+ return toolkitLock;
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java
new file mode 100644
index 000000000..e53f75251
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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.nativewindow;
+
+/** A marker interface describing a graphics configuration, visual, or
+ pixel format in a toolkit-independent manner. */
+
+public interface AbstractGraphicsConfiguration extends Cloneable {
+ /**
+ * Return the screen this graphics configuration is valid for
+ */
+ public AbstractGraphicsScreen getScreen();
+
+ /**
+ * Return the capabilities reflecting this graphics configuration,
+ * which may differ from the capabilites used to choose this configuration.
+ *
+ * @return A copy of the Capabilities to avoid mutation by the user.
+ */
+ public Capabilities getChosenCapabilities();
+
+ /**
+ * Return the capabilities used to choose this graphics configuration.
+ *
+ * These may be used to reconfigure the NativeWindow in case
+ * the device changes in a multi screen environment.
+ *
+ * @return A copy of the Capabilities to avoid mutation by the user.
+ */
+ public Capabilities getRequestedCapabilities();
+
+ /**
+ * In case this instance already reflects a native configuration,
+ * return this one.
+ * Otherwise return the encapsuled native configuration,
+ * as it shall be included e.g. in the AWT case.
+ */
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration();
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java
new file mode 100644
index 000000000..4240ec81e
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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.nativewindow;
+
+/** A interface describing a graphics device in a
+ toolkit-independent manner.
+ */
+
+public interface AbstractGraphicsDevice extends Cloneable {
+ /**
+ * Returns the type of the underlying subsystem, ie
+ * NativeWindowFactory.TYPE_KD, NativeWindowFactory.TYPE_X11, ..
+ */
+ public String getType();
+
+ /**
+ * Returns the native handle of the underlying native device,
+ * if such thing exist.
+ */
+ public long getHandle();
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java
new file mode 100644
index 000000000..eb2cc9120
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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.nativewindow;
+
+/** A interface describing a graphics screen in a
+ toolkit-independent manner.
+ */
+
+public interface AbstractGraphicsScreen extends Cloneable {
+ /**
+ * Return the device this graphics configuration is valid for
+ */
+ public AbstractGraphicsDevice getDevice();
+
+ /** Returns the screen index this graphics screen is valid for
+ */
+ public int getIndex();
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
new file mode 100644
index 000000000..6c4c93003
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
@@ -0,0 +1,259 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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.nativewindow;
+
+/** Specifies a set of capabilities that a window's rendering context
+ must support, such as color depth per channel. It currently
+ contains the minimal number of routines which allow configuration
+ on all supported window systems. */
+
+public class Capabilities implements Cloneable {
+ private int redBits = 8;
+ private int greenBits = 8;
+ private int blueBits = 8;
+ private int alphaBits = 0;
+
+ // Support for transparent windows containing OpenGL content
+ private boolean backgroundOpaque = true;
+ private int transparentValueRed = -1;
+ private int transparentValueGreen = -1;
+ private int transparentValueBlue = -1;
+ private int transparentValueAlpha = -1;
+
+ /** Creates a Capabilities object. All attributes are in a default
+ state.
+ */
+ public Capabilities() {}
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public boolean equals(Object obj) {
+ if(!(obj instanceof Capabilities)) {
+ return false;
+ }
+ Capabilities other = (Capabilities)obj;
+ boolean res = other.getRedBits()==redBits &&
+ other.getGreenBits()==greenBits &&
+ other.getBlueBits()==blueBits &&
+ other.getAlphaBits()==alphaBits &&
+ other.isBackgroundOpaque()==backgroundOpaque;
+ if(!backgroundOpaque) {
+ res = res && other.getTransparentRedValue()==transparentValueRed &&
+ other.getTransparentGreenValue()==transparentValueGreen &&
+ other.getTransparentBlueValue()==transparentValueBlue &&
+ other.getTransparentAlphaValue()==transparentValueAlpha;
+ }
+
+ return res;
+ }
+
+ /** Returns the number of bits requested for the color buffer's red
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public int getRedBits() {
+ return redBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's red
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setRedBits(int redBits) {
+ this.redBits = redBits;
+ }
+
+ /** Returns the number of bits requested for the color buffer's
+ green component. On some systems only the color depth, which is
+ the sum of the red, green, and blue bits, is considered. */
+ public int getGreenBits() {
+ return greenBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's green
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setGreenBits(int greenBits) {
+ this.greenBits = greenBits;
+ }
+
+ /** Returns the number of bits requested for the color buffer's blue
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public int getBlueBits() {
+ return blueBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's blue
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setBlueBits(int blueBits) {
+ this.blueBits = blueBits;
+ }
+
+ /** Returns the number of bits requested for the color buffer's
+ alpha component. On some systems only the color depth, which is
+ the sum of the red, green, and blue bits, is considered. */
+ public int getAlphaBits() {
+ return alphaBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's alpha
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setAlphaBits(int alphaBits) {
+ this.alphaBits = alphaBits;
+ }
+
+ /** For on-screen OpenGL contexts on some platforms, sets whether
+ the background of the context should be considered opaque. On
+ supported platforms, setting this to false, in conjunction with
+ the transparency values, may allow
+ hardware-accelerated OpenGL content inside of windows of
+ arbitrary shape. To achieve this effect it is necessary to use
+ an OpenGL clear color with an alpha less than 1.0. The default
+ value for this flag is <code>true</code>; setting it to false
+ may incur a certain performance penalty, so it is not
+ recommended to arbitrarily set it to false.<br>
+ If not set already, the transparency values for red, green, blue and alpha
+ are set to their default value, which is half of the value range
+ of the framebuffer's corresponding component,
+ ie <code> redValue = ( 1 << ( redBits - 1 ) ) -1 </code>.
+ */
+ public void setBackgroundOpaque(boolean opaque) {
+ backgroundOpaque = opaque;
+ if(!opaque) {
+ if(transparentValueRed<0)
+ transparentValueRed = ( 1 << ( getRedBits() - 1 ) ) - 1 ;
+ if(transparentValueGreen<0)
+ transparentValueGreen = ( 1 << ( getGreenBits() - 1 ) ) - 1 ;
+ if(transparentValueBlue<0)
+ transparentValueBlue = ( 1 << ( getBlueBits() - 1 ) ) - 1 ;
+ if(transparentValueAlpha<0)
+ transparentValueAlpha = ( 1 << ( getAlphaBits() - 1 ) ) - 1 ;
+ }
+ }
+
+ /** Indicates whether the background of this OpenGL context should
+ be considered opaque. Defaults to true.
+
+ @see #setBackgroundOpaque
+ */
+ public boolean isBackgroundOpaque() {
+ return backgroundOpaque;
+ }
+
+ /** Gets the transparent red value for the frame buffer configuration.
+ * This value is undefined if {@link #isBackgroundOpaque()} equals true.
+ * @see #setTransparentRedValue
+ */
+ public int getTransparentRedValue() { return transparentValueRed; }
+
+ /** Gets the transparent green value for the frame buffer configuration.
+ * This value is undefined if {@link #isBackgroundOpaque()} equals true.
+ * @see #setTransparentGreenValue
+ */
+ public int getTransparentGreenValue() { return transparentValueGreen; }
+
+ /** Gets the transparent blue value for the frame buffer configuration.
+ * This value is undefined if {@link #isBackgroundOpaque()} equals true.
+ * @see #setTransparentBlueValue
+ */
+ public int getTransparentBlueValue() { return transparentValueBlue; }
+
+ /** Gets the transparent alpha value for the frame buffer configuration.
+ * This value is undefined if {@link #isBackgroundOpaque()} equals true.
+ * @see #setTransparentAlphaValue
+ */
+ public int getTransparentAlphaValue() { return transparentValueAlpha; }
+
+ /** Sets the transparent red value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for red.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.<br>
+ It defaults to half of the frambuffer value for red. <br>
+ A value of -1 is interpreted as any value. */
+ public void setTransparentRedValue(int transValueRed) { transparentValueRed=transValueRed; }
+
+ /** Sets the transparent green value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for green.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.<br>
+ It defaults to half of the frambuffer value for green.<br>
+ A value of -1 is interpreted as any value. */
+ public void setTransparentGreenValue(int transValueGreen) { transparentValueGreen=transValueGreen; }
+
+ /** Sets the transparent blue value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for blue.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.<br>
+ It defaults to half of the frambuffer value for blue.<br>
+ A value of -1 is interpreted as any value. */
+ public void setTransparentBlueValue(int transValueBlue) { transparentValueBlue=transValueBlue; }
+
+ /** Sets the transparent alpha value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for alpha.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.<br>
+ It defaults to half of the frambuffer value for alpha.<br>
+ A value of -1 is interpreted as any value. */
+ public void setTransparentAlphaValue(int transValueAlpha) { transparentValueAlpha=transValueAlpha; }
+
+
+ /** Returns a textual representation of this Capabilities
+ object. */
+ public String toString() {
+ StringBuffer msg = new StringBuffer();
+ msg.append("Capabilities[");
+ msg.append("Red: " + redBits +
+ ", Green: " + greenBits +
+ ", Blue: " + blueBits +
+ ", Alpha: " + alphaBits +
+ ", Opaque: " + backgroundOpaque);
+ if(!backgroundOpaque) {
+ msg.append(", Transparent RGBA: [0x"+ Integer.toHexString(transparentValueRed)+
+ " 0x"+ Integer.toHexString(transparentValueGreen)+
+ " 0x"+ Integer.toHexString(transparentValueBlue)+
+ " 0x"+ Integer.toHexString(transparentValueAlpha)+"] ");
+ }
+ msg.append("]");
+ return msg.toString();
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java
new file mode 100644
index 000000000..d61ebd4ef
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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.nativewindow;
+
+/** Provides a mechanism by which applications can customize the
+ window type selection for a given {@link Capabilities}.
+ Developers can implement this interface and pass an instance into
+ the method {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration}; the chooser
+ will be called at window creation time. */
+
+public interface CapabilitiesChooser {
+ /** Chooses the index (0..available.length - 1) of the {@link
+ Capabilities} most closely matching the desired one from the
+ list of all supported. Some of the entries in the
+ <code>available</code> array may be null; the chooser must
+ ignore these. The <em>windowSystemRecommendedChoice</em>
+ parameter may be provided to the chooser by the underlying
+ window system; if this index is valid, it is recommended, but
+ not necessarily required, that the chooser select that entry.
+
+ <P> <em>Note:</em> this method is called automatically by the
+ {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration} method
+ when an instance of this class is passed in to it.
+ It should generally not be
+ invoked by users directly, unless it is desired to delegate the
+ choice to some other CapabilitiesChooser object.
+ */
+ public int chooseCapabilities(Capabilities desired,
+ Capabilities[] available,
+ int windowSystemRecommendedChoice);
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java
new file mode 100644
index 000000000..cead0a4a8
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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.nativewindow;
+
+/** <P> The default implementation of the {@link
+ CapabilitiesChooser} interface, which provides consistent visual
+ selection behavior across platforms. The precise algorithm is
+ deliberately left loosely specified. Some properties are: </P>
+
+ <LI> Attempts to match as closely as possible the given
+ Capabilities, but will select one with fewer capabilities (i.e.,
+ lower color depth) if necessary.
+
+ <LI> If there is no exact match, prefers a more-capable visual to
+ a less-capable one.
+
+ <LI> If there is more than one exact match, chooses an arbitrary
+ one.
+
+ <LI> If a valid windowSystemRecommendedChoice parameter is
+ supplied, chooses that instead of using the cross-platform code.
+
+ </UL>
+*/
+
+public class DefaultCapabilitiesChooser implements CapabilitiesChooser {
+ private static final boolean DEBUG = false; // FIXME: Debug.debug("DefaultCapabilitiesChooser");
+
+ public int chooseCapabilities(Capabilities desired,
+ Capabilities[] available,
+ int windowSystemRecommendedChoice) {
+ if (DEBUG) {
+ System.err.println("Desired: " + desired);
+ for (int i = 0; i < available.length; i++) {
+ System.err.println("Available " + i + ": " + available[i]);
+ }
+ System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice);
+ }
+
+ if (windowSystemRecommendedChoice >= 0 &&
+ windowSystemRecommendedChoice < available.length &&
+ available[windowSystemRecommendedChoice] != null) {
+ if (DEBUG) {
+ System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice);
+ System.err.println(available[windowSystemRecommendedChoice]);
+ }
+ return windowSystemRecommendedChoice;
+ }
+
+ // Create score array
+ int[] scores = new int[available.length];
+ int NO_SCORE = -9999999;
+ int COLOR_MISMATCH_PENALTY_SCALE = 36;
+ for (int i = 0; i < scores.length; i++) {
+ scores[i] = NO_SCORE;
+ }
+ // Compute score for each
+ for (int i = 0; i < scores.length; i++) {
+ Capabilities cur = available[i];
+ if (cur == null) {
+ continue;
+ }
+ int score = 0;
+ // Compute difference in color depth
+ score += (COLOR_MISMATCH_PENALTY_SCALE *
+ ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) -
+ (desired.getRedBits() + desired.getGreenBits() + desired.getBlueBits() + desired.getAlphaBits())));
+ scores[i] = score;
+ }
+
+ if (DEBUG) {
+ System.err.print("Scores: [");
+ for (int i = 0; i < available.length; i++) {
+ if (i > 0) {
+ System.err.print(",");
+ }
+ System.err.print(" " + scores[i]);
+ }
+ System.err.println(" ]");
+ }
+
+ // Ready to select. Choose score closest to 0.
+ int scoreClosestToZero = NO_SCORE;
+ int chosenIndex = -1;
+ for (int i = 0; i < scores.length; i++) {
+ int score = scores[i];
+ if (score == NO_SCORE) {
+ continue;
+ }
+ // Don't substitute a positive score for a smaller negative score
+ if ((scoreClosestToZero == NO_SCORE) ||
+ (Math.abs(score) < Math.abs(scoreClosestToZero) &&
+ ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) {
+ scoreClosestToZero = score;
+ chosenIndex = i;
+ }
+ }
+ if (chosenIndex < 0) {
+ throw new NativeWindowException("Unable to select one of the provided Capabilities");
+ }
+ if (DEBUG) {
+ System.err.println("Chosen index: " + chosenIndex);
+ System.err.println("Chosen capabilities:");
+ System.err.println(available[chosenIndex]);
+ }
+
+ return chosenIndex;
+ }
+
+ private static int sign(int score) {
+ if (score < 0) {
+ return -1;
+ }
+ return 1;
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
new file mode 100644
index 000000000..f88632476
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
@@ -0,0 +1,103 @@
+/*
+ * 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.nativewindow;
+
+public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration {
+ private AbstractGraphicsScreen screen;
+ protected Capabilities capabilitiesChosen;
+ protected Capabilities capabilitiesRequested;
+
+ public DefaultGraphicsConfiguration(AbstractGraphicsScreen screen,
+ Capabilities capsChosen, Capabilities capsRequested) {
+ this.screen = screen;
+ this.capabilitiesChosen = capsChosen;
+ this.capabilitiesRequested = capsRequested;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public AbstractGraphicsScreen getScreen() {
+ return screen;
+ }
+
+ public Capabilities getChosenCapabilities() {
+ return (Capabilities)capabilitiesChosen.clone();
+ }
+
+ public Capabilities getRequestedCapabilities() {
+ return (Capabilities)capabilitiesRequested.clone();
+ }
+
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() {
+ return this;
+ }
+
+ /**
+ * Set the capabilities to a new value.
+ *
+ * The use case for setting the Capabilities at a later time is
+ * a change of the graphics device in a multi-screen environment.<br>
+ *
+ * A copy of the passed object is being used.
+ *
+ * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ */
+ protected void setChosenCapabilities(Capabilities capsChosen) {
+ capabilitiesChosen = (Capabilities) capsChosen.clone();
+ }
+
+ /**
+ * Set a new screen.
+ *
+ * the use case for setting a new screen at a later time is
+ * a change of the graphics device in a multi-screen environment.<br>
+ *
+ * A copy of the passed object is being used.
+ */
+ protected void setScreen(DefaultGraphicsScreen screen) {
+ this.screen = (AbstractGraphicsScreen) screen.clone();
+ }
+
+ public String toString() {
+ return getClass().toString()+"[" + screen +
+ ",\n\tchosen " + capabilitiesChosen+
+ ",\n\trequested " + capabilitiesRequested+
+ "]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
new file mode 100644
index 000000000..fdc849d0f
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
@@ -0,0 +1,68 @@
+/*
+ * 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.nativewindow;
+
+public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice {
+ private String type;
+ protected long handle;
+
+ public DefaultGraphicsDevice(String type) {
+ this.type = type;
+ this.handle = 0;
+ }
+
+ public DefaultGraphicsDevice(String type, long handle) {
+ this.type = type;
+ this.handle = handle;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public long getHandle() {
+ return handle;
+ }
+
+ public String toString() {
+ return getClass().toString()+"[type "+getType()+", handle 0x"+Long.toHexString(getHandle())+"]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java
new file mode 100644
index 000000000..0af32c9ec
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java
@@ -0,0 +1,71 @@
+/*
+ * 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.nativewindow;
+
+public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen {
+ AbstractGraphicsDevice device;
+ private int idx;
+
+ public DefaultGraphicsScreen(AbstractGraphicsDevice device, int idx) {
+ this.device = device;
+ this.idx = idx;
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(int screenIdx) {
+ return new DefaultGraphicsScreen(new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT), screenIdx);
+ }
+
+ public static AbstractGraphicsScreen createDefault() {
+ return createScreenDevice(0);
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public AbstractGraphicsDevice getDevice() {
+ return device;
+ }
+
+ public int getIndex() {
+ return idx;
+ }
+
+ public String toString() {
+ return getClass().toString()+"["+device+", idx "+idx+"]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
new file mode 100644
index 000000000..023a9d488
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
@@ -0,0 +1,208 @@
+/*
+ * 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
+ * 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.nativewindow;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import com.sun.nativewindow.impl.*;
+
+/**
+ * Provides the mechanism by which the graphics configuration for a
+ * window can be chosen before the window is created. The graphics
+ * configuration decides parameters related to hardware accelerated rendering such
+ * as the OpenGL pixel format. <br>
+ * On some window systems (EGL/OpenKODE and X11 in particular) it is necessary to
+ * choose the graphics configuration early at window creation time. <br>
+ * Note that the selection of the graphics configuration is an algorithm which does not have
+ * strong dependencies on the particular Java window toolkit in use
+ * (e.g., AWT) and therefore it is strongly desirable to factor this
+ * functionality out of the core {@link NativeWindowFactory} so that
+ * new window toolkits can replace just the {@link
+ * NativeWindowFactory} and reuse the graphics configuration selection
+ * algorithm provided by, for example, an OpenGL binding.
+ */
+
+public abstract class GraphicsConfigurationFactory {
+ protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration");
+
+ private static Map/*<Class, NativeWindowFactory>*/ registeredFactories =
+ Collections.synchronizedMap(new HashMap());
+ private static Class abstractGraphicsDeviceClass;
+
+ static {
+ initialize();
+ }
+
+ /** Creates a new NativeWindowFactory instance. End users do not
+ need to call this method. */
+ protected GraphicsConfigurationFactory() {
+ }
+
+ private static void initialize() {
+ String osName = System.getProperty("os.name");
+ String osNameLowerCase = osName.toLowerCase();
+ String factoryClassName = null;
+
+ abstractGraphicsDeviceClass = javax.media.nativewindow.AbstractGraphicsDevice.class;
+
+ if (!osNameLowerCase.startsWith("wind") &&
+ !osNameLowerCase.startsWith("mac os x")) {
+ // Assume X11 platform -- should probably test for these explicitly
+ try {
+ GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory)
+ NWReflection.createInstance("com.sun.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {});
+ registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ // Register the default no-op factory for arbitrary
+ // AbstractGraphicsDevice implementations, including
+ // AWTGraphicsDevice instances -- the OpenGL binding will take
+ // care of handling AWTGraphicsDevices on X11 platforms (as
+ // well as X11GraphicsDevices in non-AWT situations)
+ registerFactory(abstractGraphicsDeviceClass, new GraphicsConfigurationFactoryImpl());
+ }
+
+ /** Returns the factory for use with the given type of
+ AbstractGraphicsDevice. */
+ public static GraphicsConfigurationFactory getFactory(AbstractGraphicsDevice device) {
+ if (device == null) {
+ return getFactory(AbstractGraphicsDevice.class);
+ }
+ return getFactory(device.getClass());
+ }
+
+ /**
+ * Returns the graphics configuration factory for use with the
+ * given class, which must implement the {@link
+ * AbstractGraphicsDevice} interface.
+ *
+ * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice
+ */
+ public static GraphicsConfigurationFactory getFactory(Class abstractGraphicsDeviceImplementor)
+ throws IllegalArgumentException, NativeWindowException
+ {
+ if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) {
+ throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice");
+ }
+
+ GraphicsConfigurationFactory factory = null;
+ Class clazz = abstractGraphicsDeviceImplementor;
+ while (clazz != null) {
+ factory =
+ (GraphicsConfigurationFactory) registeredFactories.get(clazz);
+ if (factory != null) {
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory);
+ }
+ return factory;
+ }
+ clazz = clazz.getSuperclass();
+ }
+ // Return the default
+ factory = (GraphicsConfigurationFactory)registeredFactories.get(abstractGraphicsDeviceClass);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() DEFAULT "+abstractGraphicsDeviceClass+" -> "+factory);
+ }
+ return factory;
+ }
+
+ /** Registers a GraphicsConfigurationFactory handling graphics
+ * device objects of the given class. This does not need to be
+ * called by end users, only implementors of new
+ * GraphicsConfigurationFactory subclasses.
+ *
+ * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice
+ */
+ protected static void registerFactory(Class abstractGraphicsDeviceImplementor, GraphicsConfigurationFactory factory)
+ throws IllegalArgumentException
+ {
+ if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) {
+ throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice");
+ }
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.registerFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory);
+ }
+ registeredFactories.put(abstractGraphicsDeviceImplementor, factory);
+ }
+
+ /**
+ * <P> Selects a graphics configuration on the specified graphics
+ * device compatible with the supplied {@link Capabilities}. Some
+ * platforms (e.g.: X11, EGL, KD) require the graphics configuration
+ * to be specified when the native window is created.
+ * These architectures have seperated their device, screen, window and drawable
+ * context and hence are capable of quering the capabilities for each screen.
+ * A fully established window is not required.</P>
+ *
+ * <P>Other platforms (e.g. Windows, MacOSX) don't offer the mentioned seperation
+ * and hence need a fully established window and it's drawable.
+ * Here the validation of the capabilities is performed later.
+ * In this case, the AbstractGraphicsConfiguration implementation
+ * must allow an overwrite of the Capabilites, for example
+ * {@link DefaultGraphicsConfiguration#setChosenCapabilities DefaultGraphicsConfiguration.setChosenCapabilities(..)}.
+ * </P>
+ *
+ * <P>
+ * This method is mainly intended to be both used and implemented by the
+ * OpenGL binding.</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
+ * javax.media.nativewindow.awt.AWTGraphicsDevice AWTGraphicsDevice} objects and returns {@link
+ * javax.media.nativewindow.awt.AWTGraphicsConfiguration AWTGraphicsConfiguration} objects. On
+ * X11 platforms where the AWT is not in use, it also accepts
+ * {@link javax.media.nativewindow.x11.X11GraphicsDevice
+ * X11GraphicsDevice} objects and returns {@link
+ * javax.media.nativewindow.x11.X11GraphicsConfiguration
+ * X11GraphicsConfiguration} objects.</P>
+ *
+ * @throws IllegalArgumentException if the data type of the passed
+ * AbstractGraphicsDevice is not supported by this
+ * NativeWindowFactory.
+ * @throws NativeWindowException if any window system-specific errors caused
+ * the selection of the graphics configuration to fail.
+ *
+ * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ * @see javax.media.nativewindow.DefaultGraphicsConfiguration#setChosenCapabilities(Capabilities caps)
+ */
+ public abstract AbstractGraphicsConfiguration
+ chooseGraphicsConfiguration(Capabilities capabilities,
+ CapabilitiesChooser chooser,
+ AbstractGraphicsScreen screen)
+ throws IllegalArgumentException, NativeWindowException;
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java
new file mode 100644
index 000000000..2a9782c12
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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.nativewindow;
+
+/** Provides the low-level information required for
+ hardware-accelerated rendering in a platform-independent manner. A
+ window toolkit such as the AWT may either implement this interface
+ directly with one of its components, or provide and register an
+ implementation of {@link NativeWindowFactory NativeWindowFactory}
+ which can create NativeWindow objects for its components. <P>
+
+ A NativeWindow created for a particular on-screen component is
+ expected to have the same lifetime as that component. As long as
+ the component is alive, the NativeWindow must be able to control
+ it, and any time it is visible and locked, provide information
+ such as the window handle.
+*/
+public interface NativeWindow {
+ /** Returned by {@link #lockSurface()} if the surface is not ready to be locked. */
+ public static final int LOCK_SURFACE_NOT_READY = 1;
+
+ /** Returned by {@link #lockSurface()} if the surface is locked, but has changed. */
+ public static final int LOCK_SURFACE_CHANGED = 2;
+
+ /** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged. */
+ public static final int LOCK_SUCCESS = 3;
+
+ /**
+ * Lock the surface of this native window<P>
+ *
+ * The window handle, see {@link #getWindowHandle()},
+ * and the surface handle, see {@link #lockSurface()}, <br>
+ * shall be set and be valid after a successfull call,
+ * ie a return value other than {@link #LOCK_SURFACE_NOT_READY}.<P>
+ *
+ * The semantics of the underlying native locked resource
+ * may be related to the {@link ToolkitLock} one. Hence it is
+ * important that implementation of both harmonize well.<br>
+ * The implementation may want to aquire the {@link ToolkitLock}
+ * first to become it's owner before proceeding with it's
+ * actual surface lock. <P>
+ *
+ * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}.
+ *
+ * @throws NativeWindowException if surface is already locked
+ *
+ * @see ToolkitLock
+ */
+ public int lockSurface() throws NativeWindowException ;
+
+ /**
+ * Unlock the surface of this native window
+ *
+ * Shall not modify the window handle, see {@link #getWindowHandle()},
+ * or the surface handle, see {@link #lockSurface()} <P>
+ *
+ * @throws NativeWindowException if surface is not locked
+ *
+ * @see #lockSurface
+ * @see ToolkitLock
+ */
+ public void unlockSurface() throws NativeWindowException ;
+
+ /**
+ * Return if surface is locked
+ */
+ public boolean isSurfaceLocked();
+
+ /**
+ * Return the lock-exception, or null if not locked.
+ *
+ * The lock-exception is created at {@link #lockSurface()}
+ * and hence holds the locker's call stack.
+ */
+ public Exception getLockedStack();
+
+ /**
+ * render all native window information invalid,
+ * as if the native window was destroyed
+ */
+ public void invalidate();
+
+ /**
+ * Returns the window handle for this NativeWindow. <P>
+ *
+ * The window handle should be set/update by {@link #lockSurface()},
+ * where {@link #unlockSurface()} is not allowed to modify it.<br>
+ * After {@link #unlockSurface()} it is no more guaranteed
+ * that the window handle is still valid.<p>
+ *
+ * The window handle shall reflect the platform one
+ * for all window related operations, e.g. open, close, resize. <P>
+ *
+ * On X11 this returns an entity of type Window. <BR>
+ * On Microsoft Windows this returns an entity of type HWND.
+ */
+ public long getWindowHandle();
+
+ /**
+ * Returns the handle to the surface for this NativeWindow. <P>
+ *
+ * The surface handle should be set/update by {@link #lockSurface()},
+ * where {@link #unlockSurface()} is not allowed to modify it.
+ * After {@link #unlockSurface()} it is no more guaranteed
+ * that the surface handle is still valid.
+ *
+ * The surface handle shall reflect the platform one
+ * for all drawable surface operations, e.g. opengl, swap-buffer. <P>
+ *
+ * On X11 this returns an entity of type Window,
+ * since there is no differentiation of surface and window there. <BR>
+ * On Microsoft Windows this returns an entity of type HDC.
+ */
+ public long getSurfaceHandle();
+
+ /** Returns the current width of this window. */
+ public int getWidth();
+
+ /** Returns the current height of this window. */
+ public int getHeight();
+
+ /**
+ * Returns the graphics configuration corresponding to this window.
+ * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ */
+ public AbstractGraphicsConfiguration getGraphicsConfiguration();
+
+ /**
+ * Convenience: Get display handle from
+ * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice
+ */
+ public long getDisplayHandle();
+
+ /**
+ * Convenience: Get display handle from
+ * AbstractGraphicsConfiguration . AbstractGraphicsScreen
+ */
+ public int getScreenIndex();
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java
new file mode 100644
index 000000000..593c1e7d6
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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.nativewindow;
+
+/** A generic exception for OpenGL errors used throughout the binding
+ as a substitute for {@link RuntimeException}. */
+
+public class NativeWindowException extends RuntimeException {
+ /** Constructs a NativeWindowException object. */
+ public NativeWindowException() {
+ super();
+ }
+
+ /** Constructs a NativeWindowException object with the specified detail
+ message. */
+ public NativeWindowException(String message) {
+ super(message);
+ }
+
+ /** Constructs a NativeWindowException object with the specified detail
+ message and root cause. */
+ public NativeWindowException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a NativeWindowException object with the specified root
+ cause. */
+ public NativeWindowException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
new file mode 100644
index 000000000..39ec18bc4
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -0,0 +1,352 @@
+/*
+ * 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
+ * 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.nativewindow;
+
+import java.lang.reflect.*;
+import java.security.*;
+import java.util.*;
+
+import com.sun.nativewindow.impl.*;
+
+/** Provides a pluggable mechanism for arbitrary window toolkits to
+ adapt their components to the {@link NativeWindow} interface,
+ which provides a platform-independent mechanism of accessing the
+ information required to perform operations like
+ hardware-accelerated rendering using the OpenGL API. */
+
+public abstract class NativeWindowFactory {
+ protected static final boolean DEBUG = Debug.debug("NativeWindow");
+
+ /** OpenKODE/EGL type */
+ public static final String TYPE_EGL = "EGL";
+
+ /** Microsoft Windows type */
+ public static final String TYPE_WINDOWS = "Windows";
+
+ /** X11 type */
+ public static final String TYPE_X11 = "X11";
+
+ /** Mac OS X type */
+ public static final String TYPE_MACOSX = "MacOSX";
+
+ /** Generic AWT type */
+ public static final String TYPE_AWT = "AWT";
+
+ /** Generic DEFAULT type, where platform implementation don't care */
+ public static final String TYPE_DEFAULT = "default";
+
+ private static NativeWindowFactory defaultFactory;
+ private static Map/*<Class, NativeWindowFactory>*/ registeredFactories;
+ private static Class nativeWindowClass;
+ private static String nativeWindowingTypePure;
+ private static String nativeOSNamePure;
+ private static String nativeWindowingTypeCustom;
+ private static String nativeOSNameCustom;
+
+ /** Creates a new NativeWindowFactory instance. End users do not
+ need to call this method. */
+ protected NativeWindowFactory() {
+ }
+
+ private static String _getNativeWindowingType(String osNameLowerCase) {
+ if (osNameLowerCase.startsWith("kd")) {
+ return TYPE_EGL;
+ } else if (osNameLowerCase.startsWith("wind")) {
+ return TYPE_WINDOWS;
+ } else if (osNameLowerCase.startsWith("mac os x") ||
+ osNameLowerCase.startsWith("darwin")) {
+ return TYPE_MACOSX;
+ } else if (osNameLowerCase.equals("awt")) {
+ return TYPE_AWT;
+ } else {
+ return TYPE_X11;
+ }
+ }
+
+ static {
+ // Gather the windowing OS first
+ nativeOSNamePure = System.getProperty("os.name");
+ nativeOSNameCustom = System.getProperty("nativewindow.ws.name");
+ if(null==nativeOSNameCustom||nativeOSNameCustom.length()==0) {
+ nativeOSNameCustom = nativeOSNamePure;
+ }
+ nativeWindowingTypePure = _getNativeWindowingType(nativeOSNamePure.toLowerCase());
+ nativeWindowingTypeCustom = _getNativeWindowingType(nativeOSNameCustom.toLowerCase());
+
+ registeredFactories = Collections.synchronizedMap(new HashMap());
+
+ String factoryClassName = null;
+
+ // register our default factory -> NativeWindow
+ NativeWindowFactory factory = new NativeWindowFactoryImpl();
+ nativeWindowClass = javax.media.nativewindow.NativeWindow.class;
+ registerFactory(nativeWindowClass, factory);
+ defaultFactory = factory;
+
+ // We break compile-time dependencies on the AWT here to
+ // make it easier to run this code on mobile devices
+
+ Class componentClass = null;
+ if ( NWReflection.isClassAvailable("java.awt.Component") &&
+ NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) {
+ try {
+ componentClass = NWReflection.getClass("java.awt.Component", false);
+ } catch (Exception e) { }
+ }
+
+ boolean toolkitLockDisabled = Boolean.getBoolean("nativewindow.toolkitlock.disabled"); // test ..
+
+ if(TYPE_X11.equals(nativeWindowingTypeCustom) && !toolkitLockDisabled) {
+ NativeWindowFactory _factory = null;
+
+ // FIXME: there are regressions in functionality in the
+ // JOGL 2 rewrite compared to JOGL 1.1.1 which are
+ // described in the writeup below.
+ //
+ // There are certain operations that may be done by
+ // user-level native code which must share the display
+ // connection with the underlying window toolkit. In JOGL,
+ // for example, the AWT GLCanvas makes GLX and OpenGL
+ // calls against an X Drawable that was created by the
+ // AWT. In this case, the AWT Native Interface ("JAWT") is
+ // used to lock and unlock this surface, which grabs and
+ // releases a lock which is also used internally to the
+ // AWT implementation. This is required because the AWT
+ // makes X calls from multiple threads: for example, the
+ // AWT Toolkit thread and one or more Event Dispatch
+ // Threads.
+ // CHECK: OK
+ //
+ // In the JOGL API, there are other operations that use an
+ // X display connection which do not involve locking an
+ // on-screen window created by the toolkit: visual
+ // selection, pbuffers, external contexts and external
+ // drawables.
+ //
+ // The JOGL GLPbuffer implementation uses its own display
+ // connection via "XOpenDisplay(null)". This was true even
+ // in JOGL 1.1.1. It is believed, but not 100% clear,
+ // whether X implementations are robust enough to handle
+ // the opening of a new display connection in a
+ // multithreaded fashion with no synchronization.
+ // (Semantically this should be allowed, but practically,
+ // it is unclear.) Currently the JOGL implementation locks
+ // the ToolkitLock around pbuffer-related operations.
+ // CHECK: OK - Using X11GraphicsScreen.createDefault() now,
+ // utilizing one display per thread.
+ // However, locking code is still intact.
+ // FIXME: Shall it really have one new display per
+ // Pbuffer ?
+ //
+ // Even if the pbuffer case is over-synchronized, there
+ // are definitely cases where synchronization with the
+ // toolkit is required. From recollection, visual
+ // selection is performed outside of the cover of the
+ // toolkit's lock, and the toolkit's display connection is
+ // used for this operation, so for correctness the toolkit
+ // must be locked during glXChooseFBConfig /
+ // glXChooseVisual. Synchronization with the toolkit is
+ // definitely needed for support of external GLDrawables,
+ // where JOGL creates additional OpenGL contexts on a
+ // surface that was created by a third party. External
+ // GLDrawables are the foundation of the Java 2D / JOGL
+ // bridge. While this bridge may be historical at this
+ // point, support for external GLDrawables on platforms
+ // that can support them (namely, WGL and X11 platforms;
+ // Mac OS X does not currently have the required
+ // primitives in its OpenGL window system binding) makes
+ // the JOGL library more powerful.
+ //
+ // (FIXME: from code examination, it looks like there are
+ // regressions in the support for external GLDrawables in
+ // JOGL 2 compared to JOGL 1.1.1. Note that the "default"
+ // X display connection from X11Util is being used during
+ // construction of the X11ExternalGLXDrawable instead of
+ // the result of glXGetCurrentDisplay().)
+ //
+ // The X11AWTNativeWindowFactory provides a locking
+ // mechanism compatible with the AWT. It may be desirable
+ // to replace this window factory when using third-party
+ // toolkits like Newt even when running on Java SE when
+ // the AWT is available.
+
+ if (componentClass != null) {
+ try {
+ Constructor factoryConstructor =
+ NWReflection.getConstructor("com.sun.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {});
+ _factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
+ } catch (Exception e) { }
+ }
+
+ // If it turns out that the AWT is not available, for
+ // example on embedded profiles (CDC / FP), then
+ // synchronization is still needed, for example among
+ // multiple threads that might create pbuffers
+ // or for threads using the static default display to query information.
+ // The X11NativeWindowFactory provides a simple reentrant lock
+ // for this purpose. It is expected that third-party
+ // toolkits will either replace this factory, and thereby
+ // the implementation of this lock, if stronger
+ // interoperability is desired, for example full support
+ // for external GLDrawables.
+ if (null ==_factory) {
+ // Try the non-AWT X11 native window factory
+ try {
+ Constructor factoryConstructor =
+ NWReflection.getConstructor("com.sun.nativewindow.impl.x11.X11NativeWindowFactory", new Class[] {});
+ _factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
+ } catch (Exception e) { }
+ }
+
+ if (null !=_factory) {
+ factory = _factory;
+ }
+ }
+
+ if(null!=componentClass) {
+ // register either our default factory or (if exist) the X11/AWT one -> AWT Component
+ registerFactory(componentClass, factory);
+ }
+ defaultFactory = factory;
+ if(DEBUG) {
+ System.err.println("NativeWindowFactory defaultFactory "+factory);
+ }
+ }
+
+ public static String getNativeOSName(boolean useCustom) {
+ return useCustom?nativeOSNameCustom:nativeOSNamePure;
+ }
+
+ public static String getNativeWindowType(boolean useCustom) {
+ return useCustom?nativeWindowingTypeCustom:nativeWindowingTypePure;
+ }
+
+ /** 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;
+ }
+
+ /** 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);
+ }
+ Class clazz = windowClass;
+ while (clazz != null) {
+ NativeWindowFactory factory = (NativeWindowFactory) registeredFactories.get(clazz);
+ if (factory != null) {
+ return factory;
+ }
+ clazz = clazz.getSuperclass();
+ }
+ throw new IllegalArgumentException("No registered NativeWindowFactory for class " + windowClass.getName());
+ }
+
+ /** 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) {
+ if(DEBUG) {
+ System.err.println("NativeWindowFactory.registerFactory() "+windowClass+" -> "+factory);
+ }
+ registeredFactories.put(windowClass, factory);
+ }
+
+ /** Converts the given window object and it's
+ {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration} into a
+ {@link NativeWindow NativeWindow} which can be operated upon by a custom
+ toolkit, e.g. {@link javax.media.opengl.GLDrawableFactory javax.media.opengl.GLDrawableFactory}.<br>
+ The object may be a component for a particular window toolkit, such as an AWT
+ Canvas. It may also be a NativeWindow object itself.<br>
+ You shall utilize {@link javax.media.nativewindow.GraphicsConfigurationFactory GraphicsConfigurationFactory}
+ to construct a proper {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration}.<br>
+ 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.<br>
+
+ @throws IllegalArgumentException if the given window object
+ could not be handled by any of the registered
+ NativeWindowFactory instances
+
+ @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ */
+ public static NativeWindow getNativeWindow(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException, NativeWindowException {
+ if (winObj == null) {
+ throw new IllegalArgumentException("Null window object");
+ }
+
+ return getFactory(winObj.getClass()).getNativeWindowImpl(winObj, config);
+ }
+
+ /** 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, AbstractGraphicsConfiguration config) throws IllegalArgumentException;
+
+ /** Returns the object which provides support for synchronizing
+ with the underlying window toolkit.<br>
+ @see ToolkitLock
+ */
+ public abstract ToolkitLock getToolkitLock();
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java
new file mode 100644
index 000000000..27e59d8c8
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java
@@ -0,0 +1,73 @@
+/*
+ * 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.nativewindow;
+
+/** 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. <P>
+
+ The ToolkitLock implementation can be aquired by
+ {@link NativeWindowFactory#getToolkitLock NativeWindowFactory's getToolkitLock()}.<P>
+
+ All toolkit shared resources shall be accessed by encapsulating the
+ code with a locking block as follows.
+ <PRE>
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ try {
+ long displayHandle = X11Util.getStaticDefaultDisplay();
+ ...
+ } finally {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
+ }
+ </PRE><P>
+
+ The underlying toolkit's locking mechanism may relate to {@link NativeWindow}'s
+ {@link NativeWindow#lockSurface lockSurface()}. Hence it is important
+ that both implementation harmonize well, ie {@link NativeWindow#lockSurface lockSurface()}
+ shall issue a ToolkitLock lock befor it aquires it's surface lock. This is true
+ in the AWT implementation for example. Otherwise the surface lock would <i>steal</i>
+ the ToolkitLock's lock and a deadlock would be unavoidable.<P>
+
+ However the necessity of needing a global state synchronization will of course
+ impact your performance very much, especially in case of a multithreaded/multiwindow case.
+ */
+public interface ToolkitLock {
+ /** Locks the toolkit. */
+ public void lock();
+
+ /** Unlocks the toolkit. */
+ public void unlock();
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
new file mode 100644
index 000000000..7373e7b97
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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.nativewindow.awt;
+
+import javax.media.nativewindow.*;
+import java.awt.GraphicsConfiguration;
+import java.awt.Transparency;
+import java.awt.image.ColorModel;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import com.sun.nativewindow.impl.Debug;
+
+/** A wrapper for an AWT GraphicsConfiguration allowing it to be
+ handled in a toolkit-independent manner. */
+
+public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable {
+ private GraphicsConfiguration config;
+ AbstractGraphicsConfiguration encapsulated;
+
+ public AWTGraphicsConfiguration(AWTGraphicsScreen screen,
+ Capabilities capsChosen, Capabilities capsRequested,
+ GraphicsConfiguration config, AbstractGraphicsConfiguration encapsulated) {
+ super(screen, capsChosen, capsRequested);
+ this.config = config;
+ this.encapsulated=encapsulated;
+ }
+
+ public AWTGraphicsConfiguration(AWTGraphicsScreen screen, Capabilities capsChosen, Capabilities capsRequested, GraphicsConfiguration config) {
+ super(screen, capsChosen, capsRequested);
+ this.config = config;
+ this.encapsulated=null;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+
+ public GraphicsConfiguration getGraphicsConfiguration() {
+ return config;
+ }
+
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() {
+ return (null!=encapsulated)?encapsulated:this;
+ }
+
+ /**
+ * Sets up the Capabilities' RGBA size based on the given GraphicsConfiguration's ColorModel.
+ *
+ * @param capabilities the Capabilities object whose red, green, blue, and alpha bits will be set
+ * @param gc the GraphicsConfiguration from which to derive the RGBA bit depths
+ * @return the passed Capabilities
+ */
+ public static Capabilities setupCapabilitiesRGBABits(Capabilities capabilities, GraphicsConfiguration gc) {
+ int cmTransparency = capabilities.isBackgroundOpaque()?Transparency.OPAQUE:Transparency.TRANSLUCENT;
+ ColorModel cm = gc.getColorModel(cmTransparency);
+ if(null==cm && !capabilities.isBackgroundOpaque()) {
+ capabilities.setBackgroundOpaque(true);
+ cmTransparency = Transparency.OPAQUE;
+ cm = gc.getColorModel(cmTransparency);
+ }
+ if(null==cm) {
+ throw new NativeWindowException("Could not determine AWT ColorModel");
+ }
+ int cmBitsPerPixel = cm.getPixelSize();
+ int bitsPerPixel = 0;
+ int[] bitesPerComponent = cm.getComponentSize();
+ if(bitesPerComponent.length>=3) {
+ capabilities.setRedBits(bitesPerComponent[0]);
+ bitsPerPixel += bitesPerComponent[0];
+ capabilities.setGreenBits(bitesPerComponent[1]);
+ bitsPerPixel += bitesPerComponent[1];
+ capabilities.setBlueBits(bitesPerComponent[2]);
+ bitsPerPixel += bitesPerComponent[2];
+ }
+ if(bitesPerComponent.length>=4) {
+ capabilities.setAlphaBits(bitesPerComponent[3]);
+ bitsPerPixel += bitesPerComponent[3];
+ } else {
+ capabilities.setAlphaBits(0);
+ }
+ if(Debug.debugAll()) {
+ if(cmBitsPerPixel!=bitsPerPixel) {
+ System.err.println("AWT Colormodel bits per components/pixel mismatch: "+bitsPerPixel+" != "+cmBitsPerPixel);
+ }
+ }
+ return capabilities;
+ }
+
+ public String toString() {
+ return getClass().toString()+"[" + getScreen() +
+ ",\n\tchosen " + capabilitiesChosen+
+ ",\n\trequested " + capabilitiesRequested+
+ ",\n\t" + config +
+ ",\n\tencapsulated "+encapsulated+"]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
new file mode 100644
index 000000000..077cbf8aa
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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.nativewindow.awt;
+
+import javax.media.nativewindow.*;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import com.sun.nativewindow.impl.*;
+
+/** A wrapper for an AWT GraphicsDevice allowing it to be
+ handled in a toolkit-independent manner. */
+
+public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ private GraphicsDevice device;
+
+ protected AWTGraphicsDevice(GraphicsDevice device) {
+ super(NativeWindowFactory.TYPE_AWT);
+ this.device = device;
+ }
+
+ public static AbstractGraphicsDevice createDevice(GraphicsDevice awtDevice) {
+ if(null==awtDevice) {
+ awtDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ }
+ return new AWTGraphicsDevice(awtDevice);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+
+ public GraphicsDevice getGraphicsDevice() {
+ return device;
+ }
+
+ /**
+ * In case the native handle was specified, e.g. using X11,
+ * we shall be able to mark it.
+ */
+ public void setHandle(long handle) {
+ this.handle = handle;
+ }
+
+ public String toString() {
+ return getClass().toString()+"[type "+getType()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]";
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
new file mode 100644
index 000000000..2ad8a99af
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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.nativewindow.awt;
+
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import com.sun.nativewindow.impl.*;
+
+/** A wrapper for an AWT GraphicsDevice (screen) allowing it to be
+ handled in a toolkit-independent manner. */
+
+public class AWTGraphicsScreen extends DefaultGraphicsScreen implements Cloneable {
+
+ public AWTGraphicsScreen(AWTGraphicsDevice device) {
+ super(device, findScreenIndex(device.getGraphicsDevice()));
+ }
+
+ public static GraphicsDevice getScreenDevice(int index) {
+ if(index<0) return null;
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ if(index<gs.length) {
+ return gs[index];
+ }
+ return null;
+ }
+
+ public static int findScreenIndex(GraphicsDevice awtDevice) {
+ if(null==awtDevice) return -1;
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ for (int j = 0; j < gs.length; j++) {
+ if(gs[j] == awtDevice) return j;
+ }
+ return -1;
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice) {
+ AWTGraphicsDevice device = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(awtDevice);
+ return new AWTGraphicsScreen(device);
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(int index) {
+ GraphicsDevice awtDevice = getScreenDevice(index);
+ return createScreenDevice(awtDevice);
+ }
+
+ public static AbstractGraphicsScreen createDefault() {
+ return createScreenDevice(-1);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java
new file mode 100644
index 000000000..49c337359
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java
@@ -0,0 +1,50 @@
+/*
+ * 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.nativewindow.egl;
+
+import javax.media.nativewindow.*;
+
+/** Encapsulates a graphics device on EGL platforms.
+ */
+
+public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new EGLGraphicsDevice corresponding to the given EGL display handle. */
+ public EGLGraphicsDevice(long eglDisplay) {
+ super(NativeWindowFactory.TYPE_EGL, eglDisplay);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java
new file mode 100644
index 000000000..3669ebd12
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java
@@ -0,0 +1,50 @@
+/*
+ * 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.nativewindow.macosx;
+
+import javax.media.nativewindow.*;
+
+/** Encapsulates a graphics device on MacOSX platforms.
+ */
+
+public class MacOSXGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new MacOSXGraphicsDevice */
+ public MacOSXGraphicsDevice() {
+ super(NativeWindowFactory.TYPE_MACOSX);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html
new file mode 100644
index 000000000..ce9dbbb7a
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/package.html
@@ -0,0 +1,111 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title>NativeWindow Protocol Draft Public Review Specification</title>
+</head>
+ <body>
+
+<h2><i>NativeWindow Protocol</i> Specification Overview</h2>
+
+<h3>Preface</h3>
+ This specification, an optional set of packages, describing a <i>protocol</i> for a
+ <i>native windowing interface</i> binding to Java(TM).<br>
+ Currently specified <i>native windowing systems</i> are:<br><br>
+ <ul>
+ <li> EGL/OpenKODE Windowing System</li>
+ <li> X11 Windowing System</li>
+ <li> Microsoft Windows</li>
+ <li> Apple MacOSX</li>
+ <li> Java's AWT</li>
+ </ul>
+ <br>
+ However, any other native windowing system may be added to the implementation,
+ using a generic string identifier and an optional specialisation of:<br><br>
+ <ul>
+ <li>{@link javax.media.nativewindow.AbstractGraphicsDevice AbstractGraphicsDevice},<br>
+ <br>
+ Shall return the new string identifier with {@link javax.media.nativewindow.AbstractGraphicsDevice#getType() getType()}</li><br>
+ <li>{@link javax.media.nativewindow.AbstractGraphicsScreen AbstractGraphicsScreen}</li>
+ <li>{@link javax.media.nativewindow.AbstractGraphicsConfiguration AbstractGraphicsConfiguration}</li><br>
+ </ul>
+ <br>
+ The implementor has to provide the following:<br><br>
+ <ul>
+ <li> The specialisation of the abstract class {@link javax.media.nativewindow.NativeWindowFactory NativeWindowFactory}<br>
+ <br>
+ shall be registered with {@link javax.media.nativewindow.NativeWindowFactory#registerFactory NativeWindowFactory.registerFactory(..)}.</li><br>
+
+ <li> The specialisation of the abstract class {@link javax.media.nativewindow.GraphicsConfigurationFactory GraphicsConfigurationFactory}<br>
+ <br>
+ shall be registered with {@link javax.media.nativewindow.GraphicsConfigurationFactory#registerFactory GraphicsConfigurationFactory.registerFactory(..)}.</li><br>
+ </ul><br>
+ This protocol <i>does not</i> describe how to <i>create</i> native windows, but how to <i>bind</i> a native window to an implementation of
+ {@link javax.media.nativewindow.NativeWindow NativeWindow}.<br>
+ However, an implementation of this protocol (e.g. {@link com.sun.javafx.newt}) may support the creation.<br>
+
+<h3>Dependencies</h3>
+ This binding has dependencies to the following:<br><br>
+ <ul>
+ <li> Either of the following Java implementations:<br>
+ <ul>
+ <li> <a href="http://java.sun.com/j2se/1.4.2/docs/api/">Java SE 1.4 or later</a> </li><br>
+ <li> <a href="http://java.sun.com/javame/technology/cdc/">Java ME CDC 1.1.2 (JSR 218)</a> and
+ <a href="http://java.sun.com/products/foundation/">Foundation Profile 1.1.2 (JSR 219)</a><br>
+ and either of the following <i>java.nio</i> implementations:<br>
+ <ul>
+ <li> <a href="http://java.sun.com/javame/reference/apis/jsr239/java/nio/package-summary.html"> JSR239 <i>java.nio</i> subset</a> </li>
+ <li> <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/package-summary.html"> Java 1.4 <i>java.nio</i> implementation</a> </li>
+ </ul><br>
+ </ul>
+ </ul>
+ <br>
+
+<h3>Package Structure</h3>
+ The packages defined by this specification include:<br><br>
+<ul>
+ <li>The <b>javax.media.nativewindow</b> package<br>
+ <br>
+ This package contains Java bindings for a native windowing system.<br>
+ Subsequent packages contain marker type classes, containing native characteristics of the windowing system.</li><br><br>
+ <ul>
+ <li>The <b>javax.media.nativewindow.awt</b> package<br>
+ <br>
+ This sub package contains classes to cover the native characteristics of the AWT windowing system.</li><br>
+
+ <li>The <b>javax.media.nativewindow.x11</b> package<br>
+ <br>
+ This sub package contains classes to cover the native characteristics of the X11 windowing system.</li><br>
+
+ <li>The <b>javax.media.nativewindow.windows</b> package<br>
+ <br>
+ This sub package contains classes to cover the native characteristics of the Windows windowing system.</li><br>
+
+ <li>The <b>javax.media.nativewindow.macosx</b> package<br>
+ <br>
+ This sub package contains classes to cover the native characteristics of the MacOSX windowing system.</li><br>
+
+ <li>The <b>javax.media.nativewindow.egl</b> package<br>
+ <br>
+ This sub package contains classes to cover the native characteristics of the EGL/OpenKODE windowing system.</li><br>
+ </ul>
+</ul>
+
+<h3>Factory Model</h3>
+Running on a platform with a supported windowing system, the factory model shall be used
+to instantiate a native window, see {@link javax.media.nativewindow.NativeWindowFactory NativeWindowFactory}.<br>
+The implementor has to specialize
+All supported
+Regardless of the knowledge of the underly
+<br>
+
+<h3>Revision History<br>
+ </h3>
+
+<ul>
+<li> Early Draft Review, June 2009
+</ul>
+ <br>
+ <br>
+ <br>
+</body>
+</html>
diff --git a/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java
new file mode 100644
index 000000000..69dde49af
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java
@@ -0,0 +1,50 @@
+/*
+ * 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.nativewindow.windows;
+
+import javax.media.nativewindow.*;
+
+/** Encapsulates a graphics device on Windows platforms.
+ */
+
+public class WindowsGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new WindowsGraphicsDevice */
+ public WindowsGraphicsDevice() {
+ super(NativeWindowFactory.TYPE_WINDOWS);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
new file mode 100644
index 000000000..fdecac8fc
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
@@ -0,0 +1,76 @@
+/*
+ * 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.nativewindow.x11;
+
+import javax.media.nativewindow.*;
+import com.sun.nativewindow.impl.x11.XVisualInfo;
+
+/** Encapsulates a graphics configuration, or OpenGL pixel format, on
+ X11 platforms. Objects of this type are returned from {@link
+ javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration
+ GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable {
+ private XVisualInfo info;
+
+ public X11GraphicsConfiguration(X11GraphicsScreen screen,
+ Capabilities capsChosen, Capabilities capsRequested,
+ XVisualInfo info) {
+ super(screen, capsChosen, capsRequested);
+ this.info = info;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+
+ public XVisualInfo getXVisualInfo() {
+ return info;
+ }
+
+ protected void setXVisualInfo(XVisualInfo info) {
+ this.info = info;
+ }
+
+ public long getVisualID() {
+ return (null!=info)?info.visualid():0;
+ }
+
+ public String toString() {
+ return getClass().toString()+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) +
+ ",\n\tchosen " + capabilitiesChosen+
+ ",\n\trequested " + capabilitiesRequested+
+ "]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
new file mode 100644
index 000000000..911b8f416
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
@@ -0,0 +1,55 @@
+/*
+ * 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.nativewindow.x11;
+
+import javax.media.nativewindow.*;
+
+import com.sun.nativewindow.impl.x11.*;
+
+/** Encapsulates a graphics device on X11 platforms.
+ */
+
+public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new X11GraphicsDevice corresponding to the given native display handle. */
+ public X11GraphicsDevice(long display) {
+ super(NativeWindowFactory.TYPE_X11, display);
+ if(0==display) {
+ throw new NativeWindowException("null display");
+ }
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
new file mode 100644
index 000000000..f434050f2
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
@@ -0,0 +1,91 @@
+/*
+ * 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.nativewindow.x11;
+
+import javax.media.nativewindow.*;
+
+import com.sun.nativewindow.impl.x11.*;
+
+/** Encapsulates a screen index on X11
+ platforms. Objects of this type are passed to {@link
+ javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration
+ GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneable {
+
+ /** Constructs a new X11GraphicsScreen corresponding to the given native screen index. */
+ public X11GraphicsScreen(X11GraphicsDevice device, int screen) {
+ super(device, fetchScreen(screen));
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx) {
+ if(0==display) throw new NativeWindowException("display is null");
+ return new X11GraphicsScreen(new X11GraphicsDevice(display), screenIdx);
+ }
+
+ /** Creates a new X11GraphicsScreen using a thread local display connection */
+ public static AbstractGraphicsScreen createDefault() {
+ long display = X11Util.getThreadLocalDefaultDisplay();
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return createScreenDevice(display, scrnIdx);
+ }
+
+ public long getDefaultVisualID() {
+ // It still could be an AWT hold handle ..
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ try {
+ long display = getDevice().getHandle();
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return X11Lib.DefaultVisualID(display, scrnIdx);
+ } finally {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
+ }
+ }
+
+ private static int fetchScreen(int screen) {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ try {
+ if(!com.sun.nativewindow.impl.x11.X11Util.isXineramaEnabledOnStaticDefaultDisplay()) {
+ return screen;
+ }
+ } finally {
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
+ }
+ return 0;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
diff --git a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c
new file mode 100644
index 000000000..e4afbdb70
--- /dev/null
+++ b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2003 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
+ * MIDROSYSTEMS, 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.
+ *
+ * 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.
+ */
+
+#include <jawt_md.h>
+
+#ifdef WIN32
+ #define PLATFORM_DSI_SIZE sizeof(JAWT_Win32DrawingSurfaceInfo)
+#elif defined(linux) || defined(__sun) || defined(__FreeBSD__) || defined(_HPUX)
+ #define PLATFORM_DSI_SIZE sizeof(JAWT_X11DrawingSurfaceInfo)
+#elif defined(macosx)
+ #define PLATFORM_DSI_SIZE sizeof(JAWT_MacOSXDrawingSurfaceInfo)
+#else
+ ERROR: port JAWT_DrawingSurfaceInfo.c to your platform
+#endif
+
+JNIEXPORT jobject JNICALL
+Java_com_sun_nativewindow_impl_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) {
+ JAWT_DrawingSurfaceInfo* dsi;
+ dsi = (*env)->GetDirectBufferAddress(env, jthis0);
+ if (dsi == NULL) {
+ (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"),
+ "Argument \"jthis0\" was not a direct buffer");
+ return NULL;
+ }
+ if (dsi->platformInfo == NULL) {
+ return NULL;
+ }
+ return (*env)->NewDirectByteBuffer(env, dsi->platformInfo, PLATFORM_DSI_SIZE);
+}
diff --git a/src/nativewindow/native/x11/Xinerama.c b/src/nativewindow/native/x11/Xinerama.c
new file mode 100644
index 000000000..98dcfe095
--- /dev/null
+++ b/src/nativewindow/native/x11/Xinerama.c
@@ -0,0 +1,316 @@
+/* $TOG: XPanoramiX.c /main/2 1997/11/16 08:45:41 kaleb $ */
+/****************************************************************
+* *
+* Copyright (c) Digital Equipment Corporation, 1991, 1997 *
+* *
+* All Rights Reserved. Unpublished rights reserved under *
+* the copyright laws of the United States. *
+* *
+* The software contained on this media is proprietary to *
+* and embodies the confidential technology of Digital *
+* Equipment Corporation. Possession, use, duplication or *
+* dissemination of the software and media is authorized only *
+* pursuant to a valid written license from Digital Equipment *
+* Corporation. *
+* *
+* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
+* by the U.S. Government is subject to restrictions as set *
+* forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
+* or in FAR 52.227-19, as applicable. *
+* *
+*****************************************************************/
+/* $XFree86: xc/lib/Xinerama/Xinerama.c,v 1.1 2000/02/27 23:10:04 mvojkovi Exp $ */
+
+#ifndef __linux__
+ #error This file should only be built under Linux
+#endif
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include <X11/Xlibint.h>
+#include <X11/Xutil.h>
+/* #include "Xext.h" */ /* in ../include */
+#include "extutil.h" /* in ../include */
+#include "panoramiXext.h"
+#include "panoramiXproto.h" /* in ../include */
+#include "Xinerama.h"
+
+
+static XExtensionInfo _panoramiX_ext_info_data;
+static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
+static /* const */ char *panoramiX_extension_name = PANORAMIX_PROTOCOL_NAME;
+
+#define PanoramiXCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, panoramiX_extension_name, val)
+#define PanoramiXSimpleCheckExtension(dpy,i) \
+ XextSimpleCheckExtension (dpy, i, panoramiX_extension_name)
+
+static int close_display();
+static /* const */ XExtensionHooks panoramiX_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL, /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, panoramiX_ext_info,
+ panoramiX_extension_name,
+ &panoramiX_extension_hooks,
+ 0, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, panoramiX_ext_info)
+
+
+
+/****************************************************************************
+ * *
+ * PanoramiX public interfaces *
+ * *
+ ****************************************************************************/
+
+Bool XPanoramiXQueryExtension (
+ Display *dpy,
+ int *event_basep,
+ int *error_basep
+)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ *event_basep = info->codes->first_event;
+ *error_basep = info->codes->first_error;
+ return True;
+ } else {
+ return False;
+ }
+}
+
+
+Status XPanoramiXQueryVersion(
+ Display *dpy,
+ int *major_versionp,
+ int *minor_versionp
+)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xPanoramiXQueryVersionReply rep;
+ register xPanoramiXQueryVersionReq *req;
+
+ PanoramiXCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (PanoramiXQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->panoramiXReqType = X_PanoramiXQueryVersion;
+ req->clientMajor = PANORAMIX_MAJOR_VERSION;
+ req->clientMinor = PANORAMIX_MINOR_VERSION;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ *major_versionp = rep.majorVersion;
+ *minor_versionp = rep.minorVersion;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 1;
+}
+
+XPanoramiXInfo *XPanoramiXAllocInfo(void)
+{
+ return (XPanoramiXInfo *) Xmalloc (sizeof (XPanoramiXInfo));
+}
+
+Status XPanoramiXGetState (
+ Display *dpy,
+ Drawable drawable,
+ XPanoramiXInfo *panoramiX_info
+)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xPanoramiXGetStateReply rep;
+ register xPanoramiXGetStateReq *req;
+
+ PanoramiXCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (PanoramiXGetState, req);
+ req->reqType = info->codes->major_opcode;
+ req->panoramiXReqType = X_PanoramiXGetState;
+ req->window = drawable;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ panoramiX_info->window = rep.window;
+ panoramiX_info->State = rep.state;
+ return 1;
+}
+
+Status XPanoramiXGetScreenCount (
+ Display *dpy,
+ Drawable drawable,
+ XPanoramiXInfo *panoramiX_info
+)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xPanoramiXGetScreenCountReply rep;
+ register xPanoramiXGetScreenCountReq *req;
+
+ PanoramiXCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (PanoramiXGetScreenCount, req);
+ req->reqType = info->codes->major_opcode;
+ req->panoramiXReqType = X_PanoramiXGetScreenCount;
+ req->window = drawable;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ panoramiX_info->window = rep.window;
+ panoramiX_info->ScreenCount = rep.ScreenCount;
+ return 1;
+}
+
+Status XPanoramiXGetScreenSize (
+ Display *dpy,
+ Drawable drawable,
+ int screen_num,
+ XPanoramiXInfo *panoramiX_info
+)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xPanoramiXGetScreenSizeReply rep;
+ register xPanoramiXGetScreenSizeReq *req;
+
+ PanoramiXCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (PanoramiXGetScreenSize, req);
+ req->reqType = info->codes->major_opcode;
+ req->panoramiXReqType = X_PanoramiXGetScreenSize;
+ req->window = drawable;
+ req->screen = screen_num; /* need to define */
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ panoramiX_info->window = rep.window;
+ panoramiX_info->screen = rep.screen;
+ panoramiX_info->width = rep.width;
+ panoramiX_info->height = rep.height;
+ return 1;
+}
+
+/*******************************************************************\
+ Alternate interface to make up for shortcomings in the original,
+ namely, the omission of the screen origin. The new interface is
+ in the "Xinerama" namespace instead of "PanoramiX".
+\*******************************************************************/
+
+Bool XineramaQueryExtension (
+ Display *dpy,
+ int *event_base,
+ int *error_base
+)
+{
+ return XPanoramiXQueryExtension(dpy, event_base, error_base);
+}
+
+Status XineramaQueryVersion(
+ Display *dpy,
+ int *major,
+ int *minor
+)
+{
+ return XPanoramiXQueryVersion(dpy, major, minor);
+}
+
+Bool XineramaIsActive(Display *dpy)
+{
+ xXineramaIsActiveReply rep;
+ xXineramaIsActiveReq *req;
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if(!XextHasExtension(info))
+ return False; /* server doesn't even have the extension */
+
+ LockDisplay (dpy);
+ GetReq (XineramaIsActive, req);
+ req->reqType = info->codes->major_opcode;
+ req->panoramiXReqType = X_XineramaIsActive;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return False;
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return rep.state;
+}
+
+#include <stdio.h>
+
+XineramaScreenInfo *
+XineramaQueryScreens(
+ Display *dpy,
+ int *number
+)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXineramaQueryScreensReply rep;
+ xXineramaQueryScreensReq *req;
+ XineramaScreenInfo *scrnInfo = NULL;
+
+ PanoramiXCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (XineramaQueryScreens, req);
+ req->reqType = info->codes->major_opcode;
+ req->panoramiXReqType = X_XineramaQueryScreens;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ if(rep.number) {
+ if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * rep.number))) {
+ xXineramaScreenInfo scratch;
+ CARD32 i;
+
+ for(i = 0; i < rep.number; i++) {
+ _XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
+ scrnInfo[i].screen_number = i;
+ scrnInfo[i].x_org = scratch.x_org;
+ scrnInfo[i].y_org = scratch.y_org;
+ scrnInfo[i].width = scratch.width;
+ scrnInfo[i].height = scratch.height;
+ }
+
+ *number = rep.number;
+ } else
+ _XEatData(dpy, rep.length << 2);
+ }
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return scrnInfo;
+}
diff --git a/src/nativewindow/native/x11/Xinerama.h b/src/nativewindow/native/x11/Xinerama.h
new file mode 100644
index 000000000..7177f5131
--- /dev/null
+++ b/src/nativewindow/native/x11/Xinerama.h
@@ -0,0 +1,76 @@
+/*
+Copyright (C) 1994-2001 The XFree86 Project, Inc. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Soft-
+ware"), to deal in the Software without restriction, including without
+limitation the rights to use, copy, modify, merge, publish, distribute,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, provided that the above copyright
+notice(s) and this permission notice appear in all copies of the Soft-
+ware and that both the above copyright notice(s) and this permission
+notice appear in supporting documentation.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
+THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
+QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
+MANCE OF THIS SOFTWARE.
+
+Except as contained in this notice, the name of a copyright holder shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization of
+the copyright holder.
+*/
+
+/* $XFree86: xc/include/extensions/Xinerama.h,v 3.2 2000/03/01 01:04:20 dawes Exp $ */
+
+#ifdef __linux__
+
+#ifndef _Xinerama_h
+#define _Xinerama_h
+
+typedef struct {
+ int screen_number;
+ short x_org;
+ short y_org;
+ short width;
+ short height;
+} XineramaScreenInfo;
+
+Bool XineramaQueryExtension (
+ Display *dpy,
+ int *event_base,
+ int *error_base
+);
+
+Status XineramaQueryVersion(
+ Display *dpy,
+ int *major,
+ int *minor
+);
+
+Bool XineramaIsActive(Display *dpy);
+
+
+/*
+ Returns the number of heads and a pointer to an array of
+ structures describing the position and size of the individual
+ heads. Returns NULL and number = 0 if Xinerama is not active.
+
+ Returned array should be freed with XFree().
+*/
+
+XineramaScreenInfo *
+XineramaQueryScreens(
+ Display *dpy,
+ int *number
+);
+
+#endif /* _Xinerama_h */
+
+#endif /* __linux__ */
diff --git a/src/nativewindow/native/x11/XineramaHelper.c b/src/nativewindow/native/x11/XineramaHelper.c
new file mode 100644
index 000000000..09ad0b706
--- /dev/null
+++ b/src/nativewindow/native/x11/XineramaHelper.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2003 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
+ * MIDROSYSTEMS, 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.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ */
+
+/* This file contains a helper routine to be called by Java code to
+ determine whether the Xinerama extension is in use and therefore to
+ treat the multiple AWT screens as one large screen. */
+
+#include <inttypes.h>
+#include <X11/Xlib.h>
+
+#ifdef __sun
+
+typedef Status XineramaGetInfoFunc(Display* display, int screen_number,
+ XRectangle* framebuffer_rects, unsigned char* framebuffer_hints,
+ int* num_framebuffers);
+typedef Status XineramaGetCenterHintFunc(Display* display, int screen_number,
+ int* x, int* y);
+
+XineramaGetCenterHintFunc* XineramaSolarisCenterFunc = NULL;
+#include <dlfcn.h>
+
+#elif defined(__linux__)
+
+#include "Xinerama.h"
+
+#endif
+
+Bool XineramaEnabled(Display* display) {
+#ifdef __sun
+
+#define MAXFRAMEBUFFERS 16
+ char* XinExtName = "XINERAMA";
+ int32_t major_opcode, first_event, first_error;
+ Bool gotXinExt = False;
+ void* libHandle = 0;
+ unsigned char fbhints[MAXFRAMEBUFFERS];
+ XRectangle fbrects[MAXFRAMEBUFFERS];
+ int locNumScr = 0;
+ Bool usingXinerama = False;
+
+ char* XineramaLibName= "libXext.so";
+ char* XineramaGetInfoName = "XineramaGetInfo";
+ char* XineramaGetCenterHintName = "XineramaGetCenterHint";
+ XineramaGetInfoFunc* XineramaSolarisFunc = NULL;
+
+ gotXinExt = XQueryExtension(display, XinExtName, &major_opcode,
+ &first_event, &first_error);
+
+ if (gotXinExt) {
+ /* load library, load and run XineramaGetInfo */
+ libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
+ if (libHandle != 0) {
+ XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName);
+ XineramaSolarisCenterFunc =
+ (XineramaGetCenterHintFunc*)dlsym(libHandle,
+ XineramaGetCenterHintName);
+ if (XineramaSolarisFunc != NULL) {
+ if ((*XineramaSolarisFunc)(display, 0, &fbrects[0],
+ &fbhints[0], &locNumScr) != 0) {
+
+ usingXinerama = True;
+ }
+ }
+ dlclose(libHandle);
+ }
+ }
+ return usingXinerama;
+
+#elif defined(__linux__)
+
+ char* XinExtName = "XINERAMA";
+ int32_t major_opcode, first_event, first_error;
+ Bool gotXinExt = False;
+ int32_t locNumScr = 0;
+
+ XineramaScreenInfo *xinInfo;
+
+ gotXinExt = XQueryExtension(display, XinExtName, &major_opcode,
+ &first_event, &first_error);
+
+ if (gotXinExt) {
+ xinInfo = XineramaQueryScreens(display, &locNumScr);
+ if (xinInfo != NULL) {
+ return True;
+ }
+ }
+ return False;
+
+#else
+ return False;
+#endif
+}
diff --git a/src/nativewindow/native/x11/extutil.h b/src/nativewindow/native/x11/extutil.h
new file mode 100644
index 000000000..f0d3b59c3
--- /dev/null
+++ b/src/nativewindow/native/x11/extutil.h
@@ -0,0 +1,222 @@
+/*
+ * $Xorg: extutil.h,v 1.3 2000/08/18 04:05:45 coskrey Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+All Rights Reserved.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Jim Fulton, MIT The Open Group
+ *
+ * Xlib Extension-Writing Utilities
+ *
+ * This package contains utilities for writing the client API for various
+ * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
+ * ARE SUBJECT TO CHANGE!
+ */
+/* $XFree86: xc/include/extensions/extutil.h,v 1.5 2001/01/17 17:53:20 dawes Exp $ */
+
+#ifdef __linux__
+
+#ifndef _EXTUTIL_H_
+#define _EXTUTIL_H_
+
+/*
+ * We need to keep a list of open displays since the Xlib display list isn't
+ * public. We also have to per-display info in a separate block since it isn't
+ * stored directly in the Display structure.
+ */
+typedef struct _XExtDisplayInfo {
+ struct _XExtDisplayInfo *next; /* keep a linked list */
+ Display *display; /* which display this is */
+ XExtCodes *codes; /* the extension protocol codes */
+ XPointer data; /* extra data for extension to use */
+} XExtDisplayInfo;
+
+typedef struct _XExtensionInfo {
+ XExtDisplayInfo *head; /* start of list */
+ XExtDisplayInfo *cur; /* most recently used */
+ int ndisplays; /* number of displays */
+} XExtensionInfo;
+
+typedef struct _XExtensionHooks {
+ int (*create_gc)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ GC /* gc */,
+ XExtCodes* /* codes */
+#endif
+);
+ int (*copy_gc)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ GC /* gc */,
+ XExtCodes* /* codes */
+#endif
+);
+ int (*flush_gc)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ GC /* gc */,
+ XExtCodes* /* codes */
+#endif
+);
+ int (*free_gc)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ GC /* gc */,
+ XExtCodes* /* codes */
+#endif
+);
+ int (*create_font)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ XFontStruct* /* fs */,
+ XExtCodes* /* codes */
+#endif
+);
+ int (*free_font)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ XFontStruct* /* fs */,
+ XExtCodes* /* codes */
+#endif
+);
+ int (*close_display)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ XExtCodes* /* codes */
+#endif
+);
+ Bool (*wire_to_event)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ XEvent* /* re */,
+ xEvent* /* event */
+#endif
+);
+ Status (*event_to_wire)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ XEvent* /* re */,
+ xEvent* /* event */
+#endif
+);
+ int (*error)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ xError* /* err */,
+ XExtCodes* /* codes */,
+ int* /* ret_code */
+#endif
+);
+ char *(*error_string)(
+#if NeedNestedPrototypes
+ Display* /* display */,
+ int /* code */,
+ XExtCodes* /* codes */,
+ char* /* buffer */,
+ int /* nbytes */
+#endif
+);
+} XExtensionHooks;
+
+extern XExtensionInfo *XextCreateExtension(
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+extern void XextDestroyExtension(
+#if NeedFunctionPrototypes
+ XExtensionInfo* /* info */
+#endif
+);
+extern XExtDisplayInfo *XextAddDisplay(
+#if NeedFunctionPrototypes
+ XExtensionInfo* /* extinfo */,
+ Display* /* dpy */,
+ char* /* ext_name */,
+ XExtensionHooks* /* hooks */,
+ int /* nevents */,
+ XPointer /* data */
+#endif
+);
+extern int XextRemoveDisplay(
+#if NeedFunctionPrototypes
+ XExtensionInfo* /* extinfo */,
+ Display* /* dpy */
+#endif
+);
+extern XExtDisplayInfo *XextFindDisplay(
+#if NeedFunctionPrototypes
+ XExtensionInfo* /* extinfo */,
+ Display* /* dpy */
+#endif
+);
+
+#define XextHasExtension(i) ((i) && ((i)->codes))
+#define XextCheckExtension(dpy,i,name,val) \
+ if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
+#define XextSimpleCheckExtension(dpy,i,name) \
+ if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
+
+
+/*
+ * helper macros to generate code that is common to all extensions; caller
+ * should prefix it with static if extension source is in one file; this
+ * could be a utility function, but have to stack 6 unused arguments for
+ * something that is called many, many times would be bad.
+ */
+#define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
+XExtDisplayInfo *proc (Display *dpy) \
+{ \
+ XExtDisplayInfo *dpyinfo; \
+ if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
+ if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
+ dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
+ return dpyinfo; \
+}
+
+#define XEXT_FIND_DISPLAY_PROTO(proc) \
+ XExtDisplayInfo *proc(Display *dpy)
+
+#define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
+int proc (Display *dpy, XExtCodes *codes) \
+{ \
+ return XextRemoveDisplay (extinfo, dpy); \
+}
+
+#define XEXT_CLOSE_DISPLAY_PROTO(proc) \
+ int proc(Display *dpy, XExtCodes *codes)
+
+#define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
+char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \
+{ \
+ code -= codes->first_error; \
+ if (code >= 0 && code < nerr) { \
+ char tmp[256]; \
+ sprintf (tmp, "%s.%d", extname, code); \
+ XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
+ return buf; \
+ } \
+ return (char *)0; \
+}
+
+#define XEXT_ERROR_STRING_PROTO(proc) \
+ char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)
+#endif
+
+#endif /* __linux__ */
diff --git a/src/nativewindow/native/x11/panoramiXext.h b/src/nativewindow/native/x11/panoramiXext.h
new file mode 100644
index 000000000..11267d0c1
--- /dev/null
+++ b/src/nativewindow/native/x11/panoramiXext.h
@@ -0,0 +1,54 @@
+/* $Xorg: panoramiXext.h,v 1.4 2000/08/18 04:05:45 coskrey Exp $ */
+/*****************************************************************
+Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital
+Equipment Corporation.
+******************************************************************/
+/*
+ * PanoramiX definitions
+ */
+/* $XFree86: xc/include/extensions/panoramiXext.h,v 3.6 2001/01/17 17:53:22 dawes Exp $ */
+
+#ifdef __linux__
+
+/* THIS IS NOT AN X PROJECT TEAM SPECIFICATION */
+
+#define PANORAMIX_MAJOR_VERSION 1 /* current version number */
+#define PANORAMIX_MINOR_VERSION 1
+
+typedef struct {
+ Window window; /* PanoramiX window - may not exist */
+ int screen;
+ int State; /* PanroamiXOff, PanoramiXOn */
+ int width; /* width of this screen */
+ int height; /* height of this screen */
+ int ScreenCount; /* real physical number of screens */
+ XID eventMask; /* selected events for this client */
+} XPanoramiXInfo;
+
+extern XPanoramiXInfo *XPanoramiXAllocInfo (
+#if NeedFunctionPrototypes
+ void
+#endif
+);
+
+#endif /* __linux__*/
diff --git a/src/nativewindow/native/x11/panoramiXproto.h b/src/nativewindow/native/x11/panoramiXproto.h
new file mode 100644
index 000000000..1a66940f7
--- /dev/null
+++ b/src/nativewindow/native/x11/panoramiXproto.h
@@ -0,0 +1,196 @@
+/* $Xorg: panoramiXproto.h,v 1.4 2000/08/18 04:05:45 coskrey Exp $ */
+/*****************************************************************
+Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital
+Equipment Corporation.
+******************************************************************/
+/* $XFree86: xc/include/extensions/panoramiXproto.h,v 3.6 2001/01/17 17:53:22 dawes Exp $ */
+
+#ifdef __linux__
+
+/* THIS IS NOT AN X PROJECT TEAM SPECIFICATION */
+
+#ifndef _PANORAMIXPROTO_H_
+#define _PANORAMIXPROTO_H_
+
+#define PANORAMIX_PROTOCOL_NAME "XINERAMA"
+
+#define X_PanoramiXQueryVersion 0
+#define X_PanoramiXGetState 1
+#define X_PanoramiXGetScreenCount 2
+#define X_PanoramiXGetScreenSize 3
+
+#define X_XineramaIsActive 4
+#define X_XineramaQueryScreens 5
+
+typedef struct _PanoramiXQueryVersion {
+ CARD8 reqType; /* always PanoramiXReqCode */
+ CARD8 panoramiXReqType; /* always X_PanoramiXQueryVersion */
+ CARD16 length B16;
+ CARD8 clientMajor;
+ CARD8 clientMinor;
+ CARD16 unused B16;
+} xPanoramiXQueryVersionReq;
+
+#define sz_xPanoramiXQueryVersionReq 8
+
+typedef struct {
+ CARD8 type; /* must be X_Reply */
+ CARD8 pad1; /* unused */
+ CARD16 sequenceNumber B16; /* last sequence number */
+ CARD32 length B32; /* 0 */
+ CARD16 majorVersion B16;
+ CARD16 minorVersion B16;
+ CARD32 pad2 B32; /* unused */
+ CARD32 pad3 B32; /* unused */
+ CARD32 pad4 B32; /* unused */
+ CARD32 pad5 B32; /* unused */
+ CARD32 pad6 B32; /* unused */
+} xPanoramiXQueryVersionReply;
+
+#define sz_xPanoramiXQueryVersionReply 32
+
+
+typedef struct _PanoramiXGetState {
+ CARD8 reqType; /* always PanoramiXReqCode */
+ CARD8 panoramiXReqType; /* always X_PanoramiXGetState */
+ CARD16 length B16;
+ CARD32 window B32;
+} xPanoramiXGetStateReq;
+#define sz_xPanoramiXGetStateReq 8
+
+typedef struct {
+ BYTE type;
+ BYTE state;
+ CARD16 sequenceNumber B16;
+ CARD32 length B32;
+ CARD32 window B32;
+ CARD32 pad1 B32; /* unused */
+ CARD32 pad2 B32; /* unused */
+ CARD32 pad3 B32; /* unused */
+ CARD32 pad4 B32; /* unused */
+ CARD32 pad5 B32; /* unused */
+} xPanoramiXGetStateReply;
+
+#define sz_panoramiXGetStateReply 32
+
+typedef struct _PanoramiXGetScreenCount {
+ CARD8 reqType; /* always PanoramiXReqCode */
+ CARD8 panoramiXReqType; /* always X_PanoramiXGetScreenCount */
+ CARD16 length B16;
+ CARD32 window B32;
+} xPanoramiXGetScreenCountReq;
+#define sz_xPanoramiXGetScreenCountReq 8
+
+typedef struct {
+ BYTE type;
+ BYTE ScreenCount;
+ CARD16 sequenceNumber B16;
+ CARD32 length B32;
+ CARD32 window B32;
+ CARD32 pad1 B32; /* unused */
+ CARD32 pad2 B32; /* unused */
+ CARD32 pad3 B32; /* unused */
+ CARD32 pad4 B32; /* unused */
+ CARD32 pad5 B32; /* unused */
+} xPanoramiXGetScreenCountReply;
+#define sz_panoramiXGetScreenCountReply 32
+
+typedef struct _PanoramiXGetScreenSize {
+ CARD8 reqType; /* always PanoramiXReqCode */
+ CARD8 panoramiXReqType; /* always X_PanoramiXGetState */
+ CARD16 length B16;
+ CARD32 window B32;
+ CARD32 screen B32;
+} xPanoramiXGetScreenSizeReq;
+#define sz_xPanoramiXGetScreenSizeReq 12
+
+typedef struct {
+ BYTE type;
+ CARD8 pad1;
+ CARD16 sequenceNumber B16;
+ CARD32 length B32;
+ CARD32 width B32;
+ CARD32 height B32;
+ CARD32 window B32;
+ CARD32 screen B32;
+ CARD32 pad2 B32; /* unused */
+ CARD32 pad3 B32; /* unused */
+} xPanoramiXGetScreenSizeReply;
+#define sz_panoramiXGetScreenSizeReply 32
+
+/************ Alternate protocol ******************/
+
+typedef struct {
+ CARD8 reqType;
+ CARD8 panoramiXReqType;
+ CARD16 length B16;
+} xXineramaIsActiveReq;
+#define sz_xXineramaIsActiveReq 4
+
+typedef struct {
+ BYTE type;
+ CARD8 pad1;
+ CARD16 sequenceNumber B16;
+ CARD32 length B32;
+ CARD32 state B32;
+ CARD32 pad2 B32;
+ CARD32 pad3 B32;
+ CARD32 pad4 B32;
+ CARD32 pad5 B32;
+ CARD32 pad6 B32;
+} xXineramaIsActiveReply;
+#define sz_XineramaIsActiveReply 32
+
+
+typedef struct {
+ CARD8 reqType;
+ CARD8 panoramiXReqType;
+ CARD16 length B16;
+} xXineramaQueryScreensReq;
+#define sz_xXineramaQueryScreensReq 4
+
+typedef struct {
+ BYTE type;
+ CARD8 pad1;
+ CARD16 sequenceNumber B16;
+ CARD32 length B32;
+ CARD32 number B32;
+ CARD32 pad2 B32;
+ CARD32 pad3 B32;
+ CARD32 pad4 B32;
+ CARD32 pad5 B32;
+ CARD32 pad6 B32;
+} xXineramaQueryScreensReply;
+#define sz_XineramaQueryScreensReply 32
+
+typedef struct {
+ INT16 x_org B16;
+ INT16 y_org B16;
+ CARD16 width B16;
+ CARD16 height B16;
+} xXineramaScreenInfo;
+#define sz_XineramaScreenInfo 8
+
+#endif
+
+#endif /* __linux__ */