Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: ui/display/win/screen_win.cc

Issue 2098993002: Prepare ScreenWin To Use Per-Monitor DPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/win/win_util.cc ('K') | « ui/display/win/dpi.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 if (base::win::IsProcessPerMonitorDpiAware()) {
37 using GetDpiForMonitorPtr =
38 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.
39 static GetDpiForMonitorPtr get_dpi_for_monitor_func = nullptr;
40 if (!get_dpi_for_monitor_func) {
41 HMODULE shcore_dll = ::LoadLibrary(L"shcore.dll");
42 if (shcore_dll) {
43 get_dpi_for_monitor_func =
44 reinterpret_cast<GetDpiForMonitorPtr>(
45 ::GetProcAddress(shcore_dll, "GetDpiForMonitor"));
46 }
47 }
48
49 UINT dpi_x;
50 UINT dpi_y;
51 if (get_dpi_for_monitor_func &&
52 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.
53 &dpi_x, &dpi_y))) {
54 DCHECK_EQ(dpi_x, dpi_y);
55 return GetScalingFactorFromDPI(dpi_x);
56 }
57 }
58 return GetDPIScale();
59 }
60
33 std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos( 61 std::vector<DisplayInfo> FindAndRemoveTouchingDisplayInfos(
34 const DisplayInfo& ref_display_info, 62 const DisplayInfo& ref_display_info,
35 std::vector<DisplayInfo>* display_infos) { 63 std::vector<DisplayInfo>* display_infos) {
36 std::vector<DisplayInfo> touching_display_infos; 64 std::vector<DisplayInfo> touching_display_infos;
37 display_infos->erase( 65 display_infos->erase(
38 std::remove_if(display_infos->begin(), display_infos->end(), 66 std::remove_if(display_infos->begin(), display_infos->end(),
39 [&touching_display_infos, ref_display_info]( 67 [&touching_display_infos, ref_display_info](
40 const DisplayInfo& display_info) { 68 const DisplayInfo& display_info) {
41 if (DisplayInfosTouch(ref_display_info, display_info)) { 69 if (DisplayInfosTouch(ref_display_info, display_info)) {
42 touching_display_infos.push_back(display_info); 70 touching_display_infos.push_back(display_info);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return monitor_info; 165 return monitor_info;
138 } 166 }
139 167
140 BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, 168 BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor,
141 HDC hdc, 169 HDC hdc,
142 LPRECT rect, 170 LPRECT rect,
143 LPARAM data) { 171 LPARAM data) {
144 std::vector<DisplayInfo>* display_infos = 172 std::vector<DisplayInfo>* display_infos =
145 reinterpret_cast<std::vector<DisplayInfo>*>(data); 173 reinterpret_cast<std::vector<DisplayInfo>*>(data);
146 DCHECK(display_infos); 174 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), 175 display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor),
150 GetDPIScale())); 176 GetMonitorScaleFactor(monitor)));
151 return TRUE; 177 return TRUE;
152 } 178 }
153 179
154 std::vector<DisplayInfo> GetDisplayInfosFromSystem() { 180 std::vector<DisplayInfo> GetDisplayInfosFromSystem() {
155 std::vector<DisplayInfo> display_infos; 181 std::vector<DisplayInfo> display_infos;
156 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorCallback, 182 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorCallback,
157 reinterpret_cast<LPARAM>(&display_infos)); 183 reinterpret_cast<LPARAM>(&display_infos));
158 DCHECK_EQ(static_cast<size_t>(::GetSystemMetrics(SM_CMONITORS)), 184 DCHECK_EQ(static_cast<size_t>(::GetSystemMetrics(SM_CMONITORS)),
159 display_infos.size()); 185 display_infos.size());
160 return display_infos; 186 return display_infos;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, 523 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter,
498 GetterType value) { 524 GetterType value) {
499 if (!g_screen_win_instance) 525 if (!g_screen_win_instance)
500 return ScreenWinDisplay(); 526 return ScreenWinDisplay();
501 527
502 return (g_screen_win_instance->*getter)(value); 528 return (g_screen_win_instance->*getter)(value);
503 } 529 }
504 530
505 } // namespace win 531 } // namespace win
506 } // namespace display 532 } // namespace display
OLDNEW
« base/win/win_util.cc ('K') | « ui/display/win/dpi.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698