From a2a057406ff5d21499860e8fef6ba88f07d9bf95 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 28 Sep 2013 00:20:50 +0200 Subject: Bug 816: Clarify JAWT_OSX_CALAYER_QUIRK_* semantics, add JAWT_OSX_CALAYER_QUIRK_LAYOUT --- .../classes/jogamp/nativewindow/jawt/JAWTUtil.java | 49 ++++++++++++++++++---- .../nativewindow/jawt/macosx/MacOSXJAWTWindow.java | 2 + .../native/macosx/NativeWindowProtocols.h | 7 ++++ src/nativewindow/native/macosx/OSXmisc.m | 15 +++---- 4 files changed, 58 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index b663f90b7..b20007d53 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -113,11 +113,12 @@ public class JAWTUtil { /** * CALayer size needs to be set using the AWT component size. *

- * As of today, we have to overwrite the CALayer size - * w/ the AWT component one since programmatic resize leads to differences. + * AWT's super-calayer, i.e. the AWT's own component CALayer, + * does not layout our root-calayer in respect to this component's + * position and size, at least when resizing programmatically. *

*

- * Hence this flag is always enabled. + * As of today, this flag is enabled for all known AWT versions. *

*

* Sync w/ NativeWindowProtocols.h @@ -128,17 +129,18 @@ public class JAWTUtil { /** * CALayer position needs to be set to zero. *

- * 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. + * AWT's super-calayer, i.e. the AWT's own component CALayer, + * has a broken layout and needs it's sub-layers to be located at position 0/0. + *

+ *

+ * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7172187. *

*

* 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. *

*

- * Hence this flag is enabled w/ AWT < 1.7.0_40. + * This flag is enabled w/ AWT < 1.7.0_40. *

*

* Sync w/ NativeWindowProtocols.h @@ -146,6 +148,34 @@ public class JAWTUtil { */ public static final int JAWT_OSX_CALAYER_QUIRK_POSITION = 1 << 1; + /** + * CALayer position needs to be derived from AWT position + * in relation to super CALayer. + *

+ * AWT's super-calayer, i.e. the AWT's own component CALayer, + * does not layout our root-calayer in respect to this component's + * position and size, at least when resizing programmatically. + *

+ *

+ * CALayer position has origin 0/0 at bottom/left, + * where AWT component has origin 0/0 at top/left. + *

+ *

+ * The super-calayer bounds exclude the frame's heavyweight border/insets. + *

+ *

+ * This flags also sets {@link #JAWT_OSX_CALAYER_QUIRK_SIZE}, + * i.e. they are related. + *

+ *

+ * As of today, this flag is enabled for w/ AWT >= 1.7.0_40. + *

+ *

+ * Sync w/ NativeWindowProtocols.h + *

+ */ + public static final int JAWT_OSX_CALAYER_QUIRK_LAYOUT = 1 << 2; + /** * Returns bitfield of required JAWT OSX CALayer quirks to mediate AWT impl. bugs. *

@@ -157,6 +187,7 @@ public class JAWTUtil { *

*

*/ @@ -171,6 +202,8 @@ public class JAWTUtil { 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; + } else { + res |= JAWT_OSX_CALAYER_QUIRK_LAYOUT; } } return res; diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 6d08078b6..0d81274ca 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -110,6 +110,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { // AWT position is top-left w/ insets, where CALayer position is bottom/left from root CALayer w/o insets. // Determine p0: components location on screen w/o insets. // CALayer position will be determined in native code. + // See: {@link JAWTWindow#JAWT_OSX_CALAYER_QUIRK_LAYOUT} final Point p0 = new Point(); final Component outterComp = getLocationOnScreenNonBlocking(p0, component); final java.awt.Insets ins = AWTMisc.getInsets(outterComp); @@ -131,6 +132,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { // AWT position is top-left w/ insets, where CALayer position is bottom/left from root CALayer w/o insets. // Determine p0: components location on screen w/o insets. // CALayer position will be determined in native code. + // See: {@link JAWTWindow#JAWT_OSX_CALAYER_QUIRK_LAYOUT} final Point p0 = new Point(); final Component outterComp = getLocationOnScreenNonBlocking(p0, component); final java.awt.Insets ins = AWTMisc.getInsets(outterComp); diff --git a/src/nativewindow/native/macosx/NativeWindowProtocols.h b/src/nativewindow/native/macosx/NativeWindowProtocols.h index 73c8e65c5..98e864f8b 100644 --- a/src/nativewindow/native/macosx/NativeWindowProtocols.h +++ b/src/nativewindow/native/macosx/NativeWindowProtocols.h @@ -41,6 +41,13 @@ */ #define NW_DEDICATEDFRAME_QUIRK_POSITION ( 1 << 1 ) +/** + * CALayer position needs to be derived from AWT position. + * in relation to super CALayer. + * See detailed description in JAWTUtil.java and sync w/ changed. + */ +#define NW_DEDICATEDFRAME_QUIRK_LAYOUT ( 1 << 2 ) + #import @protocol NWDedicatedFrame diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index fa40c871f..e3844455a 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -451,13 +451,14 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0 - (void)fixCALayerLayout: (CALayer*) subLayer x:(jint)x y:(jint)y width:(jint)width height:(jint)height caLayerQuirks:(jint)caLayerQuirks force:(jboolean) force { + int loutQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_LAYOUT & caLayerQuirks ); { CALayer* superLayer = [self superlayer]; CGRect superFrame = [superLayer frame]; CGRect lFrame = [self frame]; int posQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_POSITION & caLayerQuirks ) && ( lFrame.origin.x!=0 || lFrame.origin.y!=0 ); int sizeQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_SIZE & caLayerQuirks ) && ( lFrame.size.width!=width || lFrame.size.height!=height ); - if( !posQuirk ) { + if( !posQuirk || loutQuirk ) { // Use root layer position, sub-layer will be on 0/0, // Given AWT position is location on screen w/o insets and top/left origin! fixedFrame.origin.x = x; @@ -475,12 +476,12 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0 fixedFrame.size.width = width; fixedFrame.size.height = height; } - DBG_PRINT("CALayer::FixCALayerLayout0.0: Quirks [%d, pos %d, size %d], Super %p frame %lf/%lf %lfx%lf, Root %p frame %lf/%lf %lfx%lf, usr %d/%d %dx%d -> %lf/%lf %lfx%lf\n", - caLayerQuirks, posQuirk, sizeQuirk, + DBG_PRINT("CALayer::FixCALayerLayout0.0: Quirks [%d, pos %d, size %d, lout %d], Super %p frame %lf/%lf %lfx%lf, Root %p frame %lf/%lf %lfx%lf, usr %d/%d %dx%d -> %lf/%lf %lfx%lf\n", + caLayerQuirks, posQuirk, sizeQuirk, loutQuirk, superLayer, superFrame.origin.x, superFrame.origin.y, superFrame.size.width, superFrame.size.height, self, lFrame.origin.x, lFrame.origin.y, lFrame.size.width, lFrame.size.height, x, y, width, height, fixedFrame.origin.x, fixedFrame.origin.y, fixedFrame.size.width, fixedFrame.size.height); - if( posQuirk || sizeQuirk ) { + if( posQuirk || sizeQuirk || loutQuirk ) { fixedFrameSet = 1; [super setFrame: fixedFrame]; } @@ -501,10 +502,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0 _w = width; _h = height; } - DBG_PRINT("CALayer::FixCALayerLayout1.0: Quirks [%d, pos %d, size %d], SubL %p frame %lf/%lf %lfx%lf, usr %dx%d -> %lf/%lf %lfx%lf\n", - caLayerQuirks, posQuirk, sizeQuirk, subLayer, lFrame.origin.x, lFrame.origin.y, lFrame.size.width, lFrame.size.height, + DBG_PRINT("CALayer::FixCALayerLayout1.0: Quirks [%d, pos %d, size %d, lout %d], SubL %p frame %lf/%lf %lfx%lf, usr %dx%d -> %lf/%lf %lfx%lf\n", + caLayerQuirks, posQuirk, sizeQuirk, loutQuirk, subLayer, lFrame.origin.x, lFrame.origin.y, lFrame.size.width, lFrame.size.height, width, height, _x, _y, _w, _h); - if( force || posQuirk || sizeQuirk ) { + if( force || posQuirk || sizeQuirk || loutQuirk ) { lFrame.origin.x = _x; lFrame.origin.y = _y; lFrame.size.width = _w; -- cgit v1.2.3