• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "gpu/config/gpu_info.h"
6 
7 namespace {
8 
EnumerateGPUDevice(gpu::GPUInfo::Enumerator * enumerator,const gpu::GPUInfo::GPUDevice & device)9 void EnumerateGPUDevice(gpu::GPUInfo::Enumerator* enumerator,
10                         const gpu::GPUInfo::GPUDevice& device) {
11   enumerator->BeginGPUDevice();
12   enumerator->AddInt("vendorId", device.vendor_id);
13   enumerator->AddInt("deviceId", device.device_id);
14   enumerator->AddBool("active", device.active);
15   enumerator->AddString("vendorString", device.vendor_string);
16   enumerator->AddString("deviceString", device.device_string);
17   enumerator->EndGPUDevice();
18 }
19 
EnumerateVideoEncodeAcceleratorSupportedProfile(gpu::GPUInfo::Enumerator * enumerator,const media::VideoEncodeAccelerator::SupportedProfile profile)20 void EnumerateVideoEncodeAcceleratorSupportedProfile(
21     gpu::GPUInfo::Enumerator* enumerator,
22     const media::VideoEncodeAccelerator::SupportedProfile profile) {
23   enumerator->BeginVideoEncodeAcceleratorSupportedProfile();
24   enumerator->AddInt("profile", profile.profile);
25   enumerator->AddInt("maxResolutionWidth", profile.max_resolution.width());
26   enumerator->AddInt("maxResolutionHeight", profile.max_resolution.height());
27   enumerator->AddInt("maxFramerateNumerator", profile.max_framerate_numerator);
28   enumerator->AddInt("maxFramerateDenominator",
29                      profile.max_framerate_denominator);
30   enumerator->EndVideoEncodeAcceleratorSupportedProfile();
31 }
32 
33 }  // namespace
34 
35 namespace gpu {
36 
GPUDevice()37 GPUInfo::GPUDevice::GPUDevice()
38     : vendor_id(0),
39       device_id(0),
40       active(false) {
41 }
42 
~GPUDevice()43 GPUInfo::GPUDevice::~GPUDevice() { }
44 
GPUInfo()45 GPUInfo::GPUInfo()
46     : optimus(false),
47       amd_switchable(false),
48       lenovo_dcute(false),
49       adapter_luid(0),
50       gl_reset_notification_strategy(0),
51       can_lose_context(false),
52       software_rendering(false),
53       direct_rendering(true),
54       sandboxed(false),
55       process_crash_count(0),
56       basic_info_state(kCollectInfoNone),
57 #if defined(OS_WIN)
58       context_info_state(kCollectInfoNone),
59       dx_diagnostics_info_state(kCollectInfoNone) {
60 #else
61       context_info_state(kCollectInfoNone) {
62 #endif
63 }
64 
65 GPUInfo::~GPUInfo() { }
66 
67 void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
68   struct GPUInfoKnownFields {
69     base::TimeDelta initialization_time;
70     bool optimus;
71     bool amd_switchable;
72     bool lenovo_dcute;
73     Version display_link_version;
74     GPUDevice gpu;
75     std::vector<GPUDevice> secondary_gpus;
76     uint64 adapter_luid;
77     std::string driver_vendor;
78     std::string driver_version;
79     std::string driver_date;
80     std::string pixel_shader_version;
81     std::string vertex_shader_version;
82     std::string machine_model_name;
83     std::string machine_model_version;
84     std::string gl_version_string;
85     std::string gl_vendor;
86     std::string gl_renderer;
87     std::string gl_extensions;
88     std::string gl_ws_vendor;
89     std::string gl_ws_version;
90     std::string gl_ws_extensions;
91     uint32 gl_reset_notification_strategy;
92     bool can_lose_context;
93     GpuPerformanceStats performance_stats;
94     bool software_rendering;
95     bool direct_rendering;
96     bool sandboxed;
97     int process_crash_count;
98     CollectInfoResult basic_info_state;
99     CollectInfoResult context_info_state;
100 #if defined(OS_WIN)
101     CollectInfoResult dx_diagnostics_info_state;
102     DxDiagNode dx_diagnostics;
103 #endif
104     std::vector<media::VideoEncodeAccelerator::SupportedProfile>
105         video_encode_accelerator_supported_profiles;
106   };
107 
108   // If this assert fails then most likely something below needs to be updated.
109   // Note that this assert is only approximate. If a new field is added to
110   // GPUInfo which fits within the current padding then it will not be caught.
111   COMPILE_ASSERT(
112       sizeof(GPUInfo) == sizeof(GPUInfoKnownFields),
113       Fields_Have_Changed_In_GPUInfo_So_Update_Below);
114 
115   // Required fields (according to DevTools protocol) first.
116   enumerator->AddString("machineModelName", machine_model_name);
117   enumerator->AddString("machineModelVersion", machine_model_version);
118   EnumerateGPUDevice(enumerator, gpu);
119   for (size_t ii = 0; ii < secondary_gpus.size(); ++ii) {
120     EnumerateGPUDevice(enumerator, secondary_gpus[ii]);
121   }
122 
123   enumerator->BeginAuxAttributes();
124   enumerator->AddTimeDeltaInSecondsF("initializationTime",
125                                      initialization_time);
126   enumerator->AddBool("optimus", optimus);
127   enumerator->AddBool("amdSwitchable", amd_switchable);
128   enumerator->AddBool("lenovoDcute", lenovo_dcute);
129   if (display_link_version.IsValid()) {
130     enumerator->AddString("displayLinkVersion",
131                           display_link_version.GetString());
132   }
133   enumerator->AddInt64("adapterLuid", adapter_luid);
134   enumerator->AddString("driverVendor", driver_vendor);
135   enumerator->AddString("driverVersion", driver_version);
136   enumerator->AddString("driverDate", driver_date);
137   enumerator->AddString("pixelShaderVersion", pixel_shader_version);
138   enumerator->AddString("vertexShaderVersion", vertex_shader_version);
139   enumerator->AddString("glVersion", gl_version);
140   enumerator->AddString("glVendor", gl_vendor);
141   enumerator->AddString("glRenderer", gl_renderer);
142   enumerator->AddString("glExtensions", gl_extensions);
143   enumerator->AddString("glWsVendor", gl_ws_vendor);
144   enumerator->AddString("glWsVersion", gl_ws_version);
145   enumerator->AddString("glWsExtensions", gl_ws_extensions);
146   enumerator->AddInt(
147       "glResetNotificationStrategy",
148       static_cast<int>(gl_reset_notification_strategy));
149   enumerator->AddBool("can_lose_context", can_lose_context);
150   // TODO(kbr): add performance_stats.
151   enumerator->AddBool("softwareRendering", software_rendering);
152   enumerator->AddBool("directRendering", direct_rendering);
153   enumerator->AddBool("sandboxed", sandboxed);
154   enumerator->AddInt("processCrashCount", process_crash_count);
155   enumerator->AddInt("basicInfoState", basic_info_state);
156   enumerator->AddInt("contextInfoState", context_info_state);
157 #if defined(OS_WIN)
158   enumerator->AddInt("DxDiagnosticsInfoState", dx_diagnostics_info_state);
159 #endif
160   // TODO(kbr): add dx_diagnostics on Windows.
161   for (size_t ii = 0; ii < video_encode_accelerator_supported_profiles.size();
162        ++ii) {
163     EnumerateVideoEncodeAcceleratorSupportedProfile(
164         enumerator, video_encode_accelerator_supported_profiles[ii]);
165   }
166   enumerator->EndAuxAttributes();
167 }
168 
169 }  // namespace gpu
170