aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/Debug.java140
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java43
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/NWJNILibLoader.java47
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java109
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java55
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java171
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java96
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java78
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTToolkitLock.java54
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java225
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java277
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWT_PlatformInfo.java47
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java148
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java117
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java145
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java60
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java156
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java118
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java44
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java133
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java104
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/x11/X11ToolkitLock.java55
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java610
23 files changed, 3032 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/Debug.java b/src/nativewindow/classes/jogamp/nativewindow/Debug.java
new file mode 100644
index 000000000..edb682392
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/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/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java
new file mode 100644
index 000000000..f77454fac
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/DefaultGraphicsConfigurationFactoryImpl.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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 DefaultGraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory {
+ protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl(
+ CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen screen) {
+ return new DefaultGraphicsConfiguration(screen, capsChosen, capsRequested);
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/NWJNILibLoader.java b/src/nativewindow/classes/jogamp/nativewindow/NWJNILibLoader.java
new file mode 100644
index 000000000..3b2a728e5
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/NWJNILibLoader.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+
+package com.jogamp.nativewindow.impl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import com.jogamp.common.jvm.JNILibLoaderBase;
+
+public class NWJNILibLoader extends JNILibLoaderBase {
+
+ public static void loadNativeWindow(final String ossuffix) {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ loadLibrary("nativewindow_"+ossuffix, null, false);
+ return null;
+ }
+ });
+ }
+
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
new file mode 100644
index 000000000..860be6f95
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
@@ -0,0 +1,109 @@
+/*
+ * 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 com.jogamp.common.util.*;
+import java.lang.reflect.*;
+
+import javax.media.nativewindow.*;
+
+public class NativeWindowFactoryImpl extends NativeWindowFactory {
+ protected static final boolean DEBUG = Debug.debug("NativeWindow");
+
+ private static final ToolkitLock nullToolkitLock = new NullToolkitLock();
+
+ public static ToolkitLock getNullToolkitLock() {
+ return nullToolkitLock;
+ }
+
+ // 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 (NativeWindowFactory.isAWTAvailable() && ReflectionUtil.instanceOf(winObj, AWTComponentClassName)) {
+ return getAWTNativeWindow(winObj, config);
+ }
+
+ throw new IllegalArgumentException("Target window object type " +
+ winObj.getClass().getName() + " is unsupported; expected " +
+ "javax.media.nativewindow.NativeWindow or "+AWTComponentClassName);
+ }
+
+ 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 = ReflectionUtil.getConstructor(
+ windowClassName, new Class[] { Object.class, AbstractGraphicsConfiguration.class },
+ getClass().getClassLoader());
+ } 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);
+ }
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java
new file mode 100644
index 000000000..db4db1126
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/NullToolkitLock.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.nativewindow.impl;
+
+import javax.media.nativewindow.ToolkitLock;
+
+/**
+ * Implementing a singleton global recursive {@link javax.media.nativewindow.ToolkitLock}
+ * without any locking. Since there is no locking it all,
+ * it is intrinsically recursive.
+ */
+public class NullToolkitLock implements ToolkitLock {
+
+ /** Singleton via {@link NativeWindowFactoryImpl#getNullToolkitLock()} */
+ protected NullToolkitLock() { }
+
+ public final void lock() {
+ if(TRACE_LOCK) {
+ String msg = "NullToolkitLock.lock()";
+ System.err.println(msg);
+ // Throwable t = new Throwable(msg);
+ // t.printStackTrace();
+ }
+ }
+
+ public final void unlock() {
+ if(TRACE_LOCK) { System.err.println("NullToolkitLock.unlock()"); }
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java b/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java
new file mode 100644
index 000000000..e0ad95e1f
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.SurfaceChangeable;
+
+import com.jogamp.common.util.locks.RecursiveLock;
+
+public class ProxySurface implements NativeSurface, SurfaceChangeable {
+ private RecursiveLock recurLock = new RecursiveLock();
+ protected AbstractGraphicsConfiguration config;
+ protected long displayHandle;
+ protected long surfaceHandle;
+ protected int scrnIndex;
+ protected int width, height;
+
+ public ProxySurface(AbstractGraphicsConfiguration cfg) {
+ this(cfg, 0);
+ }
+
+ public ProxySurface(AbstractGraphicsConfiguration cfg, long handle) {
+ invalidate();
+ config = cfg;
+ displayHandle=cfg.getScreen().getDevice().getHandle();
+ surfaceHandle=handle;
+ scrnIndex=cfg.getScreen().getIndex();
+ }
+
+ protected void init(Object windowObject) throws NativeWindowException {
+ }
+
+ protected void initNative() throws NativeWindowException {
+ }
+
+ public NativeWindow getParent() {
+ return null;
+ }
+
+ public void destroy() {
+ invalidate();
+ }
+
+ public synchronized void invalidate() {
+ displayHandle=0;
+ scrnIndex=-1;
+ surfaceHandle=0;
+ }
+
+ public final int lockSurface() throws NativeWindowException {
+ recurLock.lock();
+
+ if(recurLock.getRecursionCount() == 0) {
+ config.getScreen().getDevice().lock();
+ }
+ return LOCK_SUCCESS;
+ }
+
+ public final void unlockSurface() {
+ recurLock.validateLocked();
+
+ if(recurLock.getRecursionCount()==0) {
+ config.getScreen().getDevice().unlock();
+ }
+ recurLock.unlock();
+ }
+
+ public final void validateSurfaceLocked() {
+ recurLock.validateLocked();
+ }
+
+ public final int getSurfaceRecursionCount() {
+ return recurLock.getRecursionCount();
+ }
+
+ public final boolean isSurfaceLockedByOtherThread() {
+ return recurLock.isLockedByOtherThread();
+ }
+
+ public final boolean isSurfaceLocked() {
+ return recurLock.isLocked();
+ }
+
+ public final Thread getSurfaceLockOwner() {
+ return recurLock.getOwner();
+ }
+
+ public boolean surfaceSwap() {
+ return false;
+ }
+
+ public long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public AbstractGraphicsConfiguration getGraphicsConfiguration() {
+ return config;
+ }
+
+ public void surfaceUpdated(Object updater, NativeSurface ns, long when) { }
+
+ public long getDisplayHandle() {
+ return displayHandle;
+ }
+ public int getScreenIndex() {
+ return scrnIndex;
+ }
+
+ public void setSurfaceHandle(long surfaceHandle) {
+ this.surfaceHandle=surfaceHandle;
+ }
+
+ public void setSize(int width, int height) {
+ this.width=width;
+ this.height=height;
+ }
+
+ public String toString() {
+ return "ProxySurface[config "+config+
+ ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+
+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
+ ", size "+getWidth()+"x"+getHeight()+"]";
+ }
+
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
new file mode 100644
index 000000000..c61ae5531
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.nativewindow.impl.awt;
+
+import java.awt.Window;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Frame;
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.WindowClosingProtocol;
+import javax.swing.MenuSelectionManager;
+
+public class AWTMisc {
+
+ public static final JFrame getJFrame(Component c) {
+ while (c != null && !(c instanceof JFrame)) {
+ c = c.getParent();
+ }
+ return (JFrame) c;
+ }
+
+ public static final Frame getFrame(Component c) {
+ while (c != null && !(c instanceof Frame)) {
+ c = c.getParent();
+ }
+ return (Frame) c;
+ }
+
+ public static final Window getWindow(Component c) {
+ while (c != null && !(c instanceof Window)) {
+ c = c.getParent();
+ }
+ return (Window) c;
+ }
+
+ public static final Container getContainer(Component c) {
+ while (c != null && !(c instanceof Container)) {
+ c = c.getParent();
+ }
+ return (Container) c;
+ }
+
+ /**
+ * Issue this when your non AWT toolkit gains focus to clear AWT menu path
+ */
+ public static final void clearAWTMenus() {
+ MenuSelectionManager.defaultManager().clearSelectedPath();
+ }
+
+ public final static int AWT2NWClosingOperation(int awtClosingOperation) {
+ switch (awtClosingOperation) {
+ case WindowConstants.DISPOSE_ON_CLOSE:
+ case WindowConstants.EXIT_ON_CLOSE:
+ return WindowClosingProtocol.DISPOSE_ON_CLOSE;
+ case WindowConstants.DO_NOTHING_ON_CLOSE:
+ case WindowConstants.HIDE_ON_CLOSE:
+ return WindowClosingProtocol.DO_NOTHING_ON_CLOSE;
+ default:
+ throw new NativeWindowException("Unhandled AWT Closing Operation: " + awtClosingOperation);
+ }
+ }
+
+ public final static int getNWClosingOperation(Component c) {
+ JFrame jf = getJFrame(c);
+ int op = (null != jf) ? jf.getDefaultCloseOperation() : WindowConstants.DO_NOTHING_ON_CLOSE ;
+ return AWT2NWClosingOperation(op);
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.java
new file mode 100644
index 000000000..4ea404c09
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTJNILibLoader.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.NWJNILibLoader;
+
+import java.awt.Toolkit;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class JAWTJNILibLoader extends NWJNILibLoader {
+ 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/jogamp/nativewindow/jawt/JAWTToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTToolkitLock.java
new file mode 100644
index 000000000..017d74874
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTToolkitLock.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.nativewindow.impl.jawt;
+
+import javax.media.nativewindow.ToolkitLock;
+
+/**
+ * Implementing a singleton global recursive {@link javax.media.nativewindow.ToolkitLock}
+ * utilizing JAWT's AWT lock via {@link JAWTUtil#lockToolkit()}.
+ * <br>
+ * This strategy should only be used if AWT is using the underlying native windowing toolkit
+ * in a not intrinsic thread safe manner, e.g. under X11 where no XInitThreads() call
+ * is issued before any other X11 usage. This is the current situation for e.g. Webstart or Applets.
+ */
+public class JAWTToolkitLock implements ToolkitLock {
+
+ /** Singleton via {@link JAWTUtil#getJAWTToolkitLock()} */
+ protected JAWTToolkitLock() {}
+
+ public final void lock() {
+ if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.lock()"); }
+ JAWTUtil.lockToolkit();
+ }
+
+ public final void unlock() {
+ if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.unlock()"); }
+ JAWTUtil.unlockToolkit();
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
new file mode 100644
index 000000000..0c6fc3f55
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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.EventQueue;
+
+import javax.media.nativewindow.*;
+
+
+import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
+import java.lang.reflect.*;
+import java.security.*;
+import java.util.ArrayList;
+import java.util.Map;
+
+public class JAWTUtil {
+ protected static final boolean DEBUG = Debug.debug("JAWT");
+
+ // See whether we're running in headless mode
+ private static final boolean headlessMode;
+
+ // Java2D magic ..
+ private static final Method isQueueFlusherThread;
+ private static final boolean j2dExist;
+
+ private static Class sunToolkitClass;
+ private static Method sunToolkitAWTLockMethod;
+ private static Method sunToolkitAWTUnlockMethod;
+ private static boolean hasSunToolkitAWTLock;
+
+ private static final JAWTToolkitLock jawtToolkitLock;
+
+ static {
+ JAWTJNILibLoader.loadAWTImpl();
+ JAWTJNILibLoader.loadNativeWindow("awt");
+
+ 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) {
+ }
+ }
+ isQueueFlusherThread = m;
+ j2dExist = ok;
+
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ try {
+ sunToolkitClass = Class.forName("sun.awt.SunToolkit");
+ sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[]{});
+ sunToolkitAWTLockMethod.setAccessible(true);
+ sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[]{});
+ sunToolkitAWTUnlockMethod.setAccessible(true);
+ } catch (Exception e) {
+ // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
+ }
+ return null;
+ }
+ });
+ boolean _hasSunToolkitAWTLock = false;
+ if (null != sunToolkitAWTLockMethod && null != sunToolkitAWTUnlockMethod) {
+ try {
+ sunToolkitAWTLockMethod.invoke(null, null);
+ sunToolkitAWTUnlockMethod.invoke(null, null);
+ _hasSunToolkitAWTLock = true;
+ } catch (Exception e) {
+ }
+ }
+ hasSunToolkitAWTLock = _hasSunToolkitAWTLock;
+ // hasSunToolkitAWTLock = false;
+
+ jawtToolkitLock = new JAWTToolkitLock();
+
+ // trigger native AWT toolkit / properties initialization
+ Map desktophints = null;
+ try {
+ if(EventQueue.isDispatchThread()) {
+ desktophints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"));
+ } else {
+ final ArrayList desktophintsBucket = new ArrayList(1);
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ Map _desktophints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"));
+ if(null!=_desktophints) {
+ desktophintsBucket.add(_desktophints);
+ }
+ }
+ });
+ desktophints = ( desktophintsBucket.size() > 0 ) ? (Map)desktophintsBucket.get(0) : null ;
+ }
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ } catch (InvocationTargetException ex) {
+ ex.printStackTrace();
+ }
+
+ if (DEBUG) {
+ System.err.println("JAWTUtil: Has sun.awt.SunToolkit.awtLock/awtUnlock " + hasSunToolkitAWTLock);
+ System.err.println("JAWTUtil: Has Java2D " + j2dExist);
+ System.err.println("JAWTUtil: Is headless " + headlessMode);
+ int hints = ( null != desktophints ) ? desktophints.size() : 0 ;
+ System.err.println("JAWTUtil: AWT Desktop hints " + hints);
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ 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;
+ }
+
+ /**
+ * Locks the AWT's global ReentrantLock.<br>
+ *
+ * JAWT's native Lock() function calls SunToolkit.awtLock(),
+ * which just uses AWT's global ReentrantLock.<br>
+ */
+ public static void awtLock() {
+ if(hasSunToolkitAWTLock) {
+ try {
+ sunToolkitAWTLockMethod.invoke(null, null);
+ } catch (Exception e) {
+ throw new NativeWindowException("SunToolkit.awtLock failed", e);
+ }
+ } else {
+ JAWT.getJAWT().Lock();
+ }
+ }
+
+ /**
+ * Unlocks the AWT's global ReentrantLock.<br>
+ *
+ * JAWT's native Unlock() function calls SunToolkit.awtUnlock(),
+ * which just uses AWT's global ReentrantLock.<br>
+ */
+ public static void awtUnlock() {
+ if(hasSunToolkitAWTLock) {
+ try {
+ sunToolkitAWTUnlockMethod.invoke(null, null);
+ } catch (Exception e) {
+ throw new NativeWindowException("SunToolkit.awtUnlock failed", e);
+ }
+ } else {
+ JAWT.getJAWT().Unlock();
+ }
+ }
+
+ public static void lockToolkit() throws NativeWindowException {
+ if(!headlessMode && !isJava2DQueueFlusherThread()) {
+ awtLock();
+ }
+ }
+
+ public static void unlockToolkit() {
+ if(!headlessMode && !isJava2DQueueFlusherThread()) {
+ awtUnlock();
+ }
+ }
+
+ public static JAWTToolkitLock getJAWTToolkitLock() {
+ return jawtToolkitLock;
+ }
+}
+
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
new file mode 100644
index 000000000..de6360212
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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.common.util.locks.RecursiveLock;
+
+import java.awt.Component;
+import java.awt.Window;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+
+public abstract class JAWTWindow implements NativeWindow {
+ protected static final boolean DEBUG = JAWTUtil.DEBUG;
+
+ // lifetime: forever
+ protected Component component;
+ protected AbstractGraphicsConfiguration config;
+
+ // lifetime: valid after lock, forever until invalidate
+ protected long drawable;
+ protected Rectangle bounds;
+
+ public JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ if (config == null) {
+ throw new NativeWindowException("Error: AbstractGraphicsConfiguration is null");
+ }
+ this.config = config;
+ init((Component)comp);
+ }
+
+ private final void init(Component windowObject) throws NativeWindowException {
+ invalidate();
+ this.component = windowObject;
+ validateNative();
+ }
+ protected abstract void validateNative() throws NativeWindowException;
+
+ protected synchronized void invalidate() {
+ component = null;
+ drawable= 0;
+ bounds = new Rectangle();
+ }
+
+ protected final void updateBounds(JAWT_Rectangle jawtBounds) {
+ bounds.setX(jawtBounds.getX());
+ bounds.setY(jawtBounds.getY());
+ bounds.setWidth(jawtBounds.getWidth());
+ bounds.setHeight(jawtBounds.getHeight());
+ }
+
+ /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */
+ public final Rectangle getBounds() { return bounds; }
+
+ public final Component getAWTComponent() {
+ return component;
+ }
+
+ //
+ // SurfaceUpdateListener
+ //
+
+ public final void surfaceUpdated(Object updater, NativeSurface ns, long when) {
+ // nop
+ }
+
+ //
+ // NativeSurface
+ //
+
+ private RecursiveLock recurLock = new RecursiveLock();
+
+ protected abstract int lockSurfaceImpl() throws NativeWindowException;
+
+ public final int lockSurface() throws NativeWindowException {
+ int res = LOCK_SURFACE_NOT_READY;
+
+ recurLock.lock();
+
+ if(recurLock.getRecursionCount() == 0) {
+ config.getScreen().getDevice().lock();
+ try {
+ res = lockSurfaceImpl();
+ } finally {
+ // Unlock in case surface couldn't be locked
+ if(LOCK_SURFACE_NOT_READY >= res ) {
+ config.getScreen().getDevice().unlock();
+ recurLock.unlock();
+ }
+ }
+ } else {
+ res = LOCK_SUCCESS;
+ }
+
+ return res;
+ }
+
+ protected abstract void unlockSurfaceImpl() throws NativeWindowException;
+
+ public final void unlockSurface() {
+ recurLock.validateLocked();
+
+ if(recurLock.getRecursionCount()==0) {
+ try {
+ unlockSurfaceImpl();
+ } finally {
+ config.getScreen().getDevice().unlock();
+ }
+ }
+ recurLock.unlock();
+ }
+
+ public final boolean isSurfaceLockedByOtherThread() {
+ return recurLock.isLockedByOtherThread();
+ }
+
+ public final boolean isSurfaceLocked() {
+ return recurLock.isLocked();
+ }
+
+ public final Thread getSurfaceLockOwner() {
+ return recurLock.getOwner();
+ }
+
+ public final boolean surfaceSwap() {
+ return false;
+ }
+
+ public final void surfaceUpdated(Object updater, NativeWindow window, long when) { }
+
+ public final long getSurfaceHandle() {
+ return drawable;
+ }
+ public final AbstractGraphicsConfiguration getGraphicsConfiguration() {
+ return config;
+ }
+
+ public final long getDisplayHandle() {
+ return config.getScreen().getDevice().getHandle();
+ }
+
+ public final int getScreenIndex() {
+ return config.getScreen().getIndex();
+ }
+
+ public final void setSize(int width, int height) {
+ component.setSize(width, height);
+ }
+
+ public final int getWidth() {
+ return component.getWidth();
+ }
+
+ public final int getHeight() {
+ return component.getHeight();
+ }
+
+ //
+ // NativeWindow
+ //
+
+ public synchronized void destroy() {
+ if(null!=component) {
+ if(component instanceof Window) {
+ ((Window)component).dispose();
+ }
+ }
+ invalidate();
+ }
+
+ public final NativeWindow getParent() {
+ return null;
+ }
+
+ public long getWindowHandle() {
+ return drawable;
+ }
+
+ public final int getX() {
+ return component.getX();
+ }
+
+ public final int getY() {
+ return component.getY();
+ }
+
+ public Point getLocationOnScreen(Point storage) {
+ if( 0 != getWindowHandle() ) {
+ Point d;
+ // windowLock.lock();
+ try {
+ d = getLocationOnScreenImpl(0, 0);
+ } finally {
+ // windowLock.unlock();
+ }
+ if(null!=d) {
+ if(null!=storage) {
+ storage.translate(d.getX(),d.getY());
+ return storage;
+ }
+ return d;
+ }
+ // fall through intended ..
+ }
+
+ if(!Thread.holdsLock(component.getTreeLock())) {
+ return null; // avoid deadlock ..
+ }
+ java.awt.Point awtLOS = component.getLocationOnScreen();
+ int dx = (int) ( awtLOS.getX() + .5 ) ;
+ int dy = (int) ( awtLOS.getY() + .5 ) ;
+ if(null!=storage) {
+ return storage.translate(dx, dy);
+ }
+ return new Point(dx, dy);
+ }
+ protected abstract Point getLocationOnScreenImpl(int x, int y);
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("JAWT-Window["+
+ "windowHandle 0x"+Long.toHexString(getWindowHandle())+
+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
+ ", bounds "+bounds);
+ if(null!=component) {
+ sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
+ ", visible "+component.isVisible());
+ } else {
+ sb.append(", component NULL");
+ }
+ sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+
+ ",\n\tconfig "+config+
+ ",\n\tawtComponent "+getAWTComponent()+"]");
+
+ return sb.toString();
+ }
+
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWT_PlatformInfo.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWT_PlatformInfo.java
new file mode 100644
index 000000000..d49e2f8d0
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/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/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
new file mode 100644
index 000000000..fc5607707
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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 java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Point;
+
+import com.jogamp.nativewindow.impl.jawt.JAWT;
+import com.jogamp.nativewindow.impl.jawt.JAWTFactory;
+import com.jogamp.nativewindow.impl.jawt.JAWTWindow;
+import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface;
+import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo;
+
+public class MacOSXJAWTWindow extends JAWTWindow {
+
+ public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
+ }
+
+ protected void validateNative() throws NativeWindowException {
+ }
+
+ protected int lockSurfaceImpl() throws NativeWindowException {
+ int ret = NativeWindow.LOCK_SUCCESS;
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ unlockSurfaceImpl();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ;
+ if (!dsLocked) {
+ unlockSurfaceImpl();
+ 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) {
+ unlockSurfaceImpl();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ firstLock = false;
+ macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo();
+ if (macosxdsi == null) {
+ unlockSurfaceImpl();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
+ drawable = macosxdsi.getCocoaViewRef();
+
+ if (drawable == 0) {
+ unlockSurfaceImpl();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ } else {
+ updateBounds(dsi.getBounds());
+ }
+ return ret;
+ }
+
+ protected void unlockSurfaceImpl() throws NativeWindowException {
+ if(null!=ds) {
+ if (null!=dsi) {
+ ds.FreeDrawingSurfaceInfo(dsi);
+ }
+ if (dsLocked) {
+ ds.Unlock();
+ }
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ }
+ ds = null;
+ dsi = null;
+ macosxdsi = null;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return null; // FIXME
+ }
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private boolean dsLocked;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
+
+ // Workaround for instance of 4796548
+ private boolean firstLock = true;
+
+}
+
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java
new file mode 100644
index 000000000..05d31a40e
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/Win32SunJDKReflection.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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 java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+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 Win32SunJDKReflection {
+ private static Class win32GraphicsDeviceClass;
+ private static Class win32GraphicsConfigClass;
+ private static Method win32GraphicsConfigGetConfigMethod;
+ private static Method win32GraphicsConfigGetVisualMethod;
+ private static boolean initted;
+
+ static {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ try {
+ win32GraphicsDeviceClass = Class.forName("sun.awt.Win32GraphicsDevice");
+ win32GraphicsConfigClass = Class.forName("sun.awt.Win32GraphicsConfig");
+ win32GraphicsConfigGetConfigMethod = win32GraphicsConfigClass.getDeclaredMethod("getConfig", new Class[] { win32GraphicsDeviceClass, int.class });
+ win32GraphicsConfigGetConfigMethod.setAccessible(true);
+ win32GraphicsConfigGetVisualMethod = win32GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {});
+ win32GraphicsConfigGetVisualMethod.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 GraphicsConfiguration graphicsConfigurationGet(GraphicsDevice device, int pfdID) {
+ if (!initted) {
+ return null;
+ }
+
+ try {
+ return (GraphicsConfiguration) win32GraphicsConfigGetConfigMethod.invoke(null, new Object[] { device, new Integer(pfdID) });
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static int graphicsConfigurationGetPixelFormatID(AbstractGraphicsConfiguration config) {
+ try {
+ if (config instanceof AWTGraphicsConfiguration) {
+ return graphicsConfigurationGetPixelFormatID(((AWTGraphicsConfiguration) config).getGraphicsConfiguration());
+ }
+ return 0;
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static int graphicsConfigurationGetPixelFormatID(GraphicsConfiguration config) {
+ if (!initted) {
+ return 0;
+ }
+
+ try {
+ return ((Integer) win32GraphicsConfigGetVisualMethod.invoke(config, null)).intValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java
new file mode 100644
index 000000000..d7cd55f9a
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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 javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Point;
+
+import com.jogamp.nativewindow.impl.jawt.JAWT;
+import com.jogamp.nativewindow.impl.jawt.JAWTFactory;
+import com.jogamp.nativewindow.impl.jawt.JAWTWindow;
+import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface;
+import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo;
+import com.jogamp.nativewindow.impl.windows.GDI;
+
+public class WindowsJAWTWindow extends JAWTWindow {
+
+ public WindowsJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
+ }
+
+ protected void validateNative() throws NativeWindowException {
+ }
+
+ protected synchronized void invalidate() {
+ super.invalidate();
+ windowHandle = 0;
+ }
+
+ protected int lockSurfaceImpl() throws NativeWindowException {
+ int ret = NativeWindow.LOCK_SUCCESS;
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ;
+ if (!dsLocked) {
+ unlockSurfaceImpl();
+ 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) {
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo();
+ if (win32dsi == null) {
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ windowHandle = win32dsi.getHandle();
+ drawable = win32dsi.getHdc();
+ if (windowHandle == 0 || drawable == 0) {
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ } else {
+ updateBounds(dsi.getBounds());
+ }
+ return ret;
+ }
+
+ protected void unlockSurfaceImpl() throws NativeWindowException {
+ long startTime = 0;
+ if(null!=ds) {
+ if (null!=dsi) {
+ ds.FreeDrawingSurfaceInfo(dsi);
+ }
+ if (dsLocked) {
+ ds.Unlock();
+ }
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ }
+ ds = null;
+ dsi = null;
+ win32dsi = null;
+ }
+
+ public long getWindowHandle() {
+ return windowHandle;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y);
+ }
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private boolean dsLocked;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_Win32DrawingSurfaceInfo win32dsi;
+
+ // lifetime: valid after lock, forever until invalidate
+ protected long windowHandle;
+}
+
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java
new file mode 100644
index 000000000..7eaac2ca6
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTToolkitLock.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.nativewindow.impl.jawt.x11;
+
+import com.jogamp.nativewindow.impl.jawt.*;
+import com.jogamp.nativewindow.impl.x11.X11Util;
+import javax.media.nativewindow.ToolkitLock;
+
+/**
+ * Implementing a recursive {@link javax.media.nativewindow.ToolkitLock}
+ * utilizing JAWT's AWT lock via {@link JAWTUtil#lockToolkit()} and {@link X11Util#XLockDisplay(long)}.
+ * <br>
+ * This strategy should only be used if AWT is using the underlying native windowing toolkit
+ * in a not intrinsic thread safe manner, e.g. under X11 where no XInitThreads() call
+ * is issued before any other X11 usage. This is the current situation for e.g. Webstart or Applets.
+ */
+public class X11JAWTToolkitLock implements ToolkitLock {
+ long displayHandle;
+
+ public X11JAWTToolkitLock(long displayHandle) {
+ this.displayHandle = displayHandle;
+ }
+
+ public final void lock() {
+ if(TRACE_LOCK) { System.err.println("X11JAWTToolkitLock.lock()"); }
+ JAWTUtil.lockToolkit();
+ X11Util.XLockDisplay(displayHandle);
+ }
+
+ public final void unlock() {
+ if(TRACE_LOCK) { System.err.println("X11JAWTToolkitLock.unlock()"); }
+ X11Util.XUnlockDisplay(displayHandle);
+ JAWTUtil.unlockToolkit();
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java
new file mode 100644
index 000000000..f87558dbc
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.AbstractGraphicsScreen;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.awt.AWTGraphicsDevice;
+import javax.media.nativewindow.util.Point;
+
+import com.jogamp.nativewindow.impl.jawt.JAWT;
+import com.jogamp.nativewindow.impl.jawt.JAWTFactory;
+import com.jogamp.nativewindow.impl.jawt.JAWTWindow;
+import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface;
+import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo;
+import com.jogamp.nativewindow.impl.x11.X11Util;
+
+public class X11JAWTWindow extends JAWTWindow {
+
+ public X11JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
+ }
+
+ protected void validateNative() throws NativeWindowException {
+ AWTGraphicsDevice awtDevice = (AWTGraphicsDevice) config.getScreen().getDevice();
+
+ if(awtDevice.getHandle() != 0) {
+ // subtype and handle set already, done
+ return;
+ }
+
+ long displayHandle = 0;
+
+ // first try a pre-existing attached native configuration, ie native X11GraphicsDevice
+ AbstractGraphicsConfiguration aconfig = (null!=config) ? config.getNativeGraphicsConfiguration() : null;
+ AbstractGraphicsScreen ascreen = (null!=aconfig) ? aconfig.getScreen() : null;
+ AbstractGraphicsDevice adevice = (null!=ascreen) ? ascreen.getDevice() : null; // X11GraphicsDevice
+ if(null!=adevice) {
+ displayHandle = adevice.getHandle();
+ }
+
+ if(0 == displayHandle) {
+ displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(awtDevice.getGraphicsDevice());
+ }
+ if(0==displayHandle) {
+ throw new InternalError("X11JAWTWindow: No X11 Display handle available");
+ }
+ awtDevice.setSubType(NativeWindowFactory.TYPE_X11, displayHandle);
+ }
+
+ protected int lockSurfaceImpl() throws NativeWindowException {
+ int ret = NativeWindow.LOCK_SUCCESS;
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ;
+ if (!dsLocked) {
+ unlockSurfaceImpl();
+ 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) {
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo();
+ if (x11dsi == null) {
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ }
+ drawable = x11dsi.getDrawable();
+ if (drawable == 0) {
+ unlockSurfaceImpl();
+ return LOCK_SURFACE_NOT_READY;
+ } else {
+ updateBounds(dsi.getBounds());
+ }
+ return ret;
+ }
+
+ protected void unlockSurfaceImpl() throws NativeWindowException {
+ if(null!=ds) {
+ if (null!=dsi) {
+ ds.FreeDrawingSurfaceInfo(dsi);
+ }
+ if (dsLocked) {
+ ds.Unlock();
+ }
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ }
+ ds = null;
+ dsi = null;
+ x11dsi = null;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return X11Util.GetRelativeLocation( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y);
+ }
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private boolean dsLocked;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_X11DrawingSurfaceInfo x11dsi;
+
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java
new file mode 100644
index 000000000..b4a99624c
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11SunJDKReflection.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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 java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+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 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");
+ 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 long graphicsDeviceGetDisplay(GraphicsDevice device) {
+ if (!initted) {
+ return 0;
+ }
+
+ try {
+ return ((Long) x11GraphicsDeviceGetDisplayMethod.invoke(device, null)).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, null)).intValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java
new file mode 100644
index 000000000..a30a81948
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClass.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.nativewindow.impl.windows;
+
+public class RegisteredClass {
+ long hInstance;
+ String className;
+
+ RegisteredClass(long hInst, String name) {
+ hInstance = hInst;
+ className = name;
+ }
+
+ public final long getHandle() { return hInstance; }
+ public final String getName() { return className; }
+
+ public final String toString() { return "RegisteredClass[handle 0x"+Long.toHexString(hInstance)+", "+className+"]"; }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java
new file mode 100644
index 000000000..d04640747
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/windows/RegisteredClassFactory.java
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.nativewindow.impl.windows;
+
+import com.jogamp.nativewindow.impl.Debug;
+import java.util.ArrayList;
+import javax.media.nativewindow.NativeWindowException;
+
+public class RegisteredClassFactory {
+ static final boolean DEBUG = Debug.debug("RegisteredClass");
+ private static ArrayList sharedClasses = new ArrayList();
+ private String classBaseName;
+ long wndProc;
+
+ private RegisteredClass sharedClass = null;
+ private int classIter = 0;
+ private int sharedRefCount = 0;
+ private Object sync = new Object();
+
+ /**
+ * Intended for a JVM shutdown hook, hence little synchronization
+ */
+ public static void shutdownSharedClasses() {
+ synchronized(sharedClasses) {
+ for(int i=0; i<sharedClasses.size(); i++) {
+ RegisteredClass sc = (RegisteredClass) sharedClasses.get(i);
+ GDI.DestroyWindowClass(sc.getHandle(), sc.getName());
+ if(DEBUG) {
+ System.err.println("RegisteredClassFactory shutdownSharedClasses "+i+"/"+sharedClasses.size()+": "+sc);
+ }
+ }
+ sharedClasses.clear();
+ }
+ }
+
+ public RegisteredClassFactory(String classBaseName, long wndProc) {
+ this.classBaseName = classBaseName;
+ this.wndProc = wndProc;
+ }
+
+ public RegisteredClass getSharedClass() throws NativeWindowException {
+ synchronized(sync) {
+ if( 0 == sharedRefCount ) {
+ if( null != sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass not null: "+sharedClass);
+ }
+ long hInstance = GDI.GetApplicationHandle();
+ if( 0 == hInstance ) {
+ throw new NativeWindowException("Error: Null ModuleHandle for Application");
+ }
+ String clazzName = null;
+ boolean registered = false;
+ while ( !registered && Integer.MAX_VALUE >= classIter ) {
+ // Retry with next clazz name, this could happen if more than one JVM is running
+ clazzName = classBaseName + classIter;
+ classIter++;
+ registered = GDI.CreateWindowClass(hInstance, clazzName, wndProc);
+ }
+ if( !registered ) {
+ throw new NativeWindowException("Error: Could not create WindowClass: "+clazzName);
+ }
+ sharedClass = new RegisteredClass(hInstance, clazzName);
+ synchronized(sharedClasses) {
+ sharedClasses.add(sharedClass);
+ }
+ if(DEBUG) {
+ System.err.println("RegisteredClassFactory getSharedClass ("+sharedRefCount+") initialized: "+sharedClass);
+ }
+ } else if ( null == sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass is null");
+ }
+ sharedRefCount++;
+ }
+ return sharedClass;
+ }
+
+ public void releaseSharedClass() {
+ synchronized(sync) {
+ if( 0 == sharedRefCount ) {
+ if( null != sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass not null: "+sharedClass);
+ }
+ return;
+ }
+ sharedRefCount--;
+ if( null == sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass is null");
+ }
+ if( 0 == sharedRefCount ) {
+ GDI.DestroyWindowClass(sharedClass.getHandle(), sharedClass.getName());
+ synchronized(sharedClasses) {
+ sharedClasses.remove(sharedClass);
+ }
+ if(DEBUG) {
+ System.err.println("RegisteredClassFactory releaseSharedClass ("+sharedRefCount+") released: "+sharedClass);
+ }
+ sharedClass = null;
+ sharedRefCount = 0;
+ classIter = 0;
+ }
+ }
+ }
+
+ public int getSharedRefCount() {
+ return sharedRefCount;
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java
new file mode 100644
index 000000000..fec7ca29d
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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.*;
+
+public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory {
+ protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl(
+ CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen screen)
+ throws IllegalArgumentException, NativeWindowException {
+
+ if(!(screen instanceof X11GraphicsScreen)) {
+ throw new NativeWindowException("Only valid X11GraphicsScreen are allowed");
+ }
+ return new X11GraphicsConfiguration((X11GraphicsScreen)screen, capsChosen, capsRequested, getXVisualInfo(screen, capsChosen));
+ }
+
+ 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();
+
+ XVisualInfo[] xvis = X11Util.XGetVisualInfo(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0);
+
+ if(xvis==null || num[0]<1) {
+ return null;
+ }
+
+ return XVisualInfo.create(xvis[0]);
+ }
+
+ public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, CapabilitiesImmutable 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, CapabilitiesImmutable 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();
+
+ XVisualInfo[] vinfos = X11Util.XGetVisualInfo(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;
+ }
+}
+
diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11ToolkitLock.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11ToolkitLock.java
new file mode 100644
index 000000000..2e0e911b9
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11ToolkitLock.java
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.nativewindow.impl.x11;
+
+import javax.media.nativewindow.ToolkitLock;
+
+/**
+ * Implementing a recursive {@link javax.media.nativewindow.ToolkitLock}
+ * utilizing {@link X11Util#XLockDisplay(long)}.
+ * <br>
+ * This strategy should not be used in case XInitThreads() is being used,
+ * or a higher level toolkit lock is required, ie AWT lock.
+ */
+public class X11ToolkitLock implements ToolkitLock {
+ long displayHandle;
+
+ public X11ToolkitLock(long displayHandle) {
+ this.displayHandle = displayHandle;
+ }
+
+ public final void lock() {
+ if(TRACE_LOCK) { System.err.println("X11ToolkitLock.lock()"); }
+ X11Util.XLockDisplay(displayHandle);
+ }
+
+ public final void unlock() {
+ if(TRACE_LOCK) { System.err.println("X11ToolkitLock.unlock()"); }
+ X11Util.XUnlockDisplay(displayHandle);
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
new file mode 100644
index 000000000..c56f632d8
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
@@ -0,0 +1,610 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. 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 com.jogamp.common.util.LongObjectHashMap;
+import com.jogamp.nativewindow.impl.Debug;
+import com.jogamp.nativewindow.impl.NWJNILibLoader;
+
+import javax.media.nativewindow.*;
+
+import java.nio.Buffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
+import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.List;
+import javax.media.nativewindow.util.Point;
+
+/**
+ * Contains a thread safe X11 utility to retrieve display connections.
+ */
+public class X11Util {
+ private static final boolean DEBUG = Debug.debug("X11Util");
+ private static final boolean TRACE_DISPLAY_LIFECYCLE = Debug.getBooleanProperty("nativewindow.debug.X11Util.TraceDisplayLifecycle", true, AccessController.getContext());
+
+ private static String nullDisplayName = null;
+ private static boolean isFirstX11ActionOnProcess = false;
+ private static boolean isInit = false;
+
+ private static int setX11ErrorHandlerRecCount = 0;
+ private static Object setX11ErrorHandlerLock = new Object();
+
+ public static synchronized void initSingleton(boolean firstX11ActionOnProcess) {
+ if(!isInit) {
+ NWJNILibLoader.loadNativeWindow("x11");
+
+ /**
+ * Always issue XInitThreads() since we have independent
+ * off-thread created Display connections able to utilize multithreading, ie NEWT */
+ initialize0( true );
+ // initialize0( firstX11ActionOnProcess );
+ isFirstX11ActionOnProcess = firstX11ActionOnProcess;
+
+ if(DEBUG) {
+ System.out.println("X11Util.isFirstX11ActionOnProcess: "+isFirstX11ActionOnProcess);
+ }
+ isInit = true;
+ }
+ }
+
+ public static void setX11ErrorHandler(boolean onoff, boolean quiet) {
+ synchronized(setX11ErrorHandlerLock) {
+ if(onoff) {
+ if(0==setX11ErrorHandlerRecCount) {
+ setX11ErrorHandler0(true, quiet);
+ }
+ setX11ErrorHandlerRecCount++;
+ } else {
+ if(0 >= setX11ErrorHandlerRecCount) {
+ throw new InternalError();
+ }
+ setX11ErrorHandlerRecCount--;
+ if(0==setX11ErrorHandlerRecCount) {
+ setX11ErrorHandler0(false, false);
+ }
+ }
+ }
+ }
+
+ public static boolean isFirstX11ActionOnProcess() {
+ return isFirstX11ActionOnProcess;
+ }
+
+ public static void lockDefaultToolkit(long dpyHandle) {
+ NativeWindowFactory.getDefaultToolkitLock().lock();
+ if(!isFirstX11ActionOnProcess) {
+ X11Util.XLockDisplay(dpyHandle);
+ }
+ }
+
+ public static void unlockDefaultToolkit(long dpyHandle) {
+ if(!isFirstX11ActionOnProcess) {
+ X11Util.XUnlockDisplay(dpyHandle);
+ }
+ NativeWindowFactory.getDefaultToolkitLock().unlock();
+ }
+
+ public static String getNullDisplayName() {
+ if(null==nullDisplayName) {
+ synchronized(X11Util.class) {
+ if(null==nullDisplayName) {
+ NativeWindowFactory.getDefaultToolkitLock().lock();
+ try {
+ long dpy = X11Lib.XOpenDisplay(null);
+ nullDisplayName = X11Lib.XDisplayString(dpy);
+ X11Lib.XCloseDisplay(dpy);
+ } finally {
+ NativeWindowFactory.getDefaultToolkitLock().unlock();
+ }
+ if(DEBUG) {
+ System.out.println("X11 Display(NULL) <"+nullDisplayName+">");
+ }
+ }
+ }
+ }
+ return nullDisplayName;
+ }
+
+ private X11Util() {}
+
+ // not exactly thread safe, but good enough for our purpose,
+ // which is to tag a NamedDisplay uncloseable after creation.
+ private static Object globalLock = new Object();
+ private static LongObjectHashMap globalNamedDisplayMap = new LongObjectHashMap();
+ private static List openDisplayList = new ArrayList();
+ private static List pendingDisplayList = new ArrayList();
+
+ public static class NamedDisplay {
+ String name;
+ long handle;
+ int refCount;
+ boolean unCloseable;
+ Throwable creationStack;
+
+ protected NamedDisplay(String name, long handle) {
+ this.name=name;
+ this.handle=handle;
+ this.refCount=1;
+ this.unCloseable=false;
+ if(DEBUG) {
+ this.creationStack=new Throwable("NamedDisplay Created at:");
+ } else {
+ this.creationStack=null;
+ }
+ }
+
+ public final String getName() { return name; }
+ public final long getHandle() { return handle; }
+ public final int getRefCount() { return refCount; }
+
+ public final void setUncloseable(boolean v) { unCloseable = v; }
+ public final boolean isUncloseable() { return unCloseable; }
+
+ public final Throwable getCreationStack() { return creationStack; }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public String toString() {
+ return "NamedX11Display["+name+", 0x"+Long.toHexString(handle)+", refCount "+refCount+", unCloseable "+unCloseable+"]";
+ }
+ }
+
+ /** Returns the number of unclosed X11 Displays.
+ * @param realXCloseAndPendingDisplays if true, {@link #closePendingDisplayConnections()} is called.
+ */
+ public static int shutdown(boolean realXCloseOpenAndPendingDisplays, boolean verbose) {
+ int num=0;
+ if(DEBUG||verbose||pendingDisplayList.size() > 0) {
+ String msg = "X11Util.Display: Shutdown (close open / pending Displays: "+realXCloseOpenAndPendingDisplays+
+ ", open (no close attempt): "+globalNamedDisplayMap.size()+"/"+openDisplayList.size()+
+ ", open (no close attempt and uncloseable): "+pendingDisplayList.size()+")" ;
+ if(DEBUG) {
+ Exception e = new Exception(msg);
+ e.printStackTrace();
+ } else {
+ System.err.println(msg);
+ }
+ if( openDisplayList.size() > 0) {
+ X11Util.dumpOpenDisplayConnections();
+ }
+ if( pendingDisplayList.size() > 0 ) {
+ X11Util.dumpPendingDisplayConnections();
+ }
+ }
+
+ synchronized(globalLock) {
+ if(realXCloseOpenAndPendingDisplays) {
+ closePendingDisplayConnections();
+ }
+ openDisplayList.clear();
+ pendingDisplayList.clear();
+ globalNamedDisplayMap.clear();
+ }
+ return num;
+ }
+
+ /**
+ * Closing pending Display connections in reverse order.
+ *
+ * @return number of closed Display connections
+ */
+ public static int closePendingDisplayConnections() {
+ int num=0;
+ synchronized(globalLock) {
+ if(DEBUG) {
+ System.err.println("X11Util: Closing Pending X11 Display Connections: "+pendingDisplayList.size());
+ }
+ for(int i=pendingDisplayList.size()-1; i>=0; i--) {
+ NamedDisplay ndpy = (NamedDisplay) pendingDisplayList.get(i);
+ if(DEBUG) {
+ System.err.println("X11Util.closePendingDisplayConnections(): Closing ["+i+"]: "+ndpy);
+ }
+ XCloseDisplay(ndpy.getHandle());
+ num++;
+ }
+ }
+ return num;
+ }
+
+ public static int getOpenDisplayConnectionNumber() {
+ synchronized(globalLock) {
+ return openDisplayList.size();
+ }
+ }
+
+ public static void dumpOpenDisplayConnections() {
+ synchronized(globalLock) {
+ System.err.println("X11Util: Open X11 Display Connections: "+openDisplayList.size());
+ for(int i=0; i<pendingDisplayList.size(); i++) {
+ NamedDisplay ndpy = (NamedDisplay) openDisplayList.get(i);
+ System.err.println("X11Util: ["+i+"]: "+ndpy);
+ if(null!=ndpy) {
+ Throwable t = ndpy.getCreationStack();
+ if(null!=t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ public static int getPendingDisplayConnectionNumber() {
+ synchronized(globalLock) {
+ return pendingDisplayList.size();
+ }
+ }
+
+ public static void dumpPendingDisplayConnections() {
+ synchronized(globalLock) {
+ System.err.println("X11Util: Pending X11 Display Connections: "+pendingDisplayList.size());
+ for(int i=0; i<pendingDisplayList.size(); i++) {
+ NamedDisplay ndpy = (NamedDisplay) pendingDisplayList.get(i);
+ System.err.println("X11Util: ["+i+"]: "+ndpy);
+ if(null!=ndpy) {
+ Throwable t = ndpy.getCreationStack();
+ if(null!=t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ public static boolean markDisplayUncloseable(long handle) {
+ NamedDisplay ndpy;
+ synchronized(globalLock) {
+ ndpy = (NamedDisplay) globalNamedDisplayMap.get(handle);
+ }
+ if( null != ndpy ) {
+ ndpy.setUncloseable(true);
+ return true;
+ }
+ return false;
+ }
+
+ /** Returns this created named display. */
+ public static long createDisplay(String name) {
+ name = validateDisplayName(name);
+ long dpy = XOpenDisplay(name);
+ if(0==dpy) {
+ throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection. Thread "+Thread.currentThread().getName());
+ }
+ // if you like to debug and synchronize X11 commands ..
+ // setSynchronizeDisplay(dpy, true);
+ NamedDisplay namedDpy = new NamedDisplay(name, dpy);
+ synchronized(globalLock) {
+ globalNamedDisplayMap.put(dpy, namedDpy);
+ openDisplayList.add(namedDpy);
+ pendingDisplayList.add(namedDpy);
+ }
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Created new "+namedDpy+". Thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ return namedDpy.getHandle();
+ }
+
+ public static void closeDisplay(long handle) {
+ NamedDisplay namedDpy;
+
+ synchronized(globalLock) {
+ namedDpy = (NamedDisplay) globalNamedDisplayMap.remove(handle);
+ if(namedDpy!=null) {
+ if(!openDisplayList.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); }
+ }
+ }
+ if(null==namedDpy) {
+ X11Util.dumpPendingDisplayConnections();
+ throw new RuntimeException("X11Util.Display: Display(0x"+Long.toHexString(handle)+") with given handle is not mapped. Thread "+Thread.currentThread().getName());
+ }
+ if(namedDpy.getHandle()!=handle) {
+ X11Util.dumpPendingDisplayConnections();
+ throw new RuntimeException("X11Util.Display: Display(0x"+Long.toHexString(handle)+") Mapping error: "+namedDpy+". Thread "+Thread.currentThread().getName());
+ }
+
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Closing new "+namedDpy+". Thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+
+ if(!namedDpy.isUncloseable()) {
+ synchronized(globalLock) {
+ if(!pendingDisplayList.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); }
+ }
+ XCloseDisplay(namedDpy.getHandle());
+ }
+ }
+
+ public static NamedDisplay getNamedDisplay(long handle) {
+ synchronized(globalLock) {
+ return (NamedDisplay) globalNamedDisplayMap.get(handle);
+ }
+ }
+
+ /**
+ * @return If name is null, it returns the previous queried NULL display name,
+ * otherwise the name. */
+ public static String validateDisplayName(String name) {
+ return ( null == name ) ? getNullDisplayName() : name ;
+ }
+
+ public static String validateDisplayName(String name, long handle) {
+ if(null==name && 0!=handle) {
+ name = XDisplayString(handle);
+ }
+ return validateDisplayName(name);
+ }
+
+ /*******************************
+ **
+ ** Locked X11Lib wrapped functions
+ **
+ *******************************/
+
+ public static long XOpenDisplay(String arg0) {
+ NativeWindowFactory.getDefaultToolkitLock().lock();
+ try {
+ long handle = X11Lib.XOpenDisplay(arg0);
+ if(TRACE_DISPLAY_LIFECYCLE) {
+ Throwable t = new Throwable(Thread.currentThread()+" - X11Util.XOpenDisplay("+arg0+") 0x"+Long.toHexString(handle));
+ t.printStackTrace();
+ }
+ return handle;
+ } finally {
+ NativeWindowFactory.getDefaultToolkitLock().unlock();
+ }
+ }
+
+ public static int XCloseDisplay(long display) {
+ NativeWindowFactory.getDefaultToolkitLock().lock();
+ try {
+ if(TRACE_DISPLAY_LIFECYCLE) {
+ Throwable t = new Throwable(Thread.currentThread()+" - X11Util.XCloseDisplay() 0x"+Long.toHexString(display));
+ t.printStackTrace();
+ }
+ return X11Lib.XCloseDisplay(display);
+ } finally {
+ NativeWindowFactory.getDefaultToolkitLock().unlock();
+ }
+ }
+
+ public static int XFree(Buffer arg0) {
+ NativeWindowFactory.getDefaultToolkitLock().lock();
+ try {
+ return X11Lib.XFree(arg0);
+ } finally {
+ NativeWindowFactory.getDefaultToolkitLock().unlock();
+ }
+ }
+
+ public static int XSync(long display, boolean discard) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XSync(display, discard);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static void XSynchronize(long display, boolean onoff) {
+ lockDefaultToolkit(display);
+ try {
+ X11Lib.XSynchronize(display, onoff);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XineramaEnabled(long display) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XineramaEnabled(display);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static int DefaultScreen(long display) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.DefaultScreen(display);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static long RootWindow(long display, int screen_number) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.RootWindow(display, screen_number);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static long XCreatePixmap(long display, long arg1, int arg2, int arg3, int arg4) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XCreatePixmap(display, arg1, arg2, arg3, arg4);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static String XDisplayString(long display) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XDisplayString(display);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static int XFlush(long display) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XFlush(display);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static int XFreePixmap(long display, long arg1) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XFreePixmap(display, arg1);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static long DefaultVisualID(long display, int screen) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.DefaultVisualID(display, screen);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static long CreateDummyWindow(long display, int screen_index, long visualID, int width, int height) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.CreateDummyWindow(display, screen_index, visualID, width, height);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static void DestroyDummyWindow(long display, long window) {
+ lockDefaultToolkit(display);
+ try {
+ X11Lib.DestroyDummyWindow(display, window);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static Point GetRelativeLocation(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.GetRelativeLocation(display, screen_index, src_win, dest_win, src_x, src_y);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static XVisualInfo[] XGetVisualInfo(long display, long arg1, XVisualInfo arg2, int[] arg3, int arg3_offset) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XGetVisualInfo(display, arg1, arg2, arg3, arg3_offset);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XF86VidModeGetGammaRamp(long display, int screen, int size, ShortBuffer red_array, ShortBuffer green_array, ShortBuffer blue_array) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XF86VidModeGetGammaRamp(display, screen, size, red_array, green_array, blue_array);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XF86VidModeGetGammaRamp(long display, int screen, int size, short[] red_array, int red_array_offset, short[] green_array, int green_array_offset, short[] blue_array, int blue_array_offset) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XF86VidModeGetGammaRamp(display, screen, size, red_array, red_array_offset, green_array, green_array_offset, blue_array, blue_array_offset);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XF86VidModeGetGammaRampSize(long display, int screen, IntBuffer size) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XF86VidModeGetGammaRampSize(display, screen, size);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XF86VidModeGetGammaRampSize(long display, int screen, int[] size, int size_offset) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XF86VidModeGetGammaRampSize(display, screen, size, size_offset);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XF86VidModeSetGammaRamp(long display, int screen, int size, ShortBuffer red_array, ShortBuffer green_array, ShortBuffer blue_array) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XF86VidModeSetGammaRamp(display, screen, size, red_array, green_array, blue_array);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static boolean XF86VidModeSetGammaRamp(long display, int screen, int size, short[] red_array, int red_array_offset, short[] green_array, int green_array_offset, short[] blue_array, int blue_array_offset) {
+ lockDefaultToolkit(display);
+ try {
+ return X11Lib.XF86VidModeSetGammaRamp(display, screen, size, red_array, red_array_offset, green_array, green_array_offset, blue_array, blue_array_offset);
+ } finally {
+ unlockDefaultToolkit(display);
+ }
+ }
+
+ public static void XLockDisplay(long handle) {
+ if(ToolkitLock.TRACE_LOCK) {
+ System.out.println("+++ X11 Display Lock get 0x"+Long.toHexString(handle));
+ }
+ X11Lib.XLockDisplay(handle);
+ }
+
+ public static void XUnlockDisplay(long handle) {
+ if(ToolkitLock.TRACE_LOCK) {
+ System.out.println("--- X11 Display Lock rel 0x"+Long.toHexString(handle));
+ }
+ X11Lib.XUnlockDisplay(handle);
+ }
+
+ private static native void initialize0(boolean firstUIActionOnProcess);
+ private static native void setX11ErrorHandler0(boolean onoff, boolean quiet);
+}