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

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: edit comment 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 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
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
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 // Multiply the reported value by 100 to display it as a percentage. Clamp
559 // it so that if it's wildly out-of-band we won't send it to the backend.
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
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