Refactoring to prepare for implementing OS X CALayer based

Display.setParent, temporarily breaks Display.setParent on Java 7 and
Java 6 Applets.
This commit is contained in:
kappaOne 2012-12-22 20:20:48 +00:00
parent f7c64c89dc
commit 284f6135f3
5 changed files with 41 additions and 13 deletions

View File

@ -44,15 +44,18 @@ import org.lwjgl.LWJGLUtil;
* $Id$
*/
abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo {
private final AWTSurfaceLock awt_surface = new AWTSurfaceLock();
protected MacOSXCanvasPeerInfo(PixelFormat pixel_format, ContextAttribs attribs, boolean support_pbuffer) throws LWJGLException {
super(pixel_format, attribs, true, true, support_pbuffer, true);
}
protected void initHandle(Canvas component) throws LWJGLException {
nInitHandle(getHandle());
nInitHandle(awt_surface.lockAndGetHandle(component), getHandle());
}
private static native void nInitHandle(ByteBuffer peer_info_handle) throws LWJGLException;
private static native void nInitHandle(ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException;
protected void doUnlock() throws LWJGLException {
awt_surface.unlock();
}
}

View File

@ -115,6 +115,9 @@ final class MacOSXDisplay implements DisplayImplementation {
boolean resizable = Display.isResizable();
boolean parented = (parent != null) && !fullscreen;
if (parented) this.canvas = parent;
else this.canvas = null;
close_requested = false;
DrawableGL gl_drawable = (DrawableGL)Display.getDrawable();
@ -124,7 +127,7 @@ final class MacOSXDisplay implements DisplayImplementation {
window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(),
fullscreen, isUndecorated(), resizable,
parented, peer_handle, window);
this.canvas = parent;
if (fullscreen) {
// when going to fullscreen viewport is set to screen size by Cocoa, ignore this value

View File

@ -54,7 +54,7 @@ typedef struct {
NSRect display_rect;
MacOSXOpenGLView *view;
MacOSXOpenGLView *view;
NSOpenGLContext *context;
// Native objects for Java callbacks
@ -100,6 +100,7 @@ typedef struct {
MacOSXWindowInfo *window_info;
NSOpenGLPixelFormat *pixel_format;
NSOpenGLPixelBuffer *pbuffer;
NSView *parent;
} MacOSXPeerInfo;

View File

@ -446,9 +446,17 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE
}
if (parented) {
window_info->window = (MacOSXKeyableWindow*)[[NSApplication sharedApplication] mainWindow];
window_info->window = [peer_info->parent window];
[window_info->window setContentView:window_info->view];
if (window_info->window != nil) {
[peer_info->parent addSubview:window_info->view];
[window_info->view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
}
else {
// failed to get parent window, create a new window
window_info->window = [[MacOSXKeyableWindow alloc] initWithContentRect:window_info->display_rect styleMask:default_window_mask backing:NSBackingStoreBuffered defer:NO];
[window_info->window setContentView:window_info->view];
}
}
else {
window_info->window = [[MacOSXKeyableWindow alloc] initWithContentRect:window_info->display_rect styleMask:default_window_mask backing:NSBackingStoreBuffered defer:NO];
@ -505,9 +513,16 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nDestroyWindow(JNIEnv
if (window_info->fullscreen) {
[window_info->view exitFullScreenModeWithOptions: nil];
}
else {
else {
if (window_info->window != nil) {
[window_info->window close];
// if the nsview has no parent then close window
if ([window_info->window contentView] == window_info->view) {
[window_info->window close];
}
else {
// the nsview has a parent, so remove it from there
[window_info->view removeFromSuperviewWithoutNeedingDisplay];
}
}
}

View File

@ -42,17 +42,23 @@
//#import <JavaNativeFoundation.h>
#include <jni.h>
#include <jawt_md.h>
#include "awt_tools.h"
#include "org_lwjgl_opengl_MacOSXCanvasPeerInfo.h"
#include "context.h"
#include "common_tools.h"
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle
(JNIEnv *env, jclass clazz, jobject peer_info_handle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
(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);
peer_info->isWindowed = true;
AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
JAWT_MacOSXDrawingSurfaceInfo *macosx_dsi = (JAWT_MacOSXDrawingSurfaceInfo *)surface->dsi->platformInfo;
peer_info->parent = macosx_dsi->cocoaViewRef;
peer_info->isWindowed = true;
[pool release];
}