| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (end == std::string::npos) | 157 if (end == std::string::npos) |
| 158 return line.substr(begin); | 158 return line.substr(begin); |
| 159 else | 159 else |
| 160 return line.substr(begin, end - begin); | 160 return line.substr(begin, end - begin); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 return ""; | 164 return ""; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Use glXGetClientString to get driver vendor. | |
| 168 // Return "" on failing. | |
| 169 std::string CollectDriverVendorGlx() { | |
| 170 // TODO(zmo): handle the EGL/GLES2 case. | |
| 171 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) | |
| 172 return ""; | |
| 173 Display* display = XOpenDisplay(NULL); | |
| 174 if (display == NULL) | |
| 175 return ""; | |
| 176 std::string vendor = glXGetClientString(display, GLX_VENDOR); | |
| 177 XCloseDisplay(display); | |
| 178 return vendor; | |
| 179 } | |
| 180 | |
| 181 // Return 0 on unrecognized vendor. | |
| 182 uint32 VendorStringToID(const std::string& vendor_string) { | |
| 183 if (StartsWithASCII(vendor_string, "NVIDIA", true)) | |
| 184 return 0x10de; | |
| 185 if (StartsWithASCII(vendor_string, "ATI", true)) | |
| 186 return 0x1002; | |
| 187 // TODO(zmo): find a way to identify Intel cards. | |
| 188 return 0; | |
| 189 } | |
| 190 | |
| 191 } // namespace anonymous | 167 } // namespace anonymous |
| 192 | 168 |
| 193 namespace gpu_info_collector { | 169 namespace gpu_info_collector { |
| 194 | 170 |
| 195 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | 171 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
| 196 DCHECK(gpu_info); | 172 DCHECK(gpu_info); |
| 197 | 173 |
| 198 if (CommandLine::ForCurrentProcess()->HasSwitch( | 174 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 199 switches::kGpuNoContextLost)) { | 175 switches::kGpuNoContextLost)) { |
| 200 gpu_info->can_lose_context = false; | 176 gpu_info->can_lose_context = false; |
| 201 } else { | 177 } else { |
| 202 // TODO(zmo): need to consider the case where we are running on top | 178 // TODO(zmo): need to consider the case where we are running on top |
| 203 // of desktop GL and GL_ARB_robustness extension is available. | 179 // of desktop GL and GL_ARB_robustness extension is available. |
| 204 gpu_info->can_lose_context = | 180 gpu_info->can_lose_context = |
| 205 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); | 181 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); |
| 206 } | 182 } |
| 207 | 183 |
| 208 gpu_info->finalized = true; | 184 gpu_info->finalized = true; |
| 209 return CollectGraphicsInfoGL(gpu_info); | 185 return CollectGraphicsInfoGL(gpu_info); |
| 210 } | 186 } |
| 211 | 187 |
| 212 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | 188 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
| 213 DCHECK(gpu_info); | 189 DCHECK(gpu_info); |
| 214 | 190 |
| 215 if (!gfx::GLSurface::InitializeOneOff()) { | |
| 216 LOG(ERROR) << "gfx::GLSurface::InitializeOneOff() failed"; | |
| 217 return false; | |
| 218 } | |
| 219 | |
| 220 bool rt = true; | 191 bool rt = true; |
| 221 if (!CollectVideoCardInfo(gpu_info)) | 192 if (!CollectVideoCardInfo(gpu_info)) |
| 222 rt = false; | 193 rt = false; |
| 223 | 194 |
| 224 if (gpu_info->vendor_id == 0x1002) { // ATI | 195 if (gpu_info->vendor_id == 0x1002) { // ATI |
| 225 std::string ati_driver_version = CollectDriverVersionATI(); | 196 std::string ati_driver_version = CollectDriverVersionATI(); |
| 226 if (ati_driver_version != "") { | 197 if (ati_driver_version != "") { |
| 227 gpu_info->driver_vendor = "ATI / AMD"; | 198 gpu_info->driver_vendor = "ATI / AMD"; |
| 228 gpu_info->driver_version = ati_driver_version; | 199 gpu_info->driver_version = ati_driver_version; |
| 229 } | 200 } |
| 230 } | 201 } |
| 231 | 202 |
| 232 return rt; | 203 return rt; |
| 233 } | 204 } |
| 234 | 205 |
| 235 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { | 206 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { |
| 236 DCHECK(gpu_info); | 207 DCHECK(gpu_info); |
| 237 | 208 |
| 238 std::string driver_vendor = CollectDriverVendorGlx(); | |
| 239 if (!driver_vendor.empty()) { | |
| 240 gpu_info->driver_vendor = driver_vendor; | |
| 241 uint32 vendor_id = VendorStringToID(driver_vendor); | |
| 242 if (vendor_id != 0) | |
| 243 gpu_info->vendor_id = vendor_id; | |
| 244 } | |
| 245 | |
| 246 if (IsPciSupported() == false) { | 209 if (IsPciSupported() == false) { |
| 247 VLOG(1) << "PCI bus scanning is not supported"; | 210 VLOG(1) << "PCI bus scanning is not supported"; |
| 248 return false; | 211 return false; |
| 249 } | 212 } |
| 250 | 213 |
| 251 // TODO(zmo): be more flexible about library name. | 214 // TODO(zmo): be more flexible about library name. |
| 252 PciInterface* interface = InitializeLibPci("libpci.so.3"); | 215 PciInterface* interface = InitializeLibPci("libpci.so.3"); |
| 253 if (interface == NULL) | 216 if (interface == NULL) |
| 254 interface = InitializeLibPci("libpci.so"); | 217 interface = InitializeLibPci("libpci.so"); |
| 255 if (interface == NULL) { | 218 if (interface == NULL) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return false; | 314 return false; |
| 352 if (pos != std::string::npos) | 315 if (pos != std::string::npos) |
| 353 driver_version = driver_version.substr(0, pos); | 316 driver_version = driver_version.substr(0, pos); |
| 354 | 317 |
| 355 gpu_info->driver_vendor = pieces[1]; | 318 gpu_info->driver_vendor = pieces[1]; |
| 356 gpu_info->driver_version = driver_version; | 319 gpu_info->driver_version = driver_version; |
| 357 return true; | 320 return true; |
| 358 } | 321 } |
| 359 | 322 |
| 360 } // namespace gpu_info_collector | 323 } // namespace gpu_info_collector |
| OLD | NEW |