Implement initial work for enabling CALayer rendering
This commit is contained in:
parent
284f6135f3
commit
0d6eac80f7
|
@ -82,8 +82,8 @@ final class AWTSurfaceLock {
|
||||||
// It is only needed on first call, so we avoid it on all subsequent calls
|
// It is only needed on first call, so we avoid it on all subsequent calls
|
||||||
// due to performance..
|
// due to performance..
|
||||||
|
|
||||||
// Allow the use of a Core Animation Layer only when using non fullscreen Display.setParent() or AWTGLCanvas
|
// 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) && isApplet(component) && LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 6);
|
final boolean allowCALayer = ((Display.getParent() != null && !Display.isFullscreen()) || component instanceof AWTGLCanvas) && LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 6);
|
||||||
|
|
||||||
if (firstLockSucceeded)
|
if (firstLockSucceeded)
|
||||||
return lockAndInitHandle(lock_buffer, component, allowCALayer);
|
return lockAndInitHandle(lock_buffer, component, allowCALayer);
|
||||||
|
@ -107,22 +107,4 @@ final class AWTSurfaceLock {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void nUnlock(ByteBuffer lock_buffer) throws LWJGLException;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -446,8 +446,13 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parented) {
|
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) {
|
if (window_info->window != nil) {
|
||||||
[peer_info->parent addSubview:window_info->view];
|
[peer_info->parent addSubview:window_info->view];
|
||||||
[window_info->view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
[window_info->view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
//#import <JavaNativeFoundation.h>
|
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <jawt_md.h>
|
#include <jawt_md.h>
|
||||||
#include "awt_tools.h"
|
#include "awt_tools.h"
|
||||||
|
@ -48,17 +46,91 @@
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "common_tools.h"
|
#include "common_tools.h"
|
||||||
|
|
||||||
|
|
||||||
|
@interface GLLayer : NSOpenGLLayer {}
|
||||||
|
- (void) attachLayer;
|
||||||
|
- (void) removeLayer;
|
||||||
|
@end
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle
|
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) {
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
|
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
|
||||||
|
|
||||||
AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
|
AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
|
||||||
JAWT_MacOSXDrawingSurfaceInfo *macosx_dsi = (JAWT_MacOSXDrawingSurfaceInfo *)surface->dsi->platformInfo;
|
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;
|
peer_info->isWindowed = true;
|
||||||
|
|
||||||
[pool release];
|
[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
|
||||||
|
|
|
@ -82,7 +82,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nCre
|
||||||
NSSize displaySize = peer_info->window_info->display_rect.size;
|
NSSize displaySize = peer_info->window_info->display_rect.size;
|
||||||
GLint dim[2] = {displaySize.width, displaySize.height};
|
GLint dim[2] = {displaySize.width, displaySize.height};
|
||||||
CGLSetParameter(cgcontext, kCGLCPSurfaceBackingSize, dim);
|
CGLSetParameter(cgcontext, kCGLCPSurfaceBackingSize, dim);
|
||||||
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
|
CGLEnable(cgcontext, kCGLCESurfaceBackingSize);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// disable any fixed backbuffer size to allow resizing
|
// disable any fixed backbuffer size to allow resizing
|
||||||
|
|
Loading…
Reference in New Issue