[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 5 | // Functions to enumerate the Dx Diagnostic Tool hierarchy and build up |
| 6 | // a tree of nodes with name / value properties. |
| 7 | |
| 8 | #define INITGUID |
| 9 | #include <dxdiag.h> |
| 10 | #include <windows.h> |
| 11 | |
Avi Drissman | 6fc2408c | 2018-12-25 21:29:08 | [diff] [blame] | 12 | #include "base/stl_util.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 13 | #include "base/strings/string_number_conversions.h" |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 14 | #include "base/strings/utf_string_conversions.h" |
Robert Liao | 1214b5e | 2017-07-29 02:48:58 | [diff] [blame] | 15 | #include "base/win/com_init_util.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 16 | #include "gpu/config/gpu_info_collector.h" |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 17 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 18 | namespace gpu { |
| 19 | |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | // Traverses the IDxDiagContainer tree and populates a tree of DxDiagNode |
| 23 | // structures that contains property name / value pairs and subtrees of DirectX |
| 24 | // diagnostic information. |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 25 | void RecurseDiagnosticTree(DxDiagNode* output, |
[email protected] | 206c5b0 | 2010-10-11 19:54:44 | [diff] [blame] | 26 | IDxDiagContainer* container, |
| 27 | int depth) { |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 28 | HRESULT hr; |
| 29 | |
| 30 | VARIANT variant; |
| 31 | VariantInit(&variant); |
| 32 | |
| 33 | DWORD prop_count; |
| 34 | hr = container->GetNumberOfProps(&prop_count); |
| 35 | if (SUCCEEDED(hr)) { |
| 36 | for (DWORD i = 0; i < prop_count; i++) { |
| 37 | WCHAR prop_name16[256]; |
Avi Drissman | 6fc2408c | 2018-12-25 21:29:08 | [diff] [blame] | 38 | hr = container->EnumPropNames(i, prop_name16, base::size(prop_name16)); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 39 | if (SUCCEEDED(hr)) { |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 40 | std::string prop_name8 = base::WideToUTF8(prop_name16); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 41 | |
| 42 | hr = container->GetProp(prop_name16, &variant); |
| 43 | if (SUCCEEDED(hr)) { |
| 44 | switch (variant.vt) { |
| 45 | case VT_UI4: |
Raul Tambre | 3658454 | 2019-02-07 23:42:08 | [diff] [blame] | 46 | output->values[prop_name8] = base::NumberToString(variant.ulVal); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 47 | break; |
| 48 | case VT_I4: |
Raul Tambre | 3658454 | 2019-02-07 23:42:08 | [diff] [blame] | 49 | output->values[prop_name8] = base::NumberToString(variant.lVal); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 50 | break; |
| 51 | case VT_BOOL: |
| 52 | output->values[prop_name8] = variant.boolVal ? "true" : "false"; |
| 53 | break; |
| 54 | case VT_BSTR: |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 55 | output->values[prop_name8] = base::WideToUTF8(variant.bstrVal); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 56 | break; |
| 57 | default: |
| 58 | break; |
| 59 | } |
| 60 | |
| 61 | // Clear the variant (this is needed to free BSTR memory). |
| 62 | VariantClear(&variant); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
[email protected] | 206c5b0 | 2010-10-11 19:54:44 | [diff] [blame] | 68 | if (depth > 0) { |
| 69 | DWORD child_count; |
| 70 | hr = container->GetNumberOfChildContainers(&child_count); |
| 71 | if (SUCCEEDED(hr)) { |
| 72 | for (DWORD i = 0; i < child_count; i++) { |
| 73 | WCHAR child_name16[256]; |
Avi Drissman | 6fc2408c | 2018-12-25 21:29:08 | [diff] [blame] | 74 | hr = container->EnumChildContainerNames(i, child_name16, |
| 75 | base::size(child_name16)); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 76 | if (SUCCEEDED(hr)) { |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 77 | std::string child_name8 = base::WideToUTF8(child_name16); |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 78 | DxDiagNode* output_child = &output->children[child_name8]; |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 79 | |
tzik | ddef0218 | 2018-08-14 07:08:33 | [diff] [blame] | 80 | IDxDiagContainer* child_container = nullptr; |
[email protected] | 206c5b0 | 2010-10-11 19:54:44 | [diff] [blame] | 81 | hr = container->GetChildContainer(child_name16, &child_container); |
| 82 | if (SUCCEEDED(hr)) { |
| 83 | RecurseDiagnosticTree(output_child, child_container, depth - 1); |
| 84 | |
| 85 | child_container->Release(); |
| 86 | } |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } // namespace anonymous |
| 93 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 94 | bool GetDxDiagnostics(DxDiagNode* output) { |
Robert Liao | 1214b5e | 2017-07-29 02:48:58 | [diff] [blame] | 95 | // CLSID_DxDiagProvider is configured as an STA only object. |
| 96 | base::win::AssertComApartmentType(base::win::ComApartmentType::STA); |
| 97 | |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 98 | HRESULT hr; |
| 99 | bool success = false; |
tzik | ddef0218 | 2018-08-14 07:08:33 | [diff] [blame] | 100 | IDxDiagProvider* provider = nullptr; |
| 101 | hr = CoCreateInstance(CLSID_DxDiagProvider, nullptr, CLSCTX_INPROC_SERVER, |
Robert Liao | 1214b5e | 2017-07-29 02:48:58 | [diff] [blame] | 102 | IID_IDxDiagProvider, |
| 103 | reinterpret_cast<void**>(&provider)); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 104 | if (SUCCEEDED(hr)) { |
| 105 | DXDIAG_INIT_PARAMS params = { sizeof(params) }; |
| 106 | params.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION; |
| 107 | params.bAllowWHQLChecks = FALSE; |
tzik | ddef0218 | 2018-08-14 07:08:33 | [diff] [blame] | 108 | params.pReserved = nullptr; |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 109 | |
| 110 | hr = provider->Initialize(¶ms); |
| 111 | if (SUCCEEDED(hr)) { |
tzik | ddef0218 | 2018-08-14 07:08:33 | [diff] [blame] | 112 | IDxDiagContainer* root = nullptr; |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 113 | hr = provider->GetRootContainer(&root); |
| 114 | if (SUCCEEDED(hr)) { |
| 115 | // Limit to the DisplayDevices subtree. The tree in its entirity is |
| 116 | // enormous and only this branch contains useful information. |
tzik | ddef0218 | 2018-08-14 07:08:33 | [diff] [blame] | 117 | IDxDiagContainer* display_devices = nullptr; |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 118 | hr = root->GetChildContainer(L"DxDiag_DisplayDevices", |
| 119 | &display_devices); |
| 120 | if (SUCCEEDED(hr)) { |
[email protected] | 206c5b0 | 2010-10-11 19:54:44 | [diff] [blame] | 121 | RecurseDiagnosticTree(output, display_devices, 1); |
[email protected] | 81f85b3 | 2010-10-08 18:03:21 | [diff] [blame] | 122 | success = true; |
| 123 | display_devices->Release(); |
| 124 | } |
| 125 | |
| 126 | root->Release(); |
| 127 | } |
| 128 | } |
| 129 | provider->Release(); |
| 130 | } |
| 131 | |
| 132 | return success; |
| 133 | } |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 134 | } // namespace gpu |