| 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> |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/scoped_native_library.h" | 15 #include "base/scoped_native_library.h" |
| 15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 17 #include "ui/gfx/gl/gl_implementation.h" | 18 #include "ui/gfx/gl/gl_implementation.h" |
| 18 #include "ui/gfx/gl/gl_surface_egl.h" | 19 #include "ui/gfx/gl/gl_surface_egl.h" |
| 19 | 20 |
| 20 // ANGLE seems to require that main.h be included before any other ANGLE header. | 21 // ANGLE seems to require that main.h be included before any other ANGLE header. |
| 21 #include "libEGL/Display.h" | 22 #include "libEGL/Display.h" |
| 22 #include "libEGL/main.h" | 23 #include "libEGL/main.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // The version number stores the major and minor version in the least 16 bits; | 27 // The version number stores the major and minor version in the least 16 bits; |
| 27 // for example, 2.5 is 0x00000205. | 28 // for example, 2.5 is 0x00000205. |
| 28 // Returned string is in the format of "major.minor". | 29 // Returned string is in the format of "major.minor". |
| 29 std::string VersionNumberToString(uint32 version_number) { | 30 std::string VersionNumberToString(uint32 version_number) { |
| 30 int hi = (version_number >> 8) & 0xff; | 31 int hi = (version_number >> 8) & 0xff; |
| 31 int low = version_number & 0xff; | 32 int low = version_number & 0xff; |
| 32 return base::IntToString(hi) + "." + base::IntToString(low); | 33 return base::IntToString(hi) + "." + base::IntToString(low); |
| 33 } | 34 } |
| 34 | 35 |
| 36 float GetAssessmentScore(IProvideWinSATResultsInfo* results, |
| 37 WINSAT_ASSESSMENT_TYPE type) { |
| 38 IProvideWinSATAssessmentInfo* subcomponent = NULL; |
| 39 if (FAILED(results->GetAssessmentInfo(type, &subcomponent))) |
| 40 return 0.0; |
| 41 |
| 42 float score = 0.0; |
| 43 if (FAILED(subcomponent->get_Score(&score))) |
| 44 score = 0.0; |
| 45 subcomponent->Release(); |
| 46 return score; |
| 47 } |
| 48 |
| 49 content::GpuPerformanceStats RetrieveGpuPerformanceStats() { |
| 50 IQueryRecentWinSATAssessment* assessment = NULL; |
| 51 IProvideWinSATResultsInfo* results = NULL; |
| 52 |
| 53 content::GpuPerformanceStats stats; |
| 54 |
| 55 do { |
| 56 HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); |
| 57 if (FAILED(hr)) { |
| 58 LOG(ERROR) << "CoInitializeEx() failed"; |
| 59 break; |
| 60 } |
| 61 |
| 62 hr = CoCreateInstance(__uuidof(CQueryWinSAT), |
| 63 NULL, |
| 64 CLSCTX_INPROC_SERVER, |
| 65 __uuidof(IQueryRecentWinSATAssessment), |
| 66 reinterpret_cast<void**>(&assessment)); |
| 67 if (FAILED(hr)) { |
| 68 LOG(ERROR) << "CoCreateInstance() failed"; |
| 69 break; |
| 70 } |
| 71 |
| 72 hr = assessment->get_Info(&results); |
| 73 if (FAILED(hr)) { |
| 74 LOG(ERROR) << "get_Info() failed"; |
| 75 break; |
| 76 } |
| 77 |
| 78 WINSAT_ASSESSMENT_STATE state = WINSAT_ASSESSMENT_STATE_UNKNOWN; |
| 79 hr = results->get_AssessmentState(&state); |
| 80 if (FAILED(hr)) { |
| 81 LOG(ERROR) << "get_AssessmentState() failed"; |
| 82 break; |
| 83 } |
| 84 if (state != WINSAT_ASSESSMENT_STATE_VALID && |
| 85 state != WINSAT_ASSESSMENT_STATE_INCOHERENT_WITH_HARDWARE) { |
| 86 LOG(ERROR) << "Can't retrieve a valid assessment"; |
| 87 break; |
| 88 } |
| 89 |
| 90 hr = results->get_SystemRating(&stats.overall); |
| 91 if (FAILED(hr)) |
| 92 LOG(ERROR) << "Get overall score failed"; |
| 93 |
| 94 stats.gaming = GetAssessmentScore(results, WINSAT_ASSESSMENT_D3D); |
| 95 if (stats.gaming == 0.0) |
| 96 LOG(ERROR) << "Get gaming score failed"; |
| 97 |
| 98 stats.graphics = GetAssessmentScore(results, WINSAT_ASSESSMENT_GRAPHICS); |
| 99 if (stats.graphics == 0.0) |
| 100 LOG(ERROR) << "Get graphics score failed"; |
| 101 } while (false); |
| 102 |
| 103 if (assessment) |
| 104 assessment->Release(); |
| 105 if (results) |
| 106 results->Release(); |
| 107 CoUninitialize(); |
| 108 |
| 109 return stats; |
| 110 } |
| 111 |
| 35 } // namespace anonymous | 112 } // namespace anonymous |
| 36 | 113 |
| 37 // Setup API functions | 114 // Setup API functions |
| 38 typedef HDEVINFO (WINAPI*SetupDiGetClassDevsWFunc)( | 115 typedef HDEVINFO (WINAPI*SetupDiGetClassDevsWFunc)( |
| 39 CONST GUID *ClassGuid, | 116 CONST GUID *ClassGuid, |
| 40 PCWSTR Enumerator, | 117 PCWSTR Enumerator, |
| 41 HWND hwndParent, | 118 HWND hwndParent, |
| 42 DWORD Flags | 119 DWORD Flags |
| 43 ); | 120 ); |
| 44 typedef BOOL (WINAPI*SetupDiEnumDeviceInfoFunc)( | 121 typedef BOOL (WINAPI*SetupDiEnumDeviceInfoFunc)( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 57 ); | 134 ); |
| 58 typedef BOOL (WINAPI*SetupDiDestroyDeviceInfoListFunc)( | 135 typedef BOOL (WINAPI*SetupDiDestroyDeviceInfoListFunc)( |
| 59 HDEVINFO DeviceInfoSet | 136 HDEVINFO DeviceInfoSet |
| 60 ); | 137 ); |
| 61 | 138 |
| 62 namespace gpu_info_collector { | 139 namespace gpu_info_collector { |
| 63 | 140 |
| 64 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | 141 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
| 65 DCHECK(gpu_info); | 142 DCHECK(gpu_info); |
| 66 | 143 |
| 144 gpu_info->performance_stats = RetrieveGpuPerformanceStats(); |
| 145 |
| 67 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { | 146 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { |
| 68 std::string requested_implementation_name = | 147 std::string requested_implementation_name = |
| 69 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); | 148 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); |
| 70 if (requested_implementation_name == "swiftshader") | 149 if (requested_implementation_name == "swiftshader") |
| 71 return false; | 150 return false; |
| 72 } | 151 } |
| 73 | 152 |
| 74 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 153 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 75 gpu_info->finalized = true; | 154 gpu_info->finalized = true; |
| 76 return CollectGraphicsInfoGL(gpu_info); | 155 return CollectGraphicsInfoGL(gpu_info); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 return true; | 185 return true; |
| 107 } | 186 } |
| 108 | 187 |
| 109 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | 188 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
| 110 DCHECK(gpu_info); | 189 DCHECK(gpu_info); |
| 111 | 190 |
| 112 bool rt = true; | 191 bool rt = true; |
| 113 if (!CollectVideoCardInfo(gpu_info)) | 192 if (!CollectVideoCardInfo(gpu_info)) |
| 114 rt = false; | 193 rt = false; |
| 115 | 194 |
| 195 gpu_info->performance_stats = RetrieveGpuPerformanceStats(); |
| 196 |
| 116 return rt; | 197 return rt; |
| 117 } | 198 } |
| 118 | 199 |
| 119 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, content::GPUInfo* gpu_info) { | 200 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, content::GPUInfo* gpu_info) { |
| 120 DCHECK(d3d); | 201 DCHECK(d3d); |
| 121 DCHECK(gpu_info); | 202 DCHECK(gpu_info); |
| 122 | 203 |
| 123 bool succeed = CollectVideoCardInfo(gpu_info); | 204 bool succeed = CollectVideoCardInfo(gpu_info); |
| 124 | 205 |
| 125 // Get version information | 206 // Get version information |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 359 |
| 279 size_t pos = gl_version_string.find_last_not_of("0123456789."); | 360 size_t pos = gl_version_string.find_last_not_of("0123456789."); |
| 280 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { | 361 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { |
| 281 gpu_info->driver_version = gl_version_string.substr(pos + 1); | 362 gpu_info->driver_version = gl_version_string.substr(pos + 1); |
| 282 return true; | 363 return true; |
| 283 } | 364 } |
| 284 return false; | 365 return false; |
| 285 } | 366 } |
| 286 | 367 |
| 287 } // namespace gpu_info_collector | 368 } // namespace gpu_info_collector |
| OLD | NEW |