From 14b278536e6f8de2ee6254796b89bd27d5419b72 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 20 Feb 2013 21:51:40 +0100 Subject: OSX/Java7/CALayer + JAWT: Partially Fix AWT/NEWT CALayer 'out of sight' bug, where our CALayer is moved out of the visible area - same erroneous behavior for GLCanvas and NewtCanvasAWT - sized-frame: Set framesize and validate() it - sized-component: Set component preferred size and call frame.pack() - added workaround 'OffscreenLayerSurface.layoutSurfaceLayer()' to fix CALayer size, which snaps for: - OK initial size before setVisible: sized-frame and sized-component - OK resize w/ sized-frame - OK manual frame resize - Invisible: w/ sized-component after setVisible() ++ - CALayer-Sublayer (GL) has additional retain/release when added/removed to be on safe side. --- .../com/jogamp/nativewindow/awt/JAWTWindow.java | 15 +++++++++-- .../media/nativewindow/OffscreenLayerSurface.java | 15 +++++++++++ .../nativewindow/jawt/macosx/MacOSXJAWTWindow.java | 12 ++++++++- .../jogamp/nativewindow/macosx/OSXUtil.java | 30 +++++++++++++++++++--- 4 files changed, 66 insertions(+), 6 deletions(-) (limited to 'src/nativewindow/classes') 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; @@ -215,6 +215,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() ) { 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. + *

+ * This method allows triggering a re-layout of the offscreen surface + * in case the implementation requires it. + *

+ *

+ * Call this method if any parent or ancestor's layout has been changed, + * which could affects the layout of this surface. + *

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

* Method will trigger a display * 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. + *

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

+ * + * @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); -- cgit v1.2.3