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/newt/native | |
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/newt/native')
-rw-r--r-- | src/newt/native/MacWindow.m | 2 | ||||
-rw-r--r-- | src/newt/native/NewtMacWindow.m | 22 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 2bd11da3c..1dbe2b7bd 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -420,7 +420,7 @@ NS_ENDHANDLER CGDirectDisplayID NewtScreen_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 diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index caf9e54e0..7b3df391d 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -784,11 +784,21 @@ static jmethodID windowRepaintID = NULL; [super viewDidChangeBackingProperties]; // HiDPI scaling - BOOL useHiDPI = [self wantsBestResolutionOpenGLSurface]; - CGFloat pixelScaleNative = [[self window] backingScaleFactor]; - CGFloat pixelScaleUse = useHiDPI ? pixelScaleNative : 1.0; - DBG_PRINT("viewDidChangeBackingProperties: PixelScale: HiDPI %d, native %f -> use %f\n", useHiDPI, (float)pixelScaleNative, (float)pixelScaleUse); - [[self layer] setContentsScale: pixelScaleUse]; + BOOL useHiDPI = false; + CGFloat maxPixelScale = 1.0; + CGFloat winPixelScale = 1.0; + NSWindow* window = [self window]; + NSScreen* screen = [window screen]; +NS_DURING + maxPixelScale = [screen backingScaleFactor]; + useHiDPI = [self wantsBestResolutionOpenGLSurface]; + if( useHiDPI ) { + winPixelScale = [window backingScaleFactor]; + } +NS_HANDLER +NS_ENDHANDLER + DBG_PRINT("viewDidChangeBackingProperties: PixelScale: HiDPI %d, max %f, window %f\n", useHiDPI, (float)maxPixelScale, (float)winPixelScale); + [[self layer] setContentsScale: winPixelScale]; if (javaWindowObject == NULL) { DBG_PRINT("viewDidChangeBackingProperties: null javaWindowObject\n"); @@ -801,7 +811,7 @@ static jmethodID windowRepaintID = NULL; return; } - (*env)->CallVoidMethod(env, javaWindowObject, updatePixelScaleID, JNI_TRUE, (jfloat)pixelScaleUse, (jfloat)pixelScaleNative); // defer + (*env)->CallVoidMethod(env, javaWindowObject, updatePixelScaleID, JNI_TRUE, (jfloat)winPixelScale, (jfloat)maxPixelScale); // defer // detaching thread not required - daemon // NewtCommon_ReleaseJNIEnv(shallBeDetached); |