提交 09ba7191 编写于 作者: A alexsch

8075244: [macosx] The fix for JDK-8043869 should be reworked

Reviewed-by: prr, serb, ant
上级 ff0db1c6
...@@ -126,12 +126,30 @@ done: ...@@ -126,12 +126,30 @@ done:
return buf; return buf;
} }
BOOL isSWTRunning() {
char envVar[80];
// If this property is present we are running SWT
snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
return getenv(envVar) != NULL;
}
char* SplashGetScaledImageName(const char* jar, const char* file, char* SplashGetScaledImageName(const char* jar, const char* file,
float *scaleFactor) { float *scaleFactor) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
*scaleFactor = 1; *scaleFactor = 1;
if(isSWTRunning()){
return nil;
}
NSAutoreleasePool *pool = [NSAutoreleasePool new];
char* scaledFile = nil; char* scaledFile = nil;
float screenScaleFactor = 1; __block float screenScaleFactor = 1;
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
// initialize NSApplication and AWT stuff
[NSApplicationAWT sharedApplication];
screenScaleFactor = [SplashNSScreen() backingScaleFactor];
}];
if (screenScaleFactor > 1) { if (screenScaleFactor > 1) {
NSString *fileName = [NSString stringWithUTF8String: file]; NSString *fileName = [NSString stringWithUTF8String: file];
...@@ -176,12 +194,8 @@ SplashInitPlatform(Splash * splash) { ...@@ -176,12 +194,8 @@ SplashInitPlatform(Splash * splash) {
splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST; splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
splash->screenFormat.depthBytes = 4; splash->screenFormat.depthBytes = 4;
// If this property is present we are running SWT and should not start a runLoop // If we are running SWT we should not start a runLoop
// Can't check if running SWT in webstart, so splash screen in webstart SWT if (!isSWTRunning()) {
// applications is not supported
char envVar[80];
snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
if (getenv(envVar) == NULL) {
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
[NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]]; [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
}]; }];
......
...@@ -23,21 +23,24 @@ ...@@ -23,21 +23,24 @@
import java.awt.Color; import java.awt.Color;
import java.awt.Dialog; import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Panel; import java.awt.Panel;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Robot; import java.awt.Robot;
import java.awt.SplashScreen; import java.awt.SplashScreen;
import java.awt.TextField;
import java.awt.Window; import java.awt.Window;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import sun.java2d.SunGraphics2D; import sun.java2d.SunGraphics2D;
/** /**
* test * @test
* @bug 8043869 * @bug 8043869 8075244
* @author Alexander Scherbatiy * @author Alexander Scherbatiy
* @summary [macosx] java -splash does not honor 2x hi dpi notation for retina * @summary [macosx] java -splash does not honor 2x hi dpi notation for retina
* support * support
...@@ -45,6 +48,7 @@ import sun.java2d.SunGraphics2D; ...@@ -45,6 +48,7 @@ import sun.java2d.SunGraphics2D;
* @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0 * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0
* @run main/othervm -splash:splash2 MultiResolutionSplashTest TEST_SPLASH 1 * @run main/othervm -splash:splash2 MultiResolutionSplashTest TEST_SPLASH 1
* @run main/othervm -splash:splash3. MultiResolutionSplashTest TEST_SPLASH 2 * @run main/othervm -splash:splash3. MultiResolutionSplashTest TEST_SPLASH 2
* @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_FOCUS
*/ */
public class MultiResolutionSplashTest { public class MultiResolutionSplashTest {
...@@ -69,6 +73,9 @@ public class MultiResolutionSplashTest { ...@@ -69,6 +73,9 @@ public class MultiResolutionSplashTest {
int index = Integer.parseInt(args[1]); int index = Integer.parseInt(args[1]);
testSplash(tests[index]); testSplash(tests[index]);
break; break;
case "TEST_FOCUS":
testFocus();
break;
default: default:
throw new RuntimeException("Unknown test: " + test); throw new RuntimeException("Unknown test: " + test);
} }
...@@ -92,12 +99,49 @@ public class MultiResolutionSplashTest { ...@@ -92,12 +99,49 @@ public class MultiResolutionSplashTest {
float scaleFactor = getScaleFactor(); float scaleFactor = getScaleFactor();
Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x; Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
if (!testColor.equals(splashScreenColor)) { if (!compare(testColor, splashScreenColor)) {
throw new RuntimeException( throw new RuntimeException(
"Image with wrong resolution is used for splash screen!"); "Image with wrong resolution is used for splash screen!");
} }
} }
static void testFocus() throws Exception {
System.out.println("Focus Test!");
Robot robot = new Robot();
robot.setAutoDelay(50);
Frame frame = new Frame();
frame.setSize(100, 100);
String test = "123";
TextField textField = new TextField(test);
frame.add(textField);
frame.setVisible(true);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_B);
robot.waitForIdle();
frame.dispose();
if(!textField.getText().equals("ab")){
throw new RuntimeException("Focus is lost!");
}
}
static boolean compare(Color c1, Color c2){
return compare(c1.getRed(), c2.getRed())
&& compare(c1.getGreen(), c2.getGreen())
&& compare(c1.getBlue(), c2.getBlue());
}
static boolean compare(int n, int m){
return Math.abs(n - m) <= 50;
}
static float getScaleFactor() { static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null); final Dialog dialog = new Dialog((Window) null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册