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 <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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return driver_version; | 90 return driver_version; |
91 } | 91 } |
92 } | 92 } |
93 return std::string(); | 93 return std::string(); |
94 } | 94 } |
95 | 95 |
96 const uint32 kVendorIDIntel = 0x8086; | 96 const uint32 kVendorIDIntel = 0x8086; |
97 const uint32 kVendorIDNVidia = 0x10de; | 97 const uint32 kVendorIDNVidia = 0x10de; |
98 const uint32 kVendorIDAMD = 0x1002; | 98 const uint32 kVendorIDAMD = 0x1002; |
99 | 99 |
100 } // namespace anonymous | 100 bool CollectPCIVideoCardInfo(content::GPUInfo* gpu_info) { |
101 | |
102 namespace gpu_info_collector { | |
103 | |
104 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | |
105 DCHECK(gpu_info); | |
106 *gpu_info = content::GPUInfo(); | |
107 | |
108 TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo"); | |
109 | |
110 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
111 switches::kGpuNoContextLost)) { | |
112 gpu_info->can_lose_context = false; | |
113 } else { | |
114 #if defined(OS_CHROMEOS) | |
115 gpu_info->can_lose_context = false; | |
116 #else | |
117 // TODO(zmo): need to consider the case where we are running on top | |
118 // of desktop GL and GL_ARB_robustness extension is available. | |
119 gpu_info->can_lose_context = | |
120 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); | |
121 #endif | |
122 } | |
123 | |
124 gpu_info->finalized = true; | |
125 bool rt = CollectGraphicsInfoGL(gpu_info); | |
126 | |
127 return rt; | |
128 } | |
129 | |
130 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | |
131 DCHECK(gpu_info); | |
132 | |
133 bool rt = CollectVideoCardInfo(gpu_info); | |
134 | |
135 std::string driver_version; | |
136 switch (gpu_info->gpu.vendor_id) { | |
137 case kVendorIDAMD: | |
138 driver_version = CollectDriverVersionATI(); | |
139 if (!driver_version.empty()) { | |
140 gpu_info->driver_vendor = "ATI / AMD"; | |
141 gpu_info->driver_version = driver_version; | |
142 } | |
143 break; | |
144 case kVendorIDNVidia: | |
145 driver_version = CollectDriverVersionNVidia(); | |
146 if (!driver_version.empty()) { | |
147 gpu_info->driver_vendor = "NVIDIA"; | |
148 gpu_info->driver_version = driver_version; | |
149 } | |
150 break; | |
151 case kVendorIDIntel: | |
152 // In dual-GPU cases, sometimes PCI scan only gives us the | |
153 // integrated GPU (i.e., the Intel one). | |
154 driver_version = CollectDriverVersionNVidia(); | |
155 if (!driver_version.empty()) { | |
156 gpu_info->driver_vendor = "NVIDIA"; | |
157 gpu_info->driver_version = driver_version; | |
158 // Machines with more than two GPUs are not handled. | |
159 if (gpu_info->secondary_gpus.size() <= 1) | |
160 gpu_info->optimus = true; | |
161 } | |
162 break; | |
163 } | |
164 | |
165 return rt; | |
166 } | |
167 | |
168 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { | |
169 DCHECK(gpu_info); | 101 DCHECK(gpu_info); |
170 | 102 |
171 if (IsPciSupported() == false) { | 103 if (IsPciSupported() == false) { |
172 VLOG(1) << "PCI bus scanning is not supported"; | 104 VLOG(1) << "PCI bus scanning is not supported"; |
173 return false; | 105 return false; |
174 } | 106 } |
175 | 107 |
176 // TODO(zmo): be more flexible about library name. | 108 // TODO(zmo): be more flexible about library name. |
177 LibPciLoader libpci_loader; | 109 LibPciLoader libpci_loader; |
178 if (!libpci_loader.Load("libpci.so.3") && | 110 if (!libpci_loader.Load("libpci.so.3") && |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (gpu_info->gpu.vendor_id == kVendorIDNVidia) | 181 if (gpu_info->gpu.vendor_id == kVendorIDNVidia) |
250 gpu_info->optimus = true; | 182 gpu_info->optimus = true; |
251 if (gpu_info->gpu.vendor_id == kVendorIDAMD) | 183 if (gpu_info->gpu.vendor_id == kVendorIDAMD) |
252 gpu_info->amd_switchable = true; | 184 gpu_info->amd_switchable = true; |
253 } | 185 } |
254 | 186 |
255 (libpci_loader.pci_cleanup)(access); | 187 (libpci_loader.pci_cleanup)(access); |
256 return (primary_gpu_identified); | 188 return (primary_gpu_identified); |
257 } | 189 } |
258 | 190 |
| 191 } // namespace anonymous |
| 192 |
| 193 namespace gpu_info_collector { |
| 194 |
| 195 bool CollectContextGraphicsInfo(content::GPUInfo* gpu_info) { |
| 196 DCHECK(gpu_info); |
| 197 |
| 198 TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo"); |
| 199 |
| 200 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 201 switches::kGpuNoContextLost)) { |
| 202 gpu_info->can_lose_context = false; |
| 203 } else { |
| 204 #if defined(OS_CHROMEOS) |
| 205 gpu_info->can_lose_context = false; |
| 206 #else |
| 207 // TODO(zmo): need to consider the case where we are running on top |
| 208 // of desktop GL and GL_ARB_robustness extension is available. |
| 209 gpu_info->can_lose_context = |
| 210 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); |
| 211 #endif |
| 212 } |
| 213 |
| 214 gpu_info->finalized = true; |
| 215 bool rt = CollectGraphicsInfoGL(gpu_info); |
| 216 |
| 217 return rt; |
| 218 } |
| 219 |
| 220 bool CollectBasicGraphicsInfo(content::GPUInfo* gpu_info) { |
| 221 DCHECK(gpu_info); |
| 222 |
| 223 bool rt = CollectPCIVideoCardInfo(gpu_info); |
| 224 |
| 225 std::string driver_version; |
| 226 switch (gpu_info->gpu.vendor_id) { |
| 227 case kVendorIDAMD: |
| 228 driver_version = CollectDriverVersionATI(); |
| 229 if (!driver_version.empty()) { |
| 230 gpu_info->driver_vendor = "ATI / AMD"; |
| 231 gpu_info->driver_version = driver_version; |
| 232 } |
| 233 break; |
| 234 case kVendorIDNVidia: |
| 235 driver_version = CollectDriverVersionNVidia(); |
| 236 if (!driver_version.empty()) { |
| 237 gpu_info->driver_vendor = "NVIDIA"; |
| 238 gpu_info->driver_version = driver_version; |
| 239 } |
| 240 break; |
| 241 case kVendorIDIntel: |
| 242 // In dual-GPU cases, sometimes PCI scan only gives us the |
| 243 // integrated GPU (i.e., the Intel one). |
| 244 driver_version = CollectDriverVersionNVidia(); |
| 245 if (!driver_version.empty()) { |
| 246 gpu_info->driver_vendor = "NVIDIA"; |
| 247 gpu_info->driver_version = driver_version; |
| 248 // Machines with more than two GPUs are not handled. |
| 249 if (gpu_info->secondary_gpus.size() <= 1) |
| 250 gpu_info->optimus = true; |
| 251 } |
| 252 break; |
| 253 } |
| 254 |
| 255 return rt; |
| 256 } |
| 257 |
259 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { | 258 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { |
260 DCHECK(gpu_info); | 259 DCHECK(gpu_info); |
261 | 260 |
262 std::string gl_version_string = gpu_info->gl_version_string; | 261 std::string gl_version_string = gpu_info->gl_version_string; |
263 if (StartsWithASCII(gl_version_string, "OpenGL ES", true)) | 262 if (StartsWithASCII(gl_version_string, "OpenGL ES", true)) |
264 gl_version_string = gl_version_string.substr(10); | 263 gl_version_string = gl_version_string.substr(10); |
265 std::vector<std::string> pieces; | 264 std::vector<std::string> pieces; |
266 base::SplitStringAlongWhitespace(gl_version_string, &pieces); | 265 base::SplitStringAlongWhitespace(gl_version_string, &pieces); |
267 // In linux, the gl version string might be in the format of | 266 // In linux, the gl version string might be in the format of |
268 // GLVersion DriverVendor DriverVersion | 267 // GLVersion DriverVendor DriverVersion |
269 if (pieces.size() < 3) | 268 if (pieces.size() < 3) |
270 return false; | 269 return false; |
271 | 270 |
272 std::string driver_version = pieces[2]; | 271 std::string driver_version = pieces[2]; |
273 size_t pos = driver_version.find_first_not_of("0123456789."); | 272 size_t pos = driver_version.find_first_not_of("0123456789."); |
274 if (pos == 0) | 273 if (pos == 0) |
275 return false; | 274 return false; |
276 if (pos != std::string::npos) | 275 if (pos != std::string::npos) |
277 driver_version = driver_version.substr(0, pos); | 276 driver_version = driver_version.substr(0, pos); |
278 | 277 |
279 gpu_info->driver_vendor = pieces[1]; | 278 gpu_info->driver_vendor = pieces[1]; |
280 gpu_info->driver_version = driver_version; | 279 gpu_info->driver_version = driver_version; |
281 return true; | 280 return true; |
282 } | 281 } |
283 | 282 |
| 283 void MergeGPUInfo(content::GPUInfo* basic_gpu_info, |
| 284 const content::GPUInfo& context_gpu_info) { |
| 285 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); |
| 286 } |
| 287 |
284 } // namespace gpu_info_collector | 288 } // namespace gpu_info_collector |
OLD | NEW |