8158411: Regression on Swingmark on 8u102 b03 comparing 8u102 b02 on several configs on win32
authoralexsch
Thu, 01 Sep 2016 12:02:22 +0300
changeset 40990 6d08b34e7f84
parent 40989 0a9030f6613d
child 40991 24c96f117cf5
8158411: Regression on Swingmark on 8u102 b03 comparing 8u102 b02 on several configs on win32 Reviewed-by: prr, ssadetsky
jdk/src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp
jdk/src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp
--- a/jdk/src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp	Thu Sep 01 10:21:29 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp	Thu Sep 01 12:02:22 2016 +0300
@@ -753,10 +753,15 @@
 }
 
 void rescale(SIZE *size) {
-    HWND hWnd = ::GetDesktopWindow();
-    HDC hDC = ::GetDC(hWnd);
-    int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
-    int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
+    static int dpiX = -1;
+    static int dpiY = -1;
+    if (dpiX == -1 || dpiY == -1) {
+        HWND hWnd = ::GetDesktopWindow();
+        HDC hDC = ::GetDC(hWnd);
+        dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
+        dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
+        ::ReleaseDC(hWnd, hDC);
+    }
 
     if (dpiX !=0 && dpiX != 96) {
         float invScaleX = 96.0f / dpiX;
@@ -766,7 +771,6 @@
         float invScaleY = 96.0f / dpiY;
         size->cy = ROUND_TO_INT(size->cy * invScaleY);
     }
-    ::ReleaseDC(hWnd, hDC);
 }
 
 /*
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp	Thu Sep 01 10:21:29 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp	Thu Sep 01 12:02:22 2016 +0300
@@ -88,11 +88,16 @@
 }
 
 void getInvScale(float &invScaleX, float &invScaleY) {
-    HWND hWnd = ::GetDesktopWindow();
-    HDC hDC = ::GetDC(hWnd);
-    int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
-    int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
-    ::ReleaseDC(hWnd, hDC);
+    static int dpiX = -1;
+    static int dpiY = -1;
+    if (dpiX == -1 || dpiY == -1) {
+        HWND hWnd = ::GetDesktopWindow();
+        HDC hDC = ::GetDC(hWnd);
+        dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
+        dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
+        ::ReleaseDC(hWnd, hDC);
+    }
+
     invScaleX = (dpiX == 0.0f) ? 1.0f : 96.0f / dpiX;
     invScaleY = (dpiY == 0.0f) ? 1.0f : 96.0f / dpiY;
 }