| 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..d84926b5ad23897bd219c0c5c1f31eecd733f808 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,31 @@ namespace {
|
| // resolved with Desktop Aura and WindowTreeHost.
|
| ScreenWin* g_screen_win_instance = nullptr;
|
|
|
| +float GetMonitorScaleFactor(HMONITOR monitor) {
|
| + DCHECK(monitor);
|
| + if (base::win::IsProcessPerMonitorDpiAware()) {
|
| + static auto get_dpi_for_monitor_func = [](){
|
| + using GetDpiForMonitorPtr = decltype(::GetDpiForMonitor)*;
|
| + HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll");
|
| + if (shcore_dll) {
|
| + return reinterpret_cast<GetDpiForMonitorPtr>(
|
| + ::GetProcAddress(shcore_dll, "GetDpiForMonitor"));
|
| + }
|
| + return reinterpret_cast<GetDpiForMonitorPtr>(nullptr);
|
| + }();
|
| +
|
| + UINT dpi_x;
|
| + UINT dpi_y;
|
| + if (get_dpi_for_monitor_func &&
|
| + SUCCEEDED(get_dpi_for_monitor_func(monitor, MDT_EFFECTIVE_DPI,
|
| + &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 +171,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;
|
| }
|
|
|
|
|