Skip to content

Commit cfe9df2

Browse files
committed
8229800: WindowsServerCore 1809 does not provide d2d1.dll library required by awt.dll
Reviewed-by: jdv, serb, aaivanov
1 parent 145c511 commit cfe9df2

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/java.desktop/windows/native/common/awt/systemscale/systemScale.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
#include "systemScale.h"
2626
#include <d2d1.h>
27-
#pragma comment(lib, "d2d1")
2827
#include <jdk_util.h>
2928
#ifndef MDT_EFFECTIVE_DPI
3029
#define MDT_EFFECTIVE_DPI 0
@@ -53,6 +52,9 @@ void GetScreenDpi(HMONITOR hmon, float *dpiX, float *dpiY)
5352
return;
5453
}
5554

55+
typedef HRESULT(WINAPI D2D1CreateFactoryFunc)
56+
(D2D1_FACTORY_TYPE, REFIID,
57+
CONST D2D1_FACTORY_OPTIONS*, ID2D1Factory**);
5658
typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);
5759
static HMODULE hLibSHCoreDll = NULL;
5860
static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL;
@@ -73,12 +75,27 @@ void GetScreenDpi(HMONITOR hmon, float *dpiX, float *dpiY)
7375
*dpiY = static_cast<float>(y);
7476
}
7577
} 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+
}
8299
}
83100
}
84101
return;

src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
#include "dither.h"
5050
#include "img_util_md.h"
5151
#include "Devices.h"
52-
#include <d2d1.h>
53-
#pragma comment(lib, "d2d1")
5452
#include "systemScale.h"
5553

5654
uns_ordered_dither_array img_oda_alpha;

0 commit comments

Comments
 (0)