[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / gpu / config / gpu_info_collector_win.cc
blobb339cd7c1d5f5678c44e40c1d2dd4c25e7824eb9
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 return stats;
105 // Get relevant scores from results file. XML schema at:
106 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa969210.aspx
107 XmlReader reader;
108 if (!reader.LoadFile(current_results_string)) {
109 LOG(ERROR) << "Could not open WinSAT results file.";
110 return stats;
112 // Descend into <WinSAT> root element.
113 if (!reader.SkipToElement() || !reader.Read()) {
114 LOG(ERROR) << "Could not read WinSAT results file.";
115 return stats;
118 // Search for <WinSPR> element containing the results.
119 do {
120 if (reader.NodeName() == "WinSPR")
121 break;
122 } while (reader.Next());
123 // Descend into <WinSPR> element.
124 if (!reader.Read()) {
125 LOG(ERROR) << "Could not find WinSPR element in results file.";
126 return stats;
129 // Read scores.
130 for (int depth = reader.Depth(); reader.Depth() == depth; reader.Next()) {
131 std::string node_name = reader.NodeName();
132 if (node_name == "SystemScore")
133 stats.overall = ReadXMLFloatValue(&reader);
134 else if (node_name == "GraphicsScore")
135 stats.graphics = ReadXMLFloatValue(&reader);
136 else if (node_name == "GamingScore")
137 stats.gaming = ReadXMLFloatValue(&reader);
140 if (stats.overall == 0.0)
141 LOG(ERROR) << "Could not read overall score from assessment results.";
142 if (stats.graphics == 0.0)
143 LOG(ERROR) << "Could not read graphics score from assessment results.";
144 if (stats.gaming == 0.0)
145 LOG(ERROR) << "Could not read gaming score from assessment results.";
147 return stats;
150 GpuPerformanceStats RetrieveGpuPerformanceStatsWithHistograms() {
151 base::TimeTicks start_time = base::TimeTicks::Now();
153 GpuPerformanceStats stats = RetrieveGpuPerformanceStats();
155 UMA_HISTOGRAM_TIMES("GPU.WinSAT.ReadResultsFileTime",
156 base::TimeTicks::Now() - start_time);
157 UMA_HISTOGRAM_CUSTOM_COUNTS("GPU.WinSAT.OverallScore2",
158 stats.overall * 10, 10, 200, 50);
159 UMA_HISTOGRAM_CUSTOM_COUNTS("GPU.WinSAT.GraphicsScore2",
160 stats.graphics * 10, 10, 200, 50);
161 UMA_HISTOGRAM_CUSTOM_COUNTS("GPU.WinSAT.GamingScore2",
162 stats.gaming * 10, 10, 200, 50);
163 UMA_HISTOGRAM_BOOLEAN(
164 "GPU.WinSAT.HasResults",
165 stats.overall != 0.0 && stats.graphics != 0.0 && stats.gaming != 0.0);
167 return stats;
170 // Returns the display link driver version or an invalid version if it is
171 // not installed.
172 Version DisplayLinkVersion() {
173 base::win::RegKey key;
175 if (key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE", KEY_READ | KEY_WOW64_64KEY))
176 return Version();
178 if (key.OpenKey(L"DisplayLink", KEY_READ | KEY_WOW64_64KEY))
179 return Version();
181 if (key.OpenKey(L"Core", KEY_READ | KEY_WOW64_64KEY))
182 return Version();
184 base::string16 version;
185 if (key.ReadValue(L"Version", &version))
186 return Version();
188 return Version(base::UTF16ToASCII(version));
191 // Returns whether Lenovo dCute is installed.
192 bool IsLenovoDCuteInstalled() {
193 base::win::RegKey key;
195 if (key.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE", KEY_READ | KEY_WOW64_64KEY))
196 return false;
198 if (key.OpenKey(L"Lenovo", KEY_READ | KEY_WOW64_64KEY))
199 return false;
201 if (key.OpenKey(L"Lenovo dCute", KEY_READ | KEY_WOW64_64KEY))
202 return false;
204 return true;
207 // Determines whether D3D11 won't work, either because it is not supported on
208 // the machine or because it is known it is likely to crash.
209 bool D3D11ShouldWork(const GPUInfo& gpu_info) {
210 // TODO(apatrick): This is a temporary change to see what impact disabling
211 // D3D11 stats collection has on Canary.
212 #if 1
213 return false;
214 #else
215 // Windows XP never supports D3D11. It seems to be less stable that D3D9 on
216 // Vista.
217 if (base::win::GetVersion() <= base::win::VERSION_VISTA)
218 return false;
220 // http://crbug.com/175525.
221 if (gpu_info.display_link_version.IsValid())
222 return false;
224 return true;
225 #endif
228 // Collects information about the level of D3D11 support and records it in
229 // the UMA stats. Records no stats when D3D11 in not supported at all.
230 void CollectD3D11SupportOnWorkerThread() {
231 TRACE_EVENT0("gpu", "CollectD3D11Support");
233 typedef HRESULT (WINAPI *D3D11CreateDeviceFunc)(
234 IDXGIAdapter* adapter,
235 D3D_DRIVER_TYPE driver_type,
236 HMODULE software,
237 UINT flags,
238 const D3D_FEATURE_LEVEL* feature_levels,
239 UINT num_feature_levels,
240 UINT sdk_version,
241 ID3D11Device** device,
242 D3D_FEATURE_LEVEL* feature_level,
243 ID3D11DeviceContext** immediate_context);
245 // This enumeration must be kept in sync with histograms.xml. Do not reorder
246 // the members; always add to the end.
247 enum FeatureLevel {
248 FEATURE_LEVEL_UNKNOWN,
249 FEATURE_LEVEL_NO_D3D11_DLL,
250 FEATURE_LEVEL_NO_CREATE_DEVICE_ENTRY_POINT,
251 FEATURE_LEVEL_DEVICE_CREATION_FAILED,
252 FEATURE_LEVEL_9_1,
253 FEATURE_LEVEL_9_2,
254 FEATURE_LEVEL_9_3,
255 FEATURE_LEVEL_10_0,
256 FEATURE_LEVEL_10_1,
257 FEATURE_LEVEL_11_0,
258 NUM_FEATURE_LEVELS
261 FeatureLevel feature_level = FEATURE_LEVEL_UNKNOWN;
262 UINT bgra_support = 0;
264 // This module is leaked in case it is hooked by third party software.
265 base::NativeLibrary d3d11_module = base::LoadNativeLibrary(
266 base::FilePath(L"d3d11.dll"),
267 NULL);
269 if (!d3d11_module) {
270 feature_level = FEATURE_LEVEL_NO_D3D11_DLL;
271 } else {
272 D3D11CreateDeviceFunc create_func =
273 reinterpret_cast<D3D11CreateDeviceFunc>(
274 base::GetFunctionPointerFromNativeLibrary(d3d11_module,
275 "D3D11CreateDevice"));
276 if (!create_func) {
277 feature_level = FEATURE_LEVEL_NO_CREATE_DEVICE_ENTRY_POINT;
278 } else {
279 static const D3D_FEATURE_LEVEL d3d_feature_levels[] = {
280 D3D_FEATURE_LEVEL_11_0,
281 D3D_FEATURE_LEVEL_10_1,
282 D3D_FEATURE_LEVEL_10_0,
283 D3D_FEATURE_LEVEL_9_3,
284 D3D_FEATURE_LEVEL_9_2,
285 D3D_FEATURE_LEVEL_9_1
288 base::win::ScopedComPtr<ID3D11Device> device;
289 D3D_FEATURE_LEVEL d3d_feature_level;
290 base::win::ScopedComPtr<ID3D11DeviceContext> device_context;
291 HRESULT hr = create_func(NULL,
292 D3D_DRIVER_TYPE_HARDWARE,
293 NULL,
295 d3d_feature_levels,
296 arraysize(d3d_feature_levels),
297 D3D11_SDK_VERSION,
298 device.Receive(),
299 &d3d_feature_level,
300 device_context.Receive());
301 if (FAILED(hr)) {
302 feature_level = FEATURE_LEVEL_DEVICE_CREATION_FAILED;
303 } else {
304 switch (d3d_feature_level) {
305 case D3D_FEATURE_LEVEL_11_0:
306 feature_level = FEATURE_LEVEL_11_0;
307 break;
308 case D3D_FEATURE_LEVEL_10_1:
309 feature_level = FEATURE_LEVEL_10_1;
310 break;
311 case D3D_FEATURE_LEVEL_10_0:
312 feature_level = FEATURE_LEVEL_10_0;
313 break;
314 case D3D_FEATURE_LEVEL_9_3:
315 feature_level = FEATURE_LEVEL_9_3;
316 break;
317 case D3D_FEATURE_LEVEL_9_2:
318 feature_level = FEATURE_LEVEL_9_2;
319 break;
320 case D3D_FEATURE_LEVEL_9_1:
321 feature_level = FEATURE_LEVEL_9_1;
322 break;
323 default:
324 NOTREACHED();
325 break;
328 hr = device->CheckFormatSupport(DXGI_FORMAT_B8G8R8A8_UNORM,
329 &bgra_support);
330 DCHECK(SUCCEEDED(hr));
335 UMA_HISTOGRAM_ENUMERATION("GPU.D3D11_FeatureLevel",
336 feature_level,
337 NUM_FEATURE_LEVELS);
339 // ANGLE requires at least feature level 10.0. Do not record any further
340 // stats if ANGLE would not work anyway.
341 if (feature_level < FEATURE_LEVEL_10_0)
342 return;
344 UMA_HISTOGRAM_BOOLEAN(
345 "GPU.D3D11_B8G8R8A8_Texture2DSupport",
346 (bgra_support & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0);
347 UMA_HISTOGRAM_BOOLEAN(
348 "GPU.D3D11_B8G8R8A8_RenderTargetSupport",
349 (bgra_support & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0);
352 // Collects information about the level of D3D11 support and records it in
353 // the UMA stats. Records no stats when D3D11 in not supported at all.
354 void CollectD3D11Support() {
355 // D3D11 takes about 50ms to initialize so do this on a worker thread.
356 base::WorkerPool::PostTask(
357 FROM_HERE,
358 base::Bind(CollectD3D11SupportOnWorkerThread),
359 false);
361 } // namespace anonymous
363 #if !defined(GOOGLE_CHROME_BUILD)
364 void GetAMDVideocardInfo(GPUInfo* gpu_info) {
365 DCHECK(gpu_info);
366 return;
368 #else
369 // This function has a real implementation for official builds that can
370 // be found in src/third_party/amd.
371 void GetAMDVideocardInfo(GPUInfo* gpu_info);
372 #endif
374 bool CollectDriverInfoD3D(const std::wstring& device_id,
375 GPUInfo* gpu_info) {
376 TRACE_EVENT0("gpu", "CollectDriverInfoD3D");
378 // create device info for the display device
379 HDEVINFO device_info = SetupDiGetClassDevsW(
380 NULL, device_id.c_str(), NULL,
381 DIGCF_PRESENT | DIGCF_PROFILE | DIGCF_ALLCLASSES);
382 if (device_info == INVALID_HANDLE_VALUE) {
383 LOG(ERROR) << "Creating device info failed";
384 return false;
387 DWORD index = 0;
388 bool found = false;
389 SP_DEVINFO_DATA device_info_data;
390 device_info_data.cbSize = sizeof(device_info_data);
391 while (SetupDiEnumDeviceInfo(device_info, index++, &device_info_data)) {
392 WCHAR value[255];
393 if (SetupDiGetDeviceRegistryPropertyW(device_info,
394 &device_info_data,
395 SPDRP_DRIVER,
396 NULL,
397 reinterpret_cast<PBYTE>(value),
398 sizeof(value),
399 NULL)) {
400 HKEY key;
401 std::wstring driver_key = L"System\\CurrentControlSet\\Control\\Class\\";
402 driver_key += value;
403 LONG result = RegOpenKeyExW(
404 HKEY_LOCAL_MACHINE, driver_key.c_str(), 0, KEY_QUERY_VALUE, &key);
405 if (result == ERROR_SUCCESS) {
406 DWORD dwcb_data = sizeof(value);
407 std::string driver_version;
408 result = RegQueryValueExW(
409 key, L"DriverVersion", NULL, NULL,
410 reinterpret_cast<LPBYTE>(value), &dwcb_data);
411 if (result == ERROR_SUCCESS)
412 driver_version = base::UTF16ToASCII(std::wstring(value));
414 std::string driver_date;
415 dwcb_data = sizeof(value);
416 result = RegQueryValueExW(
417 key, L"DriverDate", NULL, NULL,
418 reinterpret_cast<LPBYTE>(value), &dwcb_data);
419 if (result == ERROR_SUCCESS)
420 driver_date = base::UTF16ToASCII(std::wstring(value));
422 std::string driver_vendor;
423 dwcb_data = sizeof(value);
424 result = RegQueryValueExW(
425 key, L"ProviderName", NULL, NULL,
426 reinterpret_cast<LPBYTE>(value), &dwcb_data);
427 if (result == ERROR_SUCCESS) {
428 driver_vendor = base::UTF16ToASCII(std::wstring(value));
429 if (driver_vendor == "Advanced Micro Devices, Inc." ||
430 driver_vendor == "ATI Technologies Inc.") {
431 // We are conservative and assume that in the absence of a clear
432 // signal the videocard is assumed to be switchable. Additionally,
433 // some switchable systems with Intel GPUs aren't correctly
434 // detected, so always count them.
435 GetAMDVideocardInfo(gpu_info);
436 if (!gpu_info->amd_switchable &&
437 gpu_info->gpu.vendor_id == 0x8086) {
438 gpu_info->amd_switchable = true;
439 gpu_info->secondary_gpus.push_back(gpu_info->gpu);
440 gpu_info->gpu.vendor_id = 0x1002;
441 gpu_info->gpu.device_id = 0; // Unknown discrete AMD GPU.
446 gpu_info->driver_vendor = driver_vendor;
447 gpu_info->driver_version = driver_version;
448 gpu_info->driver_date = driver_date;
449 found = true;
450 RegCloseKey(key);
451 break;
455 SetupDiDestroyDeviceInfoList(device_info);
456 return found;
459 CollectInfoResult CollectContextGraphicsInfo(GPUInfo* gpu_info) {
460 TRACE_EVENT0("gpu", "CollectGraphicsInfo");
462 DCHECK(gpu_info);
464 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
465 std::string requested_implementation_name =
466 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
467 if (requested_implementation_name == "swiftshader") {
468 gpu_info->software_rendering = true;
469 return kCollectInfoNonFatalFailure;
473 CollectInfoResult result = CollectGraphicsInfoGL(gpu_info);
474 if (result != kCollectInfoSuccess)
475 return result;
477 // ANGLE's renderer strings are of the form:
478 // ANGLE (<adapter_identifier> Direct3D<version> vs_x_x ps_x_x)
479 std::string direct3d_version;
480 int vertex_shader_major_version = 0;
481 int vertex_shader_minor_version = 0;
482 int pixel_shader_major_version = 0;
483 int pixel_shader_minor_version = 0;
484 gpu_info->adapter_luid = 0;
485 if (RE2::FullMatch(gpu_info->gl_renderer,
486 "ANGLE \\(.*\\)") &&
487 RE2::PartialMatch(gpu_info->gl_renderer,
488 " Direct3D(\\w+)",
489 &direct3d_version) &&
490 RE2::PartialMatch(gpu_info->gl_renderer,
491 " vs_(\\d+)_(\\d+)",
492 &vertex_shader_major_version,
493 &vertex_shader_minor_version) &&
494 RE2::PartialMatch(gpu_info->gl_renderer,
495 " ps_(\\d+)_(\\d+)",
496 &pixel_shader_major_version,
497 &pixel_shader_minor_version)) {
498 gpu_info->can_lose_context = direct3d_version == "9";
499 gpu_info->vertex_shader_version =
500 base::StringPrintf("%d.%d",
501 vertex_shader_major_version,
502 vertex_shader_minor_version);
503 gpu_info->pixel_shader_version =
504 base::StringPrintf("%d.%d",
505 pixel_shader_major_version,
506 pixel_shader_minor_version);
508 // ANGLE's EGL vendor strings are of the form:
509 // Google, Inc. (adapter LUID: 0123456789ABCDEF)
510 // The LUID is optional and identifies the GPU adapter ANGLE is using.
511 const char* egl_vendor = eglQueryString(
512 gfx::GLSurfaceEGL::GetHardwareDisplay(),
513 EGL_VENDOR);
514 RE2::PartialMatch(egl_vendor,
515 " \\(adapter LUID: ([0-9A-Fa-f]{16})\\)",
516 RE2::Hex(&gpu_info->adapter_luid));
518 // DirectX diagnostics are collected asynchronously because it takes a
519 // couple of seconds. Do not mark gpu_info as complete until that is done.
520 gpu_info->finalized = false;
521 } else {
522 gpu_info->finalized = true;
525 return kCollectInfoSuccess;
528 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) {
529 DCHECK(vendor_id && device_id);
530 *vendor_id = 0;
531 *device_id = 0;
533 // Taken from http://developer.nvidia.com/object/device_ids.html
534 DISPLAY_DEVICE dd;
535 dd.cb = sizeof(DISPLAY_DEVICE);
536 std::wstring id;
537 for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) {
538 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
539 id = dd.DeviceID;
540 break;
544 if (id.length() > 20) {
545 int vendor = 0, device = 0;
546 std::wstring vendor_string = id.substr(8, 4);
547 std::wstring device_string = id.substr(17, 4);
548 base::HexStringToInt(base::UTF16ToASCII(vendor_string), &vendor);
549 base::HexStringToInt(base::UTF16ToASCII(device_string), &device);
550 *vendor_id = vendor;
551 *device_id = device;
552 if (*vendor_id != 0 && *device_id != 0)
553 return kGpuIDSuccess;
555 return kGpuIDFailure;
558 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) {
559 TRACE_EVENT0("gpu", "CollectPreliminaryGraphicsInfo");
561 DCHECK(gpu_info);
563 gpu_info->performance_stats = RetrieveGpuPerformanceStatsWithHistograms();
565 // nvd3d9wrap.dll is loaded into all processes when Optimus is enabled.
566 HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll");
567 gpu_info->optimus = nvd3d9wrap != NULL;
569 gpu_info->lenovo_dcute = IsLenovoDCuteInstalled();
571 gpu_info->display_link_version = DisplayLinkVersion();
573 if (!gpu_info->display_link_version .IsValid()) {
574 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus",
575 DISPLAY_LINK_NOT_INSTALLED,
576 DISPLAY_LINK_INSTALLATION_STATUS_MAX);
577 } else if (gpu_info->display_link_version.IsOlderThan("7.2")) {
578 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus",
579 DISPLAY_LINK_7_1_OR_EARLIER,
580 DISPLAY_LINK_INSTALLATION_STATUS_MAX);
581 } else {
582 UMA_HISTOGRAM_ENUMERATION("GPU.DisplayLinkInstallationStatus",
583 DISPLAY_LINK_7_2_OR_LATER,
584 DISPLAY_LINK_INSTALLATION_STATUS_MAX);
587 // Taken from http://developer.nvidia.com/object/device_ids.html
588 DISPLAY_DEVICE dd;
589 dd.cb = sizeof(DISPLAY_DEVICE);
590 std::wstring id;
591 for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) {
592 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
593 id = dd.DeviceID;
594 break;
598 if (id.length() <= 20)
599 return kCollectInfoNonFatalFailure;
601 int vendor_id = 0, device_id = 0;
602 base::string16 vendor_id_string = id.substr(8, 4);
603 base::string16 device_id_string = id.substr(17, 4);
604 base::HexStringToInt(base::UTF16ToASCII(vendor_id_string), &vendor_id);
605 base::HexStringToInt(base::UTF16ToASCII(device_id_string), &device_id);
606 gpu_info->gpu.vendor_id = vendor_id;
607 gpu_info->gpu.device_id = device_id;
608 // TODO(zmo): we only need to call CollectDriverInfoD3D() if we use ANGLE.
609 if (!CollectDriverInfoD3D(id, gpu_info))
610 return kCollectInfoNonFatalFailure;
612 // Collect basic information about supported D3D11 features. Delay for 45
613 // seconds so as not to regress performance tests.
614 if (D3D11ShouldWork(*gpu_info)) {
615 // This is on a field trial so we can turn it off easily if it blows up
616 // again in stable channel.
617 scoped_refptr<base::FieldTrial> trial(
618 base::FieldTrialList::FactoryGetFieldTrial(
619 "D3D11Experiment", 100, "Disabled", 2015, 7, 8,
620 base::FieldTrial::SESSION_RANDOMIZED, NULL));
621 const int enabled_group =
622 trial->AppendGroup("Enabled", 0);
624 if (trial->group() == enabled_group) {
625 base::MessageLoop::current()->PostDelayedTask(
626 FROM_HERE,
627 base::Bind(&CollectD3D11Support),
628 base::TimeDelta::FromSeconds(45));
632 return kCollectInfoSuccess;
635 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) {
636 TRACE_EVENT0("gpu", "CollectDriverInfoGL");
638 if (!gpu_info->driver_version.empty())
639 return kCollectInfoSuccess;
641 bool parsed = RE2::PartialMatch(
642 gpu_info->gl_version, "([\\d\\.]+)$", &gpu_info->driver_version);
643 return parsed ? kCollectInfoSuccess : kCollectInfoNonFatalFailure;
646 void MergeGPUInfo(GPUInfo* basic_gpu_info,
647 const GPUInfo& context_gpu_info) {
648 DCHECK(basic_gpu_info);
650 if (context_gpu_info.software_rendering) {
651 basic_gpu_info->software_rendering = true;
652 return;
655 MergeGPUInfoGL(basic_gpu_info, context_gpu_info);
657 basic_gpu_info->dx_diagnostics = context_gpu_info.dx_diagnostics;
660 } // namespace gpu