Implement initial support for High DPI mode on OS X

This commit is contained in:
kappaOne 2013-11-11 00:08:23 +00:00
parent ed95cd0f27
commit 225bd176cb
3 changed files with 35 additions and 23 deletions

View File

@ -96,7 +96,7 @@ final class MacOSXDisplay implements DisplayImplementation {
}
private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, boolean parented, boolean enableFullscreenModeAPI, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException;
private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, boolean parented, boolean enableFullscreenModeAPI, boolean enableHighDPI, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException;
private native Object nGetCurrentDisplayMode();
@ -135,6 +135,10 @@ final class MacOSXDisplay implements DisplayImplementation {
boolean enableFullscreenModeAPI = LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 7) && parent == null &&
!Display.getPrivilegedBoolean("org.lwjgl.opengl.Display.disableOSXFullscreenModeAPI");
// OS X high DPI mode is only available on OS X 10.7+
boolean enableHighDPI = LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 7) && parent == null &&
Display.getPrivilegedBoolean("org.lwjgl.opengl.Display.enableHighDPI");
if (parented) this.canvas = parent;
else this.canvas = null;
@ -149,7 +153,7 @@ final class MacOSXDisplay implements DisplayImplementation {
window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(),
fullscreen, isUndecorated(), resizable,
parented, enableFullscreenModeAPI, peer_handle, window_handle);
parented, enableFullscreenModeAPI, enableHighDPI, peer_handle, window_handle);
if (fullscreen) {
// when going to fullscreen viewport is set to screen size by Cocoa, ignore this value

View File

@ -64,36 +64,38 @@ enum {
@class NSOpenGLContext, NSOpenGLPixelFormat, MacOSXOpenGLView, MacOSXKeyableWindow;
typedef struct {
MacOSXKeyableWindow *window;
NSRect display_rect;
MacOSXKeyableWindow *window;
NSRect display_rect;
MacOSXOpenGLView *view;
NSOpenGLContext *context;
// Native objects for Java callbacks
jobject jdisplay;
jobject jmouse;
jobject jkeyboard;
NSOpenGLContext *context;
// Native objects for Java callbacks
jobject jdisplay;
jobject jmouse;
jobject jkeyboard;
jboolean fullscreen;
jboolean undecorated;
jboolean resizable;
jboolean parented;
jboolean enableFullscreenModeAPI;
jboolean enableFullscreenModeAPI;
jboolean enableHighDPI;
jboolean resized;
jboolean resized;
} MacOSXWindowInfo;
@interface MacOSXOpenGLView : NSView
{
@public
MacOSXWindowInfo* _parent;
@private
NSOpenGLContext* _openGLContext;
NSOpenGLPixelFormat* _pixelFormat;
@public
MacOSXWindowInfo* _parent;
@private
NSOpenGLContext* _openGLContext;
NSOpenGLPixelFormat* _pixelFormat;
NSTrackingArea * _trackingArea;
}
@ -141,9 +143,9 @@ typedef struct {
typedef struct {
bool isCALayer;
bool isWindowed;
MacOSXWindowInfo *window_info;
MacOSXWindowInfo *window_info;
NSOpenGLPixelFormat *pixel_format;
NSOpenGLPixelBuffer *pbuffer;
NSOpenGLPixelBuffer *pbuffer;
NSView *parent;
GLLayer *glLayer;
} MacOSXPeerInfo;

View File

@ -73,6 +73,11 @@ static NSUInteger lastModifierFlags = 0;
NSRect view_rect = NSMakeRect(0.0, 0.0, width, height);
window_info->view = [[MacOSXOpenGLView alloc] initWithFrame:view_rect pixelFormat:peer_info->pixel_format];
[window_info->view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
if (window_info->enableHighDPI) {
// call method using runtime selector as its a 10.7+ api and allows compiling on older SDK's
[window_info->view performSelector:NSSelectorFromString(@"setWantsBestResolutionOpenGLSurface:") withObject:YES];
}
// set nsapp delegate for catching app quit events
[NSApp setDelegate:window_info->view];
@ -640,7 +645,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nSetTitle(JNIEnv *env
[window_info->window performSelectorOnMainThread:@selector(setTitle:) withObject:title waitUntilDone:NO];
}
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIEnv *env, jobject this, jint x, jint y, jint width, jint height, jboolean fullscreen, jboolean undecorated, jboolean resizable, jboolean parented, jboolean enableFullscreenModeAPI, jobject peer_info_handle, jobject window_handle) {
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIEnv *env, jobject this, jint x, jint y, jint width, jint height, jboolean fullscreen, jboolean undecorated, jboolean resizable, jboolean parented, jboolean enableFullscreenModeAPI, jboolean enableHighDPI, jobject peer_info_handle, jobject window_handle) {
pool = [[NSAutoreleasePool alloc] init];
@ -670,7 +675,8 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE
window_info->undecorated = undecorated;
window_info->resizable = resizable;
window_info->parented = parented;
window_info->enableFullscreenModeAPI = enableFullscreenModeAPI;
window_info->enableFullscreenModeAPI = enableFullscreenModeAPI;
window_info->enableHighDPI = enableHighDPI;
peer_info->window_info = window_info;
peer_info->isWindowed = true;