diff options
author | JOGAMP DEV TEAM <[email protected]> | 2010-04-22 21:12:36 -0400 |
---|---|---|
committer | JOGAMP DEV TEAM <[email protected]> | 2010-04-22 21:12:36 -0400 |
commit | 1d889ddc4728d1534e310b44fad74a2932d22d39 (patch) | |
tree | 4ad0c3eeb3ef728522ac9459eb12c667301a0c32 /src/nativewindow/classes/com | |
parent | 8790075f074013aa3c71b96993838cf1117275f1 (diff) | |
parent | a588326d206ff32e5ff5db97560851cb9b826022 (diff) |
Merge branch 'master' of github.com:sgothel/jogl
Diffstat (limited to 'src/nativewindow/classes/com')
-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.java | 50 | ||||
-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.java | 334 | ||||
-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.java | 181 | ||||
-rw-r--r-- | src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java | 202 | ||||
-rw-r--r-- | src/nativewindow/classes/com/sun/nativewindow/impl/jvm/JVMUtil.java | 72 | ||||
-rw-r--r-- | src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java | 166 |
22 files changed, 432 insertions, 668 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); - } - -} |