24
24
*/
25
25
#include " systemScale.h"
26
26
#include < d2d1.h>
27
- #pragma comment(lib, "d2d1")
28
27
#include < jdk_util.h>
29
28
#ifndef MDT_EFFECTIVE_DPI
30
29
#define MDT_EFFECTIVE_DPI 0
@@ -53,6 +52,9 @@ void GetScreenDpi(HMONITOR hmon, float *dpiX, float *dpiY)
53
52
return ;
54
53
}
55
54
55
+ typedef HRESULT (WINAPI D2D1CreateFactoryFunc)
56
+ (D2D1_FACTORY_TYPE, REFIID,
57
+ CONST D2D1_FACTORY_OPTIONS*, ID2D1Factory**);
56
58
typedef HRESULT (WINAPI GetDpiForMonitorFunc)(HMONITOR, int , UINT*, UINT*);
57
59
static HMODULE hLibSHCoreDll = NULL ;
58
60
static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL ;
@@ -73,12 +75,27 @@ void GetScreenDpi(HMONITOR hmon, float *dpiX, float *dpiY)
73
75
*dpiY = static_cast <float >(y);
74
76
}
75
77
} else {
76
- ID2D1Factory* m_pDirect2dFactory;
77
- HRESULT res = D2D1CreateFactory (D2D1_FACTORY_TYPE_SINGLE_THREADED,
78
- &m_pDirect2dFactory);
79
- if (res == S_OK) {
80
- m_pDirect2dFactory->GetDesktopDpi (dpiX, dpiY);
81
- m_pDirect2dFactory->Release ();
78
+ static HMODULE d2dDll = NULL ;
79
+ static BOOL loadAttempted = FALSE ;
80
+ static D2D1CreateFactoryFunc *lpD2D1CreateFactory = NULL ;
81
+ if (!loadAttempted && d2dDll == NULL ) {
82
+ loadAttempted = TRUE ;
83
+ d2dDll = JDK_LoadSystemLibrary (" d2d1.dll" );
84
+ }
85
+ if (d2dDll != NULL && lpD2D1CreateFactory == NULL ) {
86
+ lpD2D1CreateFactory = (D2D1CreateFactoryFunc*)GetProcAddress (
87
+ d2dDll, " D2D1CreateFactory" );
88
+ }
89
+ if (lpD2D1CreateFactory != NULL ) {
90
+ ID2D1Factory* m_pDirect2dFactory;
91
+ HRESULT res = lpD2D1CreateFactory
92
+ (D2D1_FACTORY_TYPE_SINGLE_THREADED,
93
+ __uuidof (ID2D1Factory), NULL ,
94
+ &m_pDirect2dFactory);
95
+ if (res == S_OK) {
96
+ m_pDirect2dFactory->GetDesktopDpi (dpiX, dpiY);
97
+ m_pDirect2dFactory->Release ();
98
+ }
82
99
}
83
100
}
84
101
return ;
0 commit comments