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.java15
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java15
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java12
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java30
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m57
5 files changed, 121 insertions, 8 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index 007a917a6..d65f8c231 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -130,7 +130,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
if(changed) {
if(DEBUG) {
System.err.println("JAWTWindow.updateBounds: "+bounds+" -> "+jb);
- Thread.dumpStack();
+ // Thread.dumpStack();
}
bounds.setX(jawtBounds.getX());
bounds.setY(jawtBounds.getY());
@@ -205,7 +205,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
try {
if(DEBUG) {
- System.err.println("JAWTWindow.attachSurfaceHandle(): "+toHexString(layerHandle) + ", bounds "+bounds);
+ System.err.println("JAWTWindow.attachSurfaceHandle: "+toHexString(layerHandle) + ", bounds "+bounds);
}
attachSurfaceLayerImpl(layerHandle);
offscreenSurfaceLayer = layerHandle;
@@ -216,6 +216,17 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
protected abstract void attachSurfaceLayerImpl(final long layerHandle);
@Override
+ public void layoutSurfaceLayer() throws NativeWindowException {
+ if( !isOffscreenLayerSurfaceEnabled() ) {
+ throw new NativeWindowException("Not an offscreen layer surface");
+ }
+ if( 0 != offscreenSurfaceLayer) {
+ layoutSurfaceLayerImpl();
+ }
+ }
+ protected void layoutSurfaceLayerImpl() {}
+
+ @Override
public final void detachSurfaceLayer() throws NativeWindowException {
if( !isOffscreenLayerSurfaceEnabled() ) {
throw new java.lang.UnsupportedOperationException("Not an offscreen layer surface");
diff --git a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
index ba60a7f38..4885d5a4c 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
@@ -46,6 +46,21 @@ public interface OffscreenLayerSurface {
*/
public void attachSurfaceLayer(final long layerHandle) throws NativeWindowException;
+ /**
+ * Layout the offscreen layer according to the implementing class's constraints.
+ * <p>
+ * This method allows triggering a re-layout of the offscreen surface
+ * in case the implementation requires it.
+ * </p>
+ * <p>
+ * Call this method if any parent or ancestor's layout has been changed,
+ * which could affects the layout of this surface.
+ * </p>
+ * @see #isOffscreenLayerSurfaceEnabled()
+ * @throws NativeWindowException if {@link #isOffscreenLayerSurfaceEnabled()} == false
+ */
+ public void layoutSurfaceLayer() throws NativeWindowException;
+
/**
* Detaches a previously attached offscreen layer from this offscreen layer surface.
* @see #attachSurfaceLayer(long)
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index 9b06cce1a..b25836d3c 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -118,10 +118,20 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
OSXUtil.AddCASublayer(rootSurfaceLayerHandle, layerHandle);
}
+ protected void layoutSurfaceLayerImpl() {
+ final long osl = getAttachedSurfaceLayer();
+ final int w = getWidth();
+ final int h = getHeight();
+ if(DEBUG) {
+ System.err.println("JAWTWindow.fixSurfaceLayerLayout: "+toHexString(osl) + ", bounds "+bounds+", "+w+"x"+h);
+ }
+ OSXUtil.FixCALayerPosition(rootSurfaceLayerHandle, osl, w, h);
+ }
+
protected void detachSurfaceLayerImpl(final long layerHandle) {
OSXUtil.RemoveCASublayer(rootSurfaceLayerHandle, layerHandle);
}
-
+
@Override
public final long getWindowHandle() {
return windowHandle;
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index d85d1a84b..5ff451cc0 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -149,7 +149,7 @@ public class OSXUtil implements ToolkitProperties {
}
/**
- * Attach a sub CALayer to the root CALayer on the main-thread.
+ * Attach a sub CALayer to the root CALayer on the main-thread w/ blocking.
* <p>
* Method will trigger a <code>display</code>
* call to the CALayer hierarchy to enforce resource creation if required, e.g. an NSOpenGLContext.
@@ -173,7 +173,30 @@ public class OSXUtil implements ToolkitProperties {
}
/**
- * Detach a sub CALayer from the root CALayer on the main-thread.
+ * Fix root and sub CALayer position to 0/0 on the main-thread w/o blocking.
+ * <p>
+ * For an unknown reason, on OSX/Java7 our root CALayer's frame position gets corrupted
+ * and is moved out of 'sight' .. or oddly half way to the upper right corner.
+ * </p>
+ *
+ * @param rootCALayer the root surface layer, maybe null.
+ * @param subCALayer the client surface layer, maybe null.
+ * @param width the expected width
+ * @param height the expected height
+ */
+ public static void FixCALayerPosition(final long rootCALayer, final long subCALayer, final int width, final int height) {
+ if( 0==rootCALayer && 0==subCALayer ) {
+ return;
+ }
+ RunOnMainThread(false, new Runnable() {
+ public void run() {
+ FixCALayerPosition0(rootCALayer, subCALayer, width, height);
+ }
+ });
+ }
+
+ /**
+ * Detach a sub CALayer from the root CALayer on the main-thread w/ blocking.
*/
public static void RemoveCASublayer(final long rootCALayer, final long subCALayer) {
if(0==rootCALayer || 0==subCALayer) {
@@ -186,7 +209,7 @@ public class OSXUtil implements ToolkitProperties {
}
/**
- * Destroy a CALayer on the main-thread.
+ * Destroy a CALayer on the main-thread w/ blocking.
* @see #CreateCALayer(int, int, int, int)
*/
public static void DestroyCALayer(final long caLayer) {
@@ -323,6 +346,7 @@ public class OSXUtil implements ToolkitProperties {
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);
+ private static native void FixCALayerPosition0(long rootCALayer, long subCALayer, int width, int height);
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 4c07b4df7..28e63e875 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -429,11 +429,13 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
MyCALayer* rootLayer = (MyCALayer*) ((intptr_t) rootCALayer);
CALayer* subLayer = (CALayer*) ((intptr_t) subCALayer);
+ [subLayer retain]; // Pairs w/ RemoveCASublayer
+
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
CGRect lRectRoot = [rootLayer frame];
- DBG_PRINT("CALayer::AddCASublayer0.0: Origin %p frame0: %lf/%lf %lfx%lf\n",
+ DBG_PRINT("CALayer::AddCASublayer0.0: Origin %p frame0: %lf/%lf %lfx%lf\n",
rootLayer, lRectRoot.origin.x, lRectRoot.origin.y, lRectRoot.size.width, lRectRoot.size.height);
if(lRectRoot.origin.x!=0 || lRectRoot.origin.y!=0) {
lRectRoot.origin.x = 0;
@@ -476,6 +478,57 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: FixCALayerPosition0
+ * Signature: (JJII)V
+ */
+JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_FixCALayerPosition0
+ (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint width, jint height)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ MyCALayer* rootLayer = (MyCALayer*) ((intptr_t) rootCALayer);
+ CALayer* subLayer = (CALayer*) ((intptr_t) subCALayer);
+
+ [CATransaction begin];
+ [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
+
+ if( NULL != rootLayer ) {
+ CGRect lRect = [rootLayer frame];
+ DBG_PRINT("CALayer::FixCALayerPosition0.0: Root Origin %p exp 0/0 %dx%d frame0: %lf/%lf %lfx%lf\n",
+ rootLayer, width, height, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ if(lRect.origin.x!=0 || lRect.origin.y!=0 || lRect.size.width!=width || lRect.size.height!=height) {
+ lRect.origin.x = 0;
+ lRect.origin.y = 0;
+ lRect.size.width = width;
+ lRect.size.height = height;
+ [rootLayer setFrame: lRect];
+ DBG_PRINT("CALayer::FixCALayerPosition0.1: Root Origin %p frame*: %lf/%lf %lfx%lf\n",
+ rootLayer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ }
+ }
+ if( NULL != subLayer ) {
+ CGRect lRect = [subLayer frame];
+ DBG_PRINT("CALayer::FixCALayerPosition0.0: SubL %p exp 0/0 %dx%d frame0: %lf/%lf %lfx%lf\n",
+ subLayer, width, height, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ if(lRect.origin.x!=0 || lRect.origin.y!=0 || lRect.size.width!=width || lRect.size.height!=height) {
+ lRect.origin.x = 0;
+ lRect.origin.y = 0;
+ lRect.size.width = width;
+ lRect.size.height = height;
+ [subLayer setFrame: lRect];
+ DBG_PRINT("CALayer::FixCALayerPosition0.1: SubL Origin %p frame*: %lf/%lf %lfx%lf\n",
+ subLayer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ }
+ }
+
+ [CATransaction commit];
+
+ [pool release];
+ DBG_PRINT("CALayer::FixCALayerPosition0.X: root %p (refcnt %d) .sub %p (refcnt %d)\n",
+ rootLayer, (int)[rootLayer retainCount], subLayer, (int)[subLayer retainCount]);
+}
+
+/*
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: RemoveCASublayer0
* Signature: (JJ)V
*/
@@ -495,7 +548,7 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RemoveCASublayer0
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
[subLayer removeFromSuperlayer];
- // [subLayer release] is called explicitly, e.g. via CGL.releaseNSOpenGLLayer(..) (MyNSOpenGLLayer::releaseLayer)
+ [subLayer release]; // Pairs w/ AddCASublayer
[CATransaction commit];