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

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 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone)
168 return "";
169 Display* display = XOpenDisplay(NULL);
170 if (display == NULL)
171 return "";
172 const char* vendor = glXGetClientString(display, GLX_VENDOR);
piman 2011/04/06 22:10:00 I suspect you'll want to copy that into the std::s
zmo 2011/04/06 23:14:34 Got it. Will fix.
piman 2011/04/06 23:18:01 Ah, ok, that should be fine then
173 XCloseDisplay(display);
174 return std::string(vendor);
175 }
176
177 // Return 0 on unrecognized vendor.
178 uint32 VendorStringToID(const std::string& vendor_string) {
179 if (StartsWithASCII(vendor_string, "NVIDIA", true))
180 return 0x10de;
181 if (StartsWithASCII(vendor_string, "ATI", true))
182 return 0x1002;
183 // TODO(zmo): find a way to identify Intel cards.
piman 2011/04/06 22:10:00 The problem is that the client vendor string for I
zmo 2011/04/06 23:14:34 This is trying to collect vendor without creating
184 return 0;
185 }
186
164 } // namespace anonymous 187 } // namespace anonymous
165 188
166 namespace gpu_info_collector { 189 namespace gpu_info_collector {
167 190
168 bool CollectGraphicsInfo(GPUInfo* gpu_info) { 191 bool CollectGraphicsInfo(GPUInfo* gpu_info) {
169 DCHECK(gpu_info); 192 DCHECK(gpu_info);
170 193
171 // TODO(zmo): need to consider the case where we are running on top of 194 // TODO(zmo): need to consider the case where we are running on top of
172 // desktop GL and GL_ARB_robustness extension is available. 195 // desktop GL and GL_ARB_robustness extension is available.
173 gpu_info->can_lose_context = 196 gpu_info->can_lose_context =
(...skipping 16 matching lines...) Expand all
190 gpu_info->driver_version = ati_driver_version; 213 gpu_info->driver_version = ati_driver_version;
191 } 214 }
192 } 215 }
193 216
194 return rt; 217 return rt;
195 } 218 }
196 219
197 bool CollectVideoCardInfo(GPUInfo* gpu_info) { 220 bool CollectVideoCardInfo(GPUInfo* gpu_info) {
198 DCHECK(gpu_info); 221 DCHECK(gpu_info);
199 222
223 std::string driver_vendor = CollectDriverVendorGlx();
224 if (!driver_vendor.empty()) {
225 gpu_info->driver_vendor = driver_vendor;
226 uint32 vendor_id = VendorStringToID(driver_vendor);
227 if (vendor_id != 0)
228 gpu_info->vendor_id = vendor_id;
229 }
230
200 if (IsPciSupported() == false) { 231 if (IsPciSupported() == false) {
201 VLOG(1) << "PCI bus scanning is not supported"; 232 VLOG(1) << "PCI bus scanning is not supported";
202 return false; 233 return false;
203 } 234 }
204 235
205 // TODO(zmo): be more flexible about library name. 236 // TODO(zmo): be more flexible about library name.
206 PciInterface* interface = InitializeLibPci("libpci.so.3"); 237 PciInterface* interface = InitializeLibPci("libpci.so.3");
207 if (interface == NULL) 238 if (interface == NULL)
208 interface = InitializeLibPci("libpci.so"); 239 interface = InitializeLibPci("libpci.so");
209 if (interface == NULL) { 240 if (interface == NULL) {
210 VLOG(1) << "Failed to locate libpci"; 241 VLOG(1) << "Failed to locate libpci";
211 return false; 242 return false;
212 } 243 }
213 244
214 PciAccess* access = (interface->pci_alloc)(); 245 PciAccess* access = (interface->pci_alloc)();
215 DCHECK(access != NULL); 246 DCHECK(access != NULL);
216 (interface->pci_init)(access); 247 (interface->pci_init)(access);
217 (interface->pci_scan_bus)(access); 248 (interface->pci_scan_bus)(access);
218 std::vector<PciDevice*> gpu_list; 249 std::vector<PciDevice*> gpu_list;
219 PciDevice* gpu_active = NULL; 250 PciDevice* gpu_active = NULL;
220 for (PciDevice* device = access->device_list; 251 for (PciDevice* device = access->device_list;
221 device != NULL; device = device->next) { 252 device != NULL; device = device->next) {
222 (interface->pci_fill_info)(device, 33); // Fill the IDs and class fields. 253 (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. 254 // TODO(zmo): there might be other classes that qualify as display devices.
224 if (device->device_class == 0x0300) { // Device class is DISPLAY_VGA. 255 if (device->device_class == 0x0300) { // Device class is DISPLAY_VGA.
225 gpu_list.push_back(device); 256 if (gpu_info->vendor_id == 0 || gpu_info->vendor_id == device->vendor_id)
257 gpu_list.push_back(device);
226 } 258 }
227 } 259 }
228 if (gpu_list.size() == 1) { 260 if (gpu_list.size() == 1) {
229 gpu_active = gpu_list[0]; 261 gpu_active = gpu_list[0];
230 } else { 262 } else {
231 // If more than one graphics card are identified, find the one that matches 263 // If more than one graphics card are identified, find the one that matches
232 // gl VENDOR and RENDERER info. 264 // gl VENDOR and RENDERER info.
233 std::string gl_vendor_string = gpu_info->gl_vendor; 265 std::string gl_vendor_string = gpu_info->gl_vendor;
234 std::string gl_renderer_string = gpu_info->gl_renderer; 266 std::string gl_renderer_string = gpu_info->gl_renderer;
235 const int buffer_size = 255; 267 const int buffer_size = 255;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return false; 334 return false;
303 if (pos != std::string::npos) 335 if (pos != std::string::npos)
304 driver_version = driver_version.substr(0, pos); 336 driver_version = driver_version.substr(0, pos);
305 337
306 gpu_info->driver_vendor = pieces[1]; 338 gpu_info->driver_vendor = pieces[1];
307 gpu_info->driver_version = driver_version; 339 gpu_info->driver_version = driver_version;
308 return true; 340 return true;
309 } 341 }
310 342
311 } // namespace gpu_info_collector 343 } // 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