From dd705f1eb14b87b207e375ea0d71e00155a9933f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 14 Mar 2013 11:26:10 +0100 Subject: OSX/CALayer: Simplify FixCALayerLayout()/layoutSurfaceLayer() call, no more need for explicit call - OffscreenLayerSurface.layoutSurfaceLayer() removed, no more required - JAWTWindow adds a ComponentListener, which issues FixCALayerLayout() at resized, moved and shown. - MyNSOpenGLLayer no more requires fix*Size() methods - MyNSOpenGLLayer::setDedicatedSize() need no explicit CATransaction, performed by caller. --- .../classes/javax/media/opengl/awt/GLCanvas.java | 8 ++- .../macosx/MacOSXWindowSystemInterface-calayer.m | 63 +--------------------- .../com/jogamp/nativewindow/awt/JAWTWindow.java | 46 +++++++++++++--- .../media/nativewindow/OffscreenLayerSurface.java | 15 ------ .../nativewindow/jawt/macosx/MacOSXJAWTWindow.java | 2 +- .../jogamp/nativewindow/macosx/OSXUtil.java | 3 +- .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 3 -- 7 files changed, 46 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 63c18db5d..278e2dc37 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -434,8 +434,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing _lock.lock(); try { final GLDrawable _drawable = drawable; - if( null == _drawable || realized && ( 0 >= _drawable.getWidth() || 0 >= _drawable.getHeight() ) ) { - return; + if( null == _drawable || realized == _drawable.isRealized() || + realized && ( 0 >= _drawable.getWidth() || 0 >= _drawable.getHeight() ) ) { + return; } _drawable.setRealized(realized); if( realized && _drawable.isRealized() ) { @@ -705,9 +706,6 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } } sendReshape = true; // async if display() doesn't get called below, but avoiding deadlock - if(null != jawtWindow && jawtWindow.isOffscreenLayerSurfaceEnabled() ) { - jawtWindow.layoutSurfaceLayer(); - } } } } diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m index f93f15241..125ca8af8 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m @@ -192,8 +192,6 @@ extern GLboolean glIsVertexArray (GLuint array); - (void) applyNewPBuffer; - (void)setDedicatedSize:(CGSize)size; // @NWDedicatedSize -- (CGRect)fixMyFrame; -- (CGRect)fixSuperPosition; - (id)actionForKey:(NSString *)key ; - (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask; - (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat; @@ -364,14 +362,6 @@ static const GLfloat gl_verts[] = { if(_texHeight != texHeight || _texWidth != texWidth) { texWidth = _texWidth; texHeight = _texHeight; - /** - CGRect lRect = [self bounds]; - lRect.origin.x = 0; - lRect.origin.y = 0; - lRect.size.width = texWidth; - lRect.size.height = texHeight; - [self setFrame: lRect]; */ - CGRect lRect = [self fixMyFrame]; GLfloat texCoordWidth, texCoordHeight; if(NULL != pbuffer) { @@ -394,13 +384,13 @@ static const GLfloat gl_verts[] = { gl_texCoords[4] = texCoordWidth; gl_texCoords[6] = texCoordWidth; #ifdef VERBOSE_ON + CGRect lRect = [self bounds]; DBG_PRINT("MyNSOpenGLLayer::validateTexSize %p -> tex %dx%d, bounds: %lf/%lf %lfx%lf\n", self, texWidth, texHeight, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height); #endif return YES; } else { - [self fixMyFrame]; return NO; } } @@ -549,16 +539,11 @@ static const GLfloat gl_verts[] = { DBG_PRINT("MyNSOpenGLLayer::setDedicatedSize: %p, texSize %dx%d <- %lfx%lf\n", self, texWidth, texHeight, size.width, size.height); - [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; - dedicatedWidth = size.width; dedicatedHeight = size.height; CGRect rect = CGRectMake(0, 0, dedicatedWidth, dedicatedHeight); [self setFrame: rect]; - - [CATransaction commit]; } - (void) setFrame:(CGRect) frame { @@ -566,52 +551,6 @@ static const GLfloat gl_verts[] = { [super setFrame: rect]; } -- (CGRect)fixMyFrame -{ - CGRect lRect = [self frame]; - - // With Java7 our root CALayer's frame gets off-limit -> force 0/0 origin! - if( lRect.origin.x!=0 || lRect.origin.y!=0 || lRect.size.width!=texWidth || lRect.size.height!=texHeight) { - DBG_PRINT("MyNSOpenGLLayer::fixMyFrame: %p, 0/0 texSize %dx%d -> Frame[%lf/%lf %lfx%lf]\n", - self, texWidth, texHeight, - lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height); - - [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; - - lRect.origin.x = 0; - lRect.origin.y = 0; - lRect.size.width=texWidth; - lRect.size.height=texHeight; - [self setFrame: lRect]; - - [CATransaction commit]; - } - return lRect; -} - -- (CGRect)fixSuperPosition -{ - CALayer * superL = [self superlayer]; - CGRect lRect = [superL frame]; - - // With Java7 our root CALayer's frame gets off-limit -> force 0/0 origin! - if( lRect.origin.x!=0 || lRect.origin.y!=0 ) { - DBG_PRINT("MyNSOpenGLLayer::fixSuperPosition: %p, 0/0 -> Super Frame[%lf/%lf %lfx%lf]\n", - self, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height); - - [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; - - lRect.origin.x = 0; - lRect.origin.y = 0; - [superL setPosition: lRect.origin]; - - [CATransaction commit]; - } - return lRect; -} - - (id)actionForKey:(NSString *)key { DBG_PRINT("MyNSOpenGLLayer::actionForKey.0 %p key %s -> NIL\n", self, [key UTF8String]); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 99b629d1a..3e5e629b6 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -43,6 +43,8 @@ import com.jogamp.nativewindow.MutableGraphicsConfiguration; import java.awt.Component; 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; @@ -110,6 +112,25 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, this.component = windowObject; this.isApplet = false; this.offscreenSurfaceLayer = 0; + this.component.addComponentListener(new ComponentListener() { + @Override + public void componentResized(ComponentEvent e) { + layoutSurfaceLayerIfEnabled(); + } + + @Override + public void componentMoved(ComponentEvent e) { + layoutSurfaceLayerIfEnabled(); + } + + @Override + public void componentShown(ComponentEvent e) { + layoutSurfaceLayerIfEnabled(); + } + + @Override + public void componentHidden(ComponentEvent e) { } + }); } protected synchronized void invalidate() { @@ -215,16 +236,27 @@ 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) { + /** + * 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 + */ + protected void layoutSurfaceLayerImpl() {} + + private final void layoutSurfaceLayerIfEnabled() throws NativeWindowException { + if( isOffscreenLayerSurfaceEnabled() && 0 != offscreenSurfaceLayer ) { layoutSurfaceLayerImpl(); } } - protected void layoutSurfaceLayerImpl() {} + @Override public final void detachSurfaceLayer() throws NativeWindowException { diff --git a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java index df3f04f7f..8c02a68bb 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java +++ b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java @@ -42,21 +42,6 @@ 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 c8f758165..758105713 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -117,7 +117,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { } protected void attachSurfaceLayerImpl(final long layerHandle) { - OSXUtil.AddCASublayer(rootSurfaceLayerHandle, layerHandle); + OSXUtil.AddCASublayer(rootSurfaceLayerHandle, layerHandle, getWidth(), getHeight()); } protected void layoutSurfaceLayerImpl() { diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 59b42c249..1563a5a8b 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -158,13 +158,14 @@ public class OSXUtil implements ToolkitProperties { * @see #CreateCALayer(int, int, int, int) * @see #RemoveCASublayer(long, long) */ - public static void AddCASublayer(final long rootCALayer, final long subCALayer) { + public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int width, final int height) { if(0==rootCALayer || 0==subCALayer) { throw new IllegalArgumentException("rootCALayer 0x"+Long.toHexString(rootCALayer)+", subCALayer 0x"+Long.toHexString(subCALayer)); } RunOnMainThread(false, new Runnable() { public void run() { AddCASublayer0(rootCALayer, subCALayer); + FixCALayerLayout0(rootCALayer, subCALayer, width, height); } }); } diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 9d5a878c6..d902b0f09 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -445,9 +445,6 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } if( validateComponent(true, null) ) { // newtChild.setSize(width, height); - if(null != jawtWindow && jawtWindow.isOffscreenLayerSurfaceEnabled() ) { - jawtWindow.layoutSurfaceLayer(); - } } } } -- cgit v1.2.3