changeset 10713:f8c771c61ff2

8075244: [macosx] The fix for JDK-8043869 should be reworked Reviewed-by: prr, serb, ant
author alexsch
date Mon, 30 Mar 2015 17:09:21 +0400
parents a1b163779415
children 36d432e9be13
files src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java
diffstat 2 files changed, 69 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m	Mon Mar 30 17:03:56 2015 +0400
+++ b/src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m	Mon Mar 30 17:09:21 2015 +0400
@@ -126,12 +126,30 @@
     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,
                                float *scaleFactor) {
+    *scaleFactor = 1;
+
+    if(isSWTRunning()){
+        return nil;
+    }
+
     NSAutoreleasePool *pool = [NSAutoreleasePool new];
-    *scaleFactor = 1;
     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) {
         NSString *fileName = [NSString stringWithUTF8String: file];
@@ -176,12 +194,8 @@
     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
     splash->screenFormat.depthBytes = 4;
 
-    // If this property is present we are running SWT and should not start a runLoop
-    // Can't check if running SWT in webstart, so splash screen in webstart SWT
-    // applications is not supported
-    char envVar[80];
-    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
-    if (getenv(envVar) == NULL) {
+    // If we are running SWT we should not start a runLoop
+    if (!isSWTRunning()) {
         [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
             [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
         }];
--- a/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java	Mon Mar 30 17:03:56 2015 +0400
+++ b/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java	Mon Mar 30 17:09:21 2015 +0400
@@ -23,21 +23,24 @@
 
 import java.awt.Color;
 import java.awt.Dialog;
+import java.awt.Frame;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Panel;
 import java.awt.Rectangle;
 import java.awt.Robot;
 import java.awt.SplashScreen;
+import java.awt.TextField;
 import java.awt.Window;
+import java.awt.event.KeyEvent;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import javax.imageio.ImageIO;
 import sun.java2d.SunGraphics2D;
 
 /**
- * test
- * @bug 8043869
+ * @test
+ * @bug 8043869 8075244
  * @author Alexander Scherbatiy
  * @summary [macosx] java -splash does not honor 2x hi dpi notation for retina
  * support
@@ -45,6 +48,7 @@
  * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0
  * @run main/othervm -splash:splash2 MultiResolutionSplashTest TEST_SPLASH 1
  * @run main/othervm -splash:splash3. MultiResolutionSplashTest TEST_SPLASH 2
+ * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_FOCUS
  */
 public class MultiResolutionSplashTest {
 
@@ -69,6 +73,9 @@
                 int index = Integer.parseInt(args[1]);
                 testSplash(tests[index]);
                 break;
+            case "TEST_FOCUS":
+                testFocus();
+                break;
             default:
                 throw new RuntimeException("Unknown test: " + test);
         }
@@ -92,12 +99,49 @@
         float scaleFactor = getScaleFactor();
         Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;
 
-        if (!testColor.equals(splashScreenColor)) {
+        if (!compare(testColor, splashScreenColor)) {
             throw new RuntimeException(
                     "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() {
 
         final Dialog dialog = new Dialog((Window) null);