OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/gpu/gpu_info_collector.h" | 5 #include "content/gpu/gpu_info_collector.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <d3d9.h> | 8 #include <d3d9.h> |
9 #include <setupapi.h> | 9 #include <setupapi.h> |
10 #include <winsatcominterfacei.h> | |
11 | 10 |
12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
13 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/scoped_native_library.h" | 15 #include "base/scoped_native_library.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/win/scoped_com_initializer.h" | 18 #include "base/win/scoped_com_initializer.h" |
19 #include "base/win/scoped_comptr.h" | 19 #include "base/win/scoped_comptr.h" |
20 #include "libxml/libxml_utils.h" | |
20 #include "ui/gfx/gl/gl_implementation.h" | 21 #include "ui/gfx/gl/gl_implementation.h" |
21 #include "ui/gfx/gl/gl_surface_egl.h" | 22 #include "ui/gfx/gl/gl_surface_egl.h" |
22 | 23 |
23 // ANGLE seems to require that main.h be included before any other ANGLE header. | 24 // ANGLE seems to require that main.h be included before any other ANGLE header. |
24 #include "libEGL/Display.h" | 25 #include "libEGL/Display.h" |
25 #include "libEGL/main.h" | 26 #include "libEGL/main.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // The version number stores the major and minor version in the least 16 bits; | 30 // The version number stores the major and minor version in the least 16 bits; |
30 // for example, 2.5 is 0x00000205. | 31 // for example, 2.5 is 0x00000205. |
31 // Returned string is in the format of "major.minor". | 32 // Returned string is in the format of "major.minor". |
32 std::string VersionNumberToString(uint32 version_number) { | 33 std::string VersionNumberToString(uint32 version_number) { |
33 int hi = (version_number >> 8) & 0xff; | 34 int hi = (version_number >> 8) & 0xff; |
34 int low = version_number & 0xff; | 35 int low = version_number & 0xff; |
35 return base::IntToString(hi) + "." + base::IntToString(low); | 36 return base::IntToString(hi) + "." + base::IntToString(low); |
36 } | 37 } |
37 | 38 |
38 float GetAssessmentScore(IProvideWinSATResultsInfo* results, | 39 float ReadXMLFloatValue(XmlReader* reader) { |
39 WINSAT_ASSESSMENT_TYPE type) { | 40 std::string score_string; |
40 base::win::ScopedComPtr<IProvideWinSATAssessmentInfo> subcomponent; | 41 if (!reader->ReadElementContent(&score_string)) |
41 if (FAILED(results->GetAssessmentInfo(type, subcomponent.Receive()))) | |
42 return 0.0; | 42 return 0.0; |
43 | 43 |
44 float score = 0.0; | 44 double score; |
45 if (FAILED(subcomponent->get_Score(&score))) | 45 if (!base::StringToDouble(score_string, &score)) |
46 score = 0.0; | 46 return 0.0; |
47 return score; | 47 |
48 return static_cast<float>(score); | |
48 } | 49 } |
49 | 50 |
50 content::GpuPerformanceStats RetrieveGpuPerformanceStats() { | 51 content::GpuPerformanceStats RetrieveGpuPerformanceStats() { |
52 // If the user re-runs the assessment without restarting, the COM API | |
53 // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. Because of that and | |
54 // http://crbug.com/124325, read the assessment result files directly. | |
51 content::GpuPerformanceStats stats; | 55 content::GpuPerformanceStats stats; |
52 | 56 |
53 base::win::ScopedCOMInitializer com_initializer; | 57 // Get path to WinSAT results files. |
54 if (!com_initializer.succeeded()) { | 58 wchar_t winsat_results_path[MAX_PATH]; |
55 LOG(ERROR) << "CoInitializeEx() failed"; | 59 DWORD size = ExpandEnvironmentStrings( |
60 L"%WinDir%\\Performance\\WinSAT\\DataStore\\", | |
61 winsat_results_path, MAX_PATH); | |
62 if (size == 0 || size > MAX_PATH) { | |
63 LOG(ERROR) << "The path to the WinSAT results is too long: " | |
64 << size << " chars."; | |
56 return stats; | 65 return stats; |
57 } | 66 } |
58 | 67 |
59 base::win::ScopedComPtr<IQueryRecentWinSATAssessment> assessment; | 68 // Find most recent formal assessment results. |
60 HRESULT hr = assessment.CreateInstance(__uuidof(CQueryWinSAT), NULL, | 69 file_util::FileEnumerator file_enumerator( |
61 CLSCTX_INPROC_SERVER); | 70 FilePath(winsat_results_path), |
62 if (FAILED(hr)) { | 71 false, // not recursive |
63 LOG(ERROR) << "CoCreateInstance() failed"; | 72 file_util::FileEnumerator::FILES, |
73 FILE_PATH_LITERAL("* * Formal.Assessment (*).WinSAT.xml")); | |
74 | |
75 FilePath current_results; | |
76 for (FilePath results = file_enumerator.Next(); !results.empty(); | |
77 results = file_enumerator.Next()) { | |
78 // The filenames start with the date and time as yyyy-mm-dd hh.mm.ss.xxx, | |
79 // so the greatest file lexicographically is also the most recent file. | |
80 if (FilePath::CompareLessIgnoreCase(current_results.value(), | |
81 results.value())) | |
82 current_results = results; | |
83 } | |
84 | |
85 std::string current_results_string = current_results.MaybeAsASCII(); | |
86 if (current_results_string.empty()) { | |
87 LOG(ERROR) << "Can't retrieve a valid WinSAT assessment."; | |
64 return stats; | 88 return stats; |
65 } | 89 } |
66 | 90 |
67 base::win::ScopedComPtr<IProvideWinSATResultsInfo> results; | 91 // Get relevant scores from results file. XML schema at: |
68 hr = assessment->get_Info(results.Receive()); | 92 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa969210.aspx |
69 if (FAILED(hr)) { | 93 XmlReader reader; |
70 LOG(ERROR) << "get_Info() failed"; | 94 reader.LoadFile(current_results_string); |
71 return stats; | 95 reader.SkipToElement(); // Go to first XML tag. |
96 reader.Read(); // Descend into <WinSAT> root element. | |
97 // Search for <WinSPR> element containing the results. | |
98 do { | |
99 if (reader.NodeName() == "WinSPR") | |
100 break; | |
101 } while (reader.Next()); | |
102 reader.Read(); // Descend into <WinSPR> element. | |
vangelis
2012/05/03 20:45:37
You should probably check here that you did indeed
dtu
2012/05/15 21:59:58
Done.
| |
103 | |
104 // Read scores. | |
105 for (int depth = reader.Depth(); reader.Depth() == depth; reader.Next()) { | |
106 std::string node_name = reader.NodeName(); | |
107 if (node_name == "SystemScore") | |
108 stats.overall = ReadXMLFloatValue(&reader); | |
109 else if (node_name == "GraphicsScore") | |
110 stats.graphics = ReadXMLFloatValue(&reader); | |
111 else if (node_name == "GamingScore") | |
112 stats.gaming = ReadXMLFloatValue(&reader); | |
72 } | 113 } |
73 | 114 |
74 WINSAT_ASSESSMENT_STATE state = WINSAT_ASSESSMENT_STATE_UNKNOWN; | 115 if (stats.overall == 0.0) |
75 hr = results->get_AssessmentState(&state); | 116 LOG(ERROR) << "Could not read overall score from assessment results."; |
76 if (FAILED(hr)) { | 117 if (stats.graphics == 0.0) |
77 LOG(ERROR) << "get_AssessmentState() failed"; | 118 LOG(ERROR) << "Could not read graphics score from assessment results."; |
78 return stats; | |
79 } | |
80 | |
81 if (state != WINSAT_ASSESSMENT_STATE_VALID && | |
82 state != WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE) { | |
83 LOG(ERROR) << "Can't retrieve a valid assessment"; | |
84 return stats; | |
85 } | |
86 | |
87 hr = results->get_SystemRating(&stats.overall); | |
88 if (FAILED(hr)) | |
89 LOG(ERROR) << "Get overall score failed"; | |
90 | |
91 stats.gaming = GetAssessmentScore(results, WINSAT_ASSESSMENT_D3D); | |
92 if (stats.gaming == 0.0) | 119 if (stats.gaming == 0.0) |
93 LOG(ERROR) << "Get gaming score failed"; | 120 LOG(ERROR) << "Could not read gaming score from assessment results."; |
94 | |
95 stats.graphics = GetAssessmentScore(results, WINSAT_ASSESSMENT_GRAPHICS); | |
96 if (stats.graphics == 0.0) | |
97 LOG(ERROR) << "Get graphics score failed"; | |
98 | 121 |
99 return stats; | 122 return stats; |
100 } | 123 } |
101 | 124 |
102 } // namespace anonymous | 125 } // namespace anonymous |
103 | 126 |
104 namespace gpu_info_collector { | 127 namespace gpu_info_collector { |
105 | 128 |
106 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | 129 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
107 DCHECK(gpu_info); | 130 DCHECK(gpu_info); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 | 334 |
312 size_t pos = gl_version_string.find_last_not_of("0123456789."); | 335 size_t pos = gl_version_string.find_last_not_of("0123456789."); |
313 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { | 336 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { |
314 gpu_info->driver_version = gl_version_string.substr(pos + 1); | 337 gpu_info->driver_version = gl_version_string.substr(pos + 1); |
315 return true; | 338 return true; |
316 } | 339 } |
317 return false; | 340 return false; |
318 } | 341 } |
319 | 342 |
320 } // namespace gpu_info_collector | 343 } // namespace gpu_info_collector |
OLD | NEW |