diff options
author | Sven Gothel <[email protected]> | 2015-01-23 01:20:33 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-01-23 01:20:33 +0100 |
commit | 1341fe0216e4f12d7243e98290cc97824b1c0b5c (patch) | |
tree | 202dd91558731f9164e5f050b7aa9db50fc3c5b6 /src/nativewindow/native | |
parent | db775658a7f5d6614ae716b7492af8210f5e5f18 (diff) |
Bug 1120 - Add OSXUtil.GetPixelScale(final RectangleImmutable r, final int[] screenIndexOut) ( Part-1 )
Diffstat (limited to 'src/nativewindow/native')
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 127b329d1..997bafba0 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -249,6 +249,62 @@ 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 + */ +JNIEXPORT jdoubleArray JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetScreenData0 + (JNIEnv *env, jclass unused) +{ + 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]; + 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; +} + /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: GetPixelScale0 |