jdk/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp
changeset 36907 c3d8383e3efb
parent 34394 259d6e4e0978
child 38975 54b83c0b4333
equal deleted inserted replaced
36906:b6c9a99a8f5d 36907:c3d8383e3efb
    49 #include "dither.h"
    49 #include "dither.h"
    50 #include "img_util_md.h"
    50 #include "img_util_md.h"
    51 #include "Devices.h"
    51 #include "Devices.h"
    52 #include <d2d1.h>
    52 #include <d2d1.h>
    53 #pragma comment(lib, "d2d1")
    53 #pragma comment(lib, "d2d1")
    54 
    54 #include "systemScale.h"
    55 #ifndef MDT_Effective_DPI
       
    56 #define MDT_Effective_DPI 0
       
    57 #endif
       
    58 
    55 
    59 uns_ordered_dither_array img_oda_alpha;
    56 uns_ordered_dither_array img_oda_alpha;
    60 
    57 
    61 jclass      AwtWin32GraphicsDevice::indexCMClass;
    58 jclass      AwtWin32GraphicsDevice::indexCMClass;
    62 jclass      AwtWin32GraphicsDevice::wToolkitClass;
    59 jclass      AwtWin32GraphicsDevice::wToolkitClass;
   653     return (int)ceil(y / scaleY);
   650     return (int)ceil(y / scaleY);
   654 }
   651 }
   655 
   652 
   656 void AwtWin32GraphicsDevice::InitDesktopScales()
   653 void AwtWin32GraphicsDevice::InitDesktopScales()
   657 {
   654 {
   658     unsigned x = 0;
       
   659     unsigned y = 0;
       
   660     float dpiX = -1.0f;
   655     float dpiX = -1.0f;
   661     float dpiY = -1.0f;
   656     float dpiY = -1.0f;
   662 
   657     GetScreenDpi(GetMonitor(), &dpiX, &dpiY);
   663     // for debug purposes
       
   664     static float scale = -2.0f;
       
   665     if (scale == -2) {
       
   666         scale = -1;
       
   667         char *uiScale = getenv("J2D_UISCALE");
       
   668         if (uiScale != NULL) {
       
   669             scale = (float)strtod(uiScale, NULL);
       
   670             if (errno == ERANGE || scale <= 0) {
       
   671                 scale = -1;
       
   672             }
       
   673         }
       
   674     }
       
   675 
       
   676     if (scale > 0) {
       
   677         SetScale(scale, scale);
       
   678         return;
       
   679     }
       
   680 
       
   681     typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);
       
   682     static HMODULE hLibSHCoreDll = NULL;
       
   683     static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL;
       
   684 
       
   685     if (hLibSHCoreDll == NULL) {
       
   686         hLibSHCoreDll = JDK_LoadSystemLibrary("shcore.dll");
       
   687         if (hLibSHCoreDll != NULL) {
       
   688             lpGetDpiForMonitor = (GetDpiForMonitorFunc*)GetProcAddress(
       
   689                 hLibSHCoreDll, "GetDpiForMonitor");
       
   690         }
       
   691     }
       
   692 
       
   693     if (lpGetDpiForMonitor != NULL) {
       
   694         HRESULT hResult = lpGetDpiForMonitor(GetMonitor(),
       
   695                                              MDT_Effective_DPI, &x, &y);
       
   696         if (hResult == S_OK) {
       
   697             dpiX = static_cast<float>(x);
       
   698             dpiY = static_cast<float>(y);
       
   699         }
       
   700     } else {
       
   701         ID2D1Factory* m_pDirect2dFactory;
       
   702         HRESULT res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,
       
   703                                         &m_pDirect2dFactory);
       
   704         if (res == S_OK) {
       
   705             m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);
       
   706             m_pDirect2dFactory->Release();
       
   707         }
       
   708     }
       
   709 
       
   710     if (dpiX > 0 && dpiY > 0) {
   658     if (dpiX > 0 && dpiY > 0) {
   711         SetScale(dpiX / 96, dpiY / 96);
   659         SetScale(dpiX / 96, dpiY / 96);
   712     }
   660     }
   713 }
   661 }
   714 
   662 
  1470 
  1418 
  1471     if (device != NULL) {
  1419     if (device != NULL) {
  1472         device->InitDesktopScales();
  1420         device->InitDesktopScales();
  1473     }
  1421     }
  1474 }
  1422 }
       
  1423