[jdk9] HiDPI scale is not detected on some linux desktops

(cherry picked from commit 9279d80110)
This commit is contained in:
Anton Tarasov
2018-08-16 17:23:28 +03:00
committed by jbrbot
parent af2bf5d4e0
commit c10abfbd26
6 changed files with 40 additions and 9 deletions

View File

@@ -40,6 +40,7 @@ import com.sun.java.swing.plaf.gtk.GTKConstants.TextDirection;
import sun.awt.image.SunWritableRaster;
import sun.swing.ImageCache;
import sun.awt.X11GraphicsDevice;
/**
* GTKEngine delegates all painting job to native GTK libraries.
@@ -271,6 +272,18 @@ class GTKEngine {
regionToWidgetTypeMap.put(Region.TREE, WidgetType.TREE);
regionToWidgetTypeMap.put(Region.TREE_CELL, WidgetType.TREE_CELL);
regionToWidgetTypeMap.put(Region.VIEWPORT, WidgetType.VIEWPORT);
Object value = INSTANCE.getSetting(Settings.GTK_XFT_DPI);
if (value instanceof Integer) {
int dpi = ((Integer)value).intValue() / 1024;
if (dpi == -1) {
dpi = 96;
}
if (dpi < 50) {
dpi = 50;
}
X11GraphicsDevice.setGlobalScale(Math.round(dpi / 96f));
}
}
/** Translate Region and JComponent into WidgetType ordinals */

View File

@@ -72,6 +72,8 @@ public final class X11GraphicsDevice extends GraphicsDevice
private volatile Insets insets;
private boolean shutdownHookRegistered;
private int scale;
private volatile boolean isNativeScaleDefault;
private static int globalScale; // derived from Xft.dpi
public X11GraphicsDevice(int screennum) {
this.screen = screennum;
@@ -570,6 +572,17 @@ public final class X11GraphicsDevice extends GraphicsDevice
return (int)Math.round(getNativeScaleFactor(screen));
}
public static void setGlobalScale(int scale) {
globalScale = scale;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
X11GraphicsDevice x11gd = (X11GraphicsDevice)gd;
if (x11gd.isNativeScaleDefault) {
x11gd.scale = globalScale;
x11gd.isNativeScaleDefault = false;
}
}
}
private int initScaleFactor() {
if (SunGraphicsEnvironment.isUIScaleEnabled()) {
@@ -580,7 +593,10 @@ public final class X11GraphicsDevice extends GraphicsDevice
return (int) debugScale;
}
int nativeScale = getNativeScale();
return nativeScale >= 1 ? nativeScale : 1;
if (nativeScale > 0) return nativeScale;
if (globalScale > 0) return globalScale;
isNativeScaleDefault = true;
return 1;
}
return 1;

View File

@@ -170,6 +170,7 @@ static double getDesktopScale(char *output_name) {
}
fp_g_variant_unref(value);
}
/* [tav]
if (result > 0) {
value = get_schema_value("com.canonical.Unity.Interface",
"text-scale-factor");
@@ -177,7 +178,7 @@ static double getDesktopScale(char *output_name) {
result *= fp_g_variant_get_double(value);
fp_g_variant_unref(value);
}
}
}*/
}
if (result <= 0) {
@@ -189,6 +190,7 @@ static double getDesktopScale(char *output_name) {
}
}
/* [tav]
if (result <= 0) {
void *value = get_schema_value("org.gnome.desktop.interface",
"text-scaling-factor");
@@ -196,7 +198,7 @@ static double getDesktopScale(char *output_name) {
result = fp_g_variant_get_double(value);
fp_g_variant_unref(value);
}
}
}*/
return result;
@@ -214,7 +216,7 @@ static int getScale(const char *name) {
return -1;
}
double getNativeScaleFactor(char *output_name) {
double getNativeScaleFactor(char *output_name, double default_value) {
static int scale = -2.0;
double native_scale = 0;
int gdk_scale = 0;
@@ -230,10 +232,10 @@ double getNativeScaleFactor(char *output_name) {
native_scale = getDesktopScale(output_name);
if (native_scale <= 0) {
native_scale = 1;
native_scale = default_value;
}
gdk_scale = getScale("GDK_SCALE");
return gdk_scale > 0 ? native_scale * gdk_scale : native_scale;
return gdk_scale > 0 ? (native_scale <= 0 ? 1 : native_scale) * gdk_scale : native_scale;
}

View File

@@ -28,7 +28,7 @@
#include <signal.h>
#include <stdlib.h>
double getNativeScaleFactor(char *output_name);
double getNativeScaleFactor(char *output_name, double default_value);
#endif

View File

@@ -2075,7 +2075,7 @@ Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
(JNIEnv *env, jobject this, jint screen) {
// in case of Xinerama individual screen scales are not supported
char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
double scale = getNativeScaleFactor(name);
double scale = getNativeScaleFactor(name, -1);
if (name) {
free(name);
}

View File

@@ -813,7 +813,7 @@ SplashGetScaledImageName(const char* jarName, const char* fileName,
#ifndef __linux__
return JNI_FALSE;
#endif
*scaleFactor = (float)getNativeScaleFactor(NULL);
*scaleFactor = (float)getNativeScaleFactor(NULL, 1);
return GetScaledImageName(fileName, scaledImgName, scaleFactor, scaledImageNameLength);
}