Chromium Code Reviews| Index: ui/display/win/screen_win.cc |
| diff --git a/ui/display/win/screen_win.cc b/ui/display/win/screen_win.cc |
| index 3b6f6dfcb4ee37bb30a94ecbad8741a10a435057..19913b000f45c52b8aa7dca5641719002d29815a 100644 |
| --- a/ui/display/win/screen_win.cc |
| +++ b/ui/display/win/screen_win.cc |
| @@ -5,11 +5,13 @@ |
| #include "ui/display/win/screen_win.h" |
| #include <windows.h> |
| +#include <shellscalingapi.h> |
| #include <algorithm> |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| +#include "base/win/win_util.h" |
| #include "ui/display/display.h" |
| #include "ui/display/manager/display_layout.h" |
| #include "ui/display/manager/display_layout_builder.h" |
| @@ -30,6 +32,32 @@ namespace { |
| // resolved with Desktop Aura and WindowTreeHost. |
| ScreenWin* g_screen_win_instance = nullptr; |
| +float GetMonitorScaleFactor(HMONITOR monitor) { |
| + if (base::win::IsProcessPerMonitorDpiAware()) { |
| + using GetDpiForMonitorPtr = |
| + HRESULT (WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*); |
|
scottmg
2016/06/27 17:55:04
Same here.
nit; This will also requery each time
robliao
2016/06/27 18:39:29
Done.
|
| + static GetDpiForMonitorPtr get_dpi_for_monitor_func = nullptr; |
| + if (!get_dpi_for_monitor_func) { |
| + HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll"); |
| + if (shcore_dll) { |
| + get_dpi_for_monitor_func = |
| + reinterpret_cast<GetDpiForMonitorPtr>( |
| + ::GetProcAddress(shcore_dll, "GetDpiForMonitor")); |
| + } |
| + } |
| + |
| + UINT dpi_x; |
| + UINT dpi_y; |
| + if (get_dpi_for_monitor_func && |
| + SUCCEEDED(get_dpi_for_monitor_func(monitor, MDT_EFFECTIVE_DPI, |
|
scottmg
2016/06/27 17:55:04
Maybe DCHECK(monitor)?
robliao
2016/06/27 18:39:29
Done at the top now.
|
| + &dpi_x, &dpi_y))) { |
| + DCHECK_EQ(dpi_x, dpi_y); |
| + return GetScalingFactorFromDPI(dpi_x); |
| + } |
| + } |
| + return GetDPIScale(); |
| +} |
| + |
| std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos( |
| const DisplayInfo& ref_display_info, |
| std::vector<DisplayInfo>* display_infos) { |
| @@ -144,10 +172,8 @@ BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, |
| std::vector<DisplayInfo>* display_infos = |
| reinterpret_cast<std::vector<DisplayInfo>*>(data); |
| DCHECK(display_infos); |
| - // TODO(robliao): When ready, replace the GetDPIScale with GetDpiForMonitor |
| - // to get the actual DPI for the HMONITOR. |
| display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor), |
| - GetDPIScale())); |
| + GetMonitorScaleFactor(monitor))); |
| return TRUE; |
| } |