diff options
author | Sven Gothel <[email protected]> | 2013-09-24 23:13:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-09-24 23:13:16 +0200 |
commit | 4b5435c68c3f12d62dadb395957362eceacfb25c (patch) | |
tree | 367ffa26e9a1119ac0ca5fe74eb8a96b367f6d68 /src/nativewindow/classes/jogamp | |
parent | 2f09d266f75dfb4ab0d4504dd0a7699757bc40b3 (diff) |
Bug 816: Fix OSX CALayer 'quirks' for AWT 1.7.0_40 - See JAWTUtil JAWT_OSX_CALAYER_QUIRK_SIZE and JAWT_OSX_CALAYER_QUIRK_POSITION.
- Provide quirk bits for OSX CALayer depending on used JVM/AWT
and act accordingly.
- TestBug816OSXCALayerPosAWT: Add resize by frame
Diffstat (limited to 'src/nativewindow/classes/jogamp')
3 files changed, 94 insertions, 22 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index 1f5d33746..b663f90b7 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -68,7 +68,7 @@ public class JAWTUtil { public static final VersionNumber JAWT_MacOSXCALayerMinVersion = new VersionNumber(10,6,4); /** OSX JAWT CALayer required with Java >= 1.7.0 (implies OS X >= 10.7 */ - public static final VersionNumber JAWT_MacOSXCALayerRequiredForJavaVersion = new VersionNumber(1,7,0); + public static final VersionNumber JAWT_MacOSXCALayerRequiredForJavaVersion = Platform.Version17; // See whether we're running in headless mode private static final boolean headlessMode; @@ -98,18 +98,84 @@ public class JAWTUtil { * Returns true if this platform's JAWT implementation supports offscreen layer. */ public static boolean isOffscreenLayerSupported() { - return Platform.OS_TYPE == Platform.OSType.MACOS && - Platform.OS_VERSION_NUMBER.compareTo(JAWTUtil.JAWT_MacOSXCALayerMinVersion) >= 0; + return Platform.OS_TYPE == Platform.OSType.MACOS && + Platform.OS_VERSION_NUMBER.compareTo(JAWTUtil.JAWT_MacOSXCALayerMinVersion) >= 0; } /** * Returns true if this platform's JAWT implementation requires using offscreen layer. */ public static boolean isOffscreenLayerRequired() { - return Platform.OS_TYPE == Platform.OSType.MACOS && - Platform.JAVA_VERSION_NUMBER.compareTo(JAWT_MacOSXCALayerRequiredForJavaVersion)>=0; + return Platform.OS_TYPE == Platform.OSType.MACOS && + Platform.JAVA_VERSION_NUMBER.compareTo(JAWT_MacOSXCALayerRequiredForJavaVersion)>=0; } + /** + * CALayer size needs to be set using the AWT component size. + * <p> + * As of today, we have to overwrite the CALayer size + * w/ the AWT component one since programmatic resize leads to differences. + * </p> + * <p> + * Hence this flag is always enabled. + * </p> + * <p> + * Sync w/ NativeWindowProtocols.h + * </p> + */ + public static final int JAWT_OSX_CALAYER_QUIRK_SIZE = 1 << 0; + + /** + * CALayer position needs to be set to zero. + * <p> + * Normally we have to set the root-calayer's position to 0/0 + * and leave client-calayer's position in it's desired place. + * With pre AWT 1.7.0_40, the client-calayer's position has to + * be set to zero as well. + * </p> + * <p> + * Further more a re-layout seems to be required in this case, + * i.e. a programmatic forced resize +1 and it's inverted resize -1. + * </p> + * <p> + * Hence this flag is enabled w/ AWT < 1.7.0_40. + * </p> + * <p> + * Sync w/ NativeWindowProtocols.h + * </p> + */ + public static final int JAWT_OSX_CALAYER_QUIRK_POSITION = 1 << 1; + + /** + * Returns bitfield of required JAWT OSX CALayer quirks to mediate AWT impl. bugs. + * <p> + * Returns zero, if platform is not {@link Platform.OSType#MACOS} + * or not supporting CALayer, i.e. OSX < 10.6.4. + * </p> + * <p> + * Otherwise includes + * <ul> + * <li>{@link #JAWT_OSX_CALAYER_QUIRK_SIZE} (always)</li> + * <li>{@link #JAWT_OSX_CALAYER_QUIRK_POSITION} if JVM < 1.7.0_40</li> + * </ul> + * </p> + */ + public static int getOSXCALayerQuirks() { + int res = 0; + if( Platform.OS_TYPE == Platform.OSType.MACOS && + Platform.OS_VERSION_NUMBER.compareTo(JAWTUtil.JAWT_MacOSXCALayerMinVersion) >= 0 ) { + + /** Knowing impl. all expose the SIZE bug */ + res |= JAWT_OSX_CALAYER_QUIRK_SIZE; + + final int c = Platform.JAVA_VERSION_NUMBER.compareTo(Platform.Version17); + if( c < 0 || c == 0 && Platform.JAVA_VERSION_UPDATE < 40 ) { + res |= JAWT_OSX_CALAYER_QUIRK_POSITION; + } + } + return res; + } + /** * @param useOffscreenLayerIfAvailable * @return diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 080504a5c..666f895f4 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -49,6 +49,7 @@ import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.MutableSurface; +import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.util.Point; import com.jogamp.nativewindow.awt.JAWTWindow; @@ -105,16 +106,19 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { protected void attachSurfaceLayerImpl(final long layerHandle) { OSXUtil.RunOnMainThread(false, new Runnable() { public void run() { - OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, getWidth(), getHeight()); + OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, getWidth(), getHeight(), JAWTUtil.getOSXCALayerQuirks()); } } ); } @Override protected void layoutSurfaceLayerImpl(long layerHandle, int width, int height) { - if(DEBUG) { - System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", "+width+"x"+height+"; "+this); + final int caLayerQuirks = JAWTUtil.getOSXCALayerQuirks(); + if( 0 != caLayerQuirks ) { + if(DEBUG) { + System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", "+width+"x"+height+", caLayerQuirks "+caLayerQuirks+"; "+this); + } + OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, width, height, caLayerQuirks); } - OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, width, height); } @Override @@ -240,7 +244,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { public void run() { String errMsg = null; if(0 == rootSurfaceLayer && 0 != jawtSurfaceLayersHandle) { - rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getWidth(), bounds.getHeight()); if(0 == rootSurfaceLayer) { errMsg = "Could not create root CALayer"; } else { diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 1a90c095d..de24a76db 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -141,8 +141,8 @@ public class OSXUtil implements ToolkitProperties { * @see #DestroyCALayer(long) * @see #AddCASublayer(long, long) */ - public static long CreateCALayer(final int x, final int y, final int width, final int height) { - final long l = CreateCALayer0(x, y, width, height); + public static long CreateCALayer(final int width, final int height) { + final long l = CreateCALayer0(width, height); if(DEBUG) { System.err.println("OSXUtil.CreateCALayer: 0x"+Long.toHexString(l)+" - "+Thread.currentThread().getName()); } @@ -159,17 +159,18 @@ public class OSXUtil implements ToolkitProperties { * Hence it is important that related resources are not locked <i>if</i> * they will be used for creation. * </p> - * @see #CreateCALayer(int, int, int, int) + * @param caLayerQuirks TODO + * @see #CreateCALayer(int, int) * @see #RemoveCASublayer(long, long, boolean) */ - public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int width, final int height) { + public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int width, final int height, final int caLayerQuirks) { if(0==rootCALayer || 0==subCALayer) { throw new IllegalArgumentException("rootCALayer 0x"+Long.toHexString(rootCALayer)+", subCALayer 0x"+Long.toHexString(subCALayer)); } if(DEBUG) { - System.err.println("OSXUtil.AttachCALayer: 0x"+Long.toHexString(subCALayer)+" - "+Thread.currentThread().getName()); + System.err.println("OSXUtil.AttachCALayer: caLayerQuirks "+caLayerQuirks+", 0x"+Long.toHexString(subCALayer)+" - "+Thread.currentThread().getName()); } - AddCASublayer0(rootCALayer, subCALayer, width, height); + AddCASublayer0(rootCALayer, subCALayer, width, height, caLayerQuirks); } /** @@ -187,12 +188,13 @@ public class OSXUtil implements ToolkitProperties { * @param subCALayer the client surface layer, maybe null. * @param width the expected width * @param height the expected height + * @param caLayerQuirks TODO */ - public static void FixCALayerLayout(final long rootCALayer, final long subCALayer, final int width, final int height) { + public static void FixCALayerLayout(final long rootCALayer, final long subCALayer, final int width, final int height, final int caLayerQuirks) { if( 0==rootCALayer && 0==subCALayer ) { return; } - FixCALayerLayout0(rootCALayer, subCALayer, width, height); + FixCALayerLayout0(rootCALayer, subCALayer, width, height, caLayerQuirks); } /** @@ -210,7 +212,7 @@ public class OSXUtil implements ToolkitProperties { /** * Destroy a CALayer. - * @see #CreateCALayer(int, int, int, int) + * @see #CreateCALayer(int, int) */ public static void DestroyCALayer(final long caLayer) { if(0==caLayer) { @@ -354,9 +356,9 @@ public class OSXUtil implements ToolkitProperties { private static native void DestroyNSWindow0(long nsWindow); private static native long GetNSView0(long nsWindow); private static native long GetNSWindow0(long nsView); - private static native long CreateCALayer0(int x, int y, int width, int height); - private static native void AddCASublayer0(long rootCALayer, long subCALayer, int width, int height); - private static native void FixCALayerLayout0(long rootCALayer, long subCALayer, int width, int height); + private static native long CreateCALayer0(int width, int height); + private static native void AddCASublayer0(long rootCALayer, long subCALayer, int width, int height, int caLayerQuirks); + private static native void FixCALayerLayout0(long rootCALayer, long subCALayer, int width, int height, int caLayerQuirks); private static native void RemoveCASublayer0(long rootCALayer, long subCALayer); private static native void DestroyCALayer0(long caLayer); private static native void RunOnMainThread0(Runnable runnable); |