diff options
Diffstat (limited to 'src/nativewindow/classes')
3 files changed, 88 insertions, 18 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index c1c97eece..afcc3cbf0 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -42,6 +42,8 @@ import java.awt.EventQueue; import javax.media.nativewindow.*; +import com.jogamp.common.os.Platform; + import java.awt.GraphicsEnvironment; import java.awt.Toolkit; @@ -75,14 +77,30 @@ public class JAWTUtil { boolean ok; } + public static void setJAWTVersionFlags(boolean useOffScreenLayerIfAvailable) { + if(useOffScreenLayerIfAvailable && + Platform.OS_TYPE == Platform.OSType.MACOS && + Platform.OS_VERSION_NUMBER.compareTo(JAWT.JAWT_MacOSXCALayerMinVersion) >= 0) { + JAWT.setJAWTVersionFlags(JAWTFactory.JAWT_VERSION_1_4 | JAWT.JAWT_MACOSX_USE_CALAYER); + } else { + JAWT.setJAWTVersionFlags(JAWTFactory.JAWT_VERSION_1_4); + } + } + + public static boolean isJAWTVersionUsingOffscreenLayer() { + return 0 != ( JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER ); + } + static { JAWTJNILibLoader.loadAWTImpl(); JAWTJNILibLoader.loadNativeWindow("awt"); headlessMode = GraphicsEnvironment.isHeadless(); - + if(!headlessMode) { + JAWT.setJAWTVersionFlags(JAWTFactory.JAWT_VERSION_1_4); + } boolean ok = false; - Class jC = null; + Class<?> jC = null; Method m = null; if (!headlessMode) { try { @@ -95,11 +113,11 @@ public class JAWTUtil { isQueueFlusherThread = m; j2dExist = ok; - PrivilegedDataBlob1 pdb1 = (PrivilegedDataBlob1) AccessController.doPrivileged(new PrivilegedAction() { + PrivilegedDataBlob1 pdb1 = (PrivilegedDataBlob1) AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { PrivilegedDataBlob1 d = new PrivilegedDataBlob1(); try { - final Class sunToolkitClass = Class.forName("sun.awt.SunToolkit"); + 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[]{}); diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java index 2c80392ad..cc6493313 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java @@ -222,6 +222,14 @@ public abstract class JAWTWindow implements NativeWindow { public long getWindowHandle() { return drawable; } + + public boolean isSetWindowHandleSupported() { + return false; + } + public void setWindowHandle(long handle) { + throw new java.lang.UnsupportedOperationException(); + } + public final int getX() { return component.getX(); diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index d4f6a95d4..8b196b70e 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -51,9 +51,12 @@ import javax.media.nativewindow.util.Point; import jogamp.nativewindow.jawt.JAWT; import jogamp.nativewindow.jawt.JAWTFactory; +import jogamp.nativewindow.jawt.JAWTUtil; import jogamp.nativewindow.jawt.JAWTWindow; import jogamp.nativewindow.jawt.JAWT_DrawingSurface; import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo; +import jogamp.nativewindow.jawt.JAWT_Rectangle; +import jogamp.nativewindow.macosx.OSXUtil; // import jogamp.nativewindow.macosx.OSXUtil; public class MacOSXJAWTWindow extends JAWTWindow { @@ -66,8 +69,9 @@ public class MacOSXJAWTWindow extends JAWTWindow { } protected int lockSurfaceImpl() throws NativeWindowException { - int ret = NativeWindow.LOCK_SUCCESS; - ds = JAWT.getJAWT().GetDrawingSurface(component); + final JAWT jawt = JAWT.getJAWT(); + int ret = NativeWindow.LOCK_SURFACE_NOT_READY; + ds = jawt.GetDrawingSurface(component); if (ds == null) { // Widget not yet realized unlockSurfaceImpl(); @@ -101,23 +105,53 @@ public class MacOSXJAWTWindow extends JAWTWindow { unlockSurfaceImpl(); return NativeWindow.LOCK_SURFACE_NOT_READY; } - firstLock = false; - macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); - if (macosxdsi == null) { - unlockSurfaceImpl(); - return NativeWindow.LOCK_SURFACE_NOT_READY; + if(DEBUG && firstLock) { + dumpInfo(); } - drawable = macosxdsi.getCocoaViewRef(); - - if (drawable == 0) { - unlockSurfaceImpl(); - return NativeWindow.LOCK_SURFACE_NOT_READY; + firstLock = false; + if( 0 == ( jawt.getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER ) ) { + macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); + if (macosxdsi == null) { + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + drawable = macosxdsi.getCocoaViewRef(); + + if (drawable == 0) { + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } else { + ret = NativeWindow.LOCK_SUCCESS; + } } else { + macosxsl = (JAWT_SurfaceLayers) dsi.platformInfo(); + if (macosxsl == null) { + unlockSurfaceImpl(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + } + + if(NativeWindow.LOCK_SURFACE_CHANGED <= ret) { updateBounds(dsi.getBounds()); } return ret; } + public boolean isSetWindowHandleSupported() { + return 0 != ( JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER ) ; + } + + public void setWindowHandle(long handle) { + if( !isSetWindowHandleSupported() ) { + throw new java.lang.UnsupportedOperationException("Not using CALAYER"); + } + if( null == macosxsl) { + throw new NativeWindowException("Not locked and/or SurfaceLayers null"); + } + drawable = handle; + macosxsl.setLayer(drawable); + } + protected void unlockSurfaceImpl() throws NativeWindowException { if(null!=ds) { if (null!=dsi) { @@ -133,14 +167,22 @@ public class MacOSXJAWTWindow extends JAWTWindow { macosxdsi = null; } - protected Point getLocationOnScreenImpl(int x, int y) { + private void dumpInfo() { + System.err.println("JAWT version: 0x"+Integer.toHexString(JAWT.getJAWT().getVersionCached())+ + ", CA_LAYER: "+ (0!=(JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER))); + JAWT_Rectangle r = dsi.getBounds(); + System.err.println("dsi bounds: "+r.getX()+"/"+r.getY()+" "+r.getWidth()+"x"+r.getHeight()); + } + + protected Point getLocationOnScreenImpl(final int x0, final int y0) { + int x = x0; + int y = y0; Component c = component; while(null != c) { x += c.getX(); y += c.getY(); c = c.getParent(); } - // return OSXUtil.GetLocationOnScreen(getWindowHandle(), x, y); return new Point(x, y); } @@ -148,7 +190,9 @@ public class MacOSXJAWTWindow extends JAWTWindow { private JAWT_DrawingSurface ds; private boolean dsLocked; private JAWT_DrawingSurfaceInfo dsi; + private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; + private JAWT_SurfaceLayers macosxsl; // Workaround for instance of 4796548 private boolean firstLock = true; |