< prev index next >

src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java

Print this page

        

*** 35,51 **** --- 35,54 ---- import java.awt.Rectangle; import java.awt.Window; 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 * Win32 screen. *
*** 79,88 **** --- 82,94 ---- // mode private DisplayMode defaultDisplayMode; // 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 // pixel format calls are made. This causes problems when a Java app // is run as an NT service. To prevent the loading of ddraw.dll
*** 95,104 **** --- 101,114 ---- } 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; // we cache the strings because we want toString() and getIDstring // to reflect the original screen number (which may change if the
*** 107,116 **** --- 117,127 ---- // REMIND: may be should use class name? descString = "Win32GraphicsDevice[screen=" + screen; valid = true; initDevice(screennum); + initScaleFactors(); } /** * Returns the type of the graphics device. * @see #TYPE_RASTER_SCREEN
*** 126,135 **** --- 137,214 ---- */ public int getScreen() { 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. */ public boolean isValid() {
*** 484,493 **** --- 563,573 ---- dynamicColorModel = null; defaultConfig = null; configs = null; // pass on to all top-level windows on this display topLevels.notifyListeners(); + initScaleFactors(); } /** * Part of the DisplayChangedListener interface: devices * do not need to react to this event
< prev index next >