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 | 9 |
9 #include <algorithm> | 10 #include <algorithm> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/win/win_util.h" |
13 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
14 #include "ui/display/manager/display_layout.h" | 16 #include "ui/display/manager/display_layout.h" |
15 #include "ui/display/manager/display_layout_builder.h" | 17 #include "ui/display/manager/display_layout_builder.h" |
16 #include "ui/display/win/display_info.h" | 18 #include "ui/display/win/display_info.h" |
17 #include "ui/display/win/dpi.h" | 19 #include "ui/display/win/dpi.h" |
18 #include "ui/display/win/scaling_util.h" | 20 #include "ui/display/win/scaling_util.h" |
19 #include "ui/display/win/screen_win_display.h" | 21 #include "ui/display/win/screen_win_display.h" |
20 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
21 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
22 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
23 #include "ui/gfx/geometry/vector2d.h" | 25 #include "ui/gfx/geometry/vector2d.h" |
24 | 26 |
25 namespace display { | 27 namespace display { |
26 namespace win { | 28 namespace win { |
27 namespace { | 29 namespace { |
28 | 30 |
29 // TODO(robliao): http://crbug.com/615514 Remove when ScreenWin usage is | 31 // TODO(robliao): http://crbug.com/615514 Remove when ScreenWin usage is |
30 // resolved with Desktop Aura and WindowTreeHost. | 32 // resolved with Desktop Aura and WindowTreeHost. |
31 ScreenWin* g_screen_win_instance = nullptr; | 33 ScreenWin* g_screen_win_instance = nullptr; |
32 | 34 |
| 35 float GetMonitorScaleFactor(HMONITOR monitor) { |
| 36 DCHECK(monitor); |
| 37 if (base::win::IsProcessPerMonitorDpiAware()) { |
| 38 static auto get_dpi_for_monitor_func = [](){ |
| 39 using GetDpiForMonitorPtr = decltype(::GetDpiForMonitor)*; |
| 40 HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll"); |
| 41 if (shcore_dll) { |
| 42 return reinterpret_cast<GetDpiForMonitorPtr>( |
| 43 ::GetProcAddress(shcore_dll, "GetDpiForMonitor")); |
| 44 } |
| 45 return static_cast<GetDpiForMonitorPtr>(nullptr); |
| 46 }(); |
| 47 |
| 48 UINT dpi_x; |
| 49 UINT dpi_y; |
| 50 if (get_dpi_for_monitor_func && |
| 51 SUCCEEDED(get_dpi_for_monitor_func(monitor, MDT_EFFECTIVE_DPI, |
| 52 &dpi_x, &dpi_y))) { |
| 53 DCHECK_EQ(dpi_x, dpi_y); |
| 54 return GetScalingFactorFromDPI(dpi_x); |
| 55 } |
| 56 } |
| 57 return GetDPIScale(); |
| 58 } |
| 59 |
33 std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos( | 60 std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos( |
34 const DisplayInfo& ref_display_info, | 61 const DisplayInfo& ref_display_info, |
35 std::vector<DisplayInfo>* display_infos) { | 62 std::vector<DisplayInfo>* display_infos) { |
36 std::vector<DisplayInfo> touching_display_infos; | 63 std::vector<DisplayInfo> touching_display_infos; |
37 display_infos->erase( | 64 display_infos->erase( |
38 std::remove_if(display_infos->begin(), display_infos->end(), | 65 std::remove_if(display_infos->begin(), display_infos->end(), |
39 [&touching_display_infos, ref_display_info]( | 66 [&touching_display_infos, ref_display_info]( |
40 const DisplayInfo& display_info) { | 67 const DisplayInfo& display_info) { |
41 if (DisplayInfosTouch(ref_display_info, display_info)) { | 68 if (DisplayInfosTouch(ref_display_info, display_info)) { |
42 touching_display_infos.push_back(display_info); | 69 touching_display_infos.push_back(display_info); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 return monitor_info; | 164 return monitor_info; |
138 } | 165 } |
139 | 166 |
140 BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, | 167 BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, |
141 HDC hdc, | 168 HDC hdc, |
142 LPRECT rect, | 169 LPRECT rect, |
143 LPARAM data) { | 170 LPARAM data) { |
144 std::vector<DisplayInfo>* display_infos = | 171 std::vector<DisplayInfo>* display_infos = |
145 reinterpret_cast<std::vector<DisplayInfo>*>(data); | 172 reinterpret_cast<std::vector<DisplayInfo>*>(data); |
146 DCHECK(display_infos); | 173 DCHECK(display_infos); |
147 // TODO(robliao): When ready, replace the GetDPIScale with GetDpiForMonitor | |
148 // to get the actual DPI for the HMONITOR. | |
149 display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor), | 174 display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor), |
150 GetDPIScale())); | 175 GetMonitorScaleFactor(monitor))); |
151 return TRUE; | 176 return TRUE; |
152 } | 177 } |
153 | 178 |
154 std::vector<DisplayInfo> GetDisplayInfosFromSystem() { | 179 std::vector<DisplayInfo> GetDisplayInfosFromSystem() { |
155 std::vector<DisplayInfo> display_infos; | 180 std::vector<DisplayInfo> display_infos; |
156 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorCallback, | 181 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorCallback, |
157 reinterpret_cast<LPARAM>(&display_infos)); | 182 reinterpret_cast<LPARAM>(&display_infos)); |
158 DCHECK_EQ(static_cast<size_t>(::GetSystemMetrics(SM_CMONITORS)), | 183 DCHECK_EQ(static_cast<size_t>(::GetSystemMetrics(SM_CMONITORS)), |
159 display_infos.size()); | 184 display_infos.size()); |
160 return display_infos; | 185 return display_infos; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, | 522 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, |
498 GetterType value) { | 523 GetterType value) { |
499 if (!g_screen_win_instance) | 524 if (!g_screen_win_instance) |
500 return ScreenWinDisplay(); | 525 return ScreenWinDisplay(); |
501 | 526 |
502 return (g_screen_win_instance->*getter)(value); | 527 return (g_screen_win_instance->*getter)(value); |
503 } | 528 } |
504 | 529 |
505 } // namespace win | 530 } // namespace win |
506 } // namespace display | 531 } // namespace display |
OLD | NEW |