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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | |
16 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
17 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
18 #include "ui/gl/gl_context.h" | 19 #include "ui/gl/gl_context.h" |
19 #include "ui/gl/gl_implementation.h" | 20 #include "ui/gl/gl_implementation.h" |
20 #include "ui/gl/gl_surface.h" | 21 #include "ui/gl/gl_surface.h" |
21 #include "ui/gl/gl_version_info.h" | 22 #include "ui/gl/gl_version_info.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 scoped_refptr<gfx::GLSurface> InitializeGLSurface() { | 26 scoped_refptr<gfx::GLSurface> InitializeGLSurface() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 143 } |
143 | 144 |
144 // TODO(kbr): remove once the destruction of a current context automatically | 145 // TODO(kbr): remove once the destruction of a current context automatically |
145 // clears the current context. | 146 // clears the current context. |
146 context->ReleaseCurrent(surface.get()); | 147 context->ReleaseCurrent(surface.get()); |
147 | 148 |
148 std::string glsl_version = GetVersionFromString(glsl_version_string); | 149 std::string glsl_version = GetVersionFromString(glsl_version_string); |
149 gpu_info->pixel_shader_version = glsl_version; | 150 gpu_info->pixel_shader_version = glsl_version; |
150 gpu_info->vertex_shader_version = glsl_version; | 151 gpu_info->vertex_shader_version = glsl_version; |
151 | 152 |
153 IdentifyActiveGPU(gpu_info); | |
152 return CollectDriverInfoGL(gpu_info); | 154 return CollectDriverInfoGL(gpu_info); |
153 } | 155 } |
154 | 156 |
155 void MergeGPUInfoGL(GPUInfo* basic_gpu_info, | 157 void MergeGPUInfoGL(GPUInfo* basic_gpu_info, |
156 const GPUInfo& context_gpu_info) { | 158 const GPUInfo& context_gpu_info) { |
157 DCHECK(basic_gpu_info); | 159 DCHECK(basic_gpu_info); |
160 // Copy over active GPU setting because it might change. | |
161 basic_gpu_info->gpu.active = context_gpu_info.gpu.active; | |
162 size_t count = std::min(basic_gpu_info->secondary_gpus.size(), | |
163 context_gpu_info.secondary_gpus.size()); | |
164 for (size_t ii = 0; ii < count; ++ii) { | |
165 basic_gpu_info->secondary_gpus[ii].active = | |
166 context_gpu_info.secondary_gpus[ii].active; | |
Ken Russell (switch to Gerrit)
2015/12/08 22:58:48
Are the secondary GPUs guaranteed to be in the sam
Zhenyao Mo
2015/12/09 18:36:53
I don't think the order will change because it's t
| |
167 } | |
168 | |
158 basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer; | 169 basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer; |
159 basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor; | 170 basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor; |
160 basic_gpu_info->gl_version = context_gpu_info.gl_version; | 171 basic_gpu_info->gl_version = context_gpu_info.gl_version; |
161 basic_gpu_info->gl_extensions = context_gpu_info.gl_extensions; | 172 basic_gpu_info->gl_extensions = context_gpu_info.gl_extensions; |
162 basic_gpu_info->pixel_shader_version = | 173 basic_gpu_info->pixel_shader_version = |
163 context_gpu_info.pixel_shader_version; | 174 context_gpu_info.pixel_shader_version; |
164 basic_gpu_info->vertex_shader_version = | 175 basic_gpu_info->vertex_shader_version = |
165 context_gpu_info.vertex_shader_version; | 176 context_gpu_info.vertex_shader_version; |
166 basic_gpu_info->max_msaa_samples = | 177 basic_gpu_info->max_msaa_samples = |
167 context_gpu_info.max_msaa_samples; | 178 context_gpu_info.max_msaa_samples; |
(...skipping 15 matching lines...) Expand all Loading... | |
183 basic_gpu_info->context_info_state = context_gpu_info.context_info_state; | 194 basic_gpu_info->context_info_state = context_gpu_info.context_info_state; |
184 basic_gpu_info->initialization_time = context_gpu_info.initialization_time; | 195 basic_gpu_info->initialization_time = context_gpu_info.initialization_time; |
185 basic_gpu_info->video_decode_accelerator_supported_profiles = | 196 basic_gpu_info->video_decode_accelerator_supported_profiles = |
186 context_gpu_info.video_decode_accelerator_supported_profiles; | 197 context_gpu_info.video_decode_accelerator_supported_profiles; |
187 basic_gpu_info->video_encode_accelerator_supported_profiles = | 198 basic_gpu_info->video_encode_accelerator_supported_profiles = |
188 context_gpu_info.video_encode_accelerator_supported_profiles; | 199 context_gpu_info.video_encode_accelerator_supported_profiles; |
189 basic_gpu_info->jpeg_decode_accelerator_supported = | 200 basic_gpu_info->jpeg_decode_accelerator_supported = |
190 context_gpu_info.jpeg_decode_accelerator_supported; | 201 context_gpu_info.jpeg_decode_accelerator_supported; |
191 } | 202 } |
192 | 203 |
204 void IdentifyActiveGPU(GPUInfo* gpu_info) { | |
205 const std::string kNVidiaName = "nvidia"; | |
206 const std::string kIntelName = "intel"; | |
207 const std::string kAMDName = "amd"; | |
208 const std::string kATIName = "ati"; | |
209 const std::string kVendorNames[] = { | |
210 kNVidiaName, kIntelName, kAMDName, kATIName}; | |
211 | |
212 const uint32 kNVidiaID = 0x10de; | |
213 const uint32 kIntelID = 0x8086; | |
214 const uint32 kAMDID = 0x1002; | |
215 const uint32 kATIID = 0x1002; | |
216 const uint32 kVendorIDs[] = { | |
217 kNVidiaID, kIntelID, kAMDID, kATIID}; | |
218 | |
219 DCHECK(gpu_info); | |
220 if (gpu_info->secondary_gpus.size() == 0) | |
221 return; | |
222 | |
223 uint32 active_vendor_id = 0; | |
224 if (!gpu_info->gl_vendor.empty()) { | |
225 std::string gl_vendor_lower = base::ToLowerASCII(gpu_info->gl_vendor); | |
226 for (size_t ii = 0; ii < arraysize(kVendorNames); ++ii) { | |
227 if (gl_vendor_lower.find(kVendorNames[ii]) != std::string::npos) { | |
228 active_vendor_id = kVendorIDs[ii]; | |
Ken Russell (switch to Gerrit)
2015/12/08 22:58:48
We need to be very careful here. "ati" is a substr
Zhenyao Mo
2015/12/09 18:36:53
Done.
| |
229 break; | |
230 } | |
231 } | |
232 } | |
233 if (active_vendor_id == 0 && !gpu_info->gl_renderer.empty()) { | |
234 std::string gl_renderer_lower = base::ToLowerASCII(gpu_info->gl_renderer); | |
235 for (size_t ii = 0; ii < arraysize(kVendorNames); ++ii) { | |
236 if (gl_renderer_lower.find(kVendorNames[ii]) != std::string::npos) { | |
237 active_vendor_id = kVendorIDs[ii]; | |
238 break; | |
239 } | |
240 } | |
241 } | |
242 if (active_vendor_id == 0) { | |
243 // We fail to idendify the GPU vendor through GL_VENDOR/GL_RENDERER. | |
244 return; | |
245 } | |
246 gpu_info->gpu.active = false; | |
247 for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii) | |
248 gpu_info->secondary_gpus[ii].active = false; | |
249 | |
250 // TODO(zmo): if two GPUs are from the same vendor, this code will always | |
251 // set the first GPU as active, which could be wrong. | |
252 if (active_vendor_id == gpu_info->gpu.vendor_id) { | |
253 gpu_info->gpu.active = true; | |
254 return; | |
255 } | |
256 for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii) { | |
257 if (active_vendor_id == gpu_info->secondary_gpus[ii].vendor_id) { | |
258 gpu_info->secondary_gpus[ii].active = true; | |
259 return; | |
260 } | |
261 } | |
262 } | |
263 | |
193 } // namespace gpu | 264 } // namespace gpu |
194 | 265 |
OLD | NEW |