aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-28 09:13:19 +0100
committerSven Gothel <[email protected]>2014-02-28 09:13:19 +0100
commitecbf9742f5a4ce100388083babec25d098633021 (patch)
treeb220ffac447be7012d1a9ba3c2b2e70cb36bc953
parent72d44215a266ccb569efbd5af3142385c4442fe9 (diff)
Refine commit 9fb1e46e43900ec9b2f9c9af1fc8984e101c8811: Avoid loading [j]awt native libs and null-cursor creation in headless mode
Commit 9fb1e46e43900ec9b2f9c9af1fc8984e101c8811 exposed sideffects, i.e. libjawt.so could not be loaded in JAWTUtil's static-init while in headless mode. JAWTUtil's static init block was triggered from AWTMisc debug flag changes. Fix drops operations in headless mode: - JAWTUtil - awt native lib loading - querying headfull features (locking, java2d ..) - AWTMisc - creating null cursor
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java18
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java95
2 files changed, 63 insertions, 50 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
index 3099f293d..738936078 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
@@ -177,14 +177,16 @@ public class AWTMisc {
static final Cursor nulCursor;
static {
Cursor _nulCursor = null;
- try {
- final Toolkit toolkit = Toolkit.getDefaultToolkit();
- final BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
- _nulCursor = toolkit.createCustomCursor(img, new Point(0,0), "nullCursor");
- } catch (Exception he) {
- if( JAWTUtil.DEBUG ) {
- System.err.println("Catched exception: "+he.getMessage());
- he.printStackTrace();
+ if( !JAWTUtil.isHeadlessMode() ) {
+ try {
+ final Toolkit toolkit = Toolkit.getDefaultToolkit();
+ final BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
+ _nulCursor = toolkit.createCustomCursor(img, new Point(0,0), "nullCursor");
+ } catch (Exception he) {
+ if( JAWTUtil.DEBUG ) {
+ System.err.println("Catched exception: "+he.getMessage());
+ he.printStackTrace();
+ }
}
}
nulCursor = _nulCursor;
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index 5a1d915ce..d4edf2ba9 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -296,60 +296,71 @@ public class JAWTUtil {
System.err.println("JAWTUtil initialization (JAWT/JNI/...");
// Thread.dumpStack();
}
- JAWTJNILibLoader.initSingleton();
- if(!JAWTJNILibLoader.loadNativeWindow("awt")) {
- throw new NativeWindowException("NativeWindow AWT native library load error.");
- }
headlessMode = GraphicsEnvironment.isHeadless();
- boolean ok = false;
- Class<?> jC = null;
- Method m = null;
- if (!headlessMode) {
+
+ if( headlessMode ) {
+ // Headless case
+ jawtLockObject = null;
+ isQueueFlusherThread = null;
+ j2dExist = false;
+ sunToolkitAWTLockMethod = null;
+ sunToolkitAWTUnlockMethod = null;
+ hasSunToolkitAWTLock = false;
+ // hasSunToolkitAWTLock = false;
+ } else {
+ // Non-headless case
+ JAWTJNILibLoader.initSingleton(); // load libjawt.so
+ if(!JAWTJNILibLoader.loadNativeWindow("awt")) { // load libnativewindow_awt.so
+ throw new NativeWindowException("NativeWindow AWT native library load error.");
+ }
jawtLockObject = getJAWT(false); // don't care for offscreen layer here
+
+ boolean j2dExistTmp = false;
+ Class<?> java2DClass = null;
+ Method isQueueFlusherThreadTmp = null;
try {
- jC = Class.forName("jogamp.opengl.awt.Java2D");
- m = jC.getMethod("isQueueFlusherThread", (Class[])null);
- ok = true;
+ java2DClass = Class.forName("jogamp.opengl.awt.Java2D");
+ isQueueFlusherThreadTmp = java2DClass.getMethod("isQueueFlusherThread", (Class[])null);
+ j2dExistTmp = true;
} catch (Exception e) {
}
- } else {
- jawtLockObject = null; // headless !
- }
- isQueueFlusherThread = m;
- j2dExist = ok;
+ isQueueFlusherThread = isQueueFlusherThreadTmp;
+ j2dExist = j2dExistTmp;
- PrivilegedDataBlob1 pdb1 = (PrivilegedDataBlob1) AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- PrivilegedDataBlob1 d = new PrivilegedDataBlob1();
+ PrivilegedDataBlob1 pdb1 = (PrivilegedDataBlob1) AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ PrivilegedDataBlob1 d = new PrivilegedDataBlob1();
+ try {
+ final Class<?> sunToolkitClass = Class.forName("sun.awt.SunToolkit");
+ d.sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[]{});
+ d.sunToolkitAWTLockMethod.setAccessible(true);
+ d.sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[]{});
+ d.sunToolkitAWTUnlockMethod.setAccessible(true);
+ d.ok=true;
+ } catch (Exception e) {
+ // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
+ }
+ return d;
+ }
+ });
+ sunToolkitAWTLockMethod = pdb1.sunToolkitAWTLockMethod;
+ sunToolkitAWTUnlockMethod = pdb1.sunToolkitAWTUnlockMethod;
+
+ boolean _hasSunToolkitAWTLock = false;
+ if ( pdb1.ok ) {
try {
- final Class<?> sunToolkitClass = Class.forName("sun.awt.SunToolkit");
- d.sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[]{});
- d.sunToolkitAWTLockMethod.setAccessible(true);
- d.sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[]{});
- d.sunToolkitAWTUnlockMethod.setAccessible(true);
- d.ok=true;
+ sunToolkitAWTLockMethod.invoke(null, (Object[])null);
+ sunToolkitAWTUnlockMethod.invoke(null, (Object[])null);
+ _hasSunToolkitAWTLock = true;
} catch (Exception e) {
- // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
}
- return d;
- }
- });
- sunToolkitAWTLockMethod = pdb1.sunToolkitAWTLockMethod;
- sunToolkitAWTUnlockMethod = pdb1.sunToolkitAWTUnlockMethod;
-
- boolean _hasSunToolkitAWTLock = false;
- if ( pdb1.ok ) {
- try {
- sunToolkitAWTLockMethod.invoke(null, (Object[])null);
- sunToolkitAWTUnlockMethod.invoke(null, (Object[])null);
- _hasSunToolkitAWTLock = true;
- } catch (Exception e) {
}
+ hasSunToolkitAWTLock = _hasSunToolkitAWTLock;
+ // hasSunToolkitAWTLock = false;
}
- hasSunToolkitAWTLock = _hasSunToolkitAWTLock;
- // hasSunToolkitAWTLock = false;
+
jawtLock = LockFactory.createRecursiveLock();
jawtToolkitLock = new ToolkitLock() {