| 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 "gpu/config/gpu_info_collector.h" | 5 #include "gpu/config/gpu_info_collector.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // Use NVCtrl extention to query NV driver version. | 70 // Use NVCtrl extention to query NV driver version. |
| 71 // Return empty string on failing. | 71 // Return empty string on failing. |
| 72 std::string CollectDriverVersionNVidia() { | 72 std::string CollectDriverVersionNVidia() { |
| 73 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); | 73 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); |
| 74 if (!display) { | 74 if (!display) { |
| 75 LOG(ERROR) << "XOpenDisplay failed."; | 75 LOG(ERROR) << "XOpenDisplay failed."; |
| 76 return std::string(); | 76 return std::string(); |
| 77 } | 77 } |
| 78 int event_base = 0, error_base = 0; | 78 int event_base = 0, error_base = 0; |
| 79 if (!XNVCTRLQueryExtension(display, &event_base, &error_base)) { | 79 if (!XNVCTRLQueryExtension(display, &event_base, &error_base)) { |
| 80 LOG(INFO) << "NVCtrl extension does not exist."; | 80 VLOG(1) << "NVCtrl extension does not exist."; |
| 81 return std::string(); | 81 return std::string(); |
| 82 } | 82 } |
| 83 int screen_count = ScreenCount(display); | 83 int screen_count = ScreenCount(display); |
| 84 for (int screen = 0; screen < screen_count; ++screen) { | 84 for (int screen = 0; screen < screen_count; ++screen) { |
| 85 char* buffer = NULL; | 85 char* buffer = NULL; |
| 86 if (XNVCTRLIsNvScreen(display, screen) && | 86 if (XNVCTRLIsNvScreen(display, screen) && |
| 87 XNVCTRLQueryStringAttribute(display, screen, 0, | 87 XNVCTRLQueryStringAttribute(display, screen, 0, |
| 88 NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, | 88 NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, |
| 89 &buffer)) { | 89 &buffer)) { |
| 90 std::string driver_version(buffer); | 90 std::string driver_version(buffer); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (gpu_info->gpu.vendor_id == kVendorIDAMD) | 157 if (gpu_info->gpu.vendor_id == kVendorIDAMD) |
| 158 gpu_info->amd_switchable = true; | 158 gpu_info->amd_switchable = true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 (libpci_loader.pci_cleanup)(access); | 161 (libpci_loader.pci_cleanup)(access); |
| 162 return (primary_gpu_identified); | 162 return (primary_gpu_identified); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace anonymous | 165 } // namespace anonymous |
| 166 | 166 |
| 167 bool CollectContextGraphicsInfo(GPUInfo* gpu_info) { | 167 CollectInfoResult CollectContextGraphicsInfo(GPUInfo* gpu_info) { |
| 168 DCHECK(gpu_info); | 168 DCHECK(gpu_info); |
| 169 | 169 |
| 170 TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo"); | 170 TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo"); |
| 171 | 171 |
| 172 if (CommandLine::ForCurrentProcess()->HasSwitch( | 172 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 173 switches::kGpuNoContextLost)) { | 173 switches::kGpuNoContextLost)) { |
| 174 gpu_info->can_lose_context = false; | 174 gpu_info->can_lose_context = false; |
| 175 } else { | 175 } else { |
| 176 #if defined(OS_CHROMEOS) | 176 #if defined(OS_CHROMEOS) |
| 177 gpu_info->can_lose_context = false; | 177 gpu_info->can_lose_context = false; |
| 178 #else | 178 #else |
| 179 // TODO(zmo): need to consider the case where we are running on top | 179 // TODO(zmo): need to consider the case where we are running on top |
| 180 // of desktop GL and GL_ARB_robustness extension is available. | 180 // of desktop GL and GL_ARB_robustness extension is available. |
| 181 gpu_info->can_lose_context = | 181 gpu_info->can_lose_context = |
| 182 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); | 182 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); |
| 183 #endif | 183 #endif |
| 184 } | 184 } |
| 185 | 185 |
| 186 CollectInfoResult result = CollectGraphicsInfoGL(gpu_info); |
| 186 gpu_info->finalized = true; | 187 gpu_info->finalized = true; |
| 187 bool rt = CollectGraphicsInfoGL(gpu_info); | 188 return result; |
| 188 | |
| 189 return rt; | |
| 190 } | 189 } |
| 191 | 190 |
| 192 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { | 191 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { |
| 193 DCHECK(vendor_id && device_id); | 192 DCHECK(vendor_id && device_id); |
| 194 *vendor_id = 0; | 193 *vendor_id = 0; |
| 195 *device_id = 0; | 194 *device_id = 0; |
| 196 | 195 |
| 197 GPUInfo gpu_info; | 196 GPUInfo gpu_info; |
| 198 if (CollectPCIVideoCardInfo(&gpu_info)) { | 197 if (CollectPCIVideoCardInfo(&gpu_info)) { |
| 199 *vendor_id = gpu_info.gpu.vendor_id; | 198 *vendor_id = gpu_info.gpu.vendor_id; |
| 200 *device_id = gpu_info.gpu.device_id; | 199 *device_id = gpu_info.gpu.device_id; |
| 201 return kGpuIDSuccess; | 200 return kGpuIDSuccess; |
| 202 } | 201 } |
| 203 return kGpuIDFailure; | 202 return kGpuIDFailure; |
| 204 } | 203 } |
| 205 | 204 |
| 206 bool CollectBasicGraphicsInfo(GPUInfo* gpu_info) { | 205 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) { |
| 207 DCHECK(gpu_info); | 206 DCHECK(gpu_info); |
| 208 | 207 |
| 209 bool rt = CollectPCIVideoCardInfo(gpu_info); | 208 bool rt = CollectPCIVideoCardInfo(gpu_info); |
| 210 | 209 |
| 211 std::string driver_version; | 210 std::string driver_version; |
| 212 switch (gpu_info->gpu.vendor_id) { | 211 switch (gpu_info->gpu.vendor_id) { |
| 213 case kVendorIDAMD: | 212 case kVendorIDAMD: |
| 214 driver_version = CollectDriverVersionATI(); | 213 driver_version = CollectDriverVersionATI(); |
| 215 if (!driver_version.empty()) { | 214 if (!driver_version.empty()) { |
| 216 gpu_info->driver_vendor = "ATI / AMD"; | 215 gpu_info->driver_vendor = "ATI / AMD"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 231 if (!driver_version.empty()) { | 230 if (!driver_version.empty()) { |
| 232 gpu_info->driver_vendor = "NVIDIA"; | 231 gpu_info->driver_vendor = "NVIDIA"; |
| 233 gpu_info->driver_version = driver_version; | 232 gpu_info->driver_version = driver_version; |
| 234 // Machines with more than two GPUs are not handled. | 233 // Machines with more than two GPUs are not handled. |
| 235 if (gpu_info->secondary_gpus.size() <= 1) | 234 if (gpu_info->secondary_gpus.size() <= 1) |
| 236 gpu_info->optimus = true; | 235 gpu_info->optimus = true; |
| 237 } | 236 } |
| 238 break; | 237 break; |
| 239 } | 238 } |
| 240 | 239 |
| 241 return rt; | 240 return rt ? kCollectInfoSuccess : kCollectInfoNonFatalFailure; |
| 242 } | 241 } |
| 243 | 242 |
| 244 bool CollectDriverInfoGL(GPUInfo* gpu_info) { | 243 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) { |
| 245 DCHECK(gpu_info); | 244 DCHECK(gpu_info); |
| 246 | 245 |
| 247 std::string gl_version_string = gpu_info->gl_version_string; | 246 std::string gl_version_string = gpu_info->gl_version_string; |
| 248 if (StartsWithASCII(gl_version_string, "OpenGL ES", true)) | 247 if (StartsWithASCII(gl_version_string, "OpenGL ES", true)) |
| 249 gl_version_string = gl_version_string.substr(10); | 248 gl_version_string = gl_version_string.substr(10); |
| 250 std::vector<std::string> pieces; | 249 std::vector<std::string> pieces; |
| 251 base::SplitStringAlongWhitespace(gl_version_string, &pieces); | 250 base::SplitStringAlongWhitespace(gl_version_string, &pieces); |
| 252 // In linux, the gl version string might be in the format of | 251 // In linux, the gl version string might be in the format of |
| 253 // GLVersion DriverVendor DriverVersion | 252 // GLVersion DriverVendor DriverVersion |
| 254 if (pieces.size() < 3) | 253 if (pieces.size() < 3) |
| 255 return false; | 254 return kCollectInfoNonFatalFailure; |
| 256 | 255 |
| 257 std::string driver_version = pieces[2]; | 256 std::string driver_version = pieces[2]; |
| 258 size_t pos = driver_version.find_first_not_of("0123456789."); | 257 size_t pos = driver_version.find_first_not_of("0123456789."); |
| 259 if (pos == 0) | 258 if (pos == 0) |
| 260 return false; | 259 return kCollectInfoNonFatalFailure; |
| 261 if (pos != std::string::npos) | 260 if (pos != std::string::npos) |
| 262 driver_version = driver_version.substr(0, pos); | 261 driver_version = driver_version.substr(0, pos); |
| 263 | 262 |
| 264 gpu_info->driver_vendor = pieces[1]; | 263 gpu_info->driver_vendor = pieces[1]; |
| 265 gpu_info->driver_version = driver_version; | 264 gpu_info->driver_version = driver_version; |
| 266 return true; | 265 return kCollectInfoSuccess; |
| 267 } | 266 } |
| 268 | 267 |
| 269 void MergeGPUInfo(GPUInfo* basic_gpu_info, | 268 void MergeGPUInfo(GPUInfo* basic_gpu_info, |
| 270 const GPUInfo& context_gpu_info) { | 269 const GPUInfo& context_gpu_info) { |
| 271 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); | 270 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); |
| 272 } | 271 } |
| 273 | 272 |
| 274 } // namespace gpu | 273 } // namespace gpu |
| OLD | NEW |