Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: content/gpu/gpu_info_collector_linux.cc

Issue 6803024: Collect driver vendor in linux through glXGetClientString. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 10 #include "base/file_util.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (end == std::string::npos) 154 if (end == std::string::npos)
155 return line.substr(begin); 155 return line.substr(begin);
156 else 156 else
157 return line.substr(begin, end - begin); 157 return line.substr(begin, end - begin);
158 } 158 }
159 } 159 }
160 } 160 }
161 return ""; 161 return "";
162 } 162 }
163 163
164 // Use glXGetClientString to get driver vendor.
165 // Return "" on failing.
166 std::string CollectDriverVendorGlx() {
167 // TODO(zmo): handle the EGL/GLES2 case.
168 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL)
169 return "";
170 Display* display = XOpenDisplay(NULL);
171 if (display == NULL)
172 return "";
173 std::string vendor = glXGetClientString(display, GLX_VENDOR);
174 XCloseDisplay(display);
175 return vendor;
176 }
177
178 // Return 0 on unrecognized vendor.
179 uint32 VendorStringToID(const std::string& vendor_string) {
180 if (StartsWithASCII(vendor_string, "NVIDIA", true))
181 return 0x10de;
182 if (StartsWithASCII(vendor_string, "ATI", true))
183 return 0x1002;
184 // TODO(zmo): find a way to identify Intel cards.
185 return 0;
186 }
187
164 } // namespace anonymous 188 } // namespace anonymous
165 189
166 namespace gpu_info_collector { 190 namespace gpu_info_collector {
167 191
168 bool CollectGraphicsInfo(GPUInfo* gpu_info) { 192 bool CollectGraphicsInfo(GPUInfo* gpu_info) {
169 DCHECK(gpu_info); 193 DCHECK(gpu_info);
170 194
171 // TODO(zmo): need to consider the case where we are running on top of 195 // TODO(zmo): need to consider the case where we are running on top of
172 // desktop GL and GL_ARB_robustness extension is available. 196 // desktop GL and GL_ARB_robustness extension is available.
173 gpu_info->can_lose_context = 197 gpu_info->can_lose_context =
(...skipping 16 matching lines...) Expand all
190 gpu_info->driver_version = ati_driver_version; 214 gpu_info->driver_version = ati_driver_version;
191 } 215 }
192 } 216 }
193 217
194 return rt; 218 return rt;
195 } 219 }
196 220
197 bool CollectVideoCardInfo(GPUInfo* gpu_info) { 221 bool CollectVideoCardInfo(GPUInfo* gpu_info) {
198 DCHECK(gpu_info); 222 DCHECK(gpu_info);
199 223
224 std::string driver_vendor = CollectDriverVendorGlx();
225 if (!driver_vendor.empty()) {
226 gpu_info->driver_vendor = driver_vendor;
227 uint32 vendor_id = VendorStringToID(driver_vendor);
228 if (vendor_id != 0)
229 gpu_info->vendor_id = vendor_id;
230 }
231
200 if (IsPciSupported() == false) { 232 if (IsPciSupported() == false) {
201 VLOG(1) << "PCI bus scanning is not supported"; 233 VLOG(1) << "PCI bus scanning is not supported";
202 return false; 234 return false;
203 } 235 }
204 236
205 // TODO(zmo): be more flexible about library name. 237 // TODO(zmo): be more flexible about library name.
206 PciInterface* interface = InitializeLibPci("libpci.so.3"); 238 PciInterface* interface = InitializeLibPci("libpci.so.3");
207 if (interface == NULL) 239 if (interface == NULL)
208 interface = InitializeLibPci("libpci.so"); 240 interface = InitializeLibPci("libpci.so");
209 if (interface == NULL) { 241 if (interface == NULL) {
210 VLOG(1) << "Failed to locate libpci"; 242 VLOG(1) << "Failed to locate libpci";
211 return false; 243 return false;
212 } 244 }
213 245
214 PciAccess* access = (interface->pci_alloc)(); 246 PciAccess* access = (interface->pci_alloc)();
215 DCHECK(access != NULL); 247 DCHECK(access != NULL);
216 (interface->pci_init)(access); 248 (interface->pci_init)(access);
217 (interface->pci_scan_bus)(access); 249 (interface->pci_scan_bus)(access);
218 std::vector<PciDevice*> gpu_list; 250 std::vector<PciDevice*> gpu_list;
219 PciDevice* gpu_active = NULL; 251 PciDevice* gpu_active = NULL;
220 for (PciDevice* device = access->device_list; 252 for (PciDevice* device = access->device_list;
221 device != NULL; device = device->next) { 253 device != NULL; device = device->next) {
222 (interface->pci_fill_info)(device, 33); // Fill the IDs and class fields. 254 (interface->pci_fill_info)(device, 33); // Fill the IDs and class fields.
223 // TODO(zmo): there might be other classes that qualify as display devices. 255 // TODO(zmo): there might be other classes that qualify as display devices.
224 if (device->device_class == 0x0300) { // Device class is DISPLAY_VGA. 256 if (device->device_class == 0x0300) { // Device class is DISPLAY_VGA.
225 gpu_list.push_back(device); 257 if (gpu_info->vendor_id == 0 || gpu_info->vendor_id == device->vendor_id)
258 gpu_list.push_back(device);
226 } 259 }
227 } 260 }
228 if (gpu_list.size() == 1) { 261 if (gpu_list.size() == 1) {
229 gpu_active = gpu_list[0]; 262 gpu_active = gpu_list[0];
230 } else { 263 } else {
231 // If more than one graphics card are identified, find the one that matches 264 // If more than one graphics card are identified, find the one that matches
232 // gl VENDOR and RENDERER info. 265 // gl VENDOR and RENDERER info.
233 std::string gl_vendor_string = gpu_info->gl_vendor; 266 std::string gl_vendor_string = gpu_info->gl_vendor;
234 std::string gl_renderer_string = gpu_info->gl_renderer; 267 std::string gl_renderer_string = gpu_info->gl_renderer;
235 const int buffer_size = 255; 268 const int buffer_size = 255;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return false; 335 return false;
303 if (pos != std::string::npos) 336 if (pos != std::string::npos)
304 driver_version = driver_version.substr(0, pos); 337 driver_version = driver_version.substr(0, pos);
305 338
306 gpu_info->driver_vendor = pieces[1]; 339 gpu_info->driver_vendor = pieces[1];
307 gpu_info->driver_version = driver_version; 340 gpu_info->driver_version = driver_version;
308 return true; 341 return true;
309 } 342 }
310 343
311 } // namespace gpu_info_collector 344 } // namespace gpu_info_collector
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698