8229800: WindowsServerCore 1809 does not provide d2d1.dll library required by awt.dll
authorprr
Wed, 28 Aug 2019 09:13:01 -0700
changeset 58316 718496767a7d
parent 58315 07556f8cd819
child 58317 ddd26bd764e8
8229800: WindowsServerCore 1809 does not provide d2d1.dll library required by awt.dll Reviewed-by: jdv, serb, aaivanov
src/java.desktop/windows/native/common/awt/systemscale/systemScale.cpp
src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp
--- a/src/java.desktop/windows/native/common/awt/systemscale/systemScale.cpp	Tue Aug 27 04:43:01 2019 -0700
+++ b/src/java.desktop/windows/native/common/awt/systemscale/systemScale.cpp	Wed Aug 28 09:13:01 2019 -0700
@@ -24,7 +24,6 @@
  */
 #include "systemScale.h"
 #include <d2d1.h>
-#pragma comment(lib, "d2d1")
 #include <jdk_util.h>
 #ifndef MDT_EFFECTIVE_DPI
 #define MDT_EFFECTIVE_DPI 0
@@ -53,6 +52,9 @@
         return;
     }
 
+    typedef HRESULT(WINAPI D2D1CreateFactoryFunc)
+                   (D2D1_FACTORY_TYPE, REFIID,
+                    CONST D2D1_FACTORY_OPTIONS*, ID2D1Factory**);
     typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);
     static HMODULE hLibSHCoreDll = NULL;
     static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL;
@@ -73,12 +75,27 @@
             *dpiY = static_cast<float>(y);
         }
     } else {
-        ID2D1Factory* m_pDirect2dFactory;
-        HRESULT res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
-                                        &m_pDirect2dFactory);
-        if (res == S_OK) {
-            m_pDirect2dFactory->GetDesktopDpi(dpiX, dpiY);
-            m_pDirect2dFactory->Release();
+        static HMODULE d2dDll = NULL;
+        static BOOL loadAttempted = FALSE;
+        static D2D1CreateFactoryFunc *lpD2D1CreateFactory = NULL;
+        if (!loadAttempted && d2dDll == NULL) {
+            loadAttempted = TRUE;
+            d2dDll = JDK_LoadSystemLibrary("d2d1.dll");
+        }
+        if (d2dDll != NULL && lpD2D1CreateFactory == NULL) {
+            lpD2D1CreateFactory = (D2D1CreateFactoryFunc*)GetProcAddress(
+                    d2dDll, "D2D1CreateFactory");
+        }
+        if (lpD2D1CreateFactory != NULL) {
+            ID2D1Factory* m_pDirect2dFactory;
+            HRESULT res = lpD2D1CreateFactory
+                          (D2D1_FACTORY_TYPE_SINGLE_THREADED,
+                           __uuidof(ID2D1Factory), NULL,
+                           &m_pDirect2dFactory);
+            if (res == S_OK) {
+                m_pDirect2dFactory->GetDesktopDpi(dpiX, dpiY);
+                m_pDirect2dFactory->Release();
+            }
         }
     }
     return;
--- a/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp	Tue Aug 27 04:43:01 2019 -0700
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp	Wed Aug 28 09:13:01 2019 -0700
@@ -49,8 +49,6 @@
 #include "dither.h"
 #include "img_util_md.h"
 #include "Devices.h"
-#include <d2d1.h>
-#pragma comment(lib, "d2d1")
 #include "systemScale.h"
 
 uns_ordered_dither_array img_oda_alpha;