aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-02-20 21:51:40 +0100
committerSven Gothel <[email protected]>2013-02-20 21:51:40 +0100
commit14b278536e6f8de2ee6254796b89bd27d5419b72 (patch)
tree0f4ec76f215cbba178eb6732c1f2a9363df9d6d5 /src/nativewindow/classes
parentcf3ecdb670c0dfecd1394d5b9d5d5588c1bf71f3 (diff)
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.
Diffstat (limited to 'src/nativewindow/classes')
-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
4 files changed, 66 insertions, 6 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);