| 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" |
| 14 #include "base/logging.h" | 13 #include "base/logging.h" |
| 15 #include "base/scoped_native_library.h" | 14 #include "base/scoped_native_library.h" |
| 16 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 17 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 18 #include "ui/gfx/gl/gl_implementation.h" | 17 #include "ui/gfx/gl/gl_implementation.h" |
| 19 #include "ui/gfx/gl/gl_surface_egl.h" | 18 #include "ui/gfx/gl/gl_surface_egl.h" |
| 20 | 19 |
| 21 // ANGLE seems to require that main.h be included before any other ANGLE header. | 20 // ANGLE seems to require that main.h be included before any other ANGLE header. |
| 22 #include "libEGL/Display.h" | 21 #include "libEGL/Display.h" |
| 23 #include "libEGL/main.h" | 22 #include "libEGL/main.h" |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 // The version number stores the major and minor version in the least 16 bits; | 26 // The version number stores the major and minor version in the least 16 bits; |
| 28 // for example, 2.5 is 0x00000205. | 27 // for example, 2.5 is 0x00000205. |
| 29 // Returned string is in the format of "major.minor". | 28 // Returned string is in the format of "major.minor". |
| 30 std::string VersionNumberToString(uint32 version_number) { | 29 std::string VersionNumberToString(uint32 version_number) { |
| 31 int hi = (version_number >> 8) & 0xff; | 30 int hi = (version_number >> 8) & 0xff; |
| 32 int low = version_number & 0xff; | 31 int low = version_number & 0xff; |
| 33 return base::IntToString(hi) + "." + base::IntToString(low); | 32 return base::IntToString(hi) + "." + base::IntToString(low); |
| 34 } | 33 } |
| 35 | 34 |
| 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 | |
| 112 } // namespace anonymous | 35 } // namespace anonymous |
| 113 | 36 |
| 114 // Setup API functions | 37 // Setup API functions |
| 115 typedef HDEVINFO (WINAPI*SetupDiGetClassDevsWFunc)( | 38 typedef HDEVINFO (WINAPI*SetupDiGetClassDevsWFunc)( |
| 116 CONST GUID *ClassGuid, | 39 CONST GUID *ClassGuid, |
| 117 PCWSTR Enumerator, | 40 PCWSTR Enumerator, |
| 118 HWND hwndParent, | 41 HWND hwndParent, |
| 119 DWORD Flags | 42 DWORD Flags |
| 120 ); | 43 ); |
| 121 typedef BOOL (WINAPI*SetupDiEnumDeviceInfoFunc)( | 44 typedef BOOL (WINAPI*SetupDiEnumDeviceInfoFunc)( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 ); | 57 ); |
| 135 typedef BOOL (WINAPI*SetupDiDestroyDeviceInfoListFunc)( | 58 typedef BOOL (WINAPI*SetupDiDestroyDeviceInfoListFunc)( |
| 136 HDEVINFO DeviceInfoSet | 59 HDEVINFO DeviceInfoSet |
| 137 ); | 60 ); |
| 138 | 61 |
| 139 namespace gpu_info_collector { | 62 namespace gpu_info_collector { |
| 140 | 63 |
| 141 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | 64 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
| 142 DCHECK(gpu_info); | 65 DCHECK(gpu_info); |
| 143 | 66 |
| 144 gpu_info->performance_stats = RetrieveGpuPerformanceStats(); | |
| 145 | |
| 146 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { | 67 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { |
| 147 std::string requested_implementation_name = | 68 std::string requested_implementation_name = |
| 148 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); | 69 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); |
| 149 if (requested_implementation_name == "swiftshader") | 70 if (requested_implementation_name == "swiftshader") |
| 150 return false; | 71 return false; |
| 151 } | 72 } |
| 152 | 73 |
| 153 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { | 74 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 154 gpu_info->finalized = true; | 75 gpu_info->finalized = true; |
| 155 return CollectGraphicsInfoGL(gpu_info); | 76 return CollectGraphicsInfoGL(gpu_info); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 185 return true; | 106 return true; |
| 186 } | 107 } |
| 187 | 108 |
| 188 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | 109 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
| 189 DCHECK(gpu_info); | 110 DCHECK(gpu_info); |
| 190 | 111 |
| 191 bool rt = true; | 112 bool rt = true; |
| 192 if (!CollectVideoCardInfo(gpu_info)) | 113 if (!CollectVideoCardInfo(gpu_info)) |
| 193 rt = false; | 114 rt = false; |
| 194 | 115 |
| 195 gpu_info->performance_stats = RetrieveGpuPerformanceStats(); | |
| 196 | |
| 197 return rt; | 116 return rt; |
| 198 } | 117 } |
| 199 | 118 |
| 200 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, content::GPUInfo* gpu_info) { | 119 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, content::GPUInfo* gpu_info) { |
| 201 DCHECK(d3d); | 120 DCHECK(d3d); |
| 202 DCHECK(gpu_info); | 121 DCHECK(gpu_info); |
| 203 | 122 |
| 204 bool succeed = CollectVideoCardInfo(gpu_info); | 123 bool succeed = CollectVideoCardInfo(gpu_info); |
| 205 | 124 |
| 206 // Get version information | 125 // Get version information |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 278 |
| 360 size_t pos = gl_version_string.find_last_not_of("0123456789."); | 279 size_t pos = gl_version_string.find_last_not_of("0123456789."); |
| 361 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { | 280 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { |
| 362 gpu_info->driver_version = gl_version_string.substr(pos + 1); | 281 gpu_info->driver_version = gl_version_string.substr(pos + 1); |
| 363 return true; | 282 return true; |
| 364 } | 283 } |
| 365 return false; | 284 return false; |
| 366 } | 285 } |
| 367 | 286 |
| 368 } // namespace gpu_info_collector | 287 } // namespace gpu_info_collector |
| OLD | NEW |