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

Side by Side Diff: chrome/browser/metrics/gpu_metrics_provider.cc

Issue 291163006: Create GPUMetricsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move the Windows-specific call Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/metrics/gpu_metrics_provider.h"
6
7 #include "components/metrics/proto/system_profile.pb.h"
8 #include "content/public/browser/gpu_data_manager.h"
9 #include "gpu/config/gpu_info.h"
10 #include "ui/gfx/screen.h"
11
12 #if defined(OS_WIN)
13
14 #include <windows.h>
15
16 struct ScreenDPIInformation {
17 double max_dpi_x;
18 double max_dpi_y;
19 };
20
21 // Called once for each connected monitor.
22 BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) {
23 const double kMillimetersPerInch = 25.4;
24 ScreenDPIInformation* screen_info =
25 reinterpret_cast<ScreenDPIInformation*>(dwData);
26 // Size of screen, in mm.
27 DWORD size_x = GetDeviceCaps(hdc, HORZSIZE);
28 DWORD size_y = GetDeviceCaps(hdc, VERTSIZE);
29 double dpi_x = (size_x > 0) ?
30 GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0;
31 double dpi_y = (size_y > 0) ?
32 GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0;
33 screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x);
34 screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y);
35 return TRUE;
36 }
37
38 void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) {
39 HDC desktop_dc = GetDC(NULL);
40 if (desktop_dc) {
41 ScreenDPIInformation si = {0, 0};
42 if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback,
43 reinterpret_cast<LPARAM>(&si))) {
44 hardware->set_max_dpi_x(si.max_dpi_x);
45 hardware->set_max_dpi_y(si.max_dpi_y);
46 }
47 ReleaseDC(GetDesktopWindow(), desktop_dc);
48 }
49 }
50
51 #endif // defined(OS_WIN)
52
53 GPUMetricsProvider::GPUMetricsProvider() {
54 }
55
56 GPUMetricsProvider::~GPUMetricsProvider() {
57 }
58
59 void GPUMetricsProvider::ProvideSystemProfileMetrics(
60 metrics::SystemProfileProto* system_profile_proto) {
61 metrics::SystemProfileProto::Hardware* hardware =
62 system_profile_proto->mutable_hardware();
63
64 const gpu::GPUInfo& gpu_info =
65 content::GpuDataManager::GetInstance()->GetGPUInfo();
66 metrics::SystemProfileProto::Hardware::Graphics* gpu =
67 hardware->mutable_gpu();
68 gpu->set_vendor_id(gpu_info.gpu.vendor_id);
69 gpu->set_device_id(gpu_info.gpu.device_id);
70 gpu->set_driver_version(gpu_info.driver_version);
71 gpu->set_driver_date(gpu_info.driver_date);
72 metrics::SystemProfileProto::Hardware::Graphics::PerformanceStatistics*
73 gpu_performance = gpu->mutable_performance_statistics();
74 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
75 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
76 gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
77 gpu->set_gl_vendor(gpu_info.gl_vendor);
78 gpu->set_gl_renderer(gpu_info.gl_renderer);
79
80 const gfx::Size display_size = GetScreenSize();
81 hardware->set_primary_screen_width(display_size.width());
82 hardware->set_primary_screen_height(display_size.height());
83 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor());
84 hardware->set_screen_count(GetScreenCount());
85
86 #if defined(OS_WIN)
87 WriteScreenDPIInformationProto(hardware);
88 #endif
89 }
90
91 gfx::Size GPUMetricsProvider::GetScreenSize() const {
92 return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
93 }
94
95 float GPUMetricsProvider::GetScreenDeviceScaleFactor() const {
96 return gfx::Screen::GetNativeScreen()
97 ->GetPrimaryDisplay()
98 .device_scale_factor();
99 }
100
101 int GPUMetricsProvider::GetScreenCount() const {
102 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
103 return gfx::Screen::GetNativeScreen()->GetNumDisplays();
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698