diff options
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java | 18 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java | 95 |
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() { |