aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/native/macosx/OSXmisc.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/native/macosx/OSXmisc.m')
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m83
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];