aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorJOGAMP DEV TEAM <[email protected]>2010-04-22 21:12:36 -0400
committerJOGAMP DEV TEAM <[email protected]>2010-04-22 21:12:36 -0400
commit1d889ddc4728d1534e310b44fad74a2932d22d39 (patch)
tree4ad0c3eeb3ef728522ac9459eb12c667301a0c32 /src/nativewindow
parent8790075f074013aa3c71b96993838cf1117275f1 (diff)
parenta588326d206ff32e5ff5db97560851cb9b826022 (diff)
Merge branch 'master' of github.com:sgothel/jogl
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java)2
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java)2
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java)4
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java)2
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java50
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java)13
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java)2
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTJNILibLoader.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java)6
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java)10
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java)6
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java)4
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java)6
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java)6
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java)8
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java)4
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java)10
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java334
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java (renamed from src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java)10
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java181
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java202
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jvm/JVMUtil.java72
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java166
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java5
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java15
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/package.html2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java37
-rw-r--r--src/nativewindow/native/JAWT_DrawingSurfaceInfo.c2
-rw-r--r--src/nativewindow/native/JVM_Tool.c51
-rw-r--r--src/nativewindow/native/x11/Xmisc.c493
33 files changed, 965 insertions, 748 deletions
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java
index dd967c71a..edb682392 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/Debug.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/Debug.java
@@ -37,7 +37,7 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.nativewindow.impl;
+package com.jogamp.nativewindow.impl;
import java.security.*;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
index 4e8e281a8..22f2d544f 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
@@ -30,7 +30,7 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package com.sun.nativewindow.impl;
+package com.jogamp.nativewindow.impl;
import javax.media.nativewindow.*;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java
index 0425014df..f590e9b8b 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/InternalBufferUtil.java
@@ -31,13 +31,13 @@
*
*/
-package com.sun.nativewindow.impl;
+package com.jogamp.nativewindow.impl;
import java.lang.reflect.*;
import java.nio.*;
/** Internal copy of selected routines from BufferUtil to avoid
- outward dependencies on com.sun.opengl.util package. */
+ outward dependencies on com.jogamp.opengl.util package. */
public class InternalBufferUtil {
public static final int SIZEOF_BYTE = 1;
public static final int SIZEOF_SHORT = 2;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java
index 880fd8c7d..fd2478ab2 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/LockingNativeWindowFactory.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/LockingNativeWindowFactory.java
@@ -30,7 +30,7 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package com.sun.nativewindow.impl;
+package com.jogamp.nativewindow.impl;
import javax.media.nativewindow.*;
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java
new file mode 100644
index 000000000..c3c04287a
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NWJNILibLoader.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010, Sven Gothel
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Sven Gothel nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 Sven Gothel 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.
+ */
+
+package com.jogamp.nativewindow.impl;
+
+// FIXME: refactor Java SE dependencies
+//import java.awt.Toolkit;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashSet;
+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/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java
index c94dab2f6..d2429cdab 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java
@@ -30,8 +30,9 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package com.sun.nativewindow.impl;
+package com.jogamp.nativewindow.impl;
+import com.jogamp.common.util.*;
import java.lang.reflect.*;
import java.security.*;
@@ -55,7 +56,7 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory {
throw new IllegalArgumentException("AbstractGraphicsConfiguration is null with a non NativeWindow object");
}
- if (NWReflection.isAWTComponent(winObj)) {
+ if (ReflectionUtil.instanceOf(winObj, "java.awt.Component")) {
return getAWTNativeWindow(winObj, config);
}
@@ -76,17 +77,17 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory {
// make it easier to run this code on mobile devices
if (osType.equals(TYPE_WINDOWS)) {
- windowClassName = "com.sun.nativewindow.impl.jawt.windows.WindowsJAWTWindow";
+ windowClassName = "com.jogamp.nativewindow.impl.jawt.windows.WindowsJAWTWindow";
} else if (osType.equals(TYPE_MACOSX)) {
- windowClassName = "com.sun.nativewindow.impl.jawt.macosx.MacOSXJAWTWindow";
+ 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.sun.nativewindow.impl.jawt.x11.X11JAWTWindow";
+ windowClassName = "com.jogamp.nativewindow.impl.jawt.x11.X11JAWTWindow";
} else {
throw new IllegalArgumentException("OS " + getNativeOSName(false) + " not yet supported");
}
- nativeWindowConstructor = NWReflection.getConstructor(windowClassName, new Class[] { Object.class, AbstractGraphicsConfiguration.class });
+ nativeWindowConstructor = ReflectionUtil.getConstructor(windowClassName, new Class[] { Object.class, AbstractGraphicsConfiguration.class });
} catch (Exception e) {
throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);
}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java
index ca55aa542..4458d7b3d 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java
@@ -34,7 +34,7 @@
* facility.
*/
-package com.sun.nativewindow.impl;
+package com.jogamp.nativewindow.impl;
import javax.media.nativewindow.*;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTJNILibLoader.java
index bc963277a..4ea404c09 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTNativeLibLoader.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTJNILibLoader.java
@@ -37,10 +37,10 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.nativewindow.impl.jawt;
+package com.jogamp.nativewindow.impl.jawt;
import javax.media.nativewindow.NativeWindowFactory;
-import com.sun.nativewindow.impl.NativeLibLoaderBase;
+import com.jogamp.nativewindow.impl.NWJNILibLoader;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;
@@ -48,7 +48,7 @@ import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
-public class JAWTNativeLibLoader extends NativeLibLoaderBase {
+public class JAWTJNILibLoader extends NWJNILibLoader {
public static void loadAWTImpl() {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
index aac01e990..b3c706ed8 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
@@ -34,9 +34,9 @@
* facility.
*/
-package com.sun.nativewindow.impl.jawt;
+package com.jogamp.nativewindow.impl.jawt;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
import javax.media.nativewindow.*;
@@ -54,8 +54,8 @@ public class JAWTUtil {
private static final boolean j2dExist;
static {
- JAWTNativeLibLoader.loadAWTImpl();
- JAWTNativeLibLoader.loadNativeWindow("awt");
+ JAWTJNILibLoader.loadAWTImpl();
+ JAWTJNILibLoader.loadNativeWindow("awt");
lockedStack = null;
headlessMode = GraphicsEnvironment.isHeadless();
@@ -65,7 +65,7 @@ public class JAWTUtil {
Method m=null;
if(!headlessMode) {
try {
- jC = Class.forName("com.sun.opengl.impl.awt.Java2D");
+ jC = Class.forName("com.jogamp.opengl.impl.awt.Java2D");
m = jC.getMethod("isQueueFlusherThread", null);
ok = true;
} catch (Exception e) {}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java
index b0548bb14..d0529878f 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java
@@ -34,15 +34,15 @@
* facility.
*/
-package com.sun.nativewindow.impl.jawt;
+package com.jogamp.nativewindow.impl.jawt;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
import java.awt.Component;
import java.awt.Window;
import java.awt.GraphicsEnvironment;
import javax.media.nativewindow.*;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
public abstract class JAWTWindow implements NativeWindow {
protected static final boolean DEBUG = Debug.debug("JAWT");
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java
index cc6af7ea4..d49e2f8d0 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWT_PlatformInfo.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWT_PlatformInfo.java
@@ -37,9 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.nativewindow.impl.jawt;
+package com.jogamp.nativewindow.impl.jawt;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
/** Marker class for all window system-specific JAWT data structures. */
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
index 4ecc6aa4d..967d43d60 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
@@ -37,10 +37,10 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.nativewindow.impl.jawt.macosx;
+package com.jogamp.nativewindow.impl.jawt.macosx;
-import com.sun.nativewindow.impl.jawt.*;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.jawt.*;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
index 2b8cab9c4..b23ad3f50 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
@@ -37,10 +37,10 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.nativewindow.impl.jawt.windows;
+package com.jogamp.nativewindow.impl.jawt.windows;
-import com.sun.nativewindow.impl.*;
-import com.sun.nativewindow.impl.jawt.*;
+import com.jogamp.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.jawt.*;
import javax.media.nativewindow.*;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java
index af2b7a71c..f2977e8f0 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java
@@ -34,14 +34,14 @@
* facility.
*/
-package com.sun.nativewindow.impl.jawt.x11;
+package com.jogamp.nativewindow.impl.jawt.x11;
import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
-import com.sun.nativewindow.impl.x11.*;
-import com.sun.nativewindow.impl.jawt.*;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.x11.*;
+import com.jogamp.nativewindow.impl.jawt.*;
+import com.jogamp.nativewindow.impl.*;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
index ef1f82cee..7cca6f9f3 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
@@ -37,9 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.nativewindow.impl.jawt.x11;
+package com.jogamp.nativewindow.impl.jawt.x11;
-import com.sun.nativewindow.impl.x11.*;
+import com.jogamp.nativewindow.impl.x11.*;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
index 4709e3ef0..a6f52f3c0 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
@@ -30,12 +30,12 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package com.sun.nativewindow.impl.x11;
+package com.jogamp.nativewindow.impl.x11;
import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
-import com.sun.nativewindow.impl.x11.XVisualInfo;
-import com.sun.nativewindow.impl.x11.X11Lib;
+import com.jogamp.nativewindow.impl.x11.XVisualInfo;
+import com.jogamp.nativewindow.impl.x11.X11Lib;
public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory {
public AbstractGraphicsConfiguration
@@ -58,8 +58,8 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor
int num[] = { -1 };
long display = screen.getDevice().getHandle();
+ X11Lib.XLockDisplay(display);
try {
- X11Lib.XLockDisplay(display);
XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0);
if(xvis==null || num[0]<1) {
@@ -90,8 +90,8 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor
vinfo_template.setC_class(c_class);
long display = screen.getDevice().getHandle();
+ X11Lib.XLockDisplay(display);
try {
- X11Lib.XLockDisplay(display);
XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, vinfo_template, num, 0);
XVisualInfo best=null;
int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits();
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
new file mode 100644
index 000000000..5f5c10885
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
@@ -0,0 +1,334 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package com.jogamp.nativewindow.impl.x11;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.media.nativewindow.*;
+
+import com.jogamp.nativewindow.impl.*;
+
+/**
+ * Contains a thread safe X11 utility to retrieve thread local display connection,<br>
+ * as well as the static global display connection.<br>
+ *
+ * The TLS variant is thread safe per se, but be aware of the memory leak risk
+ * where an application heavily utilizing this class on temporary new threads.<br>
+ */
+public class X11Util {
+ private static final boolean DEBUG = Debug.debug("X11Util");
+
+ static {
+ NWJNILibLoader.loadNativeWindow("x11");
+ installIOErrorHandler();
+ }
+
+ private X11Util() {}
+
+ private static ThreadLocal currentDisplayMap = new ThreadLocal();
+
+ // 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 Collection globalNamedDisplayActive = new ArrayList();
+ private static Collection globalNamedDisplayPassive = new ArrayList();
+
+ public static final String nullDeviceName = "nil" ;
+
+ public static class NamedDisplay implements Cloneable {
+ String name;
+ long handle;
+ int refCount;
+ boolean unCloseable;
+
+ protected NamedDisplay(String name, long handle) {
+ this.name=name;
+ this.handle=handle;
+ this.refCount=1;
+ this.unCloseable=false;
+ }
+
+ public final String getName() { return name; }
+ public final String getNameSafe() { return null == name ? nullDeviceName : name; }
+ public final long getHandle() { return handle; }
+ public final int getRefCount() { return refCount; }
+ public final boolean isUncloseable() { return unCloseable; }
+
+ 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 realXClosePendingDisplays if true, call XCloseDisplay on the remaining ones
+ */
+ public static int shutdown(boolean realXClosePendingDisplays, boolean verbose) {
+ int num=0;
+ String msg;
+ if(DEBUG||verbose) {
+ msg = "X11Util.Display: Shutdown (active: "+globalNamedDisplayActive.size()+
+ ", passive: "+globalNamedDisplayPassive.size() + ")";
+ if(DEBUG) {
+ Exception e = new Exception(msg);
+ e.printStackTrace();
+ } else if(verbose) {
+ System.err.println(msg);
+ }
+ }
+
+ msg = realXClosePendingDisplays ? "Close" : "Keep" ;
+
+ synchronized(globalLock) {
+ // for all passive displays ..
+ Collection namedDisplays = globalNamedDisplayPassive;
+ globalNamedDisplayPassive = new ArrayList();
+ for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) {
+ NamedDisplay ndpy = (NamedDisplay)iter.next();
+ if(DEBUG||verbose) {
+ System.err.println(msg+" passive: "+ndpy);
+ }
+ if(realXClosePendingDisplays) {
+ X11Lib.XCloseDisplay(ndpy.getHandle());
+ }
+ num++;
+ }
+
+ // for all active displays ..
+ namedDisplays = globalNamedDisplayActive;
+ globalNamedDisplayActive = new ArrayList();
+ for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) {
+ NamedDisplay ndpy = (NamedDisplay)iter.next();
+ if(DEBUG||verbose) {
+ System.err.println(msg+" active: "+ndpy);
+ }
+ if(realXClosePendingDisplays) {
+ X11Lib.XCloseDisplay(ndpy.getHandle());
+ }
+ num++;
+ }
+ }
+ return num;
+ }
+
+ /** Returns a clone of the thread local display map, you may {@link Object#wait()} on it */
+ public static Map getCurrentDisplayMap() {
+ return (Map) ((HashMap)getCurrentDisplayMapImpl()).clone();
+ }
+
+ /** Returns this thread current default display. If it doesn not exist, it is being created, otherwise the reference count is increased */
+ public static long createThreadLocalDefaultDisplay() {
+ return createThreadLocalDisplay(null);
+ }
+
+ /** Returns this thread named display. If it doesn not exist, it is being created, otherwise the reference count is increased */
+ public static long createThreadLocalDisplay(String name) {
+ NamedDisplay namedDpy = getCurrentDisplay(name);
+ if(null==namedDpy) {
+ synchronized(globalLock) {
+ namedDpy = getNamedDisplay(globalNamedDisplayPassive, name);
+ if(null != namedDpy) {
+ if(!globalNamedDisplayPassive.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); }
+ globalNamedDisplayActive.add(namedDpy);
+ addCurrentDisplay( namedDpy );
+ }
+ }
+ }
+ if(null==namedDpy) {
+ long dpy = X11Lib.XOpenDisplay(name);
+ if(0==dpy) {
+ throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection in Thread "+Thread.currentThread().getName());
+ }
+ namedDpy = new NamedDisplay(name, dpy);
+ synchronized(globalLock) {
+ globalNamedDisplayActive.add(namedDpy);
+ addCurrentDisplay( namedDpy );
+ }
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Created new TLS "+namedDpy+" in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ } else {
+ namedDpy.refCount++;
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Reused TLS "+namedDpy+" in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ }
+ return namedDpy.getHandle();
+ }
+
+ /** Decrease the reference count of this thread named display. If it reaches 0, close it.
+ It returns the handle of the to be closed display.
+ It throws a RuntimeException in case the named display does not exist,
+ or the reference count goes below 0.
+ */
+ public static long closeThreadLocalDisplay(String name) {
+ NamedDisplay namedDpy = getCurrentDisplay(name);
+ if(null==namedDpy) {
+ throw new RuntimeException("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName());
+ }
+ if(0==namedDpy.refCount) {
+ throw new RuntimeException("X11Util.Display: "+namedDpy+" has refCount already 0 in thread "+Thread.currentThread().getName());
+ }
+ long dpy = namedDpy.getHandle();
+ namedDpy.refCount--;
+ if(0==namedDpy.refCount) {
+ synchronized(globalLock) {
+ if(!globalNamedDisplayActive.remove(namedDpy)) { throw new RuntimeException("Internal: "+namedDpy); }
+ if(namedDpy.isUncloseable()) {
+ globalNamedDisplayPassive.add(namedDpy);
+ } else {
+ X11Lib.XCloseDisplay(dpy);
+ }
+ removeCurrentDisplay(namedDpy);
+ }
+ if(DEBUG) {
+ String type = namedDpy.isUncloseable() ? "passive" : "real" ;
+ Exception e = new Exception("X11Util.Display: Closing ( "+type+" ) TLS "+namedDpy+" in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ } else if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Keep TLS "+namedDpy+" in thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ return dpy;
+ }
+
+ public static String getThreadLocalDisplayName(long handle) {
+ NamedDisplay ndpy = getNamedDisplay(getCurrentDisplayMapImpl().values(), handle);
+ return null != ndpy ? ndpy.getName() : null;
+ }
+
+ public static boolean markThreadLocalDisplayUndeletable(long handle) {
+ NamedDisplay ndpy = getNamedDisplay(getCurrentDisplayMapImpl().values(), handle);
+ if( null != ndpy ) {
+ ndpy.unCloseable=true;
+ return true;
+ }
+ return false;
+ }
+
+ public static String getGlobalDisplayName(long handle, boolean active) {
+ String name;
+ synchronized(globalLock) {
+ NamedDisplay ndpy = getNamedDisplay(active ? globalNamedDisplayActive : globalNamedDisplayPassive, handle);
+ name = null != ndpy ? ndpy.getName() : null;
+ }
+ return name;
+ }
+
+ public static boolean markGlobalDisplayUndeletable(long handle) {
+ boolean r=false;
+ synchronized(globalLock) {
+ NamedDisplay ndpy = getNamedDisplay(globalNamedDisplayActive, handle);
+ if( null != ndpy ) {
+ ndpy.unCloseable=true;
+ r=true;
+ }
+ }
+ return r;
+ }
+
+ private static Map getCurrentDisplayMapImpl() {
+ Map displayMap = (Map) currentDisplayMap.get();
+ if(null==displayMap) {
+ displayMap = new HashMap();
+ currentDisplayMap.set( displayMap );
+ }
+ return displayMap;
+ }
+
+ /** maps the given display to the thread local display map
+ * and notifies all threads synchronized to this display map. */
+ private static NamedDisplay addCurrentDisplay(NamedDisplay newDisplay) {
+ Map displayMap = getCurrentDisplayMapImpl();
+ NamedDisplay oldDisplay = null;
+ synchronized(displayMap) {
+ oldDisplay = (NamedDisplay) displayMap.put(newDisplay.getNameSafe(), newDisplay);
+ displayMap.notifyAll();
+ }
+ return oldDisplay;
+ }
+
+ /** removes the mapping of the given name from the thread local display map
+ * and notifies all threads synchronized to this display map. */
+ private static NamedDisplay removeCurrentDisplay(NamedDisplay ndpy) {
+ Map displayMap = getCurrentDisplayMapImpl();
+ synchronized(displayMap) {
+ NamedDisplay ndpyDel = (NamedDisplay) displayMap.remove(ndpy.getNameSafe());
+ if(ndpyDel!=ndpy) {
+ throw new RuntimeException("Wrong mapping req: "+ndpy+", got "+ndpyDel);
+ }
+ displayMap.notifyAll();
+ }
+ return ndpy;
+ }
+
+ /** Returns the thread local display mapped to the given name */
+ private static NamedDisplay getCurrentDisplay(String name) {
+ if(null==name) name=nullDeviceName;
+ Map displayMap = getCurrentDisplayMapImpl();
+ return (NamedDisplay) displayMap.get(name);
+ }
+
+ private static NamedDisplay getNamedDisplay(Collection namedDisplays, String name) {
+ if(null==name) name=nullDeviceName;
+ for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) {
+ NamedDisplay ndpy = (NamedDisplay)iter.next();
+ if (ndpy.getNameSafe().equals(name)) {
+ return ndpy;
+ }
+ }
+ return null;
+ }
+
+ private static NamedDisplay getNamedDisplay(Collection namedDisplays, long handle) {
+ for(Iterator iter=namedDisplays.iterator(); iter.hasNext(); ) {
+ NamedDisplay ndpy = (NamedDisplay)iter.next();
+ if (ndpy.getHandle()==handle) {
+ return ndpy;
+ }
+ }
+ return null;
+ }
+
+ private static native void installIOErrorHandler();
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java
index dff733735..616220e14 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/awt/X11AWTNativeWindowFactory.java
@@ -30,17 +30,17 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package com.sun.nativewindow.impl.x11.awt;
+package com.jogamp.nativewindow.impl.x11.awt;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.media.nativewindow.*;
-import com.sun.nativewindow.impl.*;
-import com.sun.nativewindow.impl.jawt.*;
-import com.sun.nativewindow.impl.jawt.x11.*;
-import com.sun.nativewindow.impl.x11.*;
+import com.jogamp.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.jawt.*;
+import com.jogamp.nativewindow.impl.jawt.x11.*;
+import com.jogamp.nativewindow.impl.x11.*;
public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl {
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java
deleted file mode 100644
index d86fbdc55..000000000
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- */
-
-package com.sun.nativewindow.impl;
-
-import java.lang.reflect.*;
-import javax.media.nativewindow.*;
-
-public final class NWReflection {
- public static final boolean DEBUG = Debug.debug("NWReflection");
-
- public static final boolean isClassAvailable(String clazzName) {
- try {
- Class clazz = Class.forName(clazzName, false, NWReflection.class.getClassLoader());
- return null!=clazz;
- } catch (Throwable e) { }
- return false;
- }
-
- public static final Class getClass(String clazzName, boolean initialize) {
- try {
- return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader());
- } catch (Throwable e) { }
- return null;
- }
-
- public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) {
- Class factoryClass = null;
- Constructor factory = null;
-
- try {
- factoryClass = getClass(clazzName, true);
- if (factoryClass == null) {
- throw new NativeWindowException(clazzName + " not available");
- }
- return getConstructor(factoryClass, cstrArgTypes);
- } catch (Throwable e) {
- if (DEBUG) {
- e.printStackTrace();
- }
- throw new NativeWindowException(e);
- }
- }
-
- public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) {
- Constructor factory = null;
-
- try {
- try {
- factory = clazz.getDeclaredConstructor( cstrArgTypes );
- } catch(NoSuchMethodException nsme) {
- throw new NativeWindowException("Constructor: '" + clazz + "("+cstrArgTypes+")' not found");
- }
- return factory;
- } catch (Throwable e) {
- if (DEBUG) {
- e.printStackTrace();
- }
- throw new NativeWindowException(e);
- }
- }
-
- public static final Constructor getConstructor(String clazzName) {
- return getConstructor(clazzName, new Class[0]);
- }
-
- public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) {
- Constructor factory = null;
-
- try {
- factory = getConstructor(clazz, cstrArgTypes);
- return factory.newInstance( cstrArgs ) ;
- } catch (Exception e) {
- throw new NativeWindowException(e);
- }
- }
-
- public static final Object createInstance(Class clazz, Object[] cstrArgs) {
- Class[] cstrArgTypes = new Class[cstrArgs.length];
- for(int i=0; i<cstrArgs.length; i++) {
- cstrArgTypes[i] = cstrArgs[i].getClass();
- }
- return createInstance(clazz, cstrArgTypes, cstrArgs);
- }
-
- public static final Object createInstance(String clazzName, Class[] cstrArgTypes, Object[] cstrArgs) {
- Constructor factory = null;
-
- try {
- factory = getConstructor(clazzName, cstrArgTypes);
- return factory.newInstance( cstrArgs ) ;
- } catch (Exception e) {
- throw new NativeWindowException(e);
- }
- }
-
- public static final Object createInstance(String clazzName, Object[] cstrArgs) {
- Class[] cstrArgTypes = new Class[cstrArgs.length];
- for(int i=0; i<cstrArgs.length; i++) {
- cstrArgTypes[i] = cstrArgs[i].getClass();
- }
- return createInstance(clazzName, cstrArgTypes, cstrArgs);
- }
-
- public static final Object createInstance(String clazzName) {
- return createInstance(clazzName, new Class[0], null);
- }
-
- public static final boolean instanceOf(Object obj, String clazzName) {
- return instanceOf(obj.getClass(), clazzName);
- }
- public static final boolean instanceOf(Class clazz, String clazzName) {
- do {
- if(clazz.getName().equals(clazzName)) {
- return true;
- }
- clazz = clazz.getSuperclass();
- } while (clazz!=null);
- return false;
- }
-
- public static final boolean implementationOf(Object obj, String faceName) {
- return implementationOf(obj.getClass(), faceName);
- }
- public static final boolean implementationOf(Class clazz, String faceName) {
- do {
- Class[] clazzes = clazz.getInterfaces();
- for(int i=clazzes.length-1; i>=0; i--) {
- Class face = clazzes[i];
- if(face.getName().equals(faceName)) {
- return true;
- }
- }
- clazz = clazz.getSuperclass();
- } while (clazz!=null);
- return false;
- }
-
- public static boolean isAWTComponent(Object target) {
- return instanceOf(target, "java.awt.Component");
- }
-
- public static boolean isAWTComponent(Class clazz) {
- return instanceOf(clazz, "java.awt.Component");
- }
-
-}
-
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
deleted file mode 100644
index 570cf1f9d..000000000
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- *
- * Sun gratefully acknowledges that this software was originally authored
- * and developed by Kenneth Bradley Russell and Christopher John Kline.
- */
-
-package com.sun.nativewindow.impl;
-
-// FIXME: refactor Java SE dependencies
-//import java.awt.Toolkit;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.HashSet;
-
-public class NativeLibLoaderBase {
- public static final boolean DEBUG = Debug.debug("NativeLibLoader");
-
- public interface LoaderAction {
- /**
- * Loads the library specified by libname. Optionally preloads the libraries specified by
- * preload. The implementation should ignore, if the preload-libraries have already been
- * loaded.
- * @param libname the library to load
- * @param preload the libraries to load before loading the main library if not null
- * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored
- */
- void loadLibrary(String libname, String[] preload,
- boolean preloadIgnoreError);
- }
-
- private static class DefaultAction implements LoaderAction {
- public void loadLibrary(String libname, String[] preload,
- boolean preloadIgnoreError) {
- if (null!=preload) {
- for (int i=0; i<preload.length; i++) {
- if(!isLoaded(preload[i])) {
- try {
- loadLibraryInternal(preload[i]);
- addLoaded(preload[i]);
- if(DEBUG) {
- System.err.println("NativeLibLoaderBase preloaded "+preload[i]);
- }
- }
- catch (UnsatisfiedLinkError e) {
- if(DEBUG) e.printStackTrace();
- if (!preloadIgnoreError && e.getMessage().indexOf("already loaded") < 0) {
- throw e;
- }
- }
- }
- }
- }
- loadLibraryInternal(libname);
- addLoaded(libname);
- if(DEBUG) {
- System.err.println("NativeLibLoaderBase loaded "+libname);
- }
- }
- }
-
- private static final HashSet loaded = new HashSet();
- private static LoaderAction loaderAction = new DefaultAction();
-
- public static boolean isLoaded(String libName) {
- return loaded.contains(libName);
- }
-
- public static void addLoaded(String libName) {
- loaded.add(libName);
- if(DEBUG) {
- System.err.println("NativeLibLoaderBase Loaded Native Library: "+libName);
- }
- }
-
- public static void disableLoading() {
- setLoadingAction(null);
- }
-
- public static void enableLoading() {
- setLoadingAction(new DefaultAction());
- }
-
- public static synchronized void setLoadingAction(LoaderAction action) {
- loaderAction = action;
- }
-
- protected static synchronized void loadLibrary(String libname, String[] preload,
- boolean preloadIgnoreError) {
- if (loaderAction != null && !isLoaded(libname))
- {
- loaderAction.loadLibrary(libname, preload, preloadIgnoreError);
- }
- }
-
- public static void loadNativeWindow(final String ossuffix) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- loadLibrary("nativewindow_"+ossuffix, null, false);
- return null;
- }
- });
- }
-
-
- private static final Class customLauncherClass;
- private static final Method customLoadLibraryMethod;
-
- static {
- Class launcherClass = null;
- Method loadLibraryMethod = null;
-
- if ( Debug.getBooleanProperty("sun.jnlp.applet.launcher", false) ) {
- try {
- launcherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher");
- loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
- } catch (Throwable t) {
- if(DEBUG) {
- t.printStackTrace();
- }
- launcherClass = null;
- loadLibraryMethod = null;
- }
- }
-
- if(null==launcherClass) {
- String launcherClassName = Debug.getProperty("jnlp.launcher.class", false);
- if(null!=launcherClassName) {
- try {
- launcherClass = Class.forName(launcherClassName);
- loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class });
- } catch (Throwable t) {
- if(DEBUG) {
- t.printStackTrace();
- }
- launcherClass = null;
- loadLibraryMethod = null;
- }
- }
- }
- customLauncherClass = launcherClass;
- customLoadLibraryMethod = loadLibraryMethod;
- }
-
- private static void loadLibraryInternal(String libraryName) {
- // Note: special-casing JAWT which is built in to the JDK
- if (null!=customLoadLibraryMethod && !libraryName.equals("jawt")) {
- try {
- customLoadLibraryMethod.invoke(null, new Object[] { libraryName });
- } catch (Exception e) {
- Throwable t = e;
- if (t instanceof InvocationTargetException) {
- t = ((InvocationTargetException) t).getTargetException();
- }
- if (t instanceof Error)
- throw (Error) t;
- if (t instanceof RuntimeException) {
- throw (RuntimeException) t;
- }
- // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary()
- throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e);
- }
- } else {
- // System.out.println("sun.boot.library.path=" + Debug.getProperty("sun.boot.library.path", false));
- System.loadLibrary(libraryName);
- }
- }
-}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jvm/JVMUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jvm/JVMUtil.java
deleted file mode 100644
index 3faab68bb..000000000
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jvm/JVMUtil.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-package com.sun.nativewindow.impl.jvm;
-
-import java.nio.ByteBuffer;
-import com.sun.nativewindow.impl.*;
-
-/**
- * Currently this tool works around the Hotspot race condition bugs:
- <PRE>
- 4395095 JNI access to java.nio DirectBuffer constructor/accessor
- 6852404 Race condition in JNI Direct Buffer access and creation routines
- </PRE>
- *
- * Make sure to initialize this class as soon as possible,
- * before doing any multithreading work.
- *
- */
-public class JVMUtil {
- private static final boolean DEBUG = Debug.debug("JVMUtil");
-
- static {
- NativeLibLoaderBase.loadNativeWindow("jvm");
-
- ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64);
- if( ! initialize(buffer) ) {
- throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName());
- }
- if(DEBUG) {
- Exception e = new Exception("JVMUtil.initSingleton() .. initialized "+Thread.currentThread().getName());
- e.printStackTrace();
- }
- }
-
- public static void initSingleton() {
- }
-
- private JVMUtil() {}
-
- private static native boolean initialize(java.nio.ByteBuffer buffer);
-}
-
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
deleted file mode 100644
index 11343f3e1..000000000
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-package com.sun.nativewindow.impl.x11;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.media.nativewindow.*;
-
-import com.sun.nativewindow.impl.*;
-
-/**
- * Contains a thread safe X11 utility to retrieve thread local display connection,<br>
- * as well as the static global discplay connection.<br>
- *
- * The TLS variant is thread safe per se, but be aware of the memory leak risk
- * where an application heavily utilizing this class on temporary new threads.<br>
- */
-public class X11Util {
- private static final boolean DEBUG = Debug.debug("X11Util");
-
- static {
- NativeLibLoaderBase.loadNativeWindow("x11");
- }
-
- private X11Util() {}
-
- private static ThreadLocal currentDisplayMap = new ThreadLocal();
-
- public static class NamedDisplay implements Cloneable {
- private String name;
- private long handle;
-
- protected NamedDisplay(String name, long handle) {
- this.name=name;
- this.handle=handle;
- }
-
- public String getName() { return name; }
- public long getHandle() { return handle; }
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- /** Returns a clone of the thread local display map, you may {@link Object#wait()} on it */
- public static Map getCurrentDisplayMap() {
- return (Map) ((HashMap)getCurrentDisplayMapImpl()).clone();
- }
-
- /** Returns this thread current default display. If it doesn not exist, it is being created */
- public static long getThreadLocalDefaultDisplay() {
- return getThreadLocalDisplay(null);
- }
-
- /** Returns this thread named display. If it doesn not exist, it is being created */
- public static long getThreadLocalDisplay(String name) {
- NamedDisplay namedDpy = getCurrentDisplay(name);
- if(null==namedDpy) {
- long dpy = X11Lib.XOpenDisplay(name);
- if(0==dpy) {
- throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection in Thread "+Thread.currentThread().getName());
- }
- namedDpy = new NamedDisplay(name, dpy);
- setCurrentDisplay( namedDpy );
- if(DEBUG) {
- Exception e = new Exception("X11Util.Display: Created new TLS display("+name+") connection 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName());
- e.printStackTrace();
- }
- }
- return namedDpy.getHandle();
- }
-
- /** Closes this thread named display. It returns the handle of the closed display or 0, if it does not exist. */
- public static long closeThreadLocalDisplay(String name) {
- NamedDisplay namedDpy = removeCurrentDisplay(name);
- if(null==namedDpy) {
- if(DEBUG) {
- Exception e = new Exception("X11Util.Display: Display("+name+") with given handle is not mapped to TLS in thread "+Thread.currentThread().getName());
- e.printStackTrace();
- }
- return 0;
- }
- long dpy = namedDpy.getHandle();
- X11Lib.XCloseDisplay(dpy);
- if(DEBUG) {
- Exception e = new Exception("X11Util.Display: Closed TLS Display("+name+") with handle 0x"+Long.toHexString(dpy)+" in thread "+Thread.currentThread().getName());
- e.printStackTrace();
- }
- return dpy;
- }
-
- private static Map getCurrentDisplayMapImpl() {
- Map displayMap = (Map) currentDisplayMap.get();
- if(null==displayMap) {
- displayMap = new HashMap();
- currentDisplayMap.set( displayMap );
- }
- return displayMap;
- }
-
- /** maps the given display to the thread local display map
- * and notifies all threads synchronized to this display map. */
- private static NamedDisplay setCurrentDisplay(NamedDisplay newDisplay) {
- Map displayMap = getCurrentDisplayMapImpl();
- NamedDisplay oldDisplay = null;
- synchronized(displayMap) {
- String name = (null==newDisplay.getName())?"nil":newDisplay.getName();
- oldDisplay = (NamedDisplay) displayMap.put(name, newDisplay);
- displayMap.notifyAll();
- }
- return oldDisplay;
- }
-
- /** removes the mapping of the given name from the thread local display map
- * and notifies all threads synchronized to this display map. */
- private static NamedDisplay removeCurrentDisplay(String name) {
- Map displayMap = getCurrentDisplayMapImpl();
- NamedDisplay oldDisplay = null;
- synchronized(displayMap) {
- if(null==name) name="nil";
- oldDisplay = (NamedDisplay) displayMap.remove(name);
- displayMap.notifyAll();
- }
- return oldDisplay;
- }
-
- /** Returns the thread local display mapped to the given name */
- private static NamedDisplay getCurrentDisplay(String name) {
- if(null==name) name="nil";
- Map displayMap = getCurrentDisplayMapImpl();
- return (NamedDisplay) displayMap.get(name);
- }
-
-}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
index 881499bec..c692e51c4 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
@@ -35,7 +35,8 @@ package javax.media.nativewindow;
import java.lang.reflect.*;
import java.util.*;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.common.util.*;
+import com.jogamp.nativewindow.impl.*;
/**
* Provides the mechanism by which the graphics configuration for a
@@ -77,7 +78,7 @@ public abstract class GraphicsConfigurationFactory {
if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) {
try {
GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory)
- NWReflection.createInstance("com.sun.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {});
+ ReflectionUtil.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", new Object[] {});
registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory);
} catch (Exception e) {
throw new RuntimeException(e);
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index cd89e2164..944fdee74 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -36,8 +36,9 @@ import java.lang.reflect.*;
import java.security.*;
import java.util.*;
-import com.sun.nativewindow.impl.*;
-import com.sun.nativewindow.impl.jvm.JVMUtil;
+import com.jogamp.common.util.*;
+import com.jogamp.common.jvm.JVMUtil;
+import com.jogamp.nativewindow.impl.*;
/** Provides a pluggable mechanism for arbitrary window toolkits to
adapt their components to the {@link NativeWindow} interface,
@@ -123,10 +124,10 @@ public abstract class NativeWindowFactory {
// make it easier to run this code on mobile devices
Class componentClass = null;
- if ( NWReflection.isClassAvailable("java.awt.Component") &&
- NWReflection.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) {
+ if ( ReflectionUtil.isClassAvailable("java.awt.Component") &&
+ ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) {
try {
- componentClass = NWReflection.getClass("java.awt.Component", false);
+ componentClass = ReflectionUtil.getClass("java.awt.Component", false);
} catch (Exception e) { }
}
@@ -177,7 +178,7 @@ public abstract class NativeWindowFactory {
try {
Constructor factoryConstructor =
- NWReflection.getConstructor("com.sun.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {});
+ ReflectionUtil.getConstructor("com.jogamp.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {});
_factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
} catch (Exception e) { }
}
@@ -185,7 +186,7 @@ public abstract class NativeWindowFactory {
if (toolkitLockForced && null==_factory) {
try {
Constructor factoryConstructor =
- NWReflection.getConstructor("com.sun.nativewindow.impl.LockingNativeWindowFactory", new Class[] {});
+ ReflectionUtil.getConstructor("com.jogamp.nativewindow.impl.LockingNativeWindowFactory", new Class[] {});
_factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
} catch (Exception e) { }
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
index 7373e7b97..9b48f8f6e 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -44,7 +44,7 @@ import java.awt.GraphicsConfiguration;
import java.awt.Transparency;
import java.awt.image.ColorModel;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import com.sun.nativewindow.impl.Debug;
+import com.jogamp.nativewindow.impl.Debug;
/** A wrapper for an AWT GraphicsConfiguration allowing it to be
handled in a toolkit-independent manner. */
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
index 077cbf8aa..d326b9159 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
@@ -43,7 +43,7 @@ import javax.media.nativewindow.*;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.media.nativewindow.AbstractGraphicsDevice;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
/** A wrapper for an AWT GraphicsDevice allowing it to be
handled in a toolkit-independent manner. */
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
index 2ad8a99af..6cbf2ee71 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
@@ -43,7 +43,7 @@ import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.media.nativewindow.*;
import javax.media.nativewindow.AbstractGraphicsDevice;
-import com.sun.nativewindow.impl.*;
+import com.jogamp.nativewindow.impl.*;
/** A wrapper for an AWT GraphicsDevice (screen) allowing it to be
handled in a toolkit-independent manner. */
diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html
index ce9dbbb7a..fa422b2ab 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/package.html
+++ b/src/nativewindow/classes/javax/media/nativewindow/package.html
@@ -41,7 +41,7 @@
</ul><br>
This protocol <i>does not</i> describe how to <i>create</i> native windows, but how to <i>bind</i> a native window to an implementation of
{@link javax.media.nativewindow.NativeWindow NativeWindow}.<br>
- However, an implementation of this protocol (e.g. {@link com.sun.javafx.newt}) may support the creation.<br>
+ However, an implementation of this protocol (e.g. {@link com.jogamp.newt}) may support the creation.<br>
<h3>Dependencies</h3>
This binding has dependencies to the following:<br><br>
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
index 49d5f2d83..5659dcdcc 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
@@ -33,7 +33,7 @@
package javax.media.nativewindow.x11;
import javax.media.nativewindow.*;
-import com.sun.nativewindow.impl.x11.XVisualInfo;
+import com.jogamp.nativewindow.impl.x11.XVisualInfo;
/** Encapsulates a graphics configuration, or OpenGL pixel format, on
X11 platforms. Objects of this type are returned from {@link
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
index 614d26a61..58b40efe0 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
@@ -33,8 +33,8 @@
package javax.media.nativewindow.x11;
import javax.media.nativewindow.*;
-import com.sun.nativewindow.impl.x11.X11Util;
-import com.sun.nativewindow.impl.x11.X11Lib;
+import com.jogamp.nativewindow.impl.x11.X11Util;
+import com.jogamp.nativewindow.impl.x11.X11Lib;
/** Encapsulates a screen index on X11
platforms. Objects of this type are passed to {@link
@@ -57,13 +57,16 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl
/** Creates a new X11GraphicsScreen using a thread local display connection */
public static AbstractGraphicsScreen createDefault() {
NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
- long display = X11Util.getThreadLocalDefaultDisplay();
try {
+ long display = X11Util.createThreadLocalDefaultDisplay();
X11Lib.XLockDisplay(display);
- int scrnIdx = X11Lib.DefaultScreen(display);
- return createScreenDevice(display, scrnIdx);
+ try{
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return createScreenDevice(display, scrnIdx);
+ }finally{
+ X11Lib.XUnlockDisplay(display);
+ }
} finally {
- X11Lib.XUnlockDisplay(display);
NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
}
}
@@ -71,13 +74,16 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl
public long getDefaultVisualID() {
// It still could be an AWT hold handle ..
NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
- long display = getDevice().getHandle();
try {
+ long display = getDevice().getHandle();
X11Lib.XLockDisplay(display);
- int scrnIdx = X11Lib.DefaultScreen(display);
- return X11Lib.DefaultVisualID(display, scrnIdx);
+ try{
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return X11Lib.DefaultVisualID(display, scrnIdx);
+ }finally{
+ X11Lib.XUnlockDisplay(display);
+ }
} finally {
- X11Lib.XUnlockDisplay(display);
NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
}
}
@@ -85,14 +91,17 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl
private static int fetchScreen(X11GraphicsDevice device, int screen) {
// It still could be an AWT hold handle ..
NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
- long display = device.getHandle();
try {
+ long display = device.getHandle();
X11Lib.XLockDisplay(display);
- if(X11Lib.XineramaEnabled(display)) {
- screen = 0; // Xinerama -> 1 screen
+ try{
+ if(X11Lib.XineramaEnabled(display)) {
+ screen = 0; // Xinerama -> 1 screen
+ }
+ }finally{
+ X11Lib.XUnlockDisplay(display);
}
} finally {
- X11Lib.XUnlockDisplay(display);
NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
}
return screen;
diff --git a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c
index e4afbdb70..a0422fa8e 100644
--- a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c
+++ b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c
@@ -50,7 +50,7 @@
#endif
JNIEXPORT jobject JNICALL
-Java_com_sun_nativewindow_impl_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) {
+Java_com_jogamp_nativewindow_impl_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) {
JAWT_DrawingSurfaceInfo* dsi;
dsi = (*env)->GetDirectBufferAddress(env, jthis0);
if (dsi == NULL) {
diff --git a/src/nativewindow/native/JVM_Tool.c b/src/nativewindow/native/JVM_Tool.c
deleted file mode 100644
index e04032aa2..000000000
--- a/src/nativewindow/native/JVM_Tool.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- *
- * Sun gratefully acknowledges that this software was originally authored
- * and developed by Kenneth Bradley Russell and Christopher John Kline.
- */
-
-#include <jni.h>
-
-JNIEXPORT jboolean JNICALL
-Java_com_sun_nativewindow_impl_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) {
- int res;
- void * ptr = NULL;
- if (nioBuffer != NULL) {
- ptr = (void *) (*env)->GetDirectBufferAddress(env, nioBuffer);
- }
- return ( NULL==ptr ) ? JNI_FALSE : JNI_TRUE ;
-}
-
diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c
new file mode 100644
index 000000000..52449ae84
--- /dev/null
+++ b/src/nativewindow/native/x11/Xmisc.c
@@ -0,0 +1,493 @@
+/*
+ * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+/* Linux headers don't work properly */
+#define __USE_GNU
+#include <dlfcn.h>
+#undef __USE_GNU
+
+/* Current versions of Solaris don't expose the XF86 extensions,
+ although with the recent transition to Xorg this will probably
+ happen in an upcoming release */
+#if !defined(__sun) && !defined(_HPUX)
+#include <X11/extensions/xf86vmode.h>
+#else
+/* Need to provide stubs for these */
+Bool XF86VidModeGetGammaRampSize(
+ Display *display,
+ int screen,
+ int* size)
+{
+ return False;
+}
+
+Bool XF86VidModeGetGammaRamp(
+ Display *display,
+ int screen,
+ int size,
+ unsigned short *red_array,
+ unsigned short *green_array,
+ unsigned short *blue_array) {
+ return False;
+}
+Bool XF86VidModeSetGammaRamp(
+ Display *display,
+ int screen,
+ int size,
+ unsigned short *red_array,
+ unsigned short *green_array,
+ unsigned short *blue_array) {
+ return False;
+}
+#endif /* defined(__sun) || defined(_HPUX) */
+
+/* HP-UX doesn't define RTLD_DEFAULT. */
+#if defined(_HPUX) && !defined(RTLD_DEFAULT)
+#define RTLD_DEFAULT NULL
+#endif
+
+#include "com_jogamp_nativewindow_impl_x11_X11Lib.h"
+
+// #define VERBOSE_ON 1
+
+#ifdef VERBOSE_ON
+ // Workaround for ancient compiler on Solaris/SPARC
+ // #define DBG_PRINT(args...) fprintf(stderr, args);
+ #define DBG_PRINT0(str) fprintf(stderr, str);
+ #define DBG_PRINT1(str, arg1) fprintf(stderr, str, arg1);
+ #define DBG_PRINT2(str, arg1, arg2) fprintf(stderr, str, arg1, arg2);
+ #define DBG_PRINT3(str, arg1, arg2, arg3) fprintf(stderr, str, arg1, arg2, arg3);
+ #define DBG_PRINT4(str, arg1, arg2, arg3, arg4) fprintf(stderr, str, arg1, arg2, arg3, arg4);
+ #define DBG_PRINT5(str, arg1, arg2, arg3, arg4, arg5) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5);
+ #define DBG_PRINT6(str, arg1, arg2, arg3, arg4, arg5, arg6) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5, arg6);
+ #define DBG_PRINT7(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+ #define DBG_PRINT8(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) fprintf(stderr, str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+
+#else
+
+ // Workaround for ancient compiler on Solaris/SPARC
+ // #define DBG_PRINT(args...)
+ #define DBG_PRINT0(str)
+ #define DBG_PRINT1(str, arg1)
+ #define DBG_PRINT2(str, arg1, arg2)
+ #define DBG_PRINT3(str, arg1, arg2, arg3)
+ #define DBG_PRINT4(str, arg1, arg2, arg3, arg4)
+ #define DBG_PRINT5(str, arg1, arg2, arg3, arg4, arg5)
+ #define DBG_PRINT6(str, arg1, arg2, arg3, arg4, arg5, arg6)
+ #define DBG_PRINT7(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
+ #define DBG_PRINT8(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
+
+#endif
+
+/* Need to pull this in as we don't have a stub header for it */
+extern Bool XineramaEnabled(Display* display);
+
+static void _FatalError(JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ fprintf(stderr, buffer);
+ fprintf(stderr, "\n");
+ (*env)->FatalError(env, buffer);
+}
+
+static const char * const ClazzNameInternalBufferUtil = "com/jogamp/nativewindow/impl/InternalBufferUtil";
+static const char * const ClazzNameInternalBufferUtilStaticCstrName = "copyByteBuffer";
+static const char * const ClazzNameInternalBufferUtilStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;";
+static const char * const ClazzNameByteBuffer = "java/nio/ByteBuffer";
+static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException";
+static jclass clazzInternalBufferUtil = NULL;
+static jmethodID cstrInternalBufferUtil = NULL;
+static jclass clazzByteBuffer = NULL;
+static jclass clazzRuntimeException=NULL;
+
+static void _initClazzAccess(JNIEnv *env) {
+ jclass c;
+
+ if(NULL!=clazzRuntimeException) return ;
+
+ c = (*env)->FindClass(env, ClazzNameRuntimeException);
+ if(NULL==c) {
+ _FatalError(env, "Nativewindow X11Lib: can't find %s", ClazzNameRuntimeException);
+ }
+ clazzRuntimeException = (jclass)(*env)->NewGlobalRef(env, c);
+ (*env)->DeleteLocalRef(env, c);
+ if(NULL==clazzRuntimeException) {
+ _FatalError(env, "FatalError: NEWT X11Window: can't use %s", ClazzNameRuntimeException);
+ }
+
+ c = (*env)->FindClass(env, ClazzNameInternalBufferUtil);
+ if(NULL==c) {
+ _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameInternalBufferUtil);
+ }
+ clazzInternalBufferUtil = (jclass)(*env)->NewGlobalRef(env, c);
+ (*env)->DeleteLocalRef(env, c);
+ if(NULL==clazzInternalBufferUtil) {
+ _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameInternalBufferUtil);
+ }
+ c = (*env)->FindClass(env, ClazzNameByteBuffer);
+ if(NULL==c) {
+ _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer);
+ }
+ clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c);
+ (*env)->DeleteLocalRef(env, c);
+ if(NULL==c) {
+ _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer);
+ }
+
+ cstrInternalBufferUtil = (*env)->GetStaticMethodID(env, clazzInternalBufferUtil,
+ ClazzNameInternalBufferUtilStaticCstrName, ClazzNameInternalBufferUtilStaticCstrSignature);
+ if(NULL==cstrInternalBufferUtil) {
+ _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s",
+ ClazzNameInternalBufferUtil, ClazzNameInternalBufferUtilStaticCstrName, ClazzNameInternalBufferUtilStaticCstrSignature);
+ }
+}
+
+static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ if(NULL!=unlockDisplay) {
+ XUnlockDisplay(unlockDisplay);
+ }
+
+ _initClazzAccess(env);
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ (*env)->ThrowNew(env, clazzRuntimeException, buffer);
+}
+
+static JNIEnv * x11ErrorHandlerJNIEnv = NULL;
+static XErrorHandler origErrorHandler = NULL ;
+
+static int x11ErrorHandler(Display *dpy, XErrorEvent *e)
+{
+ _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Nativewindow X11 Error: Display %p, Code 0x%X", dpy, e->error_code);
+
+ return 0;
+}
+
+static void x11ErrorHandlerEnable(int onoff, JNIEnv * env) {
+ if(onoff) {
+ if(NULL==origErrorHandler) {
+ x11ErrorHandlerJNIEnv = env;
+ origErrorHandler = XSetErrorHandler(x11ErrorHandler);
+ }
+ } else {
+ XSetErrorHandler(origErrorHandler);
+ origErrorHandler = NULL;
+ }
+}
+
+
+static XIOErrorHandler origIOErrorHandler = NULL;
+
+static int x11IOErrorHandler(Display *dpy)
+{
+ _FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p not available", dpy);
+ origIOErrorHandler(dpy);
+ return 0;
+}
+
+static void x11IOErrorHandlerEnable(int onoff, JNIEnv * env) {
+ if(onoff) {
+ if(NULL==origIOErrorHandler) {
+ x11ErrorHandlerJNIEnv = env;
+ origIOErrorHandler = XSetIOErrorHandler(x11IOErrorHandler);
+ }
+ } else {
+ XSetIOErrorHandler(origIOErrorHandler);
+ origIOErrorHandler = NULL;
+ }
+}
+
+JNIEXPORT void JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Util_installIOErrorHandler(JNIEnv *env, jclass _unused) {
+ x11ErrorHandlerEnable(1, env);
+ x11IOErrorHandlerEnable(1, env);
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlopen(JNIEnv *env, jclass _unused, jstring name) {
+ const jbyte* chars;
+ void* res;
+ chars = (*env)->GetStringUTFChars(env, name, NULL);
+ res = dlopen(chars, RTLD_LAZY | RTLD_GLOBAL);
+ (*env)->ReleaseStringUTFChars(env, name, chars);
+ return (jlong) ((intptr_t) res);
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_dlsym(JNIEnv *env, jclass _unused, jstring name) {
+ const jbyte* chars;
+ void* res;
+ chars = (*env)->GetStringUTFChars(env, name, NULL);
+ res = dlsym(RTLD_DEFAULT, chars);
+ (*env)->ReleaseStringUTFChars(env, name, chars);
+ return (jlong) ((intptr_t) res);
+}
+
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.x11.X11Lib
+ * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3)
+ * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * );
+ */
+JNIEXPORT jobject JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfoCopied1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) {
+ XVisualInfo * _ptr2 = NULL;
+ int * _ptr3 = NULL;
+ XVisualInfo * _res;
+ int count;
+ jobject jbyteSource;
+ jobject jbyteCopy;
+ if(0==arg0) {
+ _FatalError(env, "invalid display connection..");
+ }
+ if (arg2 != NULL) {
+ _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0);
+ }
+ if (arg3 != NULL) {
+ _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset);
+ }
+ _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3);
+ count = _ptr3[0];
+ if (arg3 != NULL) {
+ (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0);
+ }
+ if (_res == NULL) return NULL;
+
+ _initClazzAccess(env);
+
+ jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo));
+ jbyteCopy = (*env)->CallStaticObjectMethod(env,
+ clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource);
+
+ XFree(_res);
+
+ return jbyteCopy;
+}
+
+JNIEXPORT jlong JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) {
+ jlong r;
+ if(0==display) {
+ _FatalError(env, "invalid display connection..");
+ }
+ r = (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) );
+ return r;
+}
+
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.x11.X11Lib
+ * Java method: void XLockDisplay(long display)
+ * C function: void XLockDisplay(Display * display);
+ */
+JNIEXPORT void JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_XLockDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
+ if(0==display) {
+ _FatalError(env, "invalid display connection..");
+ }
+ XLockDisplay((Display *) (intptr_t) display);
+}
+
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.x11.X11Lib
+ * Java method: void XUnlockDisplay(long display)
+ * C function: void XUnlockDisplay(Display * display);
+ */
+JNIEXPORT void JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_XUnlockDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
+ if(0==display) {
+ _FatalError(env, "invalid display connection..");
+ }
+ XUnlockDisplay((Display *) (intptr_t) display);
+}
+
+
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.x11.X11Lib
+ * Java method: int XCloseDisplay(long display)
+ * C function: int XCloseDisplay(Display * display);
+ */
+JNIEXPORT jint JNICALL
+Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
+ int _res;
+ if(0==display) {
+ _FatalError(env, "invalid display connection..");
+ }
+ _res = XCloseDisplay((Display *) (intptr_t) display);
+ return _res;
+}
+
+/*
+ * Class: com_jogamp_nativewindow_impl_x11_X11Lib
+ * Method: CreateDummyWindow
+ * Signature: (JIJ)J
+ */
+JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow
+ (JNIEnv *env, jobject obj, jlong display, jint screen_index, jlong visualID)
+{
+ Display * dpy = (Display *)(intptr_t)display;
+ int scrn_idx = (int)screen_index;
+ Window windowParent = 0;
+ Window window = 0;
+
+ XVisualInfo visualTemplate;
+ XVisualInfo *pVisualQuery = NULL;
+ Visual *visual = NULL;
+ int depth;
+
+ XSetWindowAttributes xswa;
+ unsigned long attrMask;
+ int n;
+
+ Screen* scrn;
+
+ if(NULL==dpy) {
+ _FatalError(env, "invalid display connection..");
+ return 0;
+ }
+
+ if(visualID<0) {
+ _throwNewRuntimeException(NULL, env, "invalid VisualID ..");
+ return 0;
+ }
+
+ XLockDisplay(dpy) ;
+
+ XSync(dpy, False);
+
+ scrn = ScreenOfDisplay(dpy, scrn_idx);
+
+ // try given VisualID on screen
+ memset(&visualTemplate, 0, sizeof(XVisualInfo));
+ visualTemplate.screen = scrn_idx;
+ visualTemplate.visualid = (VisualID)visualID;
+ pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n);
+ if(pVisualQuery!=NULL) {
+ visual = pVisualQuery->visual;
+ depth = pVisualQuery->depth;
+ visualID = (jlong)pVisualQuery->visualid;
+ XFree(pVisualQuery);
+ pVisualQuery=NULL;
+ }
+ DBG_PRINT5( "X11: [CreateWindow] trying given (dpy %p, screen %d, visualID: %d, parent %p) found: %p\n", dpy, scrn_idx, (int)visualID, windowParent, visual);
+
+ if (visual==NULL)
+ {
+ _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!");
+ return 0;
+ }
+
+ if(pVisualQuery!=NULL) {
+ XFree(pVisualQuery);
+ pVisualQuery=NULL;
+ }
+
+ if(0==windowParent) {
+ windowParent = XRootWindowOfScreen(scrn);
+ }
+
+ attrMask = (CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect) ;
+
+ memset(&xswa, 0, sizeof(xswa));
+ xswa.override_redirect = True; // not decorated
+ xswa.border_pixel = 0;
+ xswa.background_pixel = 0;
+ xswa.event_mask = 0 ; // no events
+ xswa.colormap = XCreateColormap(dpy,
+ XRootWindow(dpy, scrn_idx),
+ visual,
+ AllocNone);
+
+ window = XCreateWindow(dpy,
+ windowParent,
+ 0, 0,
+ 64, 64,
+ 0, // border width
+ depth,
+ InputOutput,
+ visual,
+ attrMask,
+ &xswa);
+
+ XSync(dpy, False);
+
+ XUnlockDisplay(dpy) ;
+
+ DBG_PRINT2( "X11: [CreateWindow] created window %p on display %p\n", window, dpy);
+
+ return (jlong) window;
+}
+
+
+/*
+ * Class: com_jogamp_nativewindow_impl_x11_X11Lib
+ * Method: DestroyDummyWindow
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow
+ (JNIEnv *env, jobject obj, jlong display, jlong window)
+{
+ Display * dpy = (Display *)(intptr_t)display;
+ Window w = (Window) window;
+
+ if(NULL==dpy) {
+ _throwNewRuntimeException(NULL, env, "invalid display connection..");
+ return;
+ }
+ XLockDisplay(dpy) ;
+
+ XSync(dpy, False);
+ XUnmapWindow(dpy, w);
+ XSync(dpy, False);
+ XDestroyWindow(dpy, w);
+ XSync(dpy, False);
+
+ XUnlockDisplay(dpy) ;
+}