| 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(INFO) << "Failed to dlopen " << lib_name; |
| 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")); |
| 97 interface->pci_scan_bus = reinterpret_cast<FT_pci_scan_bus>( | 97 interface->pci_scan_bus = reinterpret_cast<FT_pci_scan_bus>( |
| 98 dlsym(handle, "pci_scan_bus")); | 98 dlsym(handle, "pci_scan_bus")); |
| 99 interface->pci_fill_info = reinterpret_cast<FT_pci_fill_info>( | 99 interface->pci_fill_info = reinterpret_cast<FT_pci_fill_info>( |
| 100 dlsym(handle, "pci_fill_info")); | 100 dlsym(handle, "pci_fill_info")); |
| 101 interface->pci_lookup_name = reinterpret_cast<FT_pci_lookup_name>( | 101 interface->pci_lookup_name = reinterpret_cast<FT_pci_lookup_name>( |
| 102 dlsym(handle, "pci_lookup_name")); | 102 dlsym(handle, "pci_lookup_name")); |
| 103 if (interface->pci_alloc == NULL || | 103 if (interface->pci_alloc == NULL || |
| 104 interface->pci_init == NULL || | 104 interface->pci_init == NULL || |
| 105 interface->pci_cleanup == NULL || | 105 interface->pci_cleanup == NULL || |
| 106 interface->pci_scan_bus == NULL || | 106 interface->pci_scan_bus == NULL || |
| 107 interface->pci_fill_info == NULL || | 107 interface->pci_fill_info == NULL || |
| 108 interface->pci_lookup_name == NULL) { | 108 interface->pci_lookup_name == NULL) { |
| 109 LOG(ERROR) << "Missing required function(s) from libpci"; | 109 LOG(ERROR) << "Missing required function(s) from " << lib_name; |
| 110 dlclose(handle); | 110 dlclose(handle); |
| 111 delete interface; | 111 delete interface; |
| 112 return NULL; | 112 return NULL; |
| 113 } | 113 } |
| 114 return interface; | 114 return interface; |
| 115 } | 115 } |
| 116 | 116 |
| 117 // This close the dynamically opened libpci and delete the interface. | 117 // This close the dynamically opened libpci and delete the interface. |
| 118 void FinalizeLibPci(PciInterface** interface) { | 118 void FinalizeLibPci(PciInterface** interface) { |
| 119 DCHECK(interface && *interface && (*interface)->lib_handle); | 119 DCHECK(interface && *interface && (*interface)->lib_handle); |
| (...skipping 16 matching lines...) Expand all 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) { |
| 148 LOG(ERROR) << "Failed to locate libpci"; |
| 146 return false; | 149 return false; |
| 150 } |
| 147 | 151 |
| 148 PciAccess* access = (interface->pci_alloc)(); | 152 PciAccess* access = (interface->pci_alloc)(); |
| 149 DCHECK(access != NULL); | 153 DCHECK(access != NULL); |
| 150 (interface->pci_init)(access); | 154 (interface->pci_init)(access); |
| 151 (interface->pci_scan_bus)(access); | 155 (interface->pci_scan_bus)(access); |
| 152 std::vector<PciDevice*> gpu_list; | 156 std::vector<PciDevice*> gpu_list; |
| 153 PciDevice* gpu_active = NULL; | 157 PciDevice* gpu_active = NULL; |
| 154 for (PciDevice* device = access->device_list; | 158 for (PciDevice* device = access->device_list; |
| 155 device != NULL; device = device->next) { | 159 device != NULL; device = device->next) { |
| 156 (interface->pci_fill_info)(device, 33); // Fill the IDs and class fields. | 160 (interface->pci_fill_info)(device, 33); // Fill the IDs and class fields. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (pos == 0) | 237 if (pos == 0) |
| 234 return false; | 238 return false; |
| 235 if (pos != std::string::npos) | 239 if (pos != std::string::npos) |
| 236 driver_version = driver_version.substr(0, pos); | 240 driver_version = driver_version.substr(0, pos); |
| 237 | 241 |
| 238 gpu_info->SetDriverInfo(pieces[1], driver_version); | 242 gpu_info->SetDriverInfo(pieces[1], driver_version); |
| 239 return true; | 243 return true; |
| 240 } | 244 } |
| 241 | 245 |
| 242 } // namespace gpu_info_collector | 246 } // namespace gpu_info_collector |
| OLD | NEW |