[Android] Battery Status API: some tweaks to the BatteryStatusManager.java.
[chromium-blink-merge.git] / gpu / config / gpu_info_collector_win.cc
blob65d75ec91a1c3ee78c255da2a57eed4c4e541144
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.
5 #include "gpu/config/gpu_info_collector.h"
7 // This has to be included before windows.h.
8 #include "third_party/re2/re2/re2.h"
10 #include <windows.h>
11 #include <d3d9.h>
12 #include <d3d11.h>
13 #include <dxgi.h>
14 #include <setupapi.h>
16 #include "base/command_line.h"
17 #include "base/debug/trace_event.h"
18 #include "base/file_util.h"
19 #include "base/files/file_enumerator.h"
20 #include "base/files/file_path.h"
21 #include "base/logging.h"
22 #include "base/message_loop/message_loop.h"
23 #include "base/metrics/field_trial.h"
24 #include "base/metrics/histogram.h"
25 #include "base/scoped_native_library.h"
26 #include "base/strings/string16.h"
27 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/string_util.h"
29 #include "base/strings/stringprintf.h"
30 #include "base/strings/utf_string_conversions.h"
31 #include "base/threading/thread.h"
32 #include "base/threading/worker_pool.h"
33 #include "base/win/registry.h"
34 #include "base/win/scoped_com_initializer.h"
35 #include "base/win/scoped_comptr.h"
36 #include "base/win/windows_version.h"
37 #include "third_party/libxml/chromium/libxml_utils.h"
38 #include "ui/gl/gl_implementation.h"
39 #include "ui/gl/gl_surface_egl.h"
41 namespace gpu {
43 namespace {
45 // This must be kept in sync with histograms.xml.
46 enum DisplayLinkInstallationStatus {
47 DISPLAY_LINK_NOT_INSTALLED,
48 DISPLAY_LINK_7_1_OR_EARLIER,
49 DISPLAY_LINK_7_2_OR_LATER,
50 DISPLAY_LINK_INSTALLATION_STATUS_MAX
53 float ReadXMLFloatValue(XmlReader* reader) {
54 std::string score_string;
55 if (!reader->ReadElementContent(&score_string))
56 return 0.0;
58 double score;
59 if (!base::StringToDouble(score_string, &score))
60 return 0.0;
62 return static_cast<float>(score);
65 GpuPerformanceStats RetrieveGpuPerformanceStats() {
66 TRACE_EVENT0("gpu", "RetrieveGpuPerformanceStats");
68 // If the user re-runs the assessment without restarting, the COM API
69 // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. Because of that and
70 // http://crbug.com/124325, read the assessment result files directly.
71 GpuPerformanceStats stats;
73 // Get path to WinSAT results files.
74 wchar_t winsat_results_path[MAX_PATH];
75 DWORD size = ExpandEnvironmentStrings(
76 L"%WinDir%\\Performance\\WinSAT\\DataStore\\",
77 winsat_results_path, MAX_PATH);
78 if (size == 0 || size > MAX_PATH) {
79 LOG(ERROR) << "The path to the WinSAT results is too long: "
80 << size << " chars.";
81 return stats;
84 // Find most recent formal assessment results.
85 base::FileEnumerator file_enumerator(
86 base::FilePath(winsat_results_path),
87 false, // not recursive
88 base::FileEnumerator::FILES,
89 FILE_PATH_LITERAL("* * Formal.Assessment (*).WinSAT.xml"));
91 base::FilePath current_results;
92 for (base::FilePath results = file_enumerator.Next(); !results.empty();
93 results = file_enumerator.Next()) {
94 // The filenames start with the date and time as yyyy-mm-dd hh.mm.ss.xxx,
95 // so the greatest file lexicographically is also the most recent file.
96 if (base::FilePath::CompareLessIgnoreCase(current_results.value(),
97 results.value()))
98 current_results = results;
101 std::string current_results_string = current_results.MaybeAsASCII();
102 if (current_results_string.empty()) {
103 LOG(ERROR) << "Can't retrieve a valid WinSAT assessment.";
104 return stats;
107 // Get relevant scores from results file. XML schema at:
108 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa969210.aspx
109 XmlReader reader;
110 if (!reader.LoadFile(current_results_string)) {
111 LOG(ERROR) << "Could not open WinSAT results file.";
112 return stats;
114 // Descend into <WinSAT> root element.
115 if (!reader.SkipToElement() || !reader.Read()) {
116 LOG(ERROR) << "Could not read WinSAT results file.";
117 return stats;
120 // Search for <WinSPR> element containing the results.
121 do {
122 if (reader.NodeName() == "WinSPR")
123 break;
124 } while (reader.Next());
125 // Descend into <WinSPR> element.
126 if (!reader.Read()) {
127 LOG(ERROR) << "Could not find WinSPR element in results file.";
128 return stats;
131 // Read scores.
132 for (int depth = reader.Depth(); reader.Depth() == depth; reader.Next()) {
133 std::string node_name = reader.NodeName();
134 if (node_name == "SystemScore")
135 stats.overall = ReadXMLFloatValue(&reader);
136 else if (node_name == "GraphicsScore")
137 stats.graphics = ReadXMLFloatValue(&reader);
138 else if (node_name == "GamingScore")
139 stats.gaming = ReadXMLFloatValue(&reader);
142 if (stats.overall == 0.0)
143 LOG(ERROR) << "Could not read overall score from assessment results.";
144 if (stats.graphics == 0.0)
145 LOG(ERROR) << "Could not read graphics score from assessment results.";
146 if (stats.gaming == 0.0)
147 LOG(ERROR) << "Could not read gaming score from assessment results.";
149 return stats;
152 GpuPerformanceStats RetrieveGpuPerformanceStatsWithHistograms() {
153 base::TimeTicks start_time = base::TimeTicks::Now();
155 GpuPerformanceStats stats = RetrieveGpuPerformanceStats();
157 UMA_HISTOGRAM_TIMES("GPU.WinSAT.ReadResultsFileTime",
158 base::TimeTicks::Now() - start_time);
159 UMA_HISTOGRAM_CUSTOM_COUNTS("GPU.WinSAT.OverallScore2",
160 stats.overall * 10, 10, 200, 50);
161 UMA_HISTOGRAM_CUSTOM_COUNTS("GPU.WinSAT.GraphicsScore2",
162 stats.graphics * 10, 10, 200, 50);
163 UMA_HISTOGRAM_CUSTOM_COUNTS("GPU.WinSAT.GamingScore2",
164 stats.gaming * 10, 10, 200, 50);
165 UMA_HISTOGRAM_BOOLEAN(
166 "GPU.WinSAT.HasResults",
167 stats.overall != 0.0 && stats.graphics != 0.0 && stats.gaming != 0.0);
169 return stats;
172 // Returns the display link driver version or an invalid version if it is
173 // not installed.
174 Version DisplayLinkVersion() {
175 base::win::RegKey key;
177 if (key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE", KEY_READ | KEY_WOW64_64KEY))
178 return Version();
180 if (key.OpenKey(L"DisplayLink", KEY_READ | KEY_WOW64_64KEY))
181 return Version();
183 if (key.OpenKey(L"Core", KEY_READ | KEY_WOW64_64KEY))
184 return Version();
186 base::string16 version;
187 if (key.ReadValue(L"Version", &version))
188 return Version();
190 return Version(base::UTF16ToASCII(version));
193 // Returns whether Lenovo dCute is installed.
194 bool IsLenovoDCuteInstalled() {
195 base::win::RegKey key;
197 if (key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE", KEY_READ | KEY_WOW64_64KEY))
198 return false;
200 if (key.OpenKey(L"Lenovo", KEY_READ | KEY_WOW64_64KEY))
201 return false;
203 if (key.OpenKey(L"Lenovo dCute", KEY_READ | KEY_WOW64_64KEY))
204 return false;
206 return true;
209 // Determines whether D3D11 won't work, either because it is not supported on
210 // the machine or because it is known it is likely to crash.
211 bool D3D11ShouldWork(const GPUInfo& gpu_info) {
212 // TODO(apatrick): This is a temporary change to see what impact disabling
213 // D3D11 stats collection has on Canary.
214 #if 1
215 return false;
216 #else
217 // Windows XP never supports D3D11. It seems to be less stable that D3D9 on
218 // Vista.
219 if (base::win::GetVersion() <= base::win::VERSION_VISTA)
220 return false;
222 // http://crbug.com/175525.
223 if (gpu_info.display_link_version.IsValid())
224 return false;
226 return true;
227 #endif
230 // Collects information about the level of D3D11 support and records it in
231 // the UMA stats. Records no stats when D3D11 in not supported at all.
232 void CollectD3D11SupportOnWorkerThread() {
233 TRACE_EVENT0("gpu", "CollectD3D11Support");
235 typedef HRESULT (WINAPI *D3D11CreateDeviceFunc)(
236 IDXGIAdapter* adapter,
237 D3D_DRIVER_TYPE driver_type,
238 HMODULE software,
239 UINT flags,
240 const D3D_FEATURE_LEVEL* feature_levels,
241 UINT num_feature_levels,
242 UINT sdk_version,
243 ID3D11Device** device,
244 D3D_FEATURE_LEVEL* feature_level,
245 ID3D11DeviceContext** immediate_context);
247 // This enumeration must be kept in sync with histograms.xml. Do not reorder
248 // the members; always add to the end.
249 enum FeatureLevel {
250 FEATURE_LEVEL_UNKNOWN,
251 FEATURE_LEVEL_NO_D3D11_DLL,
252 FEATURE_LEVEL_NO_CREATE_DEVICE_ENTRY_POINT,
253 FEATURE_LEVEL_DEVICE_CREATION_FAILED,
254 FEATURE_LEVEL_9_1,
255 FEATURE_LEVEL_9_2,
256 FEATURE_LEVEL_9_3,
257 FEATURE_LEVEL_10_0,
258 FEATURE_LEVEL_10_1,
259 FEATURE_LEVEL_11_0,
260 NUM_FEATURE_LEVELS
263 FeatureLevel feature_level = FEATURE_LEVEL_UNKNOWN;
264 UINT bgra_support = 0;
266 // This module is leaked in case it is hooked by third party software.
267 base::NativeLibrary d3d11_module = base::LoadNativeLibrary(
268 base::FilePath(L"d3d11.dll"),
269 NULL);
271 if (!d3d11_module) {
272 feature_level = FEATURE_LEVEL_NO_D3D11_DLL;
273 } else {
274 D3D11CreateDeviceFunc create_func =
275 reinterpret_cast<D3D11CreateDeviceFunc>(
276 base::GetFunctionPointerFromNativeLibrary(d3d11_module,
277 "D3D11CreateDevice"));
278 if (!create_func) {
279 feature_level = FEATURE_LEVEL_NO_CREATE_DEVICE_ENTRY_POINT;
280 } else {
281 static const D3D_FEATURE_LEVEL d3d_feature_levels[] = {
282 D3D_FEATURE_LEVEL_11_0,
283 D3D_FEATURE_LEVEL_10_1,
284 D3D_FEATURE_LEVEL_10_0,
285 D3D_FEATURE_LEVEL_9_3,
286 D3D_FEATURE_LEVEL_9_2,
287 D3D_FEATURE_LEVEL_9_1
290 base::win::ScopedComPtr<ID3D11Device> device;
291 D3D_FEATURE_LEVEL d3d_feature_level;
292 base::win::ScopedComPtr<ID3D11DeviceContext> device_context;
293 HRESULT hr = create_func(NULL,
294 D3D_DRIVER_TYPE_HARDWARE,
295 NULL,
297 d3d_feature_levels,
298 arraysize(d3d_feature_levels),
299 D3D11_SDK_VERSION,
300 device.Receive(),
301 &d3d_feature_level,
302 device_context.Receive());
303 if (FAILED(hr)) {
304 feature_level = FEATURE_LEVEL_DEVICE_CREATION_FAILED;
305 } else {
306 switch (d3d_feature_level) {
307 case D3D_FEATURE_LEVEL_11_0:
308 feature_level = FEATURE_LEVEL_11_0;
309 break;
310 case D3D_FEATURE_LEVEL_10_1:
311 feature_level = FEATURE_LEVEL_10_1;
312 break;
313 case D3D_FEATURE_LEVEL_10_0:
314 feature_level = FEATURE_LEVEL_10_0;
315 break;
316 case D3D_FEATURE_LEVEL_9_3:
317 feature_level = FEATURE_LEVEL_9_3;
318 break;
319 case D3D_FEATURE_LEVEL_9_2:
320 feature_level = FEATURE_LEVEL_9_2;
321 break;
322 case D3D_FEATURE_LEVEL_9_1:
323 feature_level = FEATURE_LEVEL_9_1;
324 break;
325 default:
326 NOTREACHED();
327 break;
330 hr = device->CheckFormatSupport(DXGI_FORMAT_B8G8R8A8_UNORM,
331 &bgra_support);
332 DCHECK(SUCCEEDED(hr));
337 UMA_HISTOGRAM_ENUMERATION("GPU.D3D11_FeatureLevel",
338 feature_level,
339 NUM_FEATURE_LEVELS);
341 // ANGLE requires at least feature level 10.0. Do not record any further
342 // stats if ANGLE would not work anyway.
343 if (feature_level < FEATURE_LEVEL_10_0)
344 return;
346 UMA_HISTOGRAM_BOOLEAN(
347 "GPU.D3D11_B8G8R8A8_Texture2DSupport",
348 (bgra_support & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0);
349 UMA_HISTOGRAM_BOOLEAN(
350 "GPU.D3D11_B8G8R8A8_RenderTargetSupport",
351 (bgra_support & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0);
354 // Collects information about the level of D3D11 support and records it in
355 // the UMA stats. Records no stats when D3D11 in not supported at all.
356 void CollectD3D11Support() {
357 // D3D11 takes about 50ms to initialize so do this on a worker thread.
358 base::WorkerPool::PostTask(
359 FROM_HERE,
360 base::Bind(CollectD3D11SupportOnWorkerThread),
361 false);
363 } // namespace anonymous
365 #if !defined(GOOGLE_CHROME_BUILD)
366 void GetAMDVideocardInfo(GPUInfo* gpu_info) {
367 DCHECK(gpu_info);
368 return;
370 #else
371 // This function has a real implementation for official builds that can
372 // be found in src/third_party/amd.
373 void GetAMDVideocardInfo(GPUInfo* gpu_info);
374 #endif
376 bool CollectDriverInfoD3D(const std::wstring& device_id,
377 GPUInfo* gpu_info) {
378 TRACE_EVENT0("gpu", "CollectDriverInfoD3D");
380 // create device info for the display device
381 HDEVINFO device_info = SetupDiGetClassDevsW(
382 NULL, device_id.c_str(), NULL,
383 DIGCF_PRESENT | DIGCF_PROFILE | DIGCF_ALLCLASSES);
384 if (device_info == INVALID_HANDLE_VALUE) {
385 LOG(ERROR) << "Creating device info failed";
386 return false;
389 DWORD index = 0;
390 bool found = false;
391 SP_DEVINFO_DATA device_info_data;
392 device_info_data.cbSize = sizeof(device_info_data);
393 while (SetupDiEnumDeviceInfo(device_info, index++, &device_info_data)) {
394 WCHAR value[255];
395 if (SetupDiGetDeviceRegistryPropertyW(device_info,
396 &device_info_data,
397 SPDRP_DRIVER,
398 NULL,
399 reinterpret_cast<PBYTE>(value),
400 sizeof(value),
401 NULL)) {
402 HKEY key;
403 std::wstring driver_key = L"System\\CurrentControlSet\\Control\\Class\\";
404 driver_key += value;
405 LONG result = RegOpenKeyExW(
406 HKEY_LOCAL_MACHINE, driver_key.c_str(), 0, KEY_QUERY_VALUE, &key);
407 if (result == ERROR_SUCCESS) {
408 DWORD dwcb_data = sizeof(value);
409 std::string driver_version;
410 result = RegQueryValueExW(
411 key, L"DriverVersion", NULL, NULL,
412 reinterpret_cast<LPBYTE>(value), &dwcb_data);
413 if (result == ERROR_SUCCESS)
414 driver_version = base::UTF16ToASCII(std::wstring(value));
416 std::string driver_date;
417 dwcb_data = sizeof(value);
418 result = RegQueryValueExW(
419 key, L"DriverDate", NULL, NULL,
420 reinterpret_cast<LPBYTE>(value), &dwcb_data);
421 if (result == ERROR_SUCCESS)
422 driver_date = base::UTF16ToASCII(std::wstring(value));
424 std::string driver_vendor;
425 dwcb_data = sizeof(value);
426 result = RegQueryValueExW(
427 key, L"ProviderName", NULL, NULL,
428 reinterpret_cast<LPBYTE>(value), &dwcb_data);
429 if (result == ERROR_SUCCESS) {
430 driver_vendor = base::UTF16ToASCII(std::wstring(value));
431 if (driver_vendor == "Advanced Micro Devices, Inc." ||
432 driver_vendor == "ATI Technologies Inc.") {
433 // We are conservative and assume that in the absence of a clear
434 // signal the videocard is assumed to be switchable. Additionally,
435 // some switchable systems with Intel GPUs aren't correctly
436 // detected, so always count them.
437 GetAMDVideocardInfo(gpu_info);
438 if (!gpu_info->amd_switchable &&
439 gpu_info->gpu.vendor_id == 0x8086) {
440 gpu_info->amd_switchable = true;
441 gpu_info->secondary_gpus.push_back(gpu_info->gpu);
442 gpu_info->gpu.vendor_id = 0x1002;
443 gpu_info->gpu.device_id = 0; // Unknown discrete AMD GPU.
448 gpu_info->driver_vendor = driver_vendor;
449 gpu_info->driver_version = driver_version;
450 gpu_info->driver_date = driver_date;
451 found = true;
452 RegCloseKey(key);
453 break;
457 SetupDiDestroyDeviceInfoList(device_info);
458 return found;
461 CollectInfoResult CollectContextGraphicsInfo(GPUInfo* gpu_info) {
462 TRACE_EVENT0("gpu", "CollectGraphicsInfo");
464 DCHECK(gpu_info);
466 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
467 std::string requested_implementation_name =
468 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
469 if (requested_implementation_name == "swiftshader") {
470 gpu_info->software_rendering = true;
471 return kCollectInfoNonFatalFailure;
475 CollectInfoResult result = CollectGraphicsInfoGL(gpu_info);
476 if (result != kCollectInfoSuccess)
477 return result;
479 // ANGLE's renderer strings are of the form:
480 // ANGLE (<adapter_identifier> Direct3D<version> vs_x_x ps_x_x)
481 std::string direct3d_version;
482 int vertex_shader_major_version = 0;
483 int vertex_shader_minor_version = 0;
484 int pixel_shader_major_version = 0;
485 int pixel_shader_minor_version = 0;
486 gpu_info->adapter_luid = 0;
487 if (RE2::FullMatch(gpu_info->gl_renderer,
488 "ANGLE \\(.*\\)") &&
489 RE2::PartialMatch(gpu_info->gl_renderer,
490 " Direct3D(\\w+)",
491 &direct3d_version) &&
492 RE2::PartialMatch(gpu_info->gl_renderer,
493 " vs_(\\d+)_(\\d+)",
494 &vertex_shader_major_version,
495 &vertex_shader_minor_version) &&
496 RE2::PartialMatch(gpu_info->gl_renderer,
497 " ps_(\\d+)_(\\d+)",
498 &pixel_shader_major_version,
499 &pixel_shader_minor_version)) {
500 gpu_info->can_lose_context = direct3d_version == "9";
501 gpu_info->vertex_shader_version =
502 base::StringPrintf("%d.%d",
503 vertex_shader_major_version,
504 vertex_shader_minor_version);
505 gpu_info->pixel_shader_version =
506 base::StringPrintf("%d.%d",
507 pixel_shader_major_version,
508 pixel_shader_minor_version);
510 // ANGLE's EGL vendor strings are of the form:
511 // Google, Inc. (adapter LUID: 0123456789ABCDEF)
512 // The LUID is optional and identifies the GPU adapter ANGLE is using.
513 const char* egl_vendor = eglQueryString(
514 gfx::GLSurfaceEGL::GetHardwareDisplay(),
515 EGL_VENDOR);
516 RE2::PartialMatch(egl_vendor,
517 " \\(adapter LUID: ([0-9A-Fa-f]{16})\\)",
518 RE2::Hex(&gpu_info->adapter_luid));
520 // DirectX diagnostics are collected asynchronously because it takes a
521 // couple of seconds. Do not mark gpu_info as complete until that is done.
522 gpu_info->finalized = false;
523 } else {
524 gpu_info->finalized = true;
527 return kCollectInfoSuccess;
530 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) {
531 DCHECK(vendor_id && device_id);
532 *vendor_id = 0;
533 *device_id = 0;
535 // Taken from http://developer.nvidia.com/object/device_ids.html
536 DISPLAY_DEVICE dd;
537 dd.cb = sizeof(DISPLAY_DEVICE);
538 std::wstring id;
539 for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) {
540 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
541 id = dd.DeviceID;
542 break;
546 if (id.length() > 20) {
547 int vendor = 0, device = 0;
548 std::wstring vendor_string = id.substr(8, 4);
549 std::wstring device_string = id.substr(17, 4);
550 base::HexStringToInt(base::UTF16ToASCII(vendor_string), &vendor);
551 base::HexStringToInt(base::UTF16ToASCII(device_string), &device);
552 *vendor_id = vendor;
553 *device_id = device;
554 if (*vendor_id != 0 && *device_id != 0)
555 return kGpuIDSuccess;
557 return kGpuIDFailure;
560 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) {
561 TRACE_EVENT0("gpu", "CollectPreliminaryGraphicsInfo");
563 DCHECK(gpu_info);
565 gpu_info->performance_stats = RetrieveGpuPerformanceStatsWithHistograms();
567 // nvd3d9wrap.dll is loaded into all processes when Optimus is enabled.
568 HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll");
569 gpu_info->optimus = nvd3d9wrap != NULL;
571 gpu_info->lenovo_dcute = IsLenovoDCuteInstalled();
573 gpu_info->display_link_version = DisplayLinkVersion();
575 if (!gpu_info->display_link_version .IsValid()) {
576 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus",
577 DISPLAY_LINK_NOT_INSTALLED,
578 DISPLAY_LINK_INSTALLATION_STATUS_MAX);
579 } else if (gpu_info->display_link_version.IsOlderThan("7.2")) {
580 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus",
581 DISPLAY_LINK_7_1_OR_EARLIER,
582 DISPLAY_LINK_INSTALLATION_STATUS_MAX);
583 } else {
584 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus",
585 DISPLAY_LINK_7_2_OR_LATER,
586 DISPLAY_LINK_INSTALLATION_STATUS_MAX);
589 // Taken from http://developer.nvidia.com/object/device_ids.html
590 DISPLAY_DEVICE dd;
591 dd.cb = sizeof(DISPLAY_DEVICE);
592 std::wstring id;
593 for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) {
594 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
595 id = dd.DeviceID;
596 break;
600 if (id.length() <= 20)
601 return kCollectInfoNonFatalFailure;
603 int vendor_id = 0, device_id = 0;
604 base::string16 vendor_id_string = id.substr(8, 4);
605 base::string16 device_id_string = id.substr(17, 4);
606 base::HexStringToInt(base::UTF16ToASCII(vendor_id_string), &vendor_id);
607 base::HexStringToInt(base::UTF16ToASCII(device_id_string), &device_id);
608 gpu_info->gpu.vendor_id = vendor_id;
609 gpu_info->gpu.device_id = device_id;
610 // TODO(zmo): we only need to call CollectDriverInfoD3D() if we use ANGLE.
611 if (!CollectDriverInfoD3D(id, gpu_info))
612 return kCollectInfoNonFatalFailure;
614 // Collect basic information about supported D3D11 features. Delay for 45
615 // seconds so as not to regress performance tests.
616 if (D3D11ShouldWork(*gpu_info)) {
617 // This is on a field trial so we can turn it off easily if it blows up
618 // again in stable channel.
619 scoped_refptr<base::FieldTrial> trial(
620 base::FieldTrialList::FactoryGetFieldTrial(
621 "D3D11Experiment", 100, "Disabled", 2015, 7, 8,
622 base::FieldTrial::SESSION_RANDOMIZED, NULL));
623 const int enabled_group =
624 trial->AppendGroup("Enabled", 0);
626 if (trial->group() == enabled_group) {
627 base::MessageLoop::current()->PostDelayedTask(
628 FROM_HERE,
629 base::Bind(&CollectD3D11Support),
630 base::TimeDelta::FromSeconds(45));
634 return kCollectInfoSuccess;
637 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) {
638 TRACE_EVENT0("gpu", "CollectDriverInfoGL");
640 if (!gpu_info->driver_version.empty())
641 return kCollectInfoSuccess;
643 bool parsed = RE2::PartialMatch(
644 gpu_info->gl_version, "([\\d\\.]+)$", &gpu_info->driver_version);
645 return parsed ? kCollectInfoSuccess : kCollectInfoNonFatalFailure;
648 void MergeGPUInfo(GPUInfo* basic_gpu_info,
649 const GPUInfo& context_gpu_info) {
650 DCHECK(basic_gpu_info);
652 if (context_gpu_info.software_rendering) {
653 basic_gpu_info->software_rendering = true;
654 return;
657 MergeGPUInfoGL(basic_gpu_info, context_gpu_info);
659 basic_gpu_info->dx_diagnostics = context_gpu_info.dx_diagnostics;
662 } // namespace gpu