| 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 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/scoped_native_library.h" | 17 #include "base/scoped_native_library.h" |
| 17 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "base/win/scoped_com_initializer.h" | 20 #include "base/win/scoped_com_initializer.h" |
| 20 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
| 21 #include "third_party/libxml/chromium/libxml_utils.h" | 22 #include "third_party/libxml/chromium/libxml_utils.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 43 return 0.0; | 44 return 0.0; |
| 44 | 45 |
| 45 double score; | 46 double score; |
| 46 if (!base::StringToDouble(score_string, &score)) | 47 if (!base::StringToDouble(score_string, &score)) |
| 47 return 0.0; | 48 return 0.0; |
| 48 | 49 |
| 49 return static_cast<float>(score); | 50 return static_cast<float>(score); |
| 50 } | 51 } |
| 51 | 52 |
| 52 content::GpuPerformanceStats RetrieveGpuPerformanceStats() { | 53 content::GpuPerformanceStats RetrieveGpuPerformanceStats() { |
| 54 TRACE_EVENT0("gpu", "RetrieveGpuPerformanceStats"); |
| 55 |
| 53 // If the user re-runs the assessment without restarting, the COM API | 56 // If the user re-runs the assessment without restarting, the COM API |
| 54 // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. Because of that and | 57 // returns WINSAT_ASSESSMENT_STATE_NOT_AVAILABLE. Because of that and |
| 55 // http://crbug.com/124325, read the assessment result files directly. | 58 // http://crbug.com/124325, read the assessment result files directly. |
| 56 content::GpuPerformanceStats stats; | 59 content::GpuPerformanceStats stats; |
| 57 | 60 |
| 58 base::TimeTicks start_time = base::TimeTicks::Now(); | 61 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 59 | 62 |
| 60 // Get path to WinSAT results files. | 63 // Get path to WinSAT results files. |
| 61 wchar_t winsat_results_path[MAX_PATH]; | 64 wchar_t winsat_results_path[MAX_PATH]; |
| 62 DWORD size = ExpandEnvironmentStrings( | 65 DWORD size = ExpandEnvironmentStrings( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 base::TimeTicks::Now() - start_time); | 147 base::TimeTicks::Now() - start_time); |
| 145 | 148 |
| 146 return stats; | 149 return stats; |
| 147 } | 150 } |
| 148 | 151 |
| 149 } // namespace anonymous | 152 } // namespace anonymous |
| 150 | 153 |
| 151 namespace gpu_info_collector { | 154 namespace gpu_info_collector { |
| 152 | 155 |
| 153 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | 156 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
| 157 TRACE_EVENT0("gpu", "CollectGraphicsInfo"); |
| 158 |
| 154 DCHECK(gpu_info); | 159 DCHECK(gpu_info); |
| 155 | 160 |
| 156 content::GpuPerformanceStats stats = RetrieveGpuPerformanceStats(); | 161 content::GpuPerformanceStats stats = RetrieveGpuPerformanceStats(); |
| 157 UMA_HISTOGRAM_BOOLEAN( | 162 UMA_HISTOGRAM_BOOLEAN( |
| 158 "GPU.WinSAT.HasResults", | 163 "GPU.WinSAT.HasResults", |
| 159 stats.overall != 0.0 && stats.graphics != 0.0 && stats.gaming != 0.0); | 164 stats.overall != 0.0 && stats.graphics != 0.0 && stats.gaming != 0.0); |
| 160 gpu_info->performance_stats = stats; | 165 gpu_info->performance_stats = stats; |
| 161 | 166 |
| 162 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { | 167 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { |
| 163 std::string requested_implementation_name = | 168 std::string requested_implementation_name = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 202 |
| 198 if (!CollectGraphicsInfoD3D(d3d, gpu_info)) | 203 if (!CollectGraphicsInfoD3D(d3d, gpu_info)) |
| 199 return false; | 204 return false; |
| 200 | 205 |
| 201 // DirectX diagnostics are collected asynchronously because it takes a | 206 // DirectX diagnostics are collected asynchronously because it takes a |
| 202 // couple of seconds. Do not mark gpu_info as complete until that is done. | 207 // couple of seconds. Do not mark gpu_info as complete until that is done. |
| 203 return true; | 208 return true; |
| 204 } | 209 } |
| 205 | 210 |
| 206 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | 211 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
| 212 TRACE_EVENT0("gpu", "CollectPreliminaryGraphicsInfo"); |
| 213 |
| 207 DCHECK(gpu_info); | 214 DCHECK(gpu_info); |
| 208 | 215 |
| 209 bool rt = true; | 216 bool rt = true; |
| 210 if (!CollectVideoCardInfo(gpu_info)) | 217 if (!CollectVideoCardInfo(gpu_info)) |
| 211 rt = false; | 218 rt = false; |
| 212 | 219 |
| 213 gpu_info->performance_stats = RetrieveGpuPerformanceStats(); | 220 gpu_info->performance_stats = RetrieveGpuPerformanceStats(); |
| 214 | 221 |
| 215 return rt; | 222 return rt; |
| 216 } | 223 } |
| 217 | 224 |
| 218 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, content::GPUInfo* gpu_info) { | 225 bool CollectGraphicsInfoD3D(IDirect3D9* d3d, content::GPUInfo* gpu_info) { |
| 226 TRACE_EVENT0("gpu", "CollectGraphicsInfoD3D"); |
| 227 |
| 219 DCHECK(d3d); | 228 DCHECK(d3d); |
| 220 DCHECK(gpu_info); | 229 DCHECK(gpu_info); |
| 221 | 230 |
| 222 bool succeed = CollectVideoCardInfo(gpu_info); | 231 bool succeed = CollectVideoCardInfo(gpu_info); |
| 223 | 232 |
| 224 // Get version information | 233 // Get version information |
| 225 D3DCAPS9 d3d_caps; | 234 D3DCAPS9 d3d_caps; |
| 226 if (d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, | 235 if (d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, |
| 227 D3DDEVTYPE_HAL, | 236 D3DDEVTYPE_HAL, |
| 228 &d3d_caps) == D3D_OK) { | 237 &d3d_caps) == D3D_OK) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 239 base::win::ScopedComPtr<IDirect3D9Ex> d3dex; | 248 base::win::ScopedComPtr<IDirect3D9Ex> d3dex; |
| 240 if (SUCCEEDED(d3dex.QueryFrom(d3d))) | 249 if (SUCCEEDED(d3dex.QueryFrom(d3d))) |
| 241 gpu_info->can_lose_context = false; | 250 gpu_info->can_lose_context = false; |
| 242 else | 251 else |
| 243 gpu_info->can_lose_context = true; | 252 gpu_info->can_lose_context = true; |
| 244 | 253 |
| 245 return true; | 254 return true; |
| 246 } | 255 } |
| 247 | 256 |
| 248 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { | 257 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { |
| 258 TRACE_EVENT0("gpu", "CollectVideoCardInfo"); |
| 259 |
| 249 DCHECK(gpu_info); | 260 DCHECK(gpu_info); |
| 250 | 261 |
| 251 // nvd3d9wrap.dll is loaded into all processes when Optimus is enabled. | 262 // nvd3d9wrap.dll is loaded into all processes when Optimus is enabled. |
| 252 HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll"); | 263 HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll"); |
| 253 gpu_info->optimus = nvd3d9wrap != NULL; | 264 gpu_info->optimus = nvd3d9wrap != NULL; |
| 254 | 265 |
| 255 // Taken from http://developer.nvidia.com/object/device_ids.html | 266 // Taken from http://developer.nvidia.com/object/device_ids.html |
| 256 DISPLAY_DEVICE dd; | 267 DISPLAY_DEVICE dd; |
| 257 dd.cb = sizeof(DISPLAY_DEVICE); | 268 dd.cb = sizeof(DISPLAY_DEVICE); |
| 258 int i = 0; | 269 int i = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 273 gpu_info->gpu.vendor_id = vendor_id; | 284 gpu_info->gpu.vendor_id = vendor_id; |
| 274 gpu_info->gpu.device_id = device_id; | 285 gpu_info->gpu.device_id = device_id; |
| 275 // TODO(zmo): we only need to call CollectDriverInfoD3D() if we use ANGLE. | 286 // TODO(zmo): we only need to call CollectDriverInfoD3D() if we use ANGLE. |
| 276 return CollectDriverInfoD3D(id, gpu_info); | 287 return CollectDriverInfoD3D(id, gpu_info); |
| 277 } | 288 } |
| 278 return false; | 289 return false; |
| 279 } | 290 } |
| 280 | 291 |
| 281 bool CollectDriverInfoD3D(const std::wstring& device_id, | 292 bool CollectDriverInfoD3D(const std::wstring& device_id, |
| 282 content::GPUInfo* gpu_info) { | 293 content::GPUInfo* gpu_info) { |
| 294 TRACE_EVENT0("gpu", "CollectDriverInfoD3D"); |
| 295 |
| 283 // create device info for the display device | 296 // create device info for the display device |
| 284 HDEVINFO device_info = SetupDiGetClassDevsW( | 297 HDEVINFO device_info = SetupDiGetClassDevsW( |
| 285 NULL, device_id.c_str(), NULL, | 298 NULL, device_id.c_str(), NULL, |
| 286 DIGCF_PRESENT | DIGCF_PROFILE | DIGCF_ALLCLASSES); | 299 DIGCF_PRESENT | DIGCF_PROFILE | DIGCF_ALLCLASSES); |
| 287 if (device_info == INVALID_HANDLE_VALUE) { | 300 if (device_info == INVALID_HANDLE_VALUE) { |
| 288 LOG(ERROR) << "Creating device info failed"; | 301 LOG(ERROR) << "Creating device info failed"; |
| 289 return false; | 302 return false; |
| 290 } | 303 } |
| 291 | 304 |
| 292 DWORD index = 0; | 305 DWORD index = 0; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 RegCloseKey(key); | 359 RegCloseKey(key); |
| 347 break; | 360 break; |
| 348 } | 361 } |
| 349 } | 362 } |
| 350 } | 363 } |
| 351 SetupDiDestroyDeviceInfoList(device_info); | 364 SetupDiDestroyDeviceInfoList(device_info); |
| 352 return found; | 365 return found; |
| 353 } | 366 } |
| 354 | 367 |
| 355 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { | 368 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { |
| 369 TRACE_EVENT0("gpu", "CollectDriverInfoGL"); |
| 370 |
| 356 DCHECK(gpu_info); | 371 DCHECK(gpu_info); |
| 357 | 372 |
| 358 std::string gl_version_string = gpu_info->gl_version_string; | 373 std::string gl_version_string = gpu_info->gl_version_string; |
| 359 | 374 |
| 360 // TODO(zmo): We assume the driver version is in the end of GL_VERSION | 375 // TODO(zmo): We assume the driver version is in the end of GL_VERSION |
| 361 // string. Need to verify if it is true for majority drivers. | 376 // string. Need to verify if it is true for majority drivers. |
| 362 | 377 |
| 363 size_t pos = gl_version_string.find_last_not_of("0123456789."); | 378 size_t pos = gl_version_string.find_last_not_of("0123456789."); |
| 364 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { | 379 if (pos != std::string::npos && pos < gl_version_string.length() - 1) { |
| 365 gpu_info->driver_version = gl_version_string.substr(pos + 1); | 380 gpu_info->driver_version = gl_version_string.substr(pos + 1); |
| 366 return true; | 381 return true; |
| 367 } | 382 } |
| 368 return false; | 383 return false; |
| 369 } | 384 } |
| 370 | 385 |
| 371 } // namespace gpu_info_collector | 386 } // namespace gpu_info_collector |
| OLD | NEW |