--- old/src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java 2015-10-21 04:33:34.105103000 -0700 +++ new/src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java 2015-10-21 04:33:33.784794600 -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,12 @@ // activation/deactivation listener for the full-screen window private WindowListener fsWindowListener; + private static final boolean uiScaleEnabled; + private static final float propsScaleX; + private static final float propsScaleY; + private float scaleX = 1.0f; + private float scaleY = 1.0f; + static { // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when @@ -92,11 +101,34 @@ new sun.security.action.GetPropertyAction("sun.awt.nopixfmt")); pfDisabled = (nopixfmt != null); initIDs(); + + uiScaleEnabled = "true".equals(AccessController.doPrivileged( + new GetPropertyAction("sun.java2d.uiScale.enabled", "true"))); + + if (uiScaleEnabled) { + float sx = getScaleFactor("sun.java2d.win.uiScaleX"); + float sy = getScaleFactor("sun.java2d.win.uiScaleY"); + if (sx > 0 && sy > 0) { + propsScaleX = sx; + propsScaleY = sy; + } else { + float scale = getScaleFactor("sun.java2d.uiScale"); + propsScaleX = scale; + propsScaleY = scale; + } + } else { + propsScaleX = -1; + propsScaleY = -1; + } } 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 +141,7 @@ valid = true; initDevice(screennum); + initScaleFactors(); } /** @@ -128,6 +161,58 @@ return screen; } + public float getDefaultScaleX() { + return scaleX; + } + + public float getDefaultScaleY() { + return scaleY; + } + + private void initScaleFactors() { + if (uiScaleEnabled) { + if (propsScaleX > 0 && propsScaleY > 0) { + scaleX = propsScaleX; + scaleY = propsScaleY; + setNativeScale(screen, scaleX, scaleY); + } else { + 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 +571,7 @@ configs = null; // pass on to all top-level windows on this display topLevels.notifyListeners(); + initScaleFactors(); } /**