--- old/src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java 2015-09-22 00:06:43.080071600 -0700 +++ new/src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java 2015-09-22 00:06:42.876958300 -0700 @@ -37,13 +37,16 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; +import java.awt.geom.Point2D; import java.awt.image.ColorModel; import java.util.ArrayList; import java.util.Vector; import java.awt.peer.WindowPeer; +import java.security.AccessController; import sun.awt.windows.WWindowPeer; import sun.java2d.opengl.WGLGraphicsConfig; import sun.java2d.windows.WindowsFlags; +import sun.security.action.GetPropertyAction; /** * This is an implementation of a GraphicsDevice object for a single @@ -81,6 +84,9 @@ // activation/deactivation listener for the full-screen window private WindowListener fsWindowListener; + private float scaleX = 1.0f; + private float scaleY = 1.0f; + static { // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when @@ -97,6 +103,10 @@ private static native void initIDs(); native void initDevice(int screen); + native void initNativeScale(int screen); + native void setNativeScale(int screen, float scaleX, float scaleY); + native float getNativeScaleX(int screen); + native float getNativeScaleY(int screen); public Win32GraphicsDevice(int screennum) { this.screen = screennum; @@ -109,6 +119,7 @@ valid = true; initDevice(screennum); + initScaleFactors(); } /** @@ -128,6 +139,74 @@ return screen; } + public float getDefaultScaleX() { + return scaleX; + } + + public float getDefaultScaleY() { + return scaleY; + } + + private void initScaleFactors() { + boolean dpiEnabled = "true".equals(AccessController.doPrivileged( + new GetPropertyAction("sun.java2d.uiScale.enabled", "true"))); + + if (!dpiEnabled) { + return; + } + + scaleX = getScaleFactor("sun.java2d.win.uiScaleX"); + scaleY = getScaleFactor("sun.java2d.win.uiScaleY"); + + if (scaleX > 0 && scaleY > 0) { + setNativeScale(screen, scaleX, scaleY); + return; + } + + float scale = getScaleFactor("sun.java2d.win.uiScale"); + + if (scale > 0) { + scaleX = scale; + scaleY = scale; + setNativeScale(screen, scaleX, scaleY); + return; + } + + initNativeScale(screen); + scaleX = getNativeScaleX(screen); + scaleY = getNativeScaleY(screen); + } + + private static float getScaleFactor(String name) { + + String scaleFactor = AccessController.doPrivileged( + new GetPropertyAction(name, "-1")); + + if (scaleFactor == null || scaleFactor.equals("-1")) { + return -1; + } + try { + + if (scaleFactor.endsWith("dpi")) { + scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3); + float scale = Float.parseFloat(scaleFactor); + return scale <= 0 ? -1 : scale / 96; + } + + if (scaleFactor.endsWith("%")) { + scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1); + float scale = Float.parseFloat(scaleFactor); + return scale <= 0 ? -1 : scale / 100; + } + + float scale = Float.parseFloat(scaleFactor); + return (scale <=0) ? -1 : scale; + + } catch (NumberFormatException ignore) { + } + return -1; + } + /** * Returns whether this is a valid devicie. Device can become * invalid as a result of device removal event. @@ -486,6 +565,7 @@ configs = null; // pass on to all top-level windows on this display topLevels.notifyListeners(); + initScaleFactors(); } /**