PR #174: Skip the call to MonitorFromRect when it is not needed.

This commit is contained in:
ManoloFLTK
2021-02-15 21:07:24 +01:00
parent bbaec9bd88
commit a723c0e889
2 changed files with 13 additions and 7 deletions
+12 -4
View File
@@ -565,13 +565,21 @@ void Fl_WinAPI_Screen_Driver::open_display_platform() {
void Fl_WinAPI_Screen_Driver::desktop_scale_factor() {
typedef HRESULT(WINAPI * GetDpiForMonitor_type)(HMONITOR, int, UINT *, UINT *);
typedef HMONITOR(WINAPI * MonitorFromRect_type)(LPCRECT, DWORD);
GetDpiForMonitor_type fl_GetDpiForMonitor = NULL;
if (is_dpi_aware)
fl_GetDpiForMonitor = (GetDpiForMonitor_type)GetProcAddress(LoadLibrary("Shcore.DLL"), "GetDpiForMonitor");
MonitorFromRect_type fl_MonitorFromRect = NULL;
if (is_dpi_aware) {
fl_GetDpiForMonitor = (GetDpiForMonitor_type)GetProcAddress(LoadLibrary("Shcore.DLL"), "GetDpiForMonitor");
if (fl_GetDpiForMonitor)
fl_MonitorFromRect = (MonitorFromRect_type)GetProcAddress(LoadLibrary("User32.DLL"), "MonitorFromRect");
}
for (int ns = 0; ns < screen_count(); ns++) {
HMONITOR hm = MonitorFromRect(&screens[ns], MONITOR_DEFAULTTONEAREST);
UINT dpiX, dpiY;
HRESULT r = fl_GetDpiForMonitor ? fl_GetDpiForMonitor(hm, 0, &dpiX, &dpiY) : !S_OK;
HRESULT r = E_INVALIDARG;
if (fl_GetDpiForMonitor && fl_MonitorFromRect) {
HMONITOR hm = fl_MonitorFromRect(&screens[ns], MONITOR_DEFAULTTONEAREST);
r = fl_GetDpiForMonitor(hm, 0, &dpiX, &dpiY);
}
if (r != S_OK) { dpiX = dpiY = 96; }
dpi[ns][0] = float(dpiX);
dpi[ns][1] = float(dpiY);
@@ -125,7 +125,7 @@ void Fl_WinAPI_Screen_Driver::init()
// NOTE: num_screens is incremented in screen_cb so we must first reset it here...
num_screens = 0;
fl_edm(0, 0, screen_cb, (LPARAM)this);
goto way_out;
return;
}
}
}
@@ -137,8 +137,6 @@ void Fl_WinAPI_Screen_Driver::init()
screens[0].right = GetSystemMetrics(SM_CXSCREEN);
screens[0].bottom = GetSystemMetrics(SM_CYSCREEN);
work_area[0] = screens[0];
way_out:
desktop_scale_factor();
}