OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/display/win/screen_win.h" | 5 #include "ui/display/win/screen_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shellscalingapi.h> | 8 #include <shellscalingapi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace display { | 28 namespace display { |
29 namespace win { | 29 namespace win { |
30 namespace { | 30 namespace { |
31 | 31 |
32 // TODO(robliao): http://crbug.com/615514 Remove when ScreenWin usage is | 32 // TODO(robliao): http://crbug.com/615514 Remove when ScreenWin usage is |
33 // resolved with Desktop Aura and WindowTreeHost. | 33 // resolved with Desktop Aura and WindowTreeHost. |
34 ScreenWin* g_screen_win_instance = nullptr; | 34 ScreenWin* g_screen_win_instance = nullptr; |
35 | 35 |
36 float GetMonitorScaleFactor(HMONITOR monitor) { | 36 float GetMonitorScaleFactor(HMONITOR monitor) { |
37 DCHECK(monitor); | |
38 if (Display::HasForceDeviceScaleFactor()) | 37 if (Display::HasForceDeviceScaleFactor()) |
39 return Display::GetForcedDeviceScaleFactor(); | 38 return Display::GetForcedDeviceScaleFactor(); |
40 | 39 return ScreenWin::GetUnforcedMonitorScaleFactor(monitor); |
41 if (base::win::IsProcessPerMonitorDpiAware()) { | |
42 static auto get_dpi_for_monitor_func = [](){ | |
43 using GetDpiForMonitorPtr = decltype(::GetDpiForMonitor)*; | |
44 HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll"); | |
45 if (shcore_dll) { | |
46 return reinterpret_cast<GetDpiForMonitorPtr>( | |
47 ::GetProcAddress(shcore_dll, "GetDpiForMonitor")); | |
48 } | |
49 return static_cast<GetDpiForMonitorPtr>(nullptr); | |
50 }(); | |
51 | |
52 UINT dpi_x; | |
53 UINT dpi_y; | |
54 if (get_dpi_for_monitor_func && | |
55 SUCCEEDED(get_dpi_for_monitor_func(monitor, MDT_EFFECTIVE_DPI, | |
56 &dpi_x, &dpi_y))) { | |
57 DCHECK_EQ(dpi_x, dpi_y); | |
58 return GetScalingFactorFromDPI(dpi_x); | |
59 } | |
60 } | |
61 return GetDPIScale(); | |
62 } | 40 } |
63 | 41 |
64 std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos( | 42 std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos( |
65 const DisplayInfo& ref_display_info, | 43 const DisplayInfo& ref_display_info, |
66 std::vector<DisplayInfo>* display_infos) { | 44 std::vector<DisplayInfo>* display_infos) { |
67 std::vector<DisplayInfo> touching_display_infos; | 45 std::vector<DisplayInfo> touching_display_infos; |
68 display_infos->erase( | 46 display_infos->erase( |
69 std::remove_if(display_infos->begin(), display_infos->end(), | 47 std::remove_if(display_infos->begin(), display_infos->end(), |
70 [&touching_display_infos, ref_display_info]( | 48 [&touching_display_infos, ref_display_info]( |
71 const DisplayInfo& display_info) { | 49 const DisplayInfo& display_info) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 return ScreenWinDisplay().display().device_scale_factor(); | 323 return ScreenWinDisplay().display().device_scale_factor(); |
346 | 324 |
347 DCHECK(hwnd); | 325 DCHECK(hwnd); |
348 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); | 326 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); |
349 ScreenWinDisplay screen_win_display = | 327 ScreenWinDisplay screen_win_display = |
350 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); | 328 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); |
351 return screen_win_display.display().device_scale_factor(); | 329 return screen_win_display.display().device_scale_factor(); |
352 } | 330 } |
353 | 331 |
354 // static | 332 // static |
| 333 float ScreenWin::GetUnforcedMonitorScaleFactor(HMONITOR monitor) { |
| 334 DCHECK(monitor); |
| 335 if (base::win::IsProcessPerMonitorDpiAware()) { |
| 336 static auto get_dpi_for_monitor_func = []() { |
| 337 using GetDpiForMonitorPtr = decltype(::GetDpiForMonitor)*; |
| 338 HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll"); |
| 339 if (shcore_dll) { |
| 340 return reinterpret_cast<GetDpiForMonitorPtr>( |
| 341 ::GetProcAddress(shcore_dll, "GetDpiForMonitor")); |
| 342 } |
| 343 return static_cast<GetDpiForMonitorPtr>(nullptr); |
| 344 }(); |
| 345 |
| 346 UINT dpi_x; |
| 347 UINT dpi_y; |
| 348 if (get_dpi_for_monitor_func && |
| 349 SUCCEEDED(get_dpi_for_monitor_func(monitor, MDT_EFFECTIVE_DPI, &dpi_x, |
| 350 &dpi_y))) { |
| 351 DCHECK_EQ(dpi_x, dpi_y); |
| 352 return GetScalingFactorFromDPI(dpi_x); |
| 353 } |
| 354 } |
| 355 return GetUnforcedDeviceScaleFactor(); |
| 356 } |
| 357 |
| 358 // static |
355 float ScreenWin::GetSystemScaleFactor() { | 359 float ScreenWin::GetSystemScaleFactor() { |
356 return GetUnforcedDeviceScaleFactor(); | 360 return GetUnforcedDeviceScaleFactor(); |
357 } | 361 } |
358 | 362 |
359 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { | 363 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { |
360 NOTREACHED(); | 364 NOTREACHED(); |
361 return nullptr; | 365 return nullptr; |
362 } | 366 } |
363 | 367 |
364 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 368 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | 596 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
593 reported_scale) == unique_scale_factors.end()) { | 597 reported_scale) == unique_scale_factors.end()) { |
594 unique_scale_factors.push_back(reported_scale); | 598 unique_scale_factors.push_back(reported_scale); |
595 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 599 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
596 } | 600 } |
597 } | 601 } |
598 } | 602 } |
599 | 603 |
600 } // namespace win | 604 } // namespace win |
601 } // namespace display | 605 } // namespace display |
OLD | NEW |