aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/com/jogamp
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-03-28 20:25:31 +0200
committerMichael Bien <[email protected]>2010-03-28 20:25:31 +0200
commitbe452bbfbb101292350cc6a483471a0e98ac937b (patch)
tree6877831b84b87d48ba928e3ac55ecf8a5c18b0ab /src/nativewindow/classes/com/jogamp
parent9e8ba29142d83d5749fc9650715019fef3539b1d (diff)
final large refactoring to move to com.jogamp.*.
Diffstat (limited to 'src/nativewindow/classes/com/jogamp')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java140
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java43
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java124
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java75
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java181
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java202
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java114
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java148
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java78
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java145
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java186
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java47
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java152
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java170
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java136
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java132
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java72
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java118
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java166
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java87
20 files changed, 2516 insertions, 0 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java
new file mode 100644
index 000000000..edb682392
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java
@@ -0,0 +1,140 @@
+/*
+ * 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.jogamp.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;
+ private static AccessControlContext localACC;
+
+ static {
+ localACC=AccessController.getContext();
+ verbose = isPropertyDefined("nativewindow.verbose", true);
+ debugAll = isPropertyDefined("nativewindow.debug", true);
+ 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());
+ }
+ }
+
+ static int getIntProperty(final String property, final boolean jnlpAlias) {
+ return getIntProperty(property, jnlpAlias, localACC);
+ }
+
+ public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) {
+ int i=0;
+ try {
+ Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc));
+ i = iv.intValue();
+ } catch (NumberFormatException nfe) {}
+ return i;
+ }
+
+ static boolean getBooleanProperty(final String property, final boolean jnlpAlias) {
+ return getBooleanProperty(property, jnlpAlias, localACC);
+ }
+
+ public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) {
+ Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc));
+ return b.booleanValue();
+ }
+
+ static boolean isPropertyDefined(final String property, final boolean jnlpAlias) {
+ return isPropertyDefined(property, jnlpAlias, localACC);
+ }
+
+ public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) {
+ return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false;
+ }
+
+ static String getProperty(final String property, final boolean jnlpAlias) {
+ return getProperty(property, jnlpAlias, localACC);
+ }
+
+ public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) {
+ String s=null;
+ if(null!=acc && acc.equals(localACC)) {
+ s = (String) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ String val=null;
+ try {
+ val = System.getProperty(property);
+ } catch (Exception e) {}
+ if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) {
+ try {
+ val = System.getProperty(jnlp_prefix + property);
+ } catch (Exception e) {}
+ }
+ return val;
+ }
+ });
+ } else {
+ try {
+ s = System.getProperty(property);
+ } catch (Exception e) {}
+ if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) {
+ try {
+ s = System.getProperty(jnlp_prefix + property);
+ } catch (Exception e) {}
+ }
+ }
+ return s;
+ }
+ public static final String jnlp_prefix = "jnlp." ;
+
+ public static boolean verbose() {
+ return verbose;
+ }
+
+ public static boolean debugAll() {
+ return debugAll;
+ }
+
+ public static boolean debug(String subcomponent) {
+ return debugAll() || isPropertyDefined("nativewindow.debug." + subcomponent, true);
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
new file mode 100644
index 000000000..22f2d544f
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.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/jogamp/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java
new file mode 100644
index 000000000..f590e9b8b
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl;
+
+import java.lang.reflect.*;
+import java.nio.*;
+
+/** Internal copy of selected routines from BufferUtil to avoid
+ outward dependencies on com.jogamp.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/jogamp/nativewindow/impl/LockingNativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java
new file mode 100644
index 000000000..fd2478ab2
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java
@@ -0,0 +1,75 @@
+/*
+ * 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.jogamp.nativewindow.impl;
+
+import javax.media.nativewindow.*;
+
+public class LockingNativeWindowFactory extends NativeWindowFactoryImpl {
+ // Provides a generic basic and recursive locking mechanism for your discretion.
+ 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/jogamp/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java
new file mode 100644
index 000000000..22bdedac9
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java
@@ -0,0 +1,181 @@
+/*
+ * 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.jogamp.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");
+ }
+ return getConstructor(factoryClass, cstrArgTypes);
+ } catch (Throwable e) {
+ if (DEBUG) {
+ e.printStackTrace();
+ }
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) {
+ Constructor factory = null;
+
+ try {
+ try {
+ factory = clazz.getDeclaredConstructor( cstrArgTypes );
+ } catch(NoSuchMethodException nsme) {
+ throw new NativeWindowException("Constructor: '" + clazz + "("+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(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) {
+ Constructor factory = null;
+
+ try {
+ factory = getConstructor(clazz, cstrArgTypes);
+ return factory.newInstance( cstrArgs ) ;
+ } catch (Exception e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public static final Object createInstance(Class clazz, Object[] cstrArgs) {
+ Class[] cstrArgTypes = new Class[cstrArgs.length];
+ for(int i=0; i<cstrArgs.length; i++) {
+ cstrArgTypes[i] = cstrArgs[i].getClass();
+ }
+ return createInstance(clazz, cstrArgTypes, cstrArgs);
+ }
+
+ 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/jogamp/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java
new file mode 100644
index 000000000..0670234d4
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java
@@ -0,0 +1,202 @@
+/*
+ * 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.jogamp.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 {
+ loadLibraryInternal(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;
+ }
+ }
+ }
+ }
+ }
+ loadLibraryInternal(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;
+ }
+ });
+ }
+
+
+ private static final Class customLauncherClass;
+ private static final Method customLoadLibraryMethod;
+
+ static {
+ Class launcherClass = null;
+ Method loadLibraryMethod = null;
+
+ if ( Debug.getBooleanProperty("sun.jnlp.applet.launcher", false) ) {
+ try {
+ launcherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher");
+ loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
+ } catch (Throwable t) {
+ if(DEBUG) {
+ t.printStackTrace();
+ }
+ launcherClass = null;
+ loadLibraryMethod = null;
+ }
+ }
+
+ if(null==launcherClass) {
+ String launcherClassName = Debug.getProperty("jnlp.launcher.class", false);
+ if(null!=launcherClassName) {
+ try {
+ launcherClass = Class.forName(launcherClassName);
+ loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
+ } catch (Throwable t) {
+ if(DEBUG) {
+ t.printStackTrace();
+ }
+ launcherClass = null;
+ loadLibraryMethod = null;
+ }
+ }
+ }
+ customLauncherClass = launcherClass;
+ customLoadLibraryMethod = loadLibraryMethod;
+ }
+
+ private static void loadLibraryInternal(String libraryName) {
+ // Note: special-casing JAWT which is built in to the JDK
+ if (null!=customLoadLibraryMethod && !libraryName.equals("jawt")) {
+ try {
+ customLoadLibraryMethod.invoke(null, new Object[] { libraryName });
+ } catch (Exception e) {
+ Throwable t = e;
+ if (t instanceof InvocationTargetException) {
+ t = ((InvocationTargetException) t).getTargetException();
+ }
+ if (t instanceof Error)
+ throw (Error) t;
+ if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ }
+ // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary()
+ throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e);
+ }
+ } else {
+ // System.out.println("sun.boot.library.path=" + Debug.getProperty("sun.boot.library.path", false));
+ System.loadLibrary(libraryName);
+ }
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java
new file mode 100644
index 000000000..e84264bd0
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.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(true);
+ 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.jogamp.nativewindow.impl.jawt.windows.WindowsJAWTWindow";
+ } else if (osType.equals(TYPE_MACOSX)) {
+ windowClassName = "com.jogamp.nativewindow.impl.jawt.macosx.MacOSXJAWTWindow";
+ } else if (osType.equals(TYPE_X11)) {
+ // Assume Linux, Solaris, etc. Should probably test for these explicitly.
+ windowClassName = "com.jogamp.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/jogamp/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java
new file mode 100644
index 000000000..4458d7b3d
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java
@@ -0,0 +1,148 @@
+/*
+ * 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.jogamp.nativewindow.impl;
+
+import javax.media.nativewindow.*;
+
+public class NullWindow implements NativeWindow, SurfaceChangeable {
+ 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 void destroy() {
+ invalidate();
+ }
+
+ 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 boolean surfaceSwap() {
+ return false;
+ }
+
+ public void surfaceUpdated(Object updater, NativeWindow window, long when) { }
+
+ public long getDisplayHandle() {
+ return displayHandle;
+ }
+ public int getScreenIndex() {
+ return scrnIndex;
+ }
+ public long getWindowHandle() {
+ return 0;
+ }
+ public long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+ public void setSurfaceHandle(long surfaceHandle) {
+ this.surfaceHandle=surfaceHandle;
+ }
+ 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;
+ }
+
+ public String toString() {
+ return "NullWindow[config "+config+
+ ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+
+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
+ ", size "+getWidth()+"x"+getHeight()+"]";
+ }
+
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java
new file mode 100644
index 000000000..9be343a7a
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTNativeLibLoader.java
@@ -0,0 +1,78 @@
+/*
+ * 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.jogamp.nativewindow.impl.jawt;
+
+import javax.media.nativewindow.NativeWindowFactory;
+import com.jogamp.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) ) ) {
+ try {
+ loadLibrary("jawt", null, true);
+ } catch (Throwable t) {
+ // It might be ok .. if it's already loaded
+ if(DEBUG) {
+ t.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
+ });
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
new file mode 100644
index 000000000..2c88b308f
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
@@ -0,0 +1,145 @@
+/*
+ * 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.jogamp.nativewindow.impl.jawt;
+
+import com.jogamp.nativewindow.impl.*;
+
+import javax.media.nativewindow.*;
+
+import java.awt.GraphicsEnvironment;
+import java.lang.reflect.*;
+
+public class JAWTUtil {
+
+ // See whether we're running in headless mode
+ private static final boolean headlessMode;
+
+ // Java2D magic ..
+ private static final Class j2dClazz;
+ private static final Method isQueueFlusherThread;
+ private static final boolean j2dExist;
+
+ static {
+ JAWTNativeLibLoader.loadAWTImpl();
+ JAWTNativeLibLoader.loadNativeWindow("awt");
+
+ lockedStack = null;
+ headlessMode = GraphicsEnvironment.isHeadless();
+
+ boolean ok=false;
+ Class jC=null;
+ Method m=null;
+ if(!headlessMode) {
+ try {
+ jC = Class.forName("com.jogamp.opengl.impl.awt.Java2D");
+ m = jC.getMethod("isQueueFlusherThread", null);
+ ok = true;
+ } catch (Exception e) {}
+ }
+ j2dClazz = jC;
+ isQueueFlusherThread = m;
+ j2dExist = ok;
+ }
+
+ private static Exception lockedStack;
+
+ // Just a hook to let this class being initialized,
+ // ie loading the native libraries ..
+ public static void init() { }
+
+ public static final boolean hasJava2D() {
+ return j2dExist;
+ }
+
+ public static final boolean isJava2DQueueFlusherThread() {
+ boolean b = false;
+ if(j2dExist) {
+ try {
+ b = ((Boolean)isQueueFlusherThread.invoke(null, null)).booleanValue();
+ } catch (Exception e) {}
+ }
+ return b;
+ }
+
+ public static boolean isHeadlessMode() {
+ return headlessMode;
+ }
+
+ public static synchronized void lockToolkit() throws NativeWindowException {
+ if (isJava2DQueueFlusherThread()) return;
+
+ 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 (isJava2DQueueFlusherThread()) return;
+
+ 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/jogamp/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java
new file mode 100644
index 000000000..d0529878f
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java
@@ -0,0 +1,186 @@
+/*
+ * 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.jogamp.nativewindow.impl.jawt;
+
+import com.jogamp.nativewindow.impl.*;
+
+import java.awt.Component;
+import java.awt.Window;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+import com.jogamp.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;
+ }
+
+ public synchronized void destroy() {
+ if(null!=component) {
+ if(component instanceof Window) {
+ ((Window)component).dispose();
+ }
+ }
+ invalidate();
+ }
+
+ 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 it's
+ // recursive and blocking lock capabitlites.
+ // Otherwise a followup ToolkitLock would deadlock,
+ // since we already have locked JAWT with the surface lock.
+ NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+
+ // recursion not necessary here, due to the blocking ToolkitLock ..
+ 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 boolean surfaceSwap() {
+ return false;
+ }
+
+ public void surfaceUpdated(Object updater, NativeWindow window, long when) { }
+
+ 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/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java
new file mode 100644
index 000000000..d49e2f8d0
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl.jawt;
+
+import com.jogamp.nativewindow.impl.*;
+
+/** Marker class for all window system-specific JAWT data structures. */
+
+public interface JAWT_PlatformInfo {
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
new file mode 100644
index 000000000..967d43d60
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl.jawt.macosx;
+
+import com.jogamp.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.jawt.*;
+
+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.getCocoaViewRef();
+
+ 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/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
new file mode 100644
index 000000000..b23ad3f50
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl.jawt.windows;
+
+import com.jogamp.nativewindow.impl.*;
+import com.jogamp.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.getHdc();
+ 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/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java
new file mode 100644
index 000000000..f2977e8f0
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl.jawt.x11;
+
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.x11.*;
+
+import com.jogamp.nativewindow.impl.x11.*;
+import com.jogamp.nativewindow.impl.jawt.*;
+import com.jogamp.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.getDrawable();
+ 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/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
new file mode 100644
index 000000000..7cca6f9f3
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl.jawt.x11;
+
+import com.jogamp.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/jogamp/nativewindow/impl/jvm/JVMUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java
new file mode 100644
index 000000000..df703aa55
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java
@@ -0,0 +1,72 @@
+/*
+ * 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.jogamp.nativewindow.impl.jvm;
+
+import java.nio.ByteBuffer;
+import com.jogamp.nativewindow.impl.*;
+
+/**
+ * Currently this tool works around the Hotspot race condition bugs:
+ <PRE>
+ 4395095 JNI access to java.nio DirectBuffer constructor/accessor
+ 6852404 Race condition in JNI Direct Buffer access and creation routines
+ </PRE>
+ *
+ * Make sure to initialize this class as soon as possible,
+ * before doing any multithreading work.
+ *
+ */
+public class JVMUtil {
+ private static final boolean DEBUG = Debug.debug("JVMUtil");
+
+ static {
+ NativeLibLoaderBase.loadNativeWindow("jvm");
+
+ ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64);
+ if( ! initialize(buffer) ) {
+ throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName());
+ }
+ if(DEBUG) {
+ Exception e = new Exception("JVMUtil.initSingleton() .. initialized "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ }
+
+ public static void initSingleton() {
+ }
+
+ private JVMUtil() {}
+
+ private static native boolean initialize(java.nio.ByteBuffer buffer);
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
new file mode 100644
index 000000000..4ffda2fae
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
@@ -0,0 +1,118 @@
+/*
+ * 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.jogamp.nativewindow.impl.x11;
+
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.x11.*;
+import com.jogamp.nativewindow.impl.x11.XVisualInfo;
+import com.jogamp.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.setVisualid(visualID);
+ xvi_temp.setScreen(screen.getIndex());
+ int num[] = { -1 };
+ long display = screen.getDevice().getHandle();
+
+ try {
+ X11Lib.XLockDisplay(display);
+ XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0);
+
+ if(xvis==null || num[0]<1) {
+ return null;
+ }
+
+ return XVisualInfo.create(xvis[0]);
+ } finally {
+ X11Lib.XUnlockDisplay(display);
+ }
+
+ }
+
+ 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.setScreen(screen.getIndex());
+ vinfo_template.setC_class(c_class);
+ long display = screen.getDevice().getHandle();
+
+ try {
+ X11Lib.XLockDisplay(display);
+ XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(display, 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.getDepth() < vinfos[i].getDepth() )
+ {
+ best = vinfos[i];
+ if(rdepth <= best.getDepth())
+ break;
+ }
+ }
+ if ( null!=best && ( rdepth <= best.getDepth() || 24 == best.getDepth()) ) {
+ ret = XVisualInfo.create(best);
+ }
+ best = null;
+
+ return ret;
+ } finally {
+ X11Lib.XUnlockDisplay(display);
+ }
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
new file mode 100644
index 000000000..9fc986180
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
@@ -0,0 +1,166 @@
+/*
+ * 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.jogamp.nativewindow.impl.x11;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.media.nativewindow.*;
+
+import com.jogamp.nativewindow.impl.*;
+
+/**
+ * Contains a thread safe X11 utility to retrieve thread local display connection,<br>
+ * as well as the static global discplay connection.<br>
+ *
+ * The TLS variant is thread safe per se, but be aware of the memory leak risk
+ * where an application heavily utilizing this class on temporary new threads.<br>
+ */
+public class X11Util {
+ private static final boolean DEBUG = Debug.debug("X11Util");
+
+ static {
+ NativeLibLoaderBase.loadNativeWindow("x11");
+ }
+
+ private X11Util() {}
+
+ private static ThreadLocal currentDisplayMap = new ThreadLocal();
+
+ public static class NamedDisplay implements Cloneable {
+ private String name;
+ private long handle;
+
+ protected NamedDisplay(String name, long handle) {
+ this.name=name;
+ this.handle=handle;
+ }
+
+ public String getName() { return name; }
+ public long getHandle() { return handle; }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+ /** Returns a clone of the thread local display map, you may {@link Object#wait()} on it */
+ public static Map getCurrentDisplayMap() {
+ return (Map) ((HashMap)getCurrentDisplayMapImpl()).clone();
+ }
+
+ /** Returns this thread current default display. If it doesn not exist, it is being created */
+ public static long getThreadLocalDefaultDisplay() {
+ return getThreadLocalDisplay(null);
+ }
+
+ /** Returns this thread named display. If it doesn not exist, it is being created */
+ public static long getThreadLocalDisplay(String name) {
+ NamedDisplay namedDpy = getCurrentDisplay(name);
+ if(null==namedDpy) {
+ long dpy = X11Lib.XOpenDisplay(name);
+ if(0==dpy) {
+ throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection in Thread "+Thread.currentThread().getName());
+ }
+ namedDpy = new NamedDisplay(name, dpy);
+ setCurrentDisplay( namedDpy );
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Created new TLS display("+name+") connection 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ }
+ return namedDpy.getHandle();
+ }
+
+ /** Closes this thread named display. It returns the handle of the closed display or 0, if it does not exist. */
+ public static long closeThreadLocalDisplay(String name) {
+ NamedDisplay namedDpy = removeCurrentDisplay(name);
+ if(null==namedDpy) {
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ return 0;
+ }
+ long dpy = namedDpy.getHandle();
+ X11Lib.XCloseDisplay(dpy);
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Closed TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ return dpy;
+ }
+
+ private static Map getCurrentDisplayMapImpl() {
+ Map displayMap = (Map) currentDisplayMap.get();
+ if(null==displayMap) {
+ displayMap = new HashMap();
+ currentDisplayMap.set( displayMap );
+ }
+ return displayMap;
+ }
+
+ /** maps the given display to the thread local display map
+ * and notifies all threads synchronized to this display map. */
+ private static NamedDisplay setCurrentDisplay(NamedDisplay newDisplay) {
+ Map displayMap = getCurrentDisplayMapImpl();
+ NamedDisplay oldDisplay = null;
+ synchronized(displayMap) {
+ String name = (null==newDisplay.getName())?"nil":newDisplay.getName();
+ oldDisplay = (NamedDisplay) displayMap.put(name, newDisplay);
+ displayMap.notifyAll();
+ }
+ return oldDisplay;
+ }
+
+ /** removes the mapping of the given name from the thread local display map
+ * and notifies all threads synchronized to this display map. */
+ private static NamedDisplay removeCurrentDisplay(String name) {
+ Map displayMap = getCurrentDisplayMapImpl();
+ NamedDisplay oldDisplay = null;
+ synchronized(displayMap) {
+ if(null==name) name="nil";
+ oldDisplay = (NamedDisplay) displayMap.remove(name);
+ displayMap.notifyAll();
+ }
+ return oldDisplay;
+ }
+
+ /** Returns the thread local display mapped to the given name */
+ private static NamedDisplay getCurrentDisplay(String name) {
+ if(null==name) name="nil";
+ Map displayMap = getCurrentDisplayMapImpl();
+ return (NamedDisplay) displayMap.get(name);
+ }
+
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java
new file mode 100644
index 000000000..616220e14
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/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.jogamp.nativewindow.impl.x11.awt;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+
+import com.jogamp.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.jawt.*;
+import com.jogamp.nativewindow.impl.jawt.x11.*;
+import com.jogamp.nativewindow.impl.x11.*;
+
+public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl {
+
+ // 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;
+ }
+}