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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/metrics/sparse_histogram.h" | |
14 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
16 #include "ui/display/manager/display_layout.h" | 17 #include "ui/display/manager/display_layout.h" |
17 #include "ui/display/manager/display_layout_builder.h" | 18 #include "ui/display/manager/display_layout_builder.h" |
18 #include "ui/display/win/display_info.h" | 19 #include "ui/display/win/display_info.h" |
19 #include "ui/display/win/dpi.h" | 20 #include "ui/display/win/dpi.h" |
20 #include "ui/display/win/scaling_util.h" | 21 #include "ui/display/win/scaling_util.h" |
21 #include "ui/display/win/screen_win_display.h" | 22 #include "ui/display/win/screen_win_display.h" |
22 #include "ui/gfx/geometry/point.h" | 23 #include "ui/gfx/geometry/point.h" |
23 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 void ScreenWin::UpdateFromDisplayInfos( | 405 void ScreenWin::UpdateFromDisplayInfos( |
405 const std::vector<DisplayInfo>& display_infos) { | 406 const std::vector<DisplayInfo>& display_infos) { |
406 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); | 407 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); |
407 } | 408 } |
408 | 409 |
409 void ScreenWin::Initialize() { | 410 void ScreenWin::Initialize() { |
410 singleton_hwnd_observer_.reset( | 411 singleton_hwnd_observer_.reset( |
411 new gfx::SingletonHwndObserver( | 412 new gfx::SingletonHwndObserver( |
412 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this)))); | 413 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this)))); |
413 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); | 414 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); |
415 RecordDisplayScaleFactors(); | |
414 } | 416 } |
415 | 417 |
416 MONITORINFOEX ScreenWin::MonitorInfoFromScreenPoint( | 418 MONITORINFOEX ScreenWin::MonitorInfoFromScreenPoint( |
417 const gfx::Point& screen_point) const { | 419 const gfx::Point& screen_point) const { |
418 POINT initial_loc = { screen_point.x(), screen_point.y() }; | 420 POINT initial_loc = { screen_point.x(), screen_point.y() }; |
419 return MonitorInfoFromHMONITOR(::MonitorFromPoint(initial_loc, | 421 return MonitorInfoFromHMONITOR(::MonitorFromPoint(initial_loc, |
420 MONITOR_DEFAULTTONEAREST)); | 422 MONITOR_DEFAULTTONEAREST)); |
421 } | 423 } |
422 | 424 |
423 MONITORINFOEX ScreenWin::MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) | 425 MONITORINFOEX ScreenWin::MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 // static | 543 // static |
542 template <typename Getter, typename GetterType> | 544 template <typename Getter, typename GetterType> |
543 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, | 545 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, |
544 GetterType value) { | 546 GetterType value) { |
545 if (!g_screen_win_instance) | 547 if (!g_screen_win_instance) |
546 return ScreenWinDisplay(); | 548 return ScreenWinDisplay(); |
547 | 549 |
548 return (g_screen_win_instance->*getter)(value); | 550 return (g_screen_win_instance->*getter)(value); |
549 } | 551 } |
550 | 552 |
553 void ScreenWin::RecordDisplayScaleFactors() const { | |
554 std::vector<int> unique_scale_factors; | |
555 for (const auto& screen_win_display : screen_win_displays_) { | |
556 const float scale_factor = | |
557 screen_win_display.display().device_scale_factor(); | |
558 // Clamp the reported value so that if it's wildly out-of-band we won't send | |
559 // it to the backend. | |
robliao
2016/07/20 19:56:59
Comment that we multiply by 100 due to the percent
Bret
2016/07/20 21:03:22
Added comment. Raw DPI is a lot less intuitive I t
| |
560 const int reported_scale = std::min( | |
561 std::max(base::checked_cast<int>(scale_factor * 100), 0), 1000); | |
562 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | |
563 reported_scale) == unique_scale_factors.end()) { | |
564 unique_scale_factors.push_back(reported_scale); | |
565 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | |
566 } | |
567 } | |
568 } | |
569 | |
551 } // namespace win | 570 } // namespace win |
552 } // namespace display | 571 } // namespace display |
OLD | NEW |