diff options
-rw-r--r-- | make/build-jogl.xml | 14 | ||||
-rw-r--r-- | make/build-nativewindow.xml | 3 | ||||
-rwxr-xr-x | make/scripts/tests.sh | 21 | ||||
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m | 197 | ||||
-rw-r--r-- | src/jogl/native/macosx/MacOSXWindowSystemInterface.m | 1 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java | 2 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java | 16 | ||||
-rw-r--r-- | src/nativewindow/native/macosx/NativeWindowProtocols.h | 34 | ||||
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 33 |
9 files changed, 219 insertions, 102 deletions
diff --git a/make/build-jogl.xml b/make/build-jogl.xml index 379758392..c481eb0f5 100644 --- a/make/build-jogl.xml +++ b/make/build-jogl.xml @@ -224,8 +224,9 @@ <property name="rootrel.generated.c.cg" value="${rootrel.src.generated}/native/jogl_cg" /> <!-- The source directories. --> - <property name="src.java" value="${project.root}/${rootrel.src.java}" /> - <property name="src.c" value="${project.root}/${rootrel.src.c}" /> + <property name="src.java" value="${project.root}/${rootrel.src.java}" /> + <property name="src.c" value="${project.root}/${rootrel.src.c}" /> + <property name="nativewindow.src.c" value="${project.root}/src/nativewindow/native" /> <!-- The generated source directories. --> <property name="src.generated" value="${build.jogl}/gensrc" /> @@ -1439,12 +1440,13 @@ <!-- This is for the generated headers for handwritten C code --> <includepath path="${src.c}"/> + <includepath path="${nativewindow.src.c}/macosx" if="isOSX"/> <includepath path="${src.generated.c}" /> - <includepath path="${src.generated.c}/X11" if="isX11"/> - <includepath path="${src.generated.c}/MacOSX" if="isOSX"/> - <includepath path="${src.generated.c}/Windows" if="isWindows"/> + <includepath path="${src.generated.c}/X11" if="isX11"/> + <includepath path="${src.generated.c}/MacOSX" if="isOSX"/> + <includepath path="${src.generated.c}/Windows" if="isWindows"/> <includepath path="${src.generated.c.libav}" /> - <includepath path="${src.generated.c.openmax}" if="setup.addNativeOpenMAX"/> + <includepath path="${src.generated.c.openmax}" if="setup.addNativeOpenMAX"/> <!-- This must come last to not override real include paths --> <!-- includepath path="stub_includes/macosx" if="isOSX" / --> diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml index a8408eaa7..d7ef73a46 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -691,8 +691,9 @@ <includepath path="${src.generated.c}/X11" if="isX11"/> <includepath path="${src.generated.c}/MacOSX" if="isOSX"/> <includepath path="${src.generated.c}/Windows" if="isWindows"/> - <includepath path="${src.c}/win32" if="isWindows"/> <includepath path="${src.c}/x11" if="isX11"/> + <includepath path="${src.c}/macosx" if="isOSX"/> + <includepath path="${src.c}/win32" if="isWindows"/> <includepath path="${src.c}"/> <!-- This must come last to not override real include paths --> diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index b3aa39dfc..7a71932ca 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -171,7 +171,8 @@ function jrun() { #D_ARGS="-Dnewt.debug.Window.MouseEvent" #D_ARGS="-Dnewt.debug.Window -Dnativewindow.debug=all" #D_ARGS="-Dnewt.debug.Window -Dnativewindow.debug.JAWT -Djogl.debug.Animator" - #D_ARGS="-Dnewt.debug.Window" + #D_ARGS="-Dnewt.debug.Window -Djogl.debug.GLDrawable" + D_ARGS="-Dnewt.debug.Window" #D_ARGS="-Xprof" #D_ARGS="-Dnativewindow.debug=all" #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Java2D -Djogl.debug.GLJPanel" @@ -261,27 +262,27 @@ function testawtswt() { # # demos (any TK, more user driven tests) # +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestOlympicES1NEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestRedSquareES1NEWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWTAnalyzeBug455 $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWT $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWTBug450 $* -#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper $* #testawtswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasSWT $* -#testawtswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2SWT $* -#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT $* -#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestOlympicES1NEWT $* -#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestRedSquareES1NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestRedSquareES2NEWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWTAnalyzeBug455 $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWTBug450 $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl3.newt.TestGeomShader01TextureGL3NEWT $* #testswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasSWT $* +#testawtswt com.jogamp.opengl.test.junit.jogl.demos.es2.swt.TestGearsES2SWT $* # # core/newt (testnoawt and testawt) diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m index b965accab..2cf74380c 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m @@ -1,6 +1,7 @@ #import "MacOSXWindowSystemInterface.h" #import <QuartzCore/QuartzCore.h> #import <pthread.h> +#import "NativeWindowProtocols.h" #include "timespec.h" #import <OpenGL/glext.h> @@ -126,7 +127,7 @@ extern GLboolean glIsVertexArray (GLuint array); @end -@interface MyNSOpenGLLayer: NSOpenGLLayer +@interface MyNSOpenGLLayer: NSOpenGLLayer <NWDedicatedSize> { @private GLfloat gl_texCoords[8]; @@ -143,8 +144,8 @@ extern GLboolean glIsVertexArray (GLuint array); NSOpenGLPixelFormat* parentPixelFmt; int texWidth; int texHeight; - int newTexWidth; - int newTexHeight; + int dedicatedWidth; + int dedicatedHeight; volatile NSOpenGLPixelBuffer* pbuffer; volatile GLuint textureID; volatile NSOpenGLPixelBuffer* newPBuffer; @@ -173,8 +174,17 @@ extern GLboolean glIsVertexArray (GLuint array); texWidth: (int) texWidth texHeight: (int) texHeight; +- (void)releaseLayer; +- (void)deallocPBuffer; +- (void)disableAnimation; +- (void)pauseAnimation:(Bool)pause; +- (void)setSwapInterval:(int)interval; +- (void)tick; +- (void)waitUntilRenderSignal: (long) to_micros; +- (Bool)isGLSourceValid; + - (void) setGLEnabled: (Bool) enable; -- (Bool) validateTexSizeWithNewSize; +- (Bool) validateTexSizeWithDedicatedSize; - (Bool) validateTexSize: (int) _texWidth texHeight: (int) _texHeight; - (void) setTextureID: (int) _texID; @@ -182,21 +192,22 @@ extern GLboolean glIsVertexArray (GLuint array); - (void) setNewPBuffer: (NSOpenGLPixelBuffer*)p; - (void) applyNewPBuffer; +- (void)setDedicatedSize:(CGSize)size; // @NWDedicatedSize +- (CGRect)fixMyFrame; +- (CGRect)fixSuperPosition; +- (id<CAAction>)actionForKey:(NSString *)key ; - (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask; - (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat; -- (void)disableAnimation; -- (void)pauseAnimation:(Bool)pause; -- (void)deallocPBuffer; -- (void)releaseLayer; +- (BOOL)canDrawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat + forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp; +- (void)drawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat + forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp; + #ifdef DBG_LIFECYCLE - (id)retain; - (oneway void)release; #endif - (void)dealloc; -- (void)setSwapInterval:(int)interval; -- (void)tick; -- (void)waitUntilRenderSignal: (long) to_micros; -- (Bool)isGLSourceValid; @end @@ -270,9 +281,9 @@ static const GLfloat gl_verts[] = { timespec_now(&lastWaitTime); shallDraw = NO; isGLEnabled = YES; - newTexWidth = _texWidth; - newTexHeight = _texHeight; - [self validateTexSizeWithNewSize]; + dedicatedWidth = _texWidth; + dedicatedHeight = _texHeight; + [self validateTexSizeWithDedicatedSize]; [self setTextureID: texID]; newPBuffer = NULL; @@ -345,9 +356,9 @@ static const GLfloat gl_verts[] = { isGLEnabled = enable; } -- (Bool) validateTexSizeWithNewSize +- (Bool) validateTexSizeWithDedicatedSize { - return [self validateTexSize: newTexWidth texHeight: newTexHeight]; + return [self validateTexSize: dedicatedWidth texHeight: dedicatedHeight]; } - (Bool) validateTexSize: (int) _texWidth texHeight: (int) _texHeight @@ -355,12 +366,14 @@ 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]; + [self setFrame: lRect]; */ + CGRect lRect = [self fixMyFrame]; GLfloat texCoordWidth, texCoordHeight; if(NULL != pbuffer) { @@ -382,8 +395,14 @@ static const GLfloat gl_verts[] = { gl_texCoords[5] = texCoordHeight; gl_texCoords[4] = texCoordWidth; gl_texCoords[6] = texCoordWidth; +#ifdef VERBOSE_ON + 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; } } @@ -450,34 +469,6 @@ static const GLfloat gl_verts[] = { } } -- (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask -{ - DBG_PRINT("MyNSOpenGLLayer::openGLPixelFormatForDisplayMask: %p (refcnt %d) - parent-pfmt %p -> new-pfmt %p\n", - self, (int)[self retainCount], parentPixelFmt, parentPixelFmt); - // We simply take over ownership of parent PixelFormat .. - return parentPixelFmt; -} - -- (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat -{ - DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.0: %p (refcnt %d) - pfmt %p, parent %p, DisplayLink %p\n", - self, (int)[self retainCount], pixelFormat, parentCtx, displayLink); - // NSLog(@"MyNSOpenGLLayer::openGLContextForPixelFormat: %@",[NSThread callStackSymbols]); - myCtx = [[MyNSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:parentCtx]; -#ifndef HAS_CADisplayLink - if(NULL != displayLink) { - CVReturn cvres; - DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.1: setup DisplayLink %p\n", displayLink); - cvres = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, [myCtx CGLContextObj], [pixelFormat CGLPixelFormatObj]); - if(kCVReturnSuccess != cvres) { - DBG_PRINT("MyNSOpenGLLayer::init %p, CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext failed: %d\n", self, cvres); - } - } -#endif - DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.X: new-ctx %p\n", myCtx); - return myCtx; -} - - (void)disableAnimation { DBG_PRINT("MyNSOpenGLLayer::disableAnimation.0: %p (refcnt %d) - displayLink %p\n", self, (int)[self retainCount], displayLink); @@ -553,29 +544,107 @@ static const GLfloat gl_verts[] = { return NULL != pbuffer || NULL != newPBuffer || 0 != textureID ; } -- (void)resizeWithOldSuperlayerSize:(CGSize)size - { - CALayer * superL = [self superlayer]; - CGRect lRectSFrame = [superL frame]; +// @NWDedicatedSize +- (void)setDedicatedSize:(CGSize)size { + 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]; - DBG_PRINT("MyNSOpenGLLayer::resizeWithOldSuperlayerSize: %p, texSize %dx%d -> size: %lfx%lf ; Super Frame[%lf/%lf %lfx%lf] (refcnt %d)\n", - self, texWidth, texHeight, size.width, size.height, - lRectSFrame.origin.x, lRectSFrame.origin.y, lRectSFrame.size.width, lRectSFrame.size.height, - (int)[self retainCount]); + [CATransaction commit]; +} + +- (void) setFrame:(CGRect) frame { + CGRect rect = CGRectMake(0, 0, dedicatedWidth, dedicatedHeight); + [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( lRectSFrame.origin.x!=0 || lRectSFrame.origin.y!=0 ) { - lRectSFrame.origin.x = 0; - lRectSFrame.origin.y = 0; - [superL setPosition: lRectSFrame.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<CAAction>)actionForKey:(NSString *)key +{ + DBG_PRINT("MyNSOpenGLLayer::actionForKey.0 %p key %s -> NIL\n", self, [key UTF8String]); + return nil; + // return [super actionForKey: key]; +} - newTexWidth = lRectSFrame.size.width; - newTexHeight = lRectSFrame.size.height; - shallDraw = [self isGLSourceValid]; - SYNC_PRINT("<SZ %dx%d>", newTexWidth, newTexHeight); +- (NSOpenGLPixelFormat *)openGLPixelFormatForDisplayMask:(uint32_t)mask +{ + DBG_PRINT("MyNSOpenGLLayer::openGLPixelFormatForDisplayMask: %p (refcnt %d) - parent-pfmt %p -> new-pfmt %p\n", + self, (int)[self retainCount], parentPixelFmt, parentPixelFmt); + // We simply take over ownership of parent PixelFormat .. + return parentPixelFmt; +} - [super resizeWithOldSuperlayerSize: size]; +- (NSOpenGLContext *)openGLContextForPixelFormat:(NSOpenGLPixelFormat *)pixelFormat +{ + DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.0: %p (refcnt %d) - pfmt %p, parent %p, DisplayLink %p\n", + self, (int)[self retainCount], pixelFormat, parentCtx, displayLink); + // NSLog(@"MyNSOpenGLLayer::openGLContextForPixelFormat: %@",[NSThread callStackSymbols]); + myCtx = [[MyNSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:parentCtx]; +#ifndef HAS_CADisplayLink + if(NULL != displayLink) { + CVReturn cvres; + DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.1: setup DisplayLink %p\n", displayLink); + cvres = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, [myCtx CGLContextObj], [pixelFormat CGLPixelFormatObj]); + if(kCVReturnSuccess != cvres) { + DBG_PRINT("MyNSOpenGLLayer::init %p, CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext failed: %d\n", self, cvres); + } + } +#endif + DBG_PRINT("MyNSOpenGLLayer::openGLContextForPixelFormat.X: new-ctx %p\n", myCtx); + return myCtx; } - (BOOL)canDrawInOpenGLContext:(NSOpenGLContext *)context pixelFormat:(NSOpenGLPixelFormat *)pixelFormat @@ -601,7 +670,7 @@ static const GLfloat gl_verts[] = { GLenum textureTarget; - Bool texSizeChanged = [self validateTexSizeWithNewSize]; + Bool texSizeChanged = [self validateTexSizeWithDedicatedSize]; if( NULL != pbuffer ) { if( texSizeChanged && 0 != textureID ) { diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m index e8925f8e8..f8faeb8d0 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m @@ -575,7 +575,6 @@ void setContextView(NSOpenGLContext* ctx, NSView* view) { [ctx setView:view]; } [pool release]; - return ctx; } Bool makeCurrentContext(NSOpenGLContext* ctx) { diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index b25836d3c..3ec54ca78 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -125,7 +125,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { if(DEBUG) { System.err.println("JAWTWindow.fixSurfaceLayerLayout: "+toHexString(osl) + ", bounds "+bounds+", "+w+"x"+h); } - OSXUtil.FixCALayerPosition(rootSurfaceLayerHandle, osl, w, h); + OSXUtil.FixCALayerLayout(rootSurfaceLayerHandle, osl, w, h); } protected void detachSurfaceLayerImpl(final long layerHandle) { diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 5ff451cc0..aa44e2d64 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -173,10 +173,14 @@ public class OSXUtil implements ToolkitProperties { } /** - * Fix root and sub CALayer position to 0/0 on the main-thread w/o blocking. + * Fix root and sub CALayer position to 0/0 and size 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. + * If the sub CALayer implements the Objective-C NativeWindow protocol NWDedicatedSize (e.g. JOGL's MyNSOpenGLLayer), + * the dedicated size is passed to the layer, which propagates it appropriately. + * </p> + * <p> + * On OSX/Java7 our root CALayer's frame position and size gets corrupted by its NSView, + * hence we have created the NWDedicatedSize protocol. * </p> * * @param rootCALayer the root surface layer, maybe null. @@ -184,13 +188,13 @@ public class OSXUtil implements ToolkitProperties { * @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) { + public static void FixCALayerLayout(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); + FixCALayerLayout0(rootCALayer, subCALayer, width, height); } }); } @@ -346,7 +350,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 FixCALayerLayout0(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/NativeWindowProtocols.h b/src/nativewindow/native/macosx/NativeWindowProtocols.h new file mode 100644 index 000000000..b91a50dfd --- /dev/null +++ b/src/nativewindow/native/macosx/NativeWindowProtocols.h @@ -0,0 +1,34 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +#import <Foundation/NSGeometry.h> + +@protocol NWDedicatedSize +- (void)setDedicatedSize:(CGSize)size; +@end + diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 28e63e875..c74d6cc58 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -33,6 +33,7 @@ #include <unistd.h> #include <AppKit/AppKit.h> #import <QuartzCore/QuartzCore.h> +#import "NativeWindowProtocols.h" #include "NativewindowCommon.h" #include "jogamp_nativewindow_macosx_OSXUtil.h" @@ -335,6 +336,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0 - (oneway void)release; - (void)dealloc; #endif +- (id<CAAction>)actionForKey:(NSString *)key ; @end @@ -378,6 +380,12 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSWindow0 #endif +- (id<CAAction>)actionForKey:(NSString *)key +{ + DBG_PRINT("MyCALayer::actionForKey.0 %p key %s -> NIL\n", self, [key UTF8String]); + return nil; + // return [super actionForKey: key]; +} @end @@ -478,10 +486,10 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0 /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil - * Method: FixCALayerPosition0 + * Method: FixCALayerLayout0 * Signature: (JJII)V */ -JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_FixCALayerPosition0 +JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_FixCALayerLayout0 (JNIEnv *env, jclass unused, jlong rootCALayer, jlong subCALayer, jint width, jint height) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -493,38 +501,37 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_FixCALayerPositio 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) { + DBG_PRINT("CALayer::FixCALayerLayout0.0: Root %p exp 0/0 %dx%d -> frame0: %lf/%lf %lfx%lf\n", + rootLayer, (int)width, (int)height, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.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) { + DBG_PRINT("CALayer::FixCALayerLayout0.0: SubL %p exp 0/0 %dx%d -> frame0: %lf/%lf %lfx%lf\n", + subLayer, (int)width, (int)height, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.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); + if( [subLayer conformsToProtocol:@protocol(NWDedicatedSize)] ) { + CALayer <NWDedicatedSize> * subLayerDS = (CALayer <NWDedicatedSize> *) subLayer; + [subLayerDS setDedicatedSize: lRect.size]; + } else { + [subLayer setFrame: lRect]; + } } } [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]); } /* |