8149151: Use local GraphicsEnvironment to get screen size in WToolkit
authoralexsch
Sat, 06 Feb 2016 09:25:56 -0800
changeset 35993 78480b291d6b
parent 35992 e81271ca6320
child 35994 3e67412f1556
8149151: Use local GraphicsEnvironment to get screen size in WToolkit Reviewed-by: prr, serb
jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java
jdk/src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp
jdk/test/java/awt/Toolkit/GetSizeTest/GetScreenSizeTest.java
--- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java	Thu Feb 04 14:27:16 2016 +0300
+++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java	Sat Feb 06 09:25:56 2016 -0800
@@ -641,10 +641,21 @@
             GraphicsEnvironment.getLocalGraphicsEnvironment();
         return ge.getXResolution();
     }
+
     @Override
-    protected native int getScreenWidth();
+    protected int getScreenWidth() {
+        return GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getDefaultScreenDevice().getDefaultConfiguration()
+                .getBounds().width;
+    }
+
     @Override
-    protected native int getScreenHeight();
+    protected int getScreenHeight() {
+        return GraphicsEnvironment.getLocalGraphicsEnvironment()
+                .getDefaultScreenDevice().getDefaultConfiguration()
+                .getBounds().height;
+    }
+
     private native Insets getScreenInsets(int screen);
 
 
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp	Thu Feb 04 14:27:16 2016 +0300
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp	Sat Feb 06 09:25:56 2016 -0800
@@ -2347,53 +2347,6 @@
 
 /*
  * Class:     sun_awt_windows_WToolkit
- * Method:    getScreenWidth
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL
-Java_sun_awt_windows_WToolkit_getScreenWidth(JNIEnv *env, jobject self)
-{
-    TRY;
-
-    int width = ::GetSystemMetrics(SM_CXSCREEN);
-
-    if (!Devices::GetInstance()) {
-        Devices::UpdateInstance(env);
-    }
-    Devices::InstanceAccess devices;
-    AwtWin32GraphicsDevice *device = devices->GetDevice(
-                        AwtWin32GraphicsDevice::GetDefaultDeviceIndex());
-
-    return (device == NULL) ? width : device->ScaleDownX(width);
-    CATCH_BAD_ALLOC_RET(0);
-}
-
-/*
- * Class:     sun_awt_windows_WToolkit
- * Method:    getScreenHeight
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL
-Java_sun_awt_windows_WToolkit_getScreenHeight(JNIEnv *env, jobject self)
-{
-    TRY;
-
-    int height = ::GetSystemMetrics(SM_CYSCREEN);
-
-    if (!Devices::GetInstance()) {
-        Devices::UpdateInstance(env);
-    }
-    Devices::InstanceAccess devices;
-    AwtWin32GraphicsDevice *device = devices->GetDevice(
-                        AwtWin32GraphicsDevice::GetDefaultDeviceIndex());
-
-    return (device == NULL) ? height : device->ScaleDownY(height);
-
-    CATCH_BAD_ALLOC_RET(0);
-}
-
-/*
- * Class:     sun_awt_windows_WToolkit
  * Method:    getSreenInsets
  * Signature: (I)Ljava/awt/Insets;
  */
--- a/jdk/test/java/awt/Toolkit/GetSizeTest/GetScreenSizeTest.java	Thu Feb 04 14:27:16 2016 +0300
+++ b/jdk/test/java/awt/Toolkit/GetSizeTest/GetScreenSizeTest.java	Sat Feb 06 09:25:56 2016 -0800
@@ -23,7 +23,7 @@
 
 /*
   @test
-  @bug 8144074 8145785
+  @bug 8144074 8145785 8149151
   @summary Crash while getting screen size during Toolkit initialisation
   @run main/othervm GetScreenSizeTest
 */