< prev index next >
src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java
Print this page
@@ -42,10 +42,11 @@
import sun.java2d.xr.XRGraphicsConfig;
import sun.java2d.loops.SurfaceType;
import sun.awt.util.ThreadGroupUtils;
import sun.misc.ManagedLocalsThread;
+import sun.security.action.GetPropertyAction;
/**
* This is an implementation of a GraphicsDevice object for a single
* X11 screen.
*
@@ -61,13 +62,15 @@
private static Boolean xrandrExtSupported;
private final Object configLock = new Object();
private SunDisplayChanger topLevels = new SunDisplayChanger();
private DisplayMode origDisplayMode;
private boolean shutdownHookRegistered;
+ private int scale;
public X11GraphicsDevice(int screennum) {
this.screen = screennum;
+ this.scale = initScaleFactor();
}
/*
* Initialize JNI field and method IDs for fields that may be
* accessed from C.
@@ -277,10 +280,11 @@
ArrayList<DisplayMode> modes);
private static native void configDisplayMode(int screen,
int width, int height,
int displayMode);
private static native void resetNativeData(int screen);
+ private static native int getNativeScaleFactor(int screen);
/**
* Returns true only if:
* - the Xrandr extension is present
* - the necessary Xrandr functions were loaded successfully
@@ -507,10 +511,37 @@
*/
public void addDisplayChangedListener(DisplayChangedListener client) {
topLevels.add(client);
}
+ public int getScaleFactor(){
+ return scale;
+ }
+
+ private int initScaleFactor() {
+
+ boolean hidpiEnabled = "true".equals(AccessController.doPrivileged(
+ new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
+
+ if (!hidpiEnabled) {
+ return 1;
+ }
+
+ String hidpiScale = AccessController.doPrivileged(
+ new GetPropertyAction("sun.java2d.uiScale", "-1"));
+ try {
+ int scale = Integer.parseInt(hidpiScale);
+ if (scale >= 1) {
+ return scale;
+ }
+ } catch (NumberFormatException ignore) {
+ }
+
+ int scale = getNativeScaleFactor(screen);
+ return scale >= 1 ? scale : 1;
+ }
+
/**
* Remove a DisplayChangeListener from this X11GraphicsDevice.
*/
public void removeDisplayChangedListener(DisplayChangedListener client) {
topLevels.remove(client);
< prev index next >