Implement initial work for enabling CALayer rendering

This commit is contained in:
kappaOne 2012-12-23 22:09:57 +00:00
parent 284f6135f3
commit 0d6eac80f7
4 changed files with 86 additions and 27 deletions

View File

@ -82,8 +82,8 @@ final class AWTSurfaceLock {
// It is only needed on first call, so we avoid it on all subsequent calls
// due to performance..
// Allow the use of a Core Animation Layer only when using non fullscreen Display.setParent() or AWTGLCanvas
final boolean allowCALayer = ((Display.getParent() != null && !Display.isFullscreen()) || component instanceof AWTGLCanvas) && isApplet(component) && LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 6);
// Allow the use of a Core Animation Layer only when using non fullscreen Display.setParent() or AWTGLCanvas and OS X 10.6+
final boolean allowCALayer = ((Display.getParent() != null && !Display.isFullscreen()) || component instanceof AWTGLCanvas) && LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 6);
if (firstLockSucceeded)
return lockAndInitHandle(lock_buffer, component, allowCALayer);
@ -107,22 +107,4 @@ final class AWTSurfaceLock {
}
private static native void nUnlock(ByteBuffer lock_buffer) throws LWJGLException;
/**
* This method will return true if the component is running in an applet
*/
public boolean isApplet(Canvas component) {
Component parent = component.getParent();
while (parent != null) {
if (parent instanceof Applet) {
return true;
}
parent = parent.getParent();
}
// not an applet
return false;
}
}

View File

@ -446,8 +446,13 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE
}
if (parented) {
window_info->window = [peer_info->parent window];
if (peer_info->parent != nil) {
window_info->window = [peer_info->parent window];
}
else {
window_info->window = nil;
}
if (window_info->window != nil) {
[peer_info->parent addSubview:window_info->view];
[window_info->view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

View File

@ -39,8 +39,6 @@
*/
#import <Cocoa/Cocoa.h>
//#import <JavaNativeFoundation.h>
#include <jni.h>
#include <jawt_md.h>
#include "awt_tools.h"
@ -48,17 +46,91 @@
#include "context.h"
#include "common_tools.h"
@interface GLLayer : NSOpenGLLayer {}
- (void) attachLayer;
- (void) removeLayer;
@end
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle
(JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject peer_info_handle) {
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;
peer_info->parent = macosx_dsi->cocoaViewRef;
// check for CALayer support
if(surface->awt.version & 0x80000000) { //JAWT_MACOSX_USE_CALAYER) {
if (macosx_dsi != NULL) {
// get the root layer of the AWT Canvas
id <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)macosx_dsi;
GLLayer *glLayer = [[GLLayer new] autorelease];
[glLayer performSelectorOnMainThread:@selector(attachLayer:) withObject:surfaceLayers waitUntilDone:NO];
}
peer_info->isWindowed = true;
peer_info->parent = nil;
[pool release];
return;
}
// no CALayer support, fallback to using legacy method of getting the NSView of an AWT Canvas
peer_info->parent = macosx_dsi->cocoaViewRef;
peer_info->isWindowed = true;
[pool release];
}
@implementation GLLayer
- (void) attachLayer:(id<JAWT_SurfaceLayers>)surfaceLayers {
self.asynchronous = YES;
self.needsDisplayOnBoundsChange = YES;
self.opaque = NO;
self.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
surfaceLayers.layer = self;
}
- (void) removeLayer:(id<JAWT_SurfaceLayers>)surfaceLayers {
surfaceLayers.layer = nil;
}
-(void)drawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:(CFTimeInterval)timeInterval
displayTime:(const CVTimeStamp *)timeStamp {
// set the current context
CGLSetCurrentContext(glContext);
// draw a single red quad spinning around based on the current time
GLfloat rotate = timeInterval * 60.0; // 60 degrees per second
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glRotatef(rotate, 0.0, 0.0, 1.0);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 0.0);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f( 0.5, 0.5);
glVertex2f( 0.5, -0.5);
glEnd();
glPopMatrix();
// call super to finalize the drawing - by default all it does is call glFlush()
[super drawInCGLContext:glContext pixelFormat:pixelFormat forLayerTime:timeInterval displayTime:timeStamp];
}
-(BOOL)canDrawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:(CFTimeInterval)timeInterval
displayTime:(const CVTimeStamp *)timeStamp {
return YES;
}
@end

View File

@ -82,7 +82,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nCre
NSSize displaySize = peer_info->window_info->display_rect.size;
GLint dim[2] = {displaySize.width, displaySize.height};
CGLSetParameter(cgcontext, kCGLCPSurfaceBackingSize, dim);
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
}
else {
// disable any fixed backbuffer size to allow resizing