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 "gpu/config/gpu_info_collector.h" | 5 #include "gpu/config/gpu_info_collector.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Find the info of the current GPU. | 55 // Find the info of the current GPU. |
56 GPUInfo::GPUDevice GetActiveGPU() { | 56 GPUInfo::GPUDevice GetActiveGPU() { |
57 GPUInfo::GPUDevice gpu; | 57 GPUInfo::GPUDevice gpu; |
58 io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay); | 58 io_registry_entry_t dsp_port = CGDisplayIOServicePort(kCGDirectMainDisplay); |
59 gpu.vendor_id = GetEntryProperty(dsp_port, CFSTR("vendor-id")); | 59 gpu.vendor_id = GetEntryProperty(dsp_port, CFSTR("vendor-id")); |
60 gpu.device_id = GetEntryProperty(dsp_port, CFSTR("device-id")); | 60 gpu.device_id = GetEntryProperty(dsp_port, CFSTR("device-id")); |
61 return gpu; | 61 return gpu; |
62 } | 62 } |
63 | 63 |
64 // Scan IO registry for PCI video cards. | 64 // Scan IO registry for PCI video cards. |
65 bool CollectPCIVideoCardInfo(GPUInfo* gpu_info) { | 65 CollectInfoResult CollectPCIVideoCardInfo(GPUInfo* gpu_info) { |
66 DCHECK(gpu_info); | 66 DCHECK(gpu_info); |
67 GPUInfo::GPUDevice active_gpu = GetActiveGPU(); | 67 GPUInfo::GPUDevice active_gpu = GetActiveGPU(); |
68 | 68 |
69 // Collect all GPUs' info. | 69 // Collect all GPUs' info. |
70 // match_dictionary will be consumed by IOServiceGetMatchingServices, no need | 70 // match_dictionary will be consumed by IOServiceGetMatchingServices, no need |
71 // to release it. | 71 // to release it. |
72 CFMutableDictionaryRef match_dictionary = IOServiceMatching("IOPCIDevice"); | 72 CFMutableDictionaryRef match_dictionary = IOServiceMatching("IOPCIDevice"); |
73 io_iterator_t entry_iterator; | 73 io_iterator_t entry_iterator; |
74 std::vector<GPUInfo::GPUDevice> gpu_list; | 74 std::vector<GPUInfo::GPUDevice> gpu_list; |
75 if (IOServiceGetMatchingServices(kIOMasterPortDefault, | 75 if (IOServiceGetMatchingServices(kIOMasterPortDefault, |
(...skipping 14 matching lines...) Expand all Loading... |
90 gpu.active = true; | 90 gpu.active = true; |
91 } | 91 } |
92 gpu_list.push_back(gpu); | 92 gpu_list.push_back(gpu); |
93 } | 93 } |
94 } | 94 } |
95 IOObjectRelease(entry_iterator); | 95 IOObjectRelease(entry_iterator); |
96 } | 96 } |
97 | 97 |
98 switch (gpu_list.size()) { | 98 switch (gpu_list.size()) { |
99 case 0: | 99 case 0: |
100 return false; | 100 return kCollectInfoNonFatalFailure; |
101 case 1: | 101 case 1: |
102 gpu_info->gpu = gpu_list[0]; | 102 gpu_info->gpu = gpu_list[0]; |
103 break; | 103 break; |
104 case 2: | 104 case 2: |
105 { | 105 { |
106 int integrated = -1; | 106 int integrated = -1; |
107 int discrete = -1; | 107 int discrete = -1; |
108 if (gpu_list[0].vendor_id == kVendorIDIntel) | 108 if (gpu_list[0].vendor_id == kVendorIDIntel) |
109 integrated = 0; | 109 integrated = 0; |
110 else if (gpu_list[1].vendor_id == kVendorIDIntel) | 110 else if (gpu_list[1].vendor_id == kVendorIDIntel) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 for (size_t i = 0; i < gpu_list.size(); ++i) { | 148 for (size_t i = 0; i < gpu_list.size(); ++i) { |
149 if (i == current) | 149 if (i == current) |
150 gpu_info->gpu = gpu_list[i]; | 150 gpu_info->gpu = gpu_list[i]; |
151 else | 151 else |
152 gpu_info->secondary_gpus.push_back(gpu_list[i]); | 152 gpu_info->secondary_gpus.push_back(gpu_list[i]); |
153 } | 153 } |
154 } | 154 } |
155 break; | 155 break; |
156 } | 156 } |
157 return (gpu_info->gpu.vendor_id && gpu_info->gpu.device_id); | 157 if (gpu_info->gpu.vendor_id == 0 || gpu_info->gpu.device_id == 0) |
| 158 return kCollectInfoNonFatalFailure; |
| 159 return kCollectInfoSuccess; |
158 } | 160 } |
159 | 161 |
160 } // namespace anonymous | 162 } // namespace anonymous |
161 | 163 |
162 CollectInfoResult CollectContextGraphicsInfo(GPUInfo* gpu_info) { | 164 CollectInfoResult CollectContextGraphicsInfo(GPUInfo* gpu_info) { |
163 DCHECK(gpu_info); | 165 DCHECK(gpu_info); |
164 | 166 |
165 TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo"); | 167 TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo"); |
166 | 168 |
167 gpu_info->can_lose_context = | 169 gpu_info->can_lose_context = |
168 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); | 170 (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2); |
169 gpu_info->finalized = true; | 171 CollectInfoResult result = CollectGraphicsInfoGL(gpu_info); |
170 return CollectGraphicsInfoGL(gpu_info); | 172 gpu_info->context_info_state = result; |
| 173 return result; |
171 } | 174 } |
172 | 175 |
173 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { | 176 CollectInfoResult CollectGpuID(uint32* vendor_id, uint32* device_id) { |
174 DCHECK(vendor_id && device_id); | 177 DCHECK(vendor_id && device_id); |
175 | 178 |
176 GPUInfo::GPUDevice gpu = GetActiveGPU(); | 179 GPUInfo::GPUDevice gpu = GetActiveGPU(); |
177 *vendor_id = gpu.vendor_id; | 180 *vendor_id = gpu.vendor_id; |
178 *device_id = gpu.device_id; | 181 *device_id = gpu.device_id; |
179 | 182 |
180 if (*vendor_id != 0 && *device_id != 0) | 183 if (*vendor_id != 0 && *device_id != 0) |
181 return kGpuIDSuccess; | 184 return kCollectInfoSuccess; |
182 return kGpuIDFailure; | 185 return kCollectInfoNonFatalFailure; |
183 } | 186 } |
184 | 187 |
185 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) { | 188 CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) { |
186 DCHECK(gpu_info); | 189 DCHECK(gpu_info); |
187 | 190 |
188 int32 model_major = 0, model_minor = 0; | 191 int32 model_major = 0, model_minor = 0; |
189 base::mac::ParseModelIdentifier(base::mac::GetModelIdentifier(), | 192 base::mac::ParseModelIdentifier(base::mac::GetModelIdentifier(), |
190 &gpu_info->machine_model_name, | 193 &gpu_info->machine_model_name, |
191 &model_major, &model_minor); | 194 &model_major, &model_minor); |
192 gpu_info->machine_model_version = | 195 gpu_info->machine_model_version = |
193 base::IntToString(model_major) + "." + base::IntToString(model_minor); | 196 base::IntToString(model_major) + "." + base::IntToString(model_minor); |
194 | 197 |
195 bool result = CollectPCIVideoCardInfo(gpu_info); | 198 CollectInfoResult result = CollectPCIVideoCardInfo(gpu_info); |
196 return result ? kCollectInfoSuccess : kCollectInfoNonFatalFailure; | 199 gpu_info->basic_info_state = result; |
| 200 return result; |
197 } | 201 } |
198 | 202 |
199 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) { | 203 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) { |
200 DCHECK(gpu_info); | 204 DCHECK(gpu_info); |
201 | 205 |
202 // Extract the OpenGL driver version string from the GL_VERSION string. | 206 // Extract the OpenGL driver version string from the GL_VERSION string. |
203 // Mac OpenGL drivers have the driver version | 207 // Mac OpenGL drivers have the driver version |
204 // at the end of the gl version string preceded by a dash. | 208 // at the end of the gl version string preceded by a dash. |
205 // Use some jiggery-pokery to turn that utf8 string into a std::wstring. | 209 // Use some jiggery-pokery to turn that utf8 string into a std::wstring. |
206 size_t pos = gpu_info->gl_version.find_last_of('-'); | 210 size_t pos = gpu_info->gl_version.find_last_of('-'); |
207 if (pos == std::string::npos) | 211 if (pos == std::string::npos) |
208 return kCollectInfoNonFatalFailure; | 212 return kCollectInfoNonFatalFailure; |
209 gpu_info->driver_version = gpu_info->gl_version.substr(pos + 1); | 213 gpu_info->driver_version = gpu_info->gl_version.substr(pos + 1); |
210 return kCollectInfoSuccess; | 214 return kCollectInfoSuccess; |
211 } | 215 } |
212 | 216 |
213 void MergeGPUInfo(GPUInfo* basic_gpu_info, | 217 void MergeGPUInfo(GPUInfo* basic_gpu_info, |
214 const GPUInfo& context_gpu_info) { | 218 const GPUInfo& context_gpu_info) { |
215 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); | 219 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); |
216 } | 220 } |
217 | 221 |
218 } // namespace gpu | 222 } // namespace gpu |
OLD | NEW |