From c5eadd89a0151beaf59af93d434087df03ccdee0 Mon Sep 17 00:00:00 2001 From: kappa1 Date: Tue, 11 Oct 2011 22:30:55 +0000 Subject: [PATCH] Limit the use to CALayer only to when using Display.setParent(), an AWTGLCanvas in non fullscreen mode. --- src/java/org/lwjgl/opengl/AWTSurfaceLock.java | 11 ++- .../lwjgl/opengl/MacOSXCanvasPeerInfo.java | 7 +- .../common/org_lwjgl_opengl_AWTSurfaceLock.c | 4 +- .../org_lwjgl_opengl_MacOSXCanvasPeerInfo.m | 89 ++++++++++--------- 4 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/java/org/lwjgl/opengl/AWTSurfaceLock.java b/src/java/org/lwjgl/opengl/AWTSurfaceLock.java index 0308c893..5a3730e6 100644 --- a/src/java/org/lwjgl/opengl/AWTSurfaceLock.java +++ b/src/java/org/lwjgl/opengl/AWTSurfaceLock.java @@ -79,14 +79,17 @@ final class AWTSurfaceLock { // http://192.18.37.44/forums/index.php?topic=10572 for a discussion. // It is only needed on first call, so we avoid it on all subsequent calls // due to performance.. - final Canvas parent = component instanceof AWTGLCanvas ? component : Display.getParent(); + + // Allow the use of a Core Animation Layer only when using Display.setParent() or AWTGLCanvas and when not in fullscreen + final boolean allowCALayer = (Display.getParent() != null || component instanceof AWTGLCanvas) && !Display.isFullscreen(); + if (firstLockSucceeded) - return lockAndInitHandle(lock_buffer, component, parent); + return lockAndInitHandle(lock_buffer, component, allowCALayer); else try { firstLockSucceeded = AccessController.doPrivileged(new PrivilegedExceptionAction() { public Boolean run() throws LWJGLException { - return lockAndInitHandle(lock_buffer, component, parent); + return lockAndInitHandle(lock_buffer, component, allowCALayer); } }); return firstLockSucceeded; @@ -95,7 +98,7 @@ final class AWTSurfaceLock { } } - private static native boolean lockAndInitHandle(ByteBuffer lock_buffer, Canvas component, Canvas display_parent) throws LWJGLException; + private static native boolean lockAndInitHandle(ByteBuffer lock_buffer, Canvas component, boolean allowCALayer) throws LWJGLException; void unlock() throws LWJGLException { nUnlock(lock_buffer); diff --git a/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java b/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java index fdfc3d7f..824a112b 100644 --- a/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java +++ b/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java @@ -50,9 +50,12 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo { } protected void initHandle(Canvas component) throws LWJGLException { - nInitHandle(awt_surface.lockAndGetHandle(component), getHandle()); + // Allow the use of a Core Animation Layer only when using Display.setParent() or AWTGLCanvas and when not in fullscreen + final boolean allowCALayer = (Display.getParent() != null || component instanceof AWTGLCanvas) && !Display.isFullscreen(); + + nInitHandle(awt_surface.lockAndGetHandle(component), getHandle(), allowCALayer); } - private static native void nInitHandle(ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException; + private static native void nInitHandle(ByteBuffer surface_buffer, ByteBuffer peer_info_handle, boolean allowCALayer) throws LWJGLException; protected void doUnlock() throws LWJGLException { awt_surface.unlock(); diff --git a/src/native/common/org_lwjgl_opengl_AWTSurfaceLock.c b/src/native/common/org_lwjgl_opengl_AWTSurfaceLock.c index 0e28d99f..d4e5f1c2 100644 --- a/src/native/common/org_lwjgl_opengl_AWTSurfaceLock.c +++ b/src/native/common/org_lwjgl_opengl_AWTSurfaceLock.c @@ -49,7 +49,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_AWTSurfaceLock_createHandle } JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_AWTSurfaceLock_lockAndInitHandle - (JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject canvas, jobject display_parent) { + (JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject canvas, jboolean allowCALayer) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo *dsi; @@ -58,7 +58,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_AWTSurfaceLock_lockAndInitHandl jboolean result = JNI_FALSE; #ifdef __MACH__ - if (display_parent) { + if (allowCALayer) { //first try CALAYER awt.version = JAWT_VERSION_1_4 | 0x80000000;//JAWT_MACOSX_USE_CALAYER; result = JAWT_GetAWT(env, &awt); diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m b/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m index 337042f6..8bd7af49 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m @@ -65,56 +65,60 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle -(JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject peer_info_handle) { +(JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject peer_info_handle, jboolean allowCALayer) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle); JAWT_MacOSXDrawingSurfaceInfo *macosx_dsi = (JAWT_MacOSXDrawingSurfaceInfo *)surface->dsi->platformInfo; - // check for CALayer support - if(surface->awt.version & 0x80000000) { //JAWT_MACOSX_USE_CALAYER) { - jint width = surface->dsi->bounds.width; - jint height = surface->dsi->bounds.height; - - if(peer_info->pbuffer == NULL || - width != [peer_info->pbuffer pixelsWide] || height != [peer_info->pbuffer pixelsHigh]) { - if(peer_info->pbuffer != NULL) { - [peer_info->pbuffer release]; - } + if (allowCALayer) { + // check for CALayer support + if(surface->awt.version & 0x80000000) { //JAWT_MACOSX_USE_CALAYER) { + jint width = surface->dsi->bounds.width; + jint height = surface->dsi->bounds.height; + + if(peer_info->pbuffer == NULL || width != [peer_info->pbuffer pixelsWide] || height != [peer_info->pbuffer pixelsHigh]) { + if(peer_info->pbuffer != NULL) { + [peer_info->pbuffer release]; + } - // make pbuffer - NSOpenGLPixelBuffer *pbuffer = nil; - NSLog(@"Make pbuffer: %d x %d", width, height); - pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_RECTANGLE_EXT - textureInternalFormat:GL_RGBA - textureMaxMipMapLevel:0 - pixelsWide:width - pixelsHigh:height]; + // make pbuffer + NSOpenGLPixelBuffer *pbuffer = nil; + NSLog(@"Make pbuffer: %d x %d", width, height); + pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_RECTANGLE_EXT + textureInternalFormat:GL_RGBA + textureMaxMipMapLevel:0 + pixelsWide:width + pixelsHigh:height]; - peer_info->pbuffer = pbuffer; - peer_info->window = false; - peer_info->canDrawGL = true; - } + peer_info->pbuffer = pbuffer; + peer_info->window = false; + peer_info->canDrawGL = true; + } - if (macosx_dsi != NULL) { - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ - // attach the "root layer" to the AWT Canvas surface layers - id surfaceLayers = (id )macosx_dsi;//dsi->platformInfo; - if(surfaceLayers.layer == NULL) { - PBufferGLLayer *caGLLayer = [[PBufferGLLayer new] autorelease]; - caGLLayer.peer_info = peer_info; - caGLLayer.asynchronous = YES; - caGLLayer.needsDisplayOnBoundsChange = YES; - caGLLayer.opaque = YES; - surfaceLayers.layer = caGLLayer; - } - }]; - } - } else { - peer_info->nsview = macosx_dsi->cocoaViewRef; - peer_info->window = true; - } + if (macosx_dsi != NULL) { + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + // attach the "root layer" to the AWT Canvas surface layers + id surfaceLayers = (id )macosx_dsi;//dsi->platformInfo; + if(surfaceLayers.layer == NULL) { + PBufferGLLayer *caGLLayer = [[PBufferGLLayer new] autorelease]; + caGLLayer.peer_info = peer_info; + caGLLayer.asynchronous = YES; + caGLLayer.needsDisplayOnBoundsChange = YES; + caGLLayer.opaque = YES; + surfaceLayers.layer = caGLLayer; + } + }]; + } + + [pool release]; + return; + } + } + + peer_info->nsview = macosx_dsi->cocoaViewRef; + peer_info->window = true; [pool release]; } @@ -122,9 +126,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle // rotates a red square when asked to draw @implementation PBufferGLLayer -//@synthesize peer_info; -//@synthesize textureID; - // override to draw custom GL content -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat