1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include <splashscreen_config.h> 25 #include <d2d1.h> 26 #pragma comment(lib, "d2d1") 27 #include <jdk_util.h> 28 #include <VersionHelpers.h> 29 #ifndef MDT_EFFECTIVE_DPI 30 #define MDT_EFFECTIVE_DPI 0 31 #endif 32 33 float GetScreenDpi() 34 { 35 float dpiX = -1.0f; 36 float dpiY = -1.0f; 37 if (IsWindows8OrGreater()) { 38 unsigned x = 0; 39 unsigned y = 0; 40 typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*); 41 static HMODULE sHCoreDll = NULL; 42 static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL; 43 44 if (sHCoreDll == NULL) { 45 sHCoreDll = JDK_LoadSystemLibrary("shcore.dll"); 46 if (sHCoreDll != NULL) { 47 lpGetDpiForMonitor = (GetDpiForMonitorFunc*)GetProcAddress( 48 sHCoreDll, "GetDpiForMonitor"); 49 } 50 } 51 if (lpGetDpiForMonitor != NULL) { 52 HMONITOR hmon = getPrimaryMonitor(); 53 HRESULT hResult = lpGetDpiForMonitor(hmon, 54 MDT_EFFECTIVE_DPI, &x, &y); 55 if (hResult == S_OK) { 56 dpiX = static_cast<float>(x); 57 dpiY = static_cast<float>(y); 58 } 59 } 60 return dpiX; 61 } 62 else if (IsWindows7OrGreater()) { 63 ID2D1Factory* m_pDirect2dFactory; 64 HRESULT res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, 65 &m_pDirect2dFactory); 66 if (res == S_OK) { 67 m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY); 68 m_pDirect2dFactory->Release(); 69 } 70 return dpiX; 71 } 72 return 1.0; 73 } 74 75 HMONITOR WINAPI getPrimaryMonitor() 76 { 77 const POINT point = { 0, 0 }; 78 return MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY); 79 } 80