OLD | NEW |
---|---|
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "chrome/gpu/gpu_info_collector.h" | 5 #include "chrome/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 "app/gfx/gl/gl_bindings.h" | 10 #include "app/gfx/gl/gl_bindings.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 FT_pci_fill_info pci_fill_info; | 76 FT_pci_fill_info pci_fill_info; |
77 FT_pci_lookup_name pci_lookup_name; | 77 FT_pci_lookup_name pci_lookup_name; |
78 }; | 78 }; |
79 | 79 |
80 // This dynamically opens libpci and get function pointers we need. Return | 80 // This dynamically opens libpci and get function pointers we need. Return |
81 // NULL if library fails to open or any functions can not be located. | 81 // NULL if library fails to open or any functions can not be located. |
82 // Returned interface (if not NULL) should be deleted in FinalizeLibPci. | 82 // Returned interface (if not NULL) should be deleted in FinalizeLibPci. |
83 PciInterface* InitializeLibPci(const char* lib_name) { | 83 PciInterface* InitializeLibPci(const char* lib_name) { |
84 void* handle = dlopen(lib_name, RTLD_LAZY); | 84 void* handle = dlopen(lib_name, RTLD_LAZY); |
85 if (handle == NULL) { | 85 if (handle == NULL) { |
86 LOG(ERROR) << "Fail to dlopen libpci"; | 86 LOG(ERROR) << "Fail to dlopen " << lib_name; |
Ken Russell (switch to Gerrit)
2011/03/01 01:38:42
Fail -> Failed. Also, reconsider whether to print
| |
87 return NULL; | 87 return NULL; |
88 } | 88 } |
89 PciInterface* interface = new struct PciInterface; | 89 PciInterface* interface = new struct PciInterface; |
90 interface->lib_handle = handle; | 90 interface->lib_handle = handle; |
91 interface->pci_alloc = reinterpret_cast<FT_pci_alloc>( | 91 interface->pci_alloc = reinterpret_cast<FT_pci_alloc>( |
92 dlsym(handle, "pci_alloc")); | 92 dlsym(handle, "pci_alloc")); |
93 interface->pci_init = reinterpret_cast<FT_pci_init>( | 93 interface->pci_init = reinterpret_cast<FT_pci_init>( |
94 dlsym(handle, "pci_init")); | 94 dlsym(handle, "pci_init")); |
95 interface->pci_cleanup = reinterpret_cast<FT_pci_cleanup>( | 95 interface->pci_cleanup = reinterpret_cast<FT_pci_cleanup>( |
96 dlsym(handle, "pci_cleanup")); | 96 dlsym(handle, "pci_cleanup")); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 gpu_info->SetLevel(GPUInfo::kComplete); | 136 gpu_info->SetLevel(GPUInfo::kComplete); |
137 return CollectGraphicsInfoGL(gpu_info); | 137 return CollectGraphicsInfoGL(gpu_info); |
138 } | 138 } |
139 | 139 |
140 bool CollectVideoCardInfo(GPUInfo* gpu_info) { | 140 bool CollectVideoCardInfo(GPUInfo* gpu_info) { |
141 DCHECK(gpu_info); | 141 DCHECK(gpu_info); |
142 | 142 |
143 // TODO(zmo): be more flexible about library name. | 143 // TODO(zmo): be more flexible about library name. |
144 PciInterface* interface = InitializeLibPci("libpci.so.3"); | 144 PciInterface* interface = InitializeLibPci("libpci.so.3"); |
145 if (interface == NULL) | 145 if (interface == NULL) |
146 interface = InitializeLibPci("libpci.so"); | |
147 if (interface == NULL) | |
146 return false; | 148 return false; |
147 | 149 |
148 PciAccess* access = (interface->pci_alloc)(); | 150 PciAccess* access = (interface->pci_alloc)(); |
149 DCHECK(access != NULL); | 151 DCHECK(access != NULL); |
150 (interface->pci_init)(access); | 152 (interface->pci_init)(access); |
151 (interface->pci_scan_bus)(access); | 153 (interface->pci_scan_bus)(access); |
152 std::vector<PciDevice*> gpu_list; | 154 std::vector<PciDevice*> gpu_list; |
153 PciDevice* gpu_active = NULL; | 155 PciDevice* gpu_active = NULL; |
154 for (PciDevice* device = access->device_list; | 156 for (PciDevice* device = access->device_list; |
155 device != NULL; device = device->next) { | 157 device != NULL; device = device->next) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 if (pos == 0) | 235 if (pos == 0) |
234 return false; | 236 return false; |
235 if (pos != std::string::npos) | 237 if (pos != std::string::npos) |
236 driver_version = driver_version.substr(0, pos); | 238 driver_version = driver_version.substr(0, pos); |
237 | 239 |
238 gpu_info->SetDriverInfo(pieces[1], driver_version); | 240 gpu_info->SetDriverInfo(pieces[1], driver_version); |
239 return true; | 241 return true; |
240 } | 242 } |
241 | 243 |
242 } // namespace gpu_info_collector | 244 } // namespace gpu_info_collector |
OLD | NEW |