aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java46
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java15
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java46
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java12
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m237
5 files changed, 230 insertions, 126 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index a71356b1c..576fcf4ed 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -46,6 +46,7 @@ import java.awt.Container;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.applet.Applet;
+
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.CapabilitiesImmutable;
@@ -60,6 +61,7 @@ import javax.media.nativewindow.util.InsetsImmutable;
import javax.media.nativewindow.util.Point;
import javax.media.nativewindow.util.Rectangle;
import javax.media.nativewindow.util.RectangleImmutable;
+import javax.swing.JRootPane;
import jogamp.nativewindow.SurfaceUpdatedHelper;
import jogamp.nativewindow.jawt.JAWT;
@@ -227,9 +229,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
if( !isOffscreenLayerSurfaceEnabled() ) {
throw new NativeWindowException("Not an offscreen layer surface");
}
- if(DEBUG) {
- System.err.println("JAWTWindow.attachSurfaceHandle: "+toHexString(layerHandle) + ", bounds "+bounds);
- }
attachSurfaceLayerImpl(layerHandle);
offscreenSurfaceLayer = layerHandle;
component.repaint();
@@ -248,14 +247,14 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
* Call this method if any parent or ancestor's layout has been changed,
* which could affects the layout of this surface.
* </p>
- * @see #isOffscreenLayerSurfaceEnabled()
+ * @see #isOffscreenLayerSurfaceEnabled()
* @throws NativeWindowException if {@link #isOffscreenLayerSurfaceEnabled()} == false
*/
- protected void layoutSurfaceLayerImpl(long layerHandle, int width, int height) {}
+ protected void layoutSurfaceLayerImpl(long layerHandle) {}
private final void layoutSurfaceLayerIfEnabled() throws NativeWindowException {
if( isOffscreenLayerSurfaceEnabled() && 0 != offscreenSurfaceLayer ) {
- layoutSurfaceLayerImpl(offscreenSurfaceLayer, getWidth(), getHeight());
+ layoutSurfaceLayerImpl(offscreenSurfaceLayer);
}
}
@@ -533,7 +532,11 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
System.err.println("Warning: JAWT Lock hold, but not the AWT tree lock: "+this);
Thread.dumpStack();
}
- return getLocationOnScreenNonBlocking(storage, component);
+ if( null == storage ) {
+ storage = new Point();
+ }
+ getLocationOnScreenNonBlocking(storage, component);
+ return storage;
}
java.awt.Point awtLOS = component.getLocationOnScreen();
if(null!=storage) {
@@ -569,21 +572,28 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
protected abstract Point getLocationOnScreenNativeImpl(int x, int y);
- protected static Point getLocationOnScreenNonBlocking(Point storage, Component comp) {
- int x = 0;
- int y = 0;
+ protected static Component getLocationOnScreenNonBlocking(Point storage, Component comp) {
+ Component last = null;
while(null != comp) {
- x += comp.getX();
- y += comp.getY();
+ final int dx = comp.getX();
+ final int dy = comp.getY();
+ if( ! ( comp instanceof JRootPane ) ) {
+ if( DEBUG ) {
+ System.err.print("LOS: "+storage+" + "+comp.getClass().getSimpleName()+"["+dx+"/"+dy+"] -> ");
+ }
+ storage.translate(dx, dy);
+ if( DEBUG ) {
+ System.err.println(storage);
+ }
+ last = comp;
+ } else if( DEBUG ) {
+ System.err.println("LOS: ignore "+comp.getClass().getSimpleName()+"["+dx+"/"+dy+"]");
+ }
comp = comp.getParent();
}
- if(null!=storage) {
- storage.translate(x, y);
- return storage;
- }
- return new Point(x, y);
+ return last;
}
-
+
@Override
public boolean hasFocus() {
return component.hasFocus();
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
index f38e7ea2b..e326b65bd 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
@@ -28,13 +28,16 @@
package jogamp.nativewindow.awt;
import java.awt.FocusTraversalPolicy;
+import java.awt.Insets;
import java.awt.Window;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
+
+import javax.swing.JComponent;
import javax.swing.JFrame;
+import javax.swing.JRootPane;
import javax.swing.WindowConstants;
-
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.WindowClosingProtocol;
import javax.swing.MenuSelectionManager;
@@ -68,6 +71,16 @@ public class AWTMisc {
}
return (Container) c;
}
+
+ public static Insets getInsets(Component c) {
+ if( c instanceof Window ) {
+ return ((Window)c).getInsets();
+ }
+ if( c instanceof JComponent ) {
+ return ((JComponent)c).getInsets();
+ }
+ return null;
+ }
public static interface ComponentAction {
/**
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index 666f895f4..6d08078b6 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -40,6 +40,7 @@
package jogamp.nativewindow.jawt.macosx;
+import java.awt.Component;
import java.nio.Buffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -49,11 +50,11 @@ 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;
+import jogamp.nativewindow.awt.AWTMisc;
import jogamp.nativewindow.jawt.JAWT;
import jogamp.nativewindow.jawt.JAWTFactory;
import jogamp.nativewindow.jawt.JAWTUtil;
@@ -105,19 +106,42 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
@Override
protected void attachSurfaceLayerImpl(final long layerHandle) {
OSXUtil.RunOnMainThread(false, new Runnable() {
- public void run() {
- OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, getWidth(), getHeight(), JAWTUtil.getOSXCALayerQuirks());
+ public void run() {
+ // 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.
+ final Point p0 = new Point();
+ final Component outterComp = getLocationOnScreenNonBlocking(p0, component);
+ final java.awt.Insets ins = AWTMisc.getInsets(outterComp);
+ if(null != ins) {
+ p0.translate(-ins.left, -ins.top);
+ }
+ if( DEBUG ) {
+ final java.awt.Point wP0 = outterComp.getLocationOnScreen();
+ System.err.println("JAWTWindow.attachSurfaceHandleImpl: "+toHexString(layerHandle) + ", wP0 "+wP0+"[ins "+ins+"], p0 "+p0+", bounds "+bounds);
+ }
+ OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p0.getX(), p0.getY(), getWidth(), getHeight(), JAWTUtil.getOSXCALayerQuirks());
} } );
}
@Override
- protected void layoutSurfaceLayerImpl(long layerHandle, int width, int height) {
+ protected void layoutSurfaceLayerImpl(long layerHandle) {
final int caLayerQuirks = JAWTUtil.getOSXCALayerQuirks();
if( 0 != caLayerQuirks ) {
- if(DEBUG) {
- System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", "+width+"x"+height+", caLayerQuirks "+caLayerQuirks+"; "+this);
+ // 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.
+ final Point p0 = new Point();
+ final Component outterComp = getLocationOnScreenNonBlocking(p0, component);
+ final java.awt.Insets ins = AWTMisc.getInsets(outterComp);
+ if( null != ins ) {
+ p0.translate(-ins.left, -ins.top);
}
- OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, width, height, caLayerQuirks);
+ if( DEBUG ) {
+ final java.awt.Point wP0 = outterComp.getLocationOnScreen();
+ System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", wP0 "+wP0+"[ins "+ins+"], p0 "+p0+", bounds "+bounds);
+ }
+ OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, p0.getX(), p0.getY(), getWidth(), getHeight(), caLayerQuirks);
}
}
@@ -312,8 +336,12 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
* </p>
*/
@Override
- public Point getLocationOnScreen(Point storage) {
- return getLocationOnScreenNonBlocking(storage, component);
+ public Point getLocationOnScreen(Point storage) {
+ if( null == storage ) {
+ storage = new Point();
+ }
+ getLocationOnScreenNonBlocking(storage, component);
+ return storage;
}
protected Point getLocationOnScreenNativeImpl(final int x0, final int y0) { return null; }
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index de24a76db..2112131ed 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -163,14 +163,14 @@ public class OSXUtil implements ToolkitProperties {
* @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, final int caLayerQuirks) {
+ public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int x, final int y, 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: caLayerQuirks "+caLayerQuirks+", 0x"+Long.toHexString(subCALayer)+" - "+Thread.currentThread().getName());
}
- AddCASublayer0(rootCALayer, subCALayer, width, height, caLayerQuirks);
+ AddCASublayer0(rootCALayer, subCALayer, x, y, width, height, caLayerQuirks);
}
/**
@@ -190,11 +190,11 @@ public class OSXUtil implements ToolkitProperties {
* @param height the expected height
* @param caLayerQuirks TODO
*/
- public static void FixCALayerLayout(final long rootCALayer, final long subCALayer, final int width, final int height, final int caLayerQuirks) {
+ public static void FixCALayerLayout(final long rootCALayer, final long subCALayer, final int x, final int y, final int width, final int height, final int caLayerQuirks) {
if( 0==rootCALayer && 0==subCALayer ) {
return;
}
- FixCALayerLayout0(rootCALayer, subCALayer, width, height, caLayerQuirks);
+ FixCALayerLayout0(rootCALayer, subCALayer, x, y, width, height, caLayerQuirks);
}
/**
@@ -357,8 +357,8 @@ public class OSXUtil implements ToolkitProperties {
private static native long GetNSView0(long nsWindow);
private static native long GetNSWindow0(long nsView);
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 AddCASublayer0(long rootCALayer, long subCALayer, int x, int y, int width, int height, int caLayerQuirks);
+ private static native void FixCALayerLayout0(long rootCALayer, long subCALayer, int x, int y, 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);
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index fbe37be7d..fa40c871f 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -333,6 +333,9 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0
*/
@interface MyCALayer: CALayer
{
+@private
+ BOOL fixedFrameSet;
+ CGRect fixedFrame;
}
- (id)init;
#ifdef DBG_LIFECYCLE
@@ -341,6 +344,9 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0
- (void)dealloc;
#endif
- (id<CAAction>)actionForKey:(NSString *)key ;
+- (void)layoutSublayers;
+- (void)setFrame:(CGRect) frame;
+- (void)fixCALayerLayout: (CALayer*) subLayer x:(jint)x y:(jint)y width:(jint)width height:(jint)height caLayerQuirks:(jint)caLayerQuirks force:(jboolean) force;
@end
@@ -350,6 +356,8 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0
{
DBG_PRINT("MyCALayer::init.0\n");
MyCALayer * o = [super init];
+ o->fixedFrameSet = 0;
+ o->fixedFrame = CGRectMake(0, 0, 0, 0);
DBG_PRINT("MyCALayer::init.X: new %p\n", o);
return o;
}
@@ -390,6 +398,127 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0
// return [super actionForKey: key];
}
+- (void)layoutSublayers
+{
+ if( fixedFrameSet ) {
+ NSArray* subs = [self sublayers];
+ if( NULL != subs ) {
+ CGRect rFrame = [self frame];
+ if( !CGRectEqualToRect(fixedFrame, rFrame) ) {
+ #ifdef VERBOSE
+ DBG_PRINT("CALayer::layoutSublayers.0: Root %p frame %lf/%lf %lfx%lf -> %lf/%lf %lfx%lf\n",
+ self,
+ rFrame.origin.x, rFrame.origin.y, rFrame.size.width, rFrame.size.height,
+ fixedFrame.origin.x, fixedFrame.origin.y, fixedFrame.size.width, fixedFrame.size.height);
+ #endif
+ [super setFrame: fixedFrame];
+ }
+ NSUInteger i = 0;
+ for(i=0; i<[subs count]; i++) {
+ CALayer* sub = [subs objectAtIndex: i];
+ CGRect sFrame = [sub frame];
+ CGRect sFrame2 = CGRectMake(0, 0, fixedFrame.size.width, fixedFrame.size.height);
+ if( !CGRectEqualToRect(sFrame2, sFrame) ) {
+ #ifdef VERBOSE
+ DBG_PRINT("CALayer::layoutSublayers.1: Sub[%d] %p frame %lf/%lf %lfx%lf -> %lf/%lf %lfx%lf\n",
+ (int)i, sub,
+ sFrame.origin.x, sFrame.origin.y, sFrame.size.width, sFrame.size.height,
+ sFrame2.origin.x, sFrame2.origin.y, sFrame2.size.width, sFrame2.size.height);
+ #endif
+ [sub setFrame: sFrame2];
+ }
+ #ifdef VERBOSE
+ DBG_PRINT("CALayer::layoutSublayers.X: Root %p . Sub[%d] %p : frame r: %lf/%lf %lfx%lf . s: %lf/%lf %lfx%lf\n",
+ self, (int)i, sub,
+ rFrame.origin.x, rFrame.origin.y, rFrame.size.width, rFrame.size.height,
+ sFrame.origin.x, sFrame.origin.y, sFrame.size.width, sFrame.size.height);
+ #endif
+ }
+ }
+ } else {
+ [super layoutSublayers];
+ }
+}
+
+- (void) setFrame:(CGRect) frame
+{
+ if( fixedFrameSet ) {
+ [super setFrame: fixedFrame];
+ } else {
+ [super setFrame: frame];
+ }
+}
+
+- (void)fixCALayerLayout: (CALayer*) subLayer x:(jint)x y:(jint)y width:(jint)width height:(jint)height caLayerQuirks:(jint)caLayerQuirks force:(jboolean) force
+{
+ {
+ 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 ) {
+ // 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;
+ fixedFrame.origin.y = superFrame.size.height - height - y; // AWT's position top/left -> bottom/left
+ posQuirk |= 8;
+ } else {
+ // Buggy super layer position, always use 0/0
+ fixedFrame.origin.x = 0;
+ fixedFrame.origin.y = 0;
+ }
+ if( !sizeQuirk ) {
+ fixedFrame.size.width = lFrame.size.width;
+ fixedFrame.size.height = lFrame.size.height;
+ } else {
+ 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,
+ 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 ) {
+ fixedFrameSet = 1;
+ [super setFrame: fixedFrame];
+ }
+ }
+ if( NULL != subLayer ) {
+ CGRect lFrame = [subLayer frame];
+ int sizeQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_SIZE & caLayerQuirks ) && ( lFrame.size.width!=width || lFrame.size.height!=height );
+ CGFloat _x, _y, _w, _h;
+ int posQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_POSITION & caLayerQuirks ) && ( lFrame.origin.x!=0 || lFrame.origin.y!=0 );
+ // Sub rel. to used root layer
+ _x = 0;
+ _y = 0;
+ posQuirk |= 8;
+ if( !sizeQuirk ) {
+ _w = lFrame.size.width;
+ _h = lFrame.size.height;
+ } else {
+ _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,
+ width, height, _x, _y, _w, _h);
+ if( force || posQuirk || sizeQuirk ) {
+ lFrame.origin.x = _x;
+ lFrame.origin.y = _y;
+ lFrame.size.width = _w;
+ lFrame.size.height = _h;
+ if( [subLayer conformsToProtocol:@protocol(NWDedicatedFrame)] ) {
+ CALayer <NWDedicatedFrame> * subLayerDS = (CALayer <NWDedicatedFrame> *) subLayer;
+ [subLayerDS setDedicatedFrame: lFrame quirks: caLayerQuirks];
+ } else {
+ [subLayer setFrame: lFrame];
+ }
+ }
+ }
+}
+
@end
/*
@@ -409,98 +538,32 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_CreateCALayer0
if(0 == height) { height = 32; }
// initial dummy size !
- CGRect lRect = [layer frame];
- lRect.origin.x = 0;
- lRect.origin.y = 0;
- lRect.size.width = width;
- lRect.size.height = height;
- [layer setFrame: lRect];
+ CGRect lFrame = [layer frame];
+ lFrame.origin.x = 0;
+ lFrame.origin.y = 0;
+ lFrame.size.width = width;
+ lFrame.size.height = height;
+ [layer setFrame: lFrame];
// no animations for add/remove/swap sublayers etc
// doesn't work: [layer removeAnimationForKey: kCAOnOrderIn, kCAOnOrderOut, kCATransition]
[layer removeAllAnimations];
// [layer addAnimation:nil forKey:kCATransition];
[layer setAutoresizingMask: (kCALayerWidthSizable|kCALayerHeightSizable)];
[layer setNeedsDisplayOnBoundsChange: YES];
- DBG_PRINT("CALayer::CreateCALayer.1: root %p %lf/%lf %lfx%lf\n", layer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ DBG_PRINT("CALayer::CreateCALayer.1: root %p %lf/%lf %lfx%lf\n", layer, lFrame.origin.x, lFrame.origin.y, lFrame.size.width, lFrame.size.height);
[pool release];
DBG_PRINT("CALayer::CreateCALayer.X: root %p (refcnt %d)\n", layer, (int)[layer retainCount]);
return (jlong) ((intptr_t) layer);
}
-static void FixCALayerLayout0(MyCALayer* rootLayer, CALayer* subLayer, jint width, jint height, jint caLayerQuirks, jboolean force) {
- if( NULL != rootLayer ) {
- CGRect lRect = [rootLayer frame];
- int posQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_POSITION & caLayerQuirks ) && ( lRect.origin.x!=0 || lRect.origin.y!=0 );
- int sizeQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_SIZE & caLayerQuirks ) && ( lRect.size.width!=width || lRect.size.height!=height );
- CGFloat _x, _y, _w, _h;
- // force root -> 0/0
- _x = 0;
- _y = 0;
- posQuirk |= 8;
- if( sizeQuirk ) {
- _w = width;
- _h = height;
- } else {
- _w = lRect.size.width;
- _h = lRect.size.height;
- }
- DBG_PRINT("CALayer::FixCALayerLayout0.0: Quirks [%d, pos %d, size %d], Root %p frame %lf/%lf %lfx%lf, usr %dx%d -> %lf/%lf %lfx%lf\n",
- caLayerQuirks, posQuirk, sizeQuirk, rootLayer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height,
- width, height, _x, _y, _w, _h);
- if( posQuirk || sizeQuirk ) {
- lRect.origin.x = _x;
- lRect.origin.y = _y;
- lRect.size.width = _w;
- lRect.size.height = _h;
- [rootLayer setFrame: lRect];
- }
- }
- if( NULL != subLayer ) {
- CGRect lRect = [subLayer frame];
- int sizeQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_SIZE & caLayerQuirks ) && ( lRect.size.width!=width || lRect.size.height!=height );
- CGFloat _x, _y, _w, _h;
- int posQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_POSITION & caLayerQuirks ) && ( lRect.origin.x!=0 || lRect.origin.y!=0 );
- if( posQuirk ) {
- _x = 0;
- _y = 0;
- } else {
- // sub always rel to root
- _x = lRect.origin.x;
- _y = lRect.origin.y;
- }
- if( sizeQuirk ) {
- _w = width;
- _h = height;
- } else {
- _w = lRect.size.width;
- _h = lRect.size.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, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height,
- width, height, _x, _y, _w, _h);
- if( force || posQuirk || sizeQuirk ) {
- lRect.origin.x = _x;
- lRect.origin.y = _y;
- lRect.size.width = _w;
- lRect.size.height = _h;
- if( [subLayer conformsToProtocol:@protocol(NWDedicatedFrame)] ) {
- CALayer <NWDedicatedFrame> * subLayerDS = (CALayer <NWDedicatedFrame> *) subLayer;
- [subLayerDS setDedicatedFrame: lRect quirks: caLayerQuirks];
- } else {
- [subLayer setFrame: lRect];
- }
- }
- }
-}
-
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: AddCASublayer0
* Signature: (JJIIIII)V
*/
JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
- (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint width, jint height, jint caLayerQuirks)
+ (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint x, jint y, jint width, jint height, jint caLayerQuirks)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
MyCALayer* rootLayer = (MyCALayer*) ((intptr_t) rootCALayer);
@@ -513,23 +576,10 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
[subLayer retain]; // Pairs w/ RemoveCASublayer
CGRect lRectRoot = [rootLayer frame];
- int posQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_POSITION & caLayerQuirks );
- int sizeQuirk = 0 != ( NW_DEDICATEDFRAME_QUIRK_SIZE & caLayerQuirks );
-
- DBG_PRINT("CALayer::AddCASublayer0.0: Quirks [%d, pos %d, size %d], Root %p (refcnt %d), Sub %p (refcnt %d), frame0: %lf/%lf %lfx%lf\n",
- caLayerQuirks, posQuirk, sizeQuirk, rootLayer, (int)[rootLayer retainCount], subLayer, (int)[subLayer retainCount],
+ DBG_PRINT("CALayer::AddCASublayer0.0: Quirks %d, Root %p (refcnt %d), Sub %p (refcnt %d), frame0: %lf/%lf %lfx%lf\n",
+ caLayerQuirks, rootLayer, (int)[rootLayer retainCount], subLayer, (int)[subLayer retainCount],
lRectRoot.origin.x, lRectRoot.origin.y, lRectRoot.size.width, lRectRoot.size.height);
- CGPoint origin = lRectRoot.origin; // save
- // force root to 0/0
- lRectRoot.origin.x = 0;
- lRectRoot.origin.y = 0;
- [rootLayer setFrame: lRectRoot];
-
- // simple 1:1 layout rel. to root-layer !
- if( !posQuirk ) {
- lRectRoot.origin = origin;
- }
[subLayer setFrame:lRectRoot];
[rootLayer addSublayer:subLayer];
@@ -545,7 +595,7 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
[subLayer setNeedsDisplayOnBoundsChange: YES];
if( 0 != caLayerQuirks ) {
- FixCALayerLayout0(rootLayer, subLayer, width, height, caLayerQuirks, JNI_TRUE);
+ [rootLayer fixCALayerLayout: subLayer x:x y:y width:width height:height caLayerQuirks:caLayerQuirks force:JNI_TRUE];
}
[CATransaction commit];
@@ -561,17 +611,20 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
* Signature: (JJIII)V
*/
JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_FixCALayerLayout0
- (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint width, jint height, jint caLayerQuirks)
+ (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint x, jint y, jint width, jint height, jint caLayerQuirks)
{
if( 0 != caLayerQuirks ) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
MyCALayer* rootLayer = (MyCALayer*) ((intptr_t) rootCALayer);
+ if( NULL == rootLayer ) {
+ NativewindowCommon_throwNewRuntimeException(env, "Argument \"rootLayer\" is null");
+ }
CALayer* subLayer = (CALayer*) ((intptr_t) subCALayer);
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
- FixCALayerLayout0(rootLayer, subLayer, width, height, caLayerQuirks, JNI_FALSE);
+ [rootLayer fixCALayerLayout: subLayer x:x y:y width:width height:height caLayerQuirks:caLayerQuirks force:JNI_FALSE];
[CATransaction commit];