diff options
author | Sven Gothel <[email protected]> | 2011-10-29 15:10:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-29 15:10:48 +0200 |
commit | 6a770d1ec80a656db62feb8100e3fe58800e79af (patch) | |
tree | b20ea684417f6945b30426782e1442382ec1afb8 | |
parent | bc826eb2e216ce82a5e6bc61403e4eff2f338380 (diff) |
MacOsX/JAWT_SurfaceLayers/CALayers: Kick off / JAWT_getAWT() CALAYER version support.
7 files changed, 149 insertions, 23 deletions
diff --git a/make/config/nativewindow/jawt-CustomJavaCode.java b/make/config/nativewindow/jawt-CustomJavaCode.java index 3223a74b1..23da6b3b9 100644 --- a/make/config/nativewindow/jawt-CustomJavaCode.java +++ b/make/config/nativewindow/jawt-CustomJavaCode.java @@ -1,4 +1,24 @@ -private static volatile JAWT jawt; +/** Available and recommended on Mac OS X >= 10.6 Update 4 */ +public static final int JAWT_MACOSX_USE_CALAYER = 0x80000000; +public static final VersionNumber JAWT_MacOSXCALayerMinVersion = new VersionNumber(10,6,4); + +private static volatile JAWT jawt = null; +private static int jawt_version_flags = 0; + +private int jawt_version_cached = 0; + +public final int getVersionCached() { + return jawt_version_cached; +} + +public static void setJAWTVersionFlags(int versionFlags) { + synchronized (JAWT.class) { + if (jawt != null) { + throw new RuntimeException("JAWT already instantiated"); + } + jawt_version_flags = versionFlags; + } +} /** Helper routine for all users to call to access the JAWT. */ public static JAWT getJAWT() { @@ -9,14 +29,25 @@ public static JAWT getJAWT() { // Workaround for 4845371. // Make sure the first reference to the JNI GetDirectBufferAddress is done // from a privileged context so the VM's internal class lookups will succeed. - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { JAWT j = JAWT.create(); - j.setVersion(JAWTFactory.JAWT_VERSION_1_4); + if( 0 != ( jawt_version_flags & JAWT_MACOSX_USE_CALAYER ) ) { + j.setVersion(jawt_version_flags); + if (JAWTFactory.JAWT_GetAWT(j)) { + jawt = j; + jawt.jawt_version_cached = jawt.getVersion(); + return null; + } + jawt_version_flags &= ~JAWT_MACOSX_USE_CALAYER; + System.err.println("MacOSX "+Platform.OS_VERSION_NUMBER+" >= "+JAWT_MacOSXCALayerMinVersion+": Failed to use JAWT_MACOSX_USE_CALAYER"); + } + j.setVersion(jawt_version_flags); if (!JAWTFactory.JAWT_GetAWT(j)) { - throw new RuntimeException("Unable to initialize JAWT"); + throw new RuntimeException("Unable to initialize JAWT: 0x"+Integer.toHexString(jawt_version_flags)); } jawt = j; + jawt.jawt_version_cached = jawt.getVersion(); return null; } }); diff --git a/make/config/nativewindow/jawt-common.cfg b/make/config/nativewindow/jawt-common.cfg index d633c47d6..55f3f368b 100644 --- a/make/config/nativewindow/jawt-common.cfg +++ b/make/config/nativewindow/jawt-common.cfg @@ -22,5 +22,7 @@ CustomCCode #include <jawt.h> import java.security.* import jogamp.nativewindow.jawt.* +import com.jogamp.common.os.Platform +import com.jogamp.common.util.VersionNumber IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nativewindow/jawt-macosx.cfg b/make/config/nativewindow/jawt-macosx.cfg index c41367f4a..20260f693 100644 --- a/make/config/nativewindow/jawt-macosx.cfg +++ b/make/config/nativewindow/jawt-macosx.cfg @@ -5,6 +5,7 @@ NativeOutputDir gensrc/native/MacOSX Opaque long void * Opaque long NSView * +Opaque long CALayer * CustomCCode #include <inttypes.h> CustomCCode #include </usr/include/machine/types.h> @@ -12,3 +13,7 @@ CustomCCode #include </usr/include/machine/types.h> StructPackage JAWT_MacOSXDrawingSurfaceInfo jogamp.nativewindow.jawt.macosx EmitStruct JAWT_MacOSXDrawingSurfaceInfo Implements JAWT_MacOSXDrawingSurfaceInfo JAWT_PlatformInfo + +StructPackage JAWT_SurfaceLayers jogamp.nativewindow.jawt.macosx +EmitStruct JAWT_SurfaceLayers +Implements JAWT_SurfaceLayers JAWT_PlatformInfo diff --git a/make/stub_includes/jni/macosx/jawt_md.h b/make/stub_includes/jni/macosx/jawt_md.h index aca47f66e..3a371af0d 100644 --- a/make/stub_includes/jni/macosx/jawt_md.h +++ b/make/stub_includes/jni/macosx/jawt_md.h @@ -9,17 +9,35 @@ #include <jawt.h> #include <AppKit/NSView.h> +#include <QuartzCore/CALayer.h> #ifdef __cplusplus extern "C" { #endif +/** + * JAWT_DrawingSurfaceInfo.getPlatformInfo() + * + * Only if not JAWT_SurfaceLayers, see below! + */ typedef struct JAWT_MacOSXDrawingSurfaceInfo { - NSView *cocoaViewRef; // the view is guaranteed to be valid only for the duration of Component.paint method + /** the view is guaranteed to be valid only for the duration of Component.paint method */ + NSView *cocoaViewRef; } JAWT_MacOSXDrawingSurfaceInfo; +/** + * JAWT_DrawingSurfaceInfo.getPlatformInfo() + * + * >= 10.6.4 if JAWT_MACOSX_USE_CALAYER is set in JAWT version + */ +typedef struct JAWT_SurfaceLayers +{ + CALayer *layer; +} +JAWT_SurfaceLayers; + #ifdef __cplusplus } #endif 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; |