aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tarasov <anton.tarasov@jetbrains.com>2017-04-24 16:53:37 +0300
committerAnton Tarasov <anton.tarasov@jetbrains.com>2017-04-24 16:53:37 +0300
commitac0f93c15ef66c84157cecfeffc08d61cf2d1b65 (patch)
tree38d72fdbaed38178297a409b8137e7c6bce585aa
parente411a730798c62d9ddb9d260bb7668fafa92f897 (diff)
downloadjdk8u_jdk-jb8u152-b838.tar.gz
JRE-326 [windows] IDEA gets wrong default ui font size on display with fractional scalejb8u152-b838
-rw-r--r--src/share/classes/sun/java2d/SunGraphicsEnvironment.java56
-rw-r--r--src/windows/classes/sun/awt/windows/WDesktopProperties.java2
-rw-r--r--src/windows/native/sun/windows/awt_DesktopProperties.cpp2
-rw-r--r--src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp15
-rw-r--r--src/windows/native/sun/windows/awt_Win32GraphicsDevice.h2
5 files changed, 33 insertions, 44 deletions
diff --git a/src/share/classes/sun/java2d/SunGraphicsEnvironment.java b/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
index 1d59f384bf..a64d38b0ff 100644
--- a/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
+++ b/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
@@ -25,48 +25,26 @@
package sun.java2d;
-import java.awt.AWTError;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
-import java.awt.Insets;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.font.TextAttribute;
+
+import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.peer.ComponentPeer;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FilenameFilter;
import java.io.InputStreamReader;
-import java.io.IOException;
-import java.text.AttributedCharacterIterator;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.Locale;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.StringTokenizer;
import java.util.TreeMap;
-import java.util.Vector;
-import java.util.concurrent.ConcurrentHashMap;
-import sun.awt.AppContext;
+
import sun.awt.DisplayChangedListener;
-import sun.awt.FontConfiguration;
import sun.awt.SunDisplayChanger;
-import sun.font.CompositeFontDescriptor;
-import sun.font.Font2D;
import sun.font.FontManager;
import sun.font.FontManagerFactory;
import sun.font.FontManagerForSGE;
-import sun.font.NativeFont;
+
import java.security.AccessController;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import sun.security.action.GetPropertyAction;
/**
@@ -83,11 +61,13 @@ public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
private static Font defaultFont;
private static final boolean uiScaleEnabled;
+ private static volatile AtomicBoolean uiScaleOn;
private static final double debugScale;
static {
uiScaleEnabled = "true".equals(AccessController.doPrivileged(
new GetPropertyAction("sun.java2d.uiScale.enabled", "false")));
+ if (!uiScaleEnabled) uiScaleOn = new AtomicBoolean(false);
debugScale = uiScaleEnabled ? getScaleFactor("sun.java2d.uiScale") : -1;
}
@@ -356,18 +336,28 @@ public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
}
/**
+ * Whether the ui-scale functionality is natively enabled.
+ *
* [tav] todo: Temp, until fractional scale is supported well enough.
* Called via reflection from the client code.
+ * Called via JNI from Toolkit.
*/
- protected boolean isUIScaleOn() {
- // [tav] check if native JDK scaled up any of the displays
- for (GraphicsDevice d : getScreenDevices()) {
+ public static boolean isUIScaleOn() {
+ if (uiScaleOn != null) return uiScaleOn.get();
+
+ assert EventQueue.isDispatchThread(); // must be initialized on EDT
+
+ uiScaleOn = new AtomicBoolean(false);
+ if (GraphicsEnvironment.isHeadless()) return false;
+
+ for (GraphicsDevice d : getLocalGraphicsEnvironment().getScreenDevices()) {
if (d.getDefaultConfiguration().getDefaultTransform().getScaleX() > 1 ||
d.getDefaultConfiguration().getDefaultTransform().getScaleY() > 1) {
- return true;
+ uiScaleOn.set(true);
+ break;
}
}
- return false;
+ return uiScaleOn.get();
}
public static double getDebugScale() {
diff --git a/src/windows/classes/sun/awt/windows/WDesktopProperties.java b/src/windows/classes/sun/awt/windows/WDesktopProperties.java
index 367bb126de..23bbea1719 100644
--- a/src/windows/classes/sun/awt/windows/WDesktopProperties.java
+++ b/src/windows/classes/sun/awt/windows/WDesktopProperties.java
@@ -34,6 +34,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import sun.java2d.SunGraphicsEnvironment;
import sun.util.logging.PlatformLogger;
import sun.awt.SunToolkit;
@@ -80,6 +81,7 @@ final class WDesktopProperties {
WDesktopProperties(WToolkit wToolkit) {
this.wToolkit = wToolkit;
+ SunGraphicsEnvironment.isUIScaleOn(); // ensure initialized
init();
}
diff --git a/src/windows/native/sun/windows/awt_DesktopProperties.cpp b/src/windows/native/sun/windows/awt_DesktopProperties.cpp
index ba66d7dd5d..05f3a1bfb7 100644
--- a/src/windows/native/sun/windows/awt_DesktopProperties.cpp
+++ b/src/windows/native/sun/windows/awt_DesktopProperties.cpp
@@ -83,7 +83,7 @@ void AwtDesktopProperties::GetWindowsParameters() {
}
void getInvScale(float &invScaleX, float &invScaleY) {
- if (!AwtWin32GraphicsDevice::IsUiScaleEnabled()) {
+ if (!AwtWin32GraphicsDevice::IsUIScaleOn()) {
invScaleX = 1.0f;
invScaleY = 1.0f;
return;
diff --git a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
index eddfb290ef..e59b323366 100644
--- a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
+++ b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp
@@ -973,16 +973,13 @@ int AwtWin32GraphicsDevice::GetScreenFromHMONITOR(HMONITOR mon) {
* End of static deviceIndex-based methods
*/
-BOOL AwtWin32GraphicsDevice::IsUiScaleEnabled()
+BOOL AwtWin32GraphicsDevice::IsUIScaleOn()
{
- JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
- static jclass cls = env->FindClass("sun/java2d/SunGraphicsEnvironment");
- CHECK_NULL_RETURN(cls, FALSE);
-
- static jmethodID isUIScaleEnabledID = env->GetStaticMethodID(cls, "isUIScaleEnabled", "()Z");
- CHECK_NULL_RETURN(isUIScaleEnabledID, FALSE);
-
- return (BOOL)env->CallStaticBooleanMethod(cls, isUIScaleEnabledID);
+ return JNU_CallStaticMethodByName(AwtToolkit::GetEnv(),
+ NULL,
+ "sun/java2d/SunGraphicsEnvironment",
+ "isUIScaleOn",
+ "()Z").z;
}
AwtWin32GraphicsDevice* AwtWin32GraphicsDevice::GetDeviceByBounds(RECT_BOUNDS bounds, HWND hwnd) // bounds in user space
diff --git a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h
index a391bf3d5c..335a20e5e0 100644
--- a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h
+++ b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.h
@@ -106,7 +106,7 @@ public:
static void DisableOffscreenAccelerationForDevice(HMONITOR hMonitor);
static HDC GetDCFromScreen(int screen);
static int GetScreenFromHMONITOR(HMONITOR mon);
- static BOOL IsUiScaleEnabled(); // if not, be dpi-unaware (backward compatible behaviour)
+ static BOOL IsUIScaleOn(); // if not, be dpi-unaware (backward compatible behaviour)
static AwtWin32GraphicsDevice* GetDeviceByBounds(RECT_BOUNDS bounds , HWND hwnd = NULL); // bounds in user space
inline static RECT_BOUNDS GetWindowRect(HWND hwnd)