diff options
author | Sven Gothel <[email protected]> | 2015-01-27 00:49:51 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-01-27 00:49:51 +0100 |
commit | 6516a52d3da5cced924db63b64af911d55355325 (patch) | |
tree | fe4404bbd72d4db624722459c76a520019cfb4ca /src/nativewindow/native/macosx/OSXmisc.m | |
parent | 26f965bbe7b40968158901c3f4ef2f54e821ac70 (diff) |
Bug 1120 - Refine HiDPI Support ( Part-2 ) (API CHANGE)
- Use float[2] for pixel-scale.
Utilize simple integer rounding:
int-pixel-units = (int) ( int-window-units * pixel-scale + 0.5f )
- Provide minimum and maximum allowed pixel-scale values
to be set by platform, supporting generic pixel-scale validation.
- Remove 'OSXUtil.GetPixelScale(final RectangleImmutable r, final int[] screenIndexOut)',
implementation for all platforms would cause huge redundancy of
Screen and MonitorDevice code (duplication of NEWT).
- instead, add 'float[2] pixelScale' to NEWT's MonitorDevice
- Detect change of pixel-scale and propagate accordingly.
This allows GLCanvas, GLJPanel and NewtCanvasAWT instances
to be dragged between monitor devices w/ different pixel-scale.
- OSX: Handle native triggered reshape events off-thread to avoid EDT congestion
due to locked window when consuming deferred events on EDT.
Diffstat (limited to 'src/nativewindow/native/macosx/OSXmisc.m')
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 83 |
1 files changed, 31 insertions, 52 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 997bafba0..c86025ea8 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -138,12 +138,24 @@ Java_jogamp_nativewindow_macosx_OSXUtil_isNSWindow0(JNIEnv *env, jclass _unused, } static CGDirectDisplayID OSXUtil_getCGDirectDisplayIDByNSScreen(NSScreen *screen) { - // Mind: typedef uint32_t CGDirectDisplayID; - however, we assume it's 64bit on 64bit ?! + // Mind: typedef uint32_t CGDirectDisplayID; NSDictionary * dict = [screen deviceDescription]; NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"]; // [NSNumber integerValue] returns NSInteger which is 32 or 64 bit native size return (CGDirectDisplayID) [val integerValue]; } +static NSScreen * OSXUtil_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displayID) { + NSArray *screens = [NSScreen screens]; + int i; + for(i=[screens count]-1; i>=0; i--) { + NSScreen * screen = (NSScreen *) [screens objectAtIndex: i]; + CGDirectDisplayID dID = OSXUtil_getCGDirectDisplayIDByNSScreen(screen); + if( dID == displayID ) { + return screen; + } + } + return (NSScreen *) [screens objectAtIndex: 0]; +} /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil @@ -249,87 +261,54 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0 return res; } -static CGDirectDisplayID GetCGDirectDisplayIDByNSScreen(NSScreen *screen) { - // Mind: typedef uint32_t CGDirectDisplayID; - however, we assume it's 64bit on 64bit ?! - NSDictionary * dict = [screen deviceDescription]; - NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"]; - // [NSNumber integerValue] returns NSInteger which is 32 or 64 bit native size - return (CGDirectDisplayID) [val integerValue]; -} - /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil - * Method: GetScreenData0 - * Signature: ()[F + * Method: GetPixelScale0 + * Signature: (I)D */ -JNIEXPORT jdoubleArray JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetScreenData0 - (JNIEnv *env, jclass unused) +JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale0 + (JNIEnv *env, jclass unused, jint screen_idx) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; CGFloat pixelScale; - CGDirectDisplayID display; - NSRect dBounds; NSScreen *screen; NSArray *screens = [NSScreen screens]; - int sCount = [screens count]; - jdouble res[sCount*5]; - int i,j; - - for(i=0; i<sCount; i++) { - j = i*5; - screen = (NSScreen *) [screens objectAtIndex: i]; + if( screen_idx<0 || screen_idx>=[screens count] ) { + screen = NULL; + pixelScale = 1.0; + } else { + screen = (NSScreen *) [screens objectAtIndex: screen_idx]; pixelScale = 1.0; // default NS_DURING // Available >= 10.7 pixelScale = [screen backingScaleFactor]; // HiDPI scaling NS_HANDLER NS_ENDHANDLER - display = GetCGDirectDisplayIDByNSScreen(screen); - dBounds = CGDisplayBounds (display); // origin top-left - res[j+0] = (jdouble)pixelScale; - res[j+1] = (jdouble)dBounds.origin.x; - res[j+2] = (jdouble)dBounds.origin.y; - res[j+3] = (jdouble)dBounds.size.width; - res[j+4] = (jdouble)dBounds.size.height; } - - jdoubleArray jniRes = (*env)->NewDoubleArray(env, sCount*5); // x,y,w,h,scale - if (jniRes == NULL) { - NativewindowCommon_throwNewRuntimeException(env, "Could not allocate double array of size %d", sCount*5); - } - (*env)->SetDoubleArrayRegion(env, jniRes, 0, sCount*5, res); - [pool release]; - return jniRes; + return (jdouble)pixelScale; } /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil - * Method: GetPixelScale0 + * Method: GetPixelScale1 * Signature: (I)D */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale0 - (JNIEnv *env, jclass unused, jint screen_idx) +JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale1 + (JNIEnv *env, jclass unused, jint displayID) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; CGFloat pixelScale; - NSScreen *screen; - NSArray *screens = [NSScreen screens]; - if( screen_idx<0 || screen_idx>=[screens count] ) { - screen = NULL; - pixelScale = 0.0; - } else { - screen = (NSScreen *) [screens objectAtIndex: screen_idx]; - pixelScale = 1.0; // default + NSScreen *screen = OSXUtil_getNSScreenByCGDirectDisplayID((CGDirectDisplayID)displayID); + pixelScale = 1.0; // default NS_DURING - // Available >= 10.7 - pixelScale = [screen backingScaleFactor]; // HiDPI scaling + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling NS_HANDLER NS_ENDHANDLER - } [pool release]; return (jdouble)pixelScale; @@ -340,7 +319,7 @@ NS_ENDHANDLER * Method: GetPixelScale1 * Signature: (J)D */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale1 +JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale2 (JNIEnv *env, jclass unused, jlong winOrView) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |