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

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

Issue 2151413002: Add a UMA histogram for a user's device scale at startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert dpi.cc 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
« no previous file with comments | « ui/display/win/screen_win.h ('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 #include <shellscalingapi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <set>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/metrics/sparse_histogram.h"
14 #include "base/win/win_util.h" 16 #include "base/win/win_util.h"
15 #include "ui/display/display.h" 17 #include "ui/display/display.h"
16 #include "ui/display/manager/display_layout.h" 18 #include "ui/display/manager/display_layout.h"
17 #include "ui/display/manager/display_layout_builder.h" 19 #include "ui/display/manager/display_layout_builder.h"
18 #include "ui/display/win/display_info.h" 20 #include "ui/display/win/display_info.h"
19 #include "ui/display/win/dpi.h" 21 #include "ui/display/win/dpi.h"
20 #include "ui/display/win/scaling_util.h" 22 #include "ui/display/win/scaling_util.h"
21 #include "ui/display/win/screen_win_display.h" 23 #include "ui/display/win/screen_win_display.h"
22 #include "ui/gfx/geometry/point.h" 24 #include "ui/gfx/geometry/point.h"
23 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 void ScreenWin::UpdateFromDisplayInfos( 406 void ScreenWin::UpdateFromDisplayInfos(
405 const std::vector<DisplayInfo>& display_infos) { 407 const std::vector<DisplayInfo>& display_infos) {
406 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos); 408 screen_win_displays_ = DisplayInfosToScreenWinDisplays(display_infos);
407 } 409 }
408 410
409 void ScreenWin::Initialize() { 411 void ScreenWin::Initialize() {
410 singleton_hwnd_observer_.reset( 412 singleton_hwnd_observer_.reset(
411 new gfx::SingletonHwndObserver( 413 new gfx::SingletonHwndObserver(
412 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this)))); 414 base::Bind(&ScreenWin::OnWndProc, base::Unretained(this))));
413 UpdateFromDisplayInfos(GetDisplayInfosFromSystem()); 415 UpdateFromDisplayInfos(GetDisplayInfosFromSystem());
416 RecordDisplayScaleFactors();
414 } 417 }
415 418
416 MONITORINFOEX ScreenWin::MonitorInfoFromScreenPoint( 419 MONITORINFOEX ScreenWin::MonitorInfoFromScreenPoint(
417 const gfx::Point& screen_point) const { 420 const gfx::Point& screen_point) const {
418 POINT initial_loc = { screen_point.x(), screen_point.y() }; 421 POINT initial_loc = { screen_point.x(), screen_point.y() };
419 return MonitorInfoFromHMONITOR(::MonitorFromPoint(initial_loc, 422 return MonitorInfoFromHMONITOR(::MonitorFromPoint(initial_loc,
420 MONITOR_DEFAULTTONEAREST)); 423 MONITOR_DEFAULTTONEAREST));
421 } 424 }
422 425
423 MONITORINFOEX ScreenWin::MonitorInfoFromScreenRect(const gfx::Rect& screen_rect) 426 MONITORINFOEX ScreenWin::MonitorInfoFromScreenRect(const gfx::Rect& screen_rect)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // static 544 // static
542 template <typename Getter, typename GetterType> 545 template <typename Getter, typename GetterType>
543 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, 546 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter,
544 GetterType value) { 547 GetterType value) {
545 if (!g_screen_win_instance) 548 if (!g_screen_win_instance)
546 return ScreenWinDisplay(); 549 return ScreenWinDisplay();
547 550
548 return (g_screen_win_instance->*getter)(value); 551 return (g_screen_win_instance->*getter)(value);
549 } 552 }
550 553
554 void ScreenWin::RecordDisplayScaleFactors() const {
555 std::set<int> already_reported_scale_factors;
robliao 2016/07/20 00:58:10 Go with an unordered_set or a vector (n is small e
Bret 2016/07/20 18:59:42 Done.
556 for (const auto& screen_win_display : screen_win_displays_) {
557 const float scale_factor =
558 screen_win_display.display().device_scale_factor();
559 // Clamp the reported value so that if it's wildly out-of-band we won't send
560 // it to the backend.
561 const int reported_scale = std::min(
562 std::max(base::checked_cast<int>(scale_factor * 100), 0), 1000);
563 if (!already_reported_scale_factors.count(reported_scale)) {
564 already_reported_scale_factors.insert(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
OLDNEW
« no previous file with comments | « ui/display/win/screen_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698