8150844: [hidpi] [macosx] -Dsun.java2d.uiScale should be taken into account for OS X
Reviewed-by: serb, avstepan
--- a/jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java Tue Mar 22 14:46:48 2016 -0700
+++ b/jdk/src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java Wed Mar 23 14:25:22 2016 +0400
@@ -32,7 +32,7 @@
import java.awt.Insets;
import java.awt.Window;
import java.util.Objects;
-
+import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.opengl.CGLGraphicsConfig;
public final class CGraphicsDevice extends GraphicsDevice
@@ -140,7 +140,7 @@
public void displayChanged() {
xResolution = nativeGetXResolution(displayID);
yResolution = nativeGetYResolution(displayID);
- scale = (int) nativeGetScaleFactor(displayID);
+ initScaleFactor();
//TODO configs/fullscreenWindow/modes?
}
@@ -249,6 +249,17 @@
return nativeGetDisplayModes(displayID);
}
+ private void initScaleFactor() {
+ if (SunGraphicsEnvironment.isUIScaleEnabled()) {
+ double debugScale = SunGraphicsEnvironment.getDebugScale();
+ scale = (int) (debugScale >= 1
+ ? Math.round(debugScale)
+ : nativeGetScaleFactor(displayID));
+ } else {
+ scale = 1;
+ }
+ }
+
private static native double nativeGetScaleFactor(int displayID);
private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
--- a/jdk/test/java/awt/hidpi/properties/HiDPIPropertiesLinuxTest.java Tue Mar 22 14:46:48 2016 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.awt.Dialog;
-import java.awt.Frame;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
-import javax.swing.UIManager;
-
-/* @test
- * @bug 8137571
- * @summary Linux HiDPI Graphics support
- * @author Alexander Scherbatiy
- * @requires (os.family == "linux")
- * @run main/othervm -Dsun.java2d.uiScale.enabled=false
- * -Dsun.java2d.uiScale=2
- * HiDPIPropertiesLinuxTest UISCALE_DISABLED
- * HiDPIPropertiesTest UISCALE_DISABLED
- * @run main/othervm -Dsun.java2d.uiScale.enabled=true
- * -Dsun.java2d.uiScale=3
- * HiDPIPropertiesLinuxTest UISCALE_3
- * @run main/othervm -Dsun.java2d.uiScale=4
- * HiDPIPropertiesLinuxTest UISCALE_4
- */
-public class HiDPIPropertiesLinuxTest {
-
- public static void main(String[] args) throws Exception {
-
- try {
- UIManager.setLookAndFeel(
- "com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
- } catch (Exception e) {
- return;
- }
-
- String testCase = args[0];
- switch (testCase) {
- case "UISCALE_DISABLED":
- testScale(1.0, 1.0);
- break;
- case "UISCALE_3":
- testScale(3.0, 3.0);
- break;
- case "UISCALE_4":
- testScale(4.0, 4.0);
- break;
- default:
- throw new RuntimeException("Unknown test case: " + testCase);
- }
- }
-
- private static void testScale(double scaleX, double scaleY) {
-
- Dialog dialog = new Dialog((Frame) null, true) {
-
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- AffineTransform tx = ((Graphics2D) g).getTransform();
- dispose();
- if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
- throw new RuntimeException(String.format("Wrong scale:"
- + "[%f, %f] instead of [%f, %f].",
- tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
- }
- }
- };
- dialog.setSize(200, 300);
- dialog.setVisible(true);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/hidpi/properties/HiDPIPropertiesUnixTest.java Wed Mar 23 14:25:22 2016 +0400
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import javax.swing.UIManager;
+
+/* @test
+ * @bug 8137571
+ * @summary Linux HiDPI Graphics support
+ * @author Alexander Scherbatiy
+ * @requires (os.family == "linux" | os.family == "mac")
+ * @run main/othervm -Dsun.java2d.uiScale.enabled=false
+ * -Dsun.java2d.uiScale=2
+ * HiDPIPropertiesUnixTest UISCALE_DISABLED
+ * @run main/othervm -Dsun.java2d.uiScale.enabled=true
+ * -Dsun.java2d.uiScale=3
+ * HiDPIPropertiesUnixTest UISCALE_3
+ * @run main/othervm -Dsun.java2d.uiScale=4
+ * HiDPIPropertiesUnixTest UISCALE_4
+ */
+public class HiDPIPropertiesUnixTest {
+
+ public static void main(String[] args) throws Exception {
+
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+
+ String testCase = args[0];
+ switch (testCase) {
+ case "UISCALE_DISABLED":
+ testScale(1.0, 1.0);
+ break;
+ case "UISCALE_3":
+ testScale(3.0, 3.0);
+ break;
+ case "UISCALE_4":
+ testScale(4.0, 4.0);
+ break;
+ default:
+ throw new RuntimeException("Unknown test case: " + testCase);
+ }
+ }
+
+ private static void testScale(double scaleX, double scaleY) {
+
+ Dialog dialog = new Dialog((Frame) null, true) {
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ AffineTransform tx = ((Graphics2D) g).getTransform();
+ dispose();
+ if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
+ throw new RuntimeException(String.format("Wrong scale:"
+ + "[%f, %f] instead of [%f, %f].",
+ tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
+ }
+ }
+ };
+ dialog.setSize(200, 300);
+ dialog.setVisible(true);
+ }
+}
--- a/jdk/test/java/awt/image/multiresolution/Corrupted2XImageTest.java Tue Mar 22 14:46:48 2016 -0700
+++ b/jdk/test/java/awt/image/multiresolution/Corrupted2XImageTest.java Wed Mar 23 14:25:22 2016 +0400
@@ -37,7 +37,6 @@
*/
import java.awt.*;
-import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.*;
@@ -116,25 +115,11 @@
dispose();
}
- private static boolean is2x() {
-
- AffineTransform tr = GraphicsEnvironment.getLocalGraphicsEnvironment().
- getDefaultScreenDevice().getDefaultConfiguration().
- getDefaultTransform();
- return Math.min(tr.getScaleX(), tr.getScaleY()) > 1.001;
- }
-
public static void main(String[] args) throws Exception {
- // TODO: update the test with sun.java2d.uiScale option (remove is2x())
- // after fix of JDK-8150844 enh. to run it on non-HiDPI machines as well
- if (is2x()) {
- // formats supported by Toolkit.getImage()
- for (String format: new String[]{"gif", "jpg", "png"}) {
- (new Corrupted2XImageTest(format)).doTest();
- }
- } else {
- System.out.println("this test is for HiDPI only");
+ // formats supported by Toolkit.getImage()
+ for (String format : new String[]{"gif", "jpg", "png"}) {
+ (new Corrupted2XImageTest(format)).doTest();
}
}
}
--- a/jdk/test/java/awt/image/multiresolution/MenuMultiresolutionIconTest.java Tue Mar 22 14:46:48 2016 -0700
+++ b/jdk/test/java/awt/image/multiresolution/MenuMultiresolutionIconTest.java Wed Mar 23 14:25:22 2016 +0400
@@ -115,13 +115,6 @@
}
}
- private static boolean is2x() {
-
- return GraphicsEnvironment.getLocalGraphicsEnvironment().
- getDefaultScreenDevice().getDefaultConfiguration().
- getDefaultTransform().getScaleX() > 1.001;
- }
-
private boolean eqColors(Color c1, Color c2) {
int tol = 15;
@@ -133,7 +126,8 @@
private void checkIconColor(Point p, String what) {
- Color expected = is2x() ? C2X : C1X;
+ String scale = System.getProperty(SCALE);
+ Color expected = "2".equals(scale) ? C2X : C1X;
Color c = r.getPixelColor(p.x + SZ / 2, p.y + SZ / 2);
if (!eqColors(c, expected)) {
frame.dispose();
@@ -177,9 +171,6 @@
public static void main(String s[]) throws Exception {
- // TODO: remove is2x() after JDK-8150844 fix
- if (is2x() == "2".equals(System.getProperty(SCALE))) {
- (new MenuMultiresolutionIconTest()).doTest();
- }
+ (new MenuMultiresolutionIconTest()).doTest();
}
}
--- a/jdk/test/java/awt/image/multiresolution/MultiresolutionIconTest.java Tue Mar 22 14:46:48 2016 -0700
+++ b/jdk/test/java/awt/image/multiresolution/MultiresolutionIconTest.java Wed Mar 23 14:25:22 2016 +0400
@@ -28,8 +28,6 @@
* @summary Check that correct resolution variants are chosen for icons
* when multiresolution image is used for their construction.
*
- * @requires (os.family != "mac")
- *
* @library ../../../../lib/testlibrary/
* @build ExtendedRobot
* @run main/othervm/timeout=240 -Dsun.java2d.uiScale=1 MultiresolutionIconTest
@@ -42,7 +40,6 @@
import java.awt.*;
import java.awt.event.InputEvent;
-import java.awt.geom.AffineTransform;
import java.awt.image.BaseMultiResolutionImage;
import java.awt.image.BufferedImage;
import javax.swing.*;
@@ -128,14 +125,6 @@
setVisible(true);
}
- private static boolean is2x() {
-
- AffineTransform tr = GraphicsEnvironment.getLocalGraphicsEnvironment().
- getDefaultScreenDevice().getDefaultConfiguration().
- getDefaultTransform();
- return (Math.min(tr.getScaleX(), tr.getScaleY()) > 1.001);
- }
-
private boolean checkPressedColor(int x, int y, Color ok) {
r.mouseMove(x, y);
@@ -175,10 +164,9 @@
r.waitForIdle(2000);
String scale = System.getProperty(SCALE);
- System.out.println("scale = " + scale);
- Color
- expected = is2x() ? C2X : C1X,
- unexpected = is2x() ? C1X : C2X;
+ boolean is2x = "2".equals(scale);
+ Color expected = is2x ? C2X : C1X;
+ Color unexpected = is2x ? C1X : C2X;
Point p = lbl.getLocationOnScreen();
int x = p.x + lbl.getWidth() / 2;
@@ -227,9 +215,6 @@
public static void main(String[] args) throws Exception {
- // TODO: remove is2x() check after JDK-8150844 fix
- if (is2x() != "2".equals(System.getProperty(SCALE))) { return; }
-
for (UIManager.LookAndFeelInfo LF: UIManager.getInstalledLookAndFeels()) {
System.out.println("\nL&F: " + LF.getName());
(new MultiresolutionIconTest(LF)).doTest();