23
24 import java.awt.Color;
25 import java.awt.Dialog;
26 import java.awt.Frame;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.Panel;
30 import java.awt.Rectangle;
31 import java.awt.Robot;
32 import java.awt.SplashScreen;
33 import java.awt.TextField;
34 import java.awt.Window;
35 import java.awt.event.KeyEvent;
36 import java.awt.image.BufferedImage;
37 import java.io.File;
38 import javax.imageio.ImageIO;
39 import sun.java2d.SunGraphics2D;
40
41 /**
42 * @test
43 * @bug 8043869 8075244 8078082
44 * @author Alexander Scherbatiy
45 * @summary [macosx] java -splash does not honor 2x hi dpi notation for retina
46 * support
47 * @modules java.desktop/sun.java2d
48 * @run main MultiResolutionSplashTest GENERATE_IMAGES
49 * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0
50 * @run main/othervm -splash:splash2 MultiResolutionSplashTest TEST_SPLASH 1
51 * @run main/othervm -splash:splash3. MultiResolutionSplashTest TEST_SPLASH 2
52 * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_FOCUS
53 */
54 public class MultiResolutionSplashTest {
55
56 private static final int IMAGE_WIDTH = 300;
57 private static final int IMAGE_HEIGHT = 200;
58
59 private static final ImageInfo[] tests = {
60 new ImageInfo("splash1.png", "splash1@2x.png", Color.BLUE, Color.GREEN),
61 new ImageInfo("splash2", "splash2@2x", Color.WHITE, Color.BLACK),
62 new ImageInfo("splash3.", "splash3@2x.", Color.YELLOW, Color.RED)
63 };
64
65 public static void main(String[] args) throws Exception {
66
67 String test = args[0];
68
69 switch (test) {
70 case "GENERATE_IMAGES":
71 generateImages();
72 break;
73 case "TEST_SPLASH":
74 int index = Integer.parseInt(args[1]);
75 testSplash(tests[index]);
76 break;
77 case "TEST_FOCUS":
78 testFocus();
79 break;
80 default:
81 throw new RuntimeException("Unknown test: " + test);
82 }
83 }
84
85 static void testSplash(ImageInfo test) throws Exception {
86 SplashScreen splashScreen = SplashScreen.getSplashScreen();
87
88 if (splashScreen == null) {
139 && compare(c1.getGreen(), c2.getGreen())
140 && compare(c1.getBlue(), c2.getBlue());
141 }
142
143 static boolean compare(int n, int m){
144 return Math.abs(n - m) <= 50;
145 }
146
147 static float getScaleFactor() {
148
149 final Dialog dialog = new Dialog((Window) null);
150 dialog.setSize(100, 100);
151 dialog.setModal(true);
152 final float[] scaleFactors = new float[1];
153 Panel panel = new Panel() {
154
155 @Override
156 public void paint(Graphics g) {
157 float scaleFactor = 1;
158 if (g instanceof SunGraphics2D) {
159 scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
160 }
161 scaleFactors[0] = scaleFactor;
162 dialog.setVisible(false);
163 }
164 };
165
166 dialog.add(panel);
167 dialog.setVisible(true);
168 dialog.dispose();
169
170 return scaleFactors[0];
171 }
172
173 static void generateImages() throws Exception {
174 for (ImageInfo test : tests) {
175 generateImage(test.name1x, test.color1x, 1);
176 generateImage(test.name2x, test.color2x, 2);
177 }
178 }
179
|
23
24 import java.awt.Color;
25 import java.awt.Dialog;
26 import java.awt.Frame;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.Panel;
30 import java.awt.Rectangle;
31 import java.awt.Robot;
32 import java.awt.SplashScreen;
33 import java.awt.TextField;
34 import java.awt.Window;
35 import java.awt.event.KeyEvent;
36 import java.awt.image.BufferedImage;
37 import java.io.File;
38 import javax.imageio.ImageIO;
39 import sun.java2d.SunGraphics2D;
40
41 /**
42 * @test
43 * @bug 8043869 8075244 8078082 8145173
44 * @summary Tests the HiDPI splash screen support for windows and MAC
45 * @modules java.desktop/sun.java2d
46 * @run main MultiResolutionSplashTest GENERATE_IMAGES
47 * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0
48 * @run main/othervm -splash:splash2 MultiResolutionSplashTest TEST_SPLASH 1
49 * @run main/othervm -splash:splash3. MultiResolutionSplashTest TEST_SPLASH 2
50 * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_FOCUS
51 */
52 public class MultiResolutionSplashTest {
53
54 private static final int IMAGE_WIDTH = 300;
55 private static final int IMAGE_HEIGHT = 200;
56
57 private static final ImageInfo[] macTests = {
58 new ImageInfo("splash1.png", "splash1@2x.png", Color.BLUE, Color.GREEN),
59 new ImageInfo("splash2", "splash2@2x", Color.WHITE, Color.BLACK),
60 new ImageInfo("splash3.", "splash3@2x.", Color.YELLOW, Color.RED)
61 };
62 private static final ImageInfo[] windowsTests = {
63 new ImageInfo("splash1.png", "splash1.scale-120.png", Color.BLUE, Color.GREEN),
64 new ImageInfo("splash2", "splash2.scale-120", Color.WHITE, Color.BLACK),
65 new ImageInfo("splash3.", "splash3.scale-120.", Color.YELLOW, Color.RED)
66 };
67 private static ImageInfo[] tests;
68
69 public static void main(String[] args) throws Exception {
70
71 String test = args[0];
72 tests = windowsTests;
73 String osName = System.getProperty("os.name");
74 if(osName != null && osName.equalsIgnoreCase("mac")) {
75 tests = macTests;
76 }
77 switch (test) {
78 case "GENERATE_IMAGES":
79 generateImages();
80 break;
81 case "TEST_SPLASH":
82 int index = Integer.parseInt(args[1]);
83 testSplash(tests[index]);
84 break;
85 case "TEST_FOCUS":
86 testFocus();
87 break;
88 default:
89 throw new RuntimeException("Unknown test: " + test);
90 }
91 }
92
93 static void testSplash(ImageInfo test) throws Exception {
94 SplashScreen splashScreen = SplashScreen.getSplashScreen();
95
96 if (splashScreen == null) {
147 && compare(c1.getGreen(), c2.getGreen())
148 && compare(c1.getBlue(), c2.getBlue());
149 }
150
151 static boolean compare(int n, int m){
152 return Math.abs(n - m) <= 50;
153 }
154
155 static float getScaleFactor() {
156
157 final Dialog dialog = new Dialog((Window) null);
158 dialog.setSize(100, 100);
159 dialog.setModal(true);
160 final float[] scaleFactors = new float[1];
161 Panel panel = new Panel() {
162
163 @Override
164 public void paint(Graphics g) {
165 float scaleFactor = 1;
166 if (g instanceof SunGraphics2D) {
167 scaleFactor = (float)((SunGraphics2D) g).surfaceData.getDefaultScaleX();
168 }
169 scaleFactors[0] = scaleFactor;
170 dialog.setVisible(false);
171 }
172 };
173
174 dialog.add(panel);
175 dialog.setVisible(true);
176 dialog.dispose();
177
178 return scaleFactors[0];
179 }
180
181 static void generateImages() throws Exception {
182 for (ImageInfo test : tests) {
183 generateImage(test.name1x, test.color1x, 1);
184 generateImage(test.name2x, test.color2x, 2);
185 }
186 }
187
|