1 // Copyright (c) 2011 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 // Functions to enumerate the Dx Diagnostic Tool hierarchy and build up
6 // a tree of nodes with name / value properties.
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/scoped_com_initializer.h"
15 #include "gpu/config/gpu_info_collector.h"
21 // Traverses the IDxDiagContainer tree and populates a tree of DxDiagNode
22 // structures that contains property name / value pairs and subtrees of DirectX
23 // diagnostic information.
24 void RecurseDiagnosticTree(DxDiagNode
* output
,
25 IDxDiagContainer
* container
,
30 VariantInit(&variant
);
33 hr
= container
->GetNumberOfProps(&prop_count
);
35 for (DWORD i
= 0; i
< prop_count
; i
++) {
36 WCHAR prop_name16
[256];
37 hr
= container
->EnumPropNames(i
, prop_name16
, arraysize(prop_name16
));
39 std::string prop_name8
= base::WideToUTF8(prop_name16
);
41 hr
= container
->GetProp(prop_name16
, &variant
);
45 output
->values
[prop_name8
] = base::UintToString(variant
.ulVal
);
48 output
->values
[prop_name8
] = base::IntToString(variant
.lVal
);
51 output
->values
[prop_name8
] = variant
.boolVal
? "true" : "false";
54 output
->values
[prop_name8
] = base::WideToUTF8(variant
.bstrVal
);
60 // Clear the variant (this is needed to free BSTR memory).
61 VariantClear(&variant
);
69 hr
= container
->GetNumberOfChildContainers(&child_count
);
71 for (DWORD i
= 0; i
< child_count
; i
++) {
72 WCHAR child_name16
[256];
73 hr
= container
->EnumChildContainerNames(i
,
75 arraysize(child_name16
));
77 std::string child_name8
= base::WideToUTF8(child_name16
);
78 DxDiagNode
* output_child
= &output
->children
[child_name8
];
80 IDxDiagContainer
* child_container
= NULL
;
81 hr
= container
->GetChildContainer(child_name16
, &child_container
);
83 RecurseDiagnosticTree(output_child
, child_container
, depth
- 1);
85 child_container
->Release();
92 } // namespace anonymous
94 bool GetDxDiagnostics(DxDiagNode
* output
) {
97 base::win::ScopedCOMInitializer com_initializer
;
99 IDxDiagProvider
* provider
= NULL
;
100 hr
= CoCreateInstance(CLSID_DxDiagProvider
,
102 CLSCTX_INPROC_SERVER
,
104 reinterpret_cast<void**>(&provider
));
106 DXDIAG_INIT_PARAMS params
= { sizeof(params
) };
107 params
.dwDxDiagHeaderVersion
= DXDIAG_DX9_SDK_VERSION
;
108 params
.bAllowWHQLChecks
= FALSE
;
109 params
.pReserved
= NULL
;
111 hr
= provider
->Initialize(¶ms
);
113 IDxDiagContainer
* root
= NULL
;
114 hr
= provider
->GetRootContainer(&root
);
116 // Limit to the DisplayDevices subtree. The tree in its entirity is
117 // enormous and only this branch contains useful information.
118 IDxDiagContainer
* display_devices
= NULL
;
119 hr
= root
->GetChildContainer(L
"DxDiag_DisplayDevices",
122 RecurseDiagnosticTree(output
, display_devices
, 1);
124 display_devices
->Release();