src/java.desktop/windows/native/common/awt/systemscale/systemScale.cpp
branchJEP-349-branch
changeset 58343 ca19b94eac7a
parent 58129 7b751fe181a5
parent 58316 718496767a7d
equal deleted inserted replaced
58271:e47423f1318b 58343:ca19b94eac7a
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 #include "systemScale.h"
    25 #include "systemScale.h"
    26 #include <d2d1.h>
    26 #include <d2d1.h>
    27 #pragma comment(lib, "d2d1")
       
    28 #include <jdk_util.h>
    27 #include <jdk_util.h>
    29 #ifndef MDT_EFFECTIVE_DPI
    28 #ifndef MDT_EFFECTIVE_DPI
    30 #define MDT_EFFECTIVE_DPI 0
    29 #define MDT_EFFECTIVE_DPI 0
    31 #endif
    30 #endif
    32 
    31 
    51     if (scale > 0) {
    50     if (scale > 0) {
    52         *dpiX = *dpiY = scale;
    51         *dpiX = *dpiY = scale;
    53         return;
    52         return;
    54     }
    53     }
    55 
    54 
       
    55     typedef HRESULT(WINAPI D2D1CreateFactoryFunc)
       
    56                    (D2D1_FACTORY_TYPE, REFIID,
       
    57                     CONST D2D1_FACTORY_OPTIONS*, ID2D1Factory**);
    56     typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);
    58     typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);
    57     static HMODULE hLibSHCoreDll = NULL;
    59     static HMODULE hLibSHCoreDll = NULL;
    58     static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL;
    60     static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL;
    59 
    61 
    60     if (hLibSHCoreDll == NULL) {
    62     if (hLibSHCoreDll == NULL) {
    71         if (hResult == S_OK) {
    73         if (hResult == S_OK) {
    72             *dpiX = static_cast<float>(x);
    74             *dpiX = static_cast<float>(x);
    73             *dpiY = static_cast<float>(y);
    75             *dpiY = static_cast<float>(y);
    74         }
    76         }
    75     } else {
    77     } else {
    76         ID2D1Factory* m_pDirect2dFactory;
    78         static HMODULE d2dDll = NULL;
    77         HRESULT res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
    79         static BOOL loadAttempted = FALSE;
    78                                         &m_pDirect2dFactory);
    80         static D2D1CreateFactoryFunc *lpD2D1CreateFactory = NULL;
    79         if (res == S_OK) {
    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) {
    80            // m_pDirect2dFactory->GetDesktopDpi(dpiX, dpiY);
    96            // m_pDirect2dFactory->GetDesktopDpi(dpiX, dpiY);
    81             m_pDirect2dFactory->Release();
    97                 m_pDirect2dFactory->Release();
       
    98             }
    82         }
    99         }
    83     }
   100     }
    84     return;
   101     return;
    85 }
   102 }
    86 
   103