summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/native/macosx
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-01-04 16:58:49 +0100
committerSven Gothel <[email protected]>2020-01-04 16:58:49 +0100
commite6d53e29f05a6928192f6c4a988b2aa558be8d65 (patch)
tree710620d57a7fa906a7be052802d740deec1cdbe8 /src/nativewindow/native/macosx
parent2be7001101dbb16e5264c9c38b9764ba1e39ab5c (diff)
Bug 1358: Add OSXUtil.GetWindowPixelScale(..)
It is now possible to retrieve the pixel scale [NSWindow backingScaleFactor] after native creation by NEWT - as we have changed the lifecycly (all-in-one native method on AppKit)
Diffstat (limited to 'src/nativewindow/native/macosx')
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index 51bbdcba3..8cbfde8ed 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -308,7 +308,7 @@ NS_ENDHANDLER
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
- * Method: GetScreenPixelScale1
+ * Method: GetScreenPixelScale2
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetScreenPixelScale2
@@ -347,6 +347,49 @@ NS_ENDHANDLER
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: GetWindowPixelScale1
+ * Signature: (J)F
+ */
+JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetWindowPixelScale1
+ (JNIEnv *env, jclass unused, jlong winOrView)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ NSObject *nsObj = (NSObject*) (intptr_t) winOrView;
+ NSWindow* win = NULL;
+ NSView* view = NULL;
+ NSScreen *screen = NULL;
+
+ if( [nsObj isKindOfClass:[NSWindow class]] ) {
+ win = (NSWindow*) nsObj;
+ view = [win contentView];
+ screen = [win screen];
+ } else if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) {
+ view = (NSView*) nsObj;
+ win = [view window];
+ screen = [win screen];
+ } else {
+ NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj);
+ }
+
+ BOOL useHiDPI = false;
+ CGFloat pixelScale = 1.0; // default
+NS_DURING
+ // Available >= 10.7
+ useHiDPI = [view wantsBestResolutionOpenGLSurface];
+ if( useHiDPI ) {
+ pixelScale = [win backingScaleFactor]; // HiDPI scaling
+ }
+NS_HANDLER
+NS_ENDHANDLER
+
+ [pool release];
+
+ return (jfloat)pixelScale;
+}
+
+/*
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: CreateNSWindow0
* Signature: (IIIIZ)J
*/