Limit the use to CALayer only to when using Display.setParent(), an AWTGLCanvas in non fullscreen mode.

This commit is contained in:
kappa1 2011-10-11 22:30:55 +00:00
parent c9cac6406b
commit c5eadd89a0
4 changed files with 59 additions and 52 deletions

View File

@ -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<Boolean>() {
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);

View File

@ -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();

View File

@ -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);

View File

@ -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 <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)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 <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)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