From 225bd176cb9d73acd011419f50bb06942e314aee Mon Sep 17 00:00:00 2001 From: kappaOne Date: Mon, 11 Nov 2013 00:08:23 +0000 Subject: [PATCH] Implement initial support for High DPI mode on OS X --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 8 +++- src/native/macosx/context.h | 40 ++++++++++---------- src/native/macosx/org_lwjgl_opengl_Display.m | 10 ++++- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 59eab15d..2bcf5a9b 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -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 diff --git a/src/native/macosx/context.h b/src/native/macosx/context.h index a5f09949..2753d3e5 100644 --- a/src/native/macosx/context.h +++ b/src/native/macosx/context.h @@ -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; diff --git a/src/native/macosx/org_lwjgl_opengl_Display.m b/src/native/macosx/org_lwjgl_opengl_Display.m index 7c0d92c4..21f41d76 100644 --- a/src/native/macosx/org_lwjgl_opengl_Display.m +++ b/src/native/macosx/org_lwjgl_opengl_Display.m @@ -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;