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_info.h"
6
7 namespace {
8
EnumerateGPUDevice(const gpu::GPUInfo::GPUDevice & device,gpu::GPUInfo::Enumerator * enumerator)9 void EnumerateGPUDevice(const gpu::GPUInfo::GPUDevice& device,
10 gpu::GPUInfo::Enumerator* enumerator) {
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
20 } // namespace
21
22 namespace gpu {
23
GPUDevice()24 GPUInfo::GPUDevice::GPUDevice()
25 : vendor_id(0),
26 device_id(0),
27 active(false) {
28 }
29
~GPUDevice()30 GPUInfo::GPUDevice::~GPUDevice() { }
31
GPUInfo()32 GPUInfo::GPUInfo()
33 : optimus(false),
34 amd_switchable(false),
35 lenovo_dcute(false),
36 adapter_luid(0),
37 gl_reset_notification_strategy(0),
38 can_lose_context(false),
39 software_rendering(false),
40 direct_rendering(true),
41 sandboxed(false),
42 process_crash_count(0),
43 in_process_gpu(true),
44 basic_info_state(kCollectInfoNone),
45 context_info_state(kCollectInfoNone),
46 jpeg_decode_accelerator_supported(false) {
47 }
48
~GPUInfo()49 GPUInfo::~GPUInfo() { }
50
EnumerateFields(Enumerator * enumerator) const51 void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
52 struct GPUInfoKnownFields {
53 bool optimus;
54 bool amd_switchable;
55 bool lenovo_dcute;
56 GPUDevice gpu;
57 std::vector<GPUDevice> secondary_gpus;
58 uint64 adapter_luid;
59 std::string driver_vendor;
60 std::string driver_version;
61 std::string driver_date;
62 std::string pixel_shader_version;
63 std::string vertex_shader_version;
64 std::string max_msaa_samples;
65 std::string machine_model_name;
66 std::string machine_model_version;
67 std::string gl_version_string;
68 std::string gl_vendor;
69 std::string gl_renderer;
70 std::string gl_extensions;
71 std::string gl_ws_vendor;
72 std::string gl_ws_version;
73 std::string gl_ws_extensions;
74 uint32 gl_reset_notification_strategy;
75 bool can_lose_context;
76 bool software_rendering;
77 bool direct_rendering;
78 bool sandboxed;
79 int process_crash_count;
80 bool in_process_gpu;
81 CollectInfoResult basic_info_state;
82 CollectInfoResult context_info_state;
83 bool jpeg_decode_accelerator_supported;
84 };
85
86 // If this assert fails then most likely something below needs to be updated.
87 // Note that this assert is only approximate. If a new field is added to
88 // GPUInfo which fits within the current padding then it will not be caught.
89 static_assert(
90 sizeof(GPUInfo) == sizeof(GPUInfoKnownFields),
91 "fields have changed in GPUInfo, GPUInfoKnownFields must be updated");
92
93 // Required fields (according to DevTools protocol) first.
94 enumerator->AddString("machineModelName", machine_model_name);
95 enumerator->AddString("machineModelVersion", machine_model_version);
96 EnumerateGPUDevice(gpu, enumerator);
97 for (const auto& secondary_gpu: secondary_gpus)
98 EnumerateGPUDevice(secondary_gpu, enumerator);
99
100 enumerator->BeginAuxAttributes();
101 enumerator->AddBool("optimus", optimus);
102 enumerator->AddBool("amdSwitchable", amd_switchable);
103 enumerator->AddBool("lenovoDcute", lenovo_dcute);
104 enumerator->AddInt64("adapterLuid", adapter_luid);
105 enumerator->AddString("driverVendor", driver_vendor);
106 enumerator->AddString("driverVersion", driver_version);
107 enumerator->AddString("driverDate", driver_date);
108 enumerator->AddString("pixelShaderVersion", pixel_shader_version);
109 enumerator->AddString("vertexShaderVersion", vertex_shader_version);
110 enumerator->AddString("maxMsaaSamples", max_msaa_samples);
111 enumerator->AddString("glVersion", gl_version);
112 enumerator->AddString("glVendor", gl_vendor);
113 enumerator->AddString("glRenderer", gl_renderer);
114 enumerator->AddString("glExtensions", gl_extensions);
115 enumerator->AddString("glWsVendor", gl_ws_vendor);
116 enumerator->AddString("glWsVersion", gl_ws_version);
117 enumerator->AddString("glWsExtensions", gl_ws_extensions);
118 enumerator->AddInt(
119 "glResetNotificationStrategy",
120 static_cast<int>(gl_reset_notification_strategy));
121 enumerator->AddBool("can_lose_context", can_lose_context);
122 // TODO(kbr): add performance_stats.
123 enumerator->AddBool("softwareRendering", software_rendering);
124 enumerator->AddBool("directRendering", direct_rendering);
125 enumerator->AddBool("sandboxed", sandboxed);
126 enumerator->AddInt("processCrashCount", process_crash_count);
127 enumerator->AddBool("inProcessGpu", in_process_gpu);
128 enumerator->AddInt("basicInfoState", basic_info_state);
129 enumerator->AddInt("contextInfoState", context_info_state);
130 // TODO(kbr): add dx_diagnostics on Windows.
131 enumerator->AddBool("jpegDecodeAcceleratorSupported",
132 jpeg_decode_accelerator_supported);
133 enumerator->EndAuxAttributes();
134 }
135
136 } // namespace gpu
137