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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 else | 72 else |
72 sub_string = version_string.substr(begin); | 73 sub_string = version_string.substr(begin); |
73 std::vector<std::string> pieces = base::SplitString( | 74 std::vector<std::string> pieces = base::SplitString( |
74 sub_string, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 75 sub_string, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
75 if (pieces.size() >= 2) | 76 if (pieces.size() >= 2) |
76 return pieces[0] + "." + pieces[1]; | 77 return pieces[0] + "." + pieces[1]; |
77 } | 78 } |
78 return std::string(); | 79 return std::string(); |
79 } | 80 } |
80 | 81 |
82 // Return the array index of the found name, or return -1. | |
83 int StringContainsName( | |
84 const std::string& str, const std::string* names, size_t num_names) { | |
85 std::vector<std::string> tokens = base::SplitString( | |
86 str, " .,()-_", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
87 for (size_t ii = 0; ii < tokens.size(); ++ii) { | |
88 for (size_t name_index = 0; name_index < num_names; ++name_index) { | |
89 if (tokens[ii] == names[name_index]) | |
90 return name_index; | |
91 } | |
92 } | |
93 return -1; | |
94 } | |
95 | |
81 } // namespace anonymous | 96 } // namespace anonymous |
82 | 97 |
83 namespace gpu { | 98 namespace gpu { |
84 | 99 |
85 CollectInfoResult CollectGraphicsInfoGL(GPUInfo* gpu_info) { | 100 CollectInfoResult CollectGraphicsInfoGL(GPUInfo* gpu_info) { |
86 TRACE_EVENT0("startup", "gpu_info_collector::CollectGraphicsInfoGL"); | 101 TRACE_EVENT0("startup", "gpu_info_collector::CollectGraphicsInfoGL"); |
87 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); | 102 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); |
88 | 103 |
89 scoped_refptr<gfx::GLSurface> surface(InitializeGLSurface()); | 104 scoped_refptr<gfx::GLSurface> surface(InitializeGLSurface()); |
90 if (!surface.get()) { | 105 if (!surface.get()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 157 } |
143 | 158 |
144 // TODO(kbr): remove once the destruction of a current context automatically | 159 // TODO(kbr): remove once the destruction of a current context automatically |
145 // clears the current context. | 160 // clears the current context. |
146 context->ReleaseCurrent(surface.get()); | 161 context->ReleaseCurrent(surface.get()); |
147 | 162 |
148 std::string glsl_version = GetVersionFromString(glsl_version_string); | 163 std::string glsl_version = GetVersionFromString(glsl_version_string); |
149 gpu_info->pixel_shader_version = glsl_version; | 164 gpu_info->pixel_shader_version = glsl_version; |
150 gpu_info->vertex_shader_version = glsl_version; | 165 gpu_info->vertex_shader_version = glsl_version; |
151 | 166 |
167 IdentifyActiveGPU(gpu_info); | |
152 return CollectDriverInfoGL(gpu_info); | 168 return CollectDriverInfoGL(gpu_info); |
153 } | 169 } |
154 | 170 |
155 void MergeGPUInfoGL(GPUInfo* basic_gpu_info, | 171 void MergeGPUInfoGL(GPUInfo* basic_gpu_info, |
156 const GPUInfo& context_gpu_info) { | 172 const GPUInfo& context_gpu_info) { |
157 DCHECK(basic_gpu_info); | 173 DCHECK(basic_gpu_info); |
174 // Copy over GPUs because which one is active could change. | |
175 basic_gpu_info->gpu = context_gpu_info.gpu; | |
176 basic_gpu_info->secondary_gpus = context_gpu_info.secondary_gpus; | |
177 | |
158 basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer; | 178 basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer; |
159 basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor; | 179 basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor; |
160 basic_gpu_info->gl_version = context_gpu_info.gl_version; | 180 basic_gpu_info->gl_version = context_gpu_info.gl_version; |
161 basic_gpu_info->gl_extensions = context_gpu_info.gl_extensions; | 181 basic_gpu_info->gl_extensions = context_gpu_info.gl_extensions; |
162 basic_gpu_info->pixel_shader_version = | 182 basic_gpu_info->pixel_shader_version = |
163 context_gpu_info.pixel_shader_version; | 183 context_gpu_info.pixel_shader_version; |
164 basic_gpu_info->vertex_shader_version = | 184 basic_gpu_info->vertex_shader_version = |
165 context_gpu_info.vertex_shader_version; | 185 context_gpu_info.vertex_shader_version; |
166 basic_gpu_info->max_msaa_samples = | 186 basic_gpu_info->max_msaa_samples = |
167 context_gpu_info.max_msaa_samples; | 187 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; | 203 basic_gpu_info->context_info_state = context_gpu_info.context_info_state; |
184 basic_gpu_info->initialization_time = context_gpu_info.initialization_time; | 204 basic_gpu_info->initialization_time = context_gpu_info.initialization_time; |
185 basic_gpu_info->video_decode_accelerator_supported_profiles = | 205 basic_gpu_info->video_decode_accelerator_supported_profiles = |
186 context_gpu_info.video_decode_accelerator_supported_profiles; | 206 context_gpu_info.video_decode_accelerator_supported_profiles; |
187 basic_gpu_info->video_encode_accelerator_supported_profiles = | 207 basic_gpu_info->video_encode_accelerator_supported_profiles = |
188 context_gpu_info.video_encode_accelerator_supported_profiles; | 208 context_gpu_info.video_encode_accelerator_supported_profiles; |
189 basic_gpu_info->jpeg_decode_accelerator_supported = | 209 basic_gpu_info->jpeg_decode_accelerator_supported = |
190 context_gpu_info.jpeg_decode_accelerator_supported; | 210 context_gpu_info.jpeg_decode_accelerator_supported; |
191 } | 211 } |
192 | 212 |
213 void IdentifyActiveGPU(GPUInfo* gpu_info) { | |
214 const std::string kNVidiaName = "nvidia"; | |
215 const std::string kIntelName = "intel"; | |
216 const std::string kAMDName = "amd"; | |
217 const std::string kATIName = "ati"; | |
218 const std::string kVendorNames[] = { | |
219 kNVidiaName, kIntelName, kAMDName, kATIName}; | |
220 | |
221 const uint32 kNVidiaID = 0x10de; | |
222 const uint32 kIntelID = 0x8086; | |
223 const uint32 kAMDID = 0x1002; | |
224 const uint32 kATIID = 0x1002; | |
225 const uint32 kVendorIDs[] = { | |
226 kNVidiaID, kIntelID, kAMDID, kATIID}; | |
227 | |
228 DCHECK(gpu_info); | |
229 if (gpu_info->secondary_gpus.size() == 0) | |
230 return; | |
231 | |
232 uint32 active_vendor_id = 0; | |
233 if (!gpu_info->gl_vendor.empty()) { | |
234 std::string gl_vendor_lower = base::ToLowerASCII(gpu_info->gl_vendor); | |
235 int index = StringContainsName( | |
236 gl_vendor_lower, kVendorNames, arraysize(kVendorNames)); | |
237 if (index >= 0) { | |
238 active_vendor_id = kVendorIDs[index]; | |
239 } | |
240 } | |
241 if (active_vendor_id == 0 && !gpu_info->gl_renderer.empty()) { | |
242 std::string gl_renderer_lower = base::ToLowerASCII(gpu_info->gl_renderer); | |
243 int index = StringContainsName( | |
244 gl_renderer_lower, kVendorNames, arraysize(kVendorNames)); | |
245 if (index >= 0) { | |
246 active_vendor_id = kVendorIDs[index]; | |
247 } | |
248 } | |
249 if (active_vendor_id == 0) { | |
250 // We fail to idendify the GPU vendor through GL_VENDOR/GL_RENDERER. | |
Ken Russell (switch to Gerrit)
2015/12/09 21:05:12
typo: identify
| |
251 return; | |
252 } | |
253 gpu_info->gpu.active = false; | |
254 for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii) | |
255 gpu_info->secondary_gpus[ii].active = false; | |
256 | |
257 // TODO(zmo): if two GPUs are from the same vendor, this code will always | |
258 // set the first GPU as active, which could be wrong. | |
259 if (active_vendor_id == gpu_info->gpu.vendor_id) { | |
260 gpu_info->gpu.active = true; | |
261 return; | |
262 } | |
263 for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii) { | |
264 if (active_vendor_id == gpu_info->secondary_gpus[ii].vendor_id) { | |
265 gpu_info->secondary_gpus[ii].active = true; | |
266 return; | |
267 } | |
268 } | |
269 } | |
270 | |
193 } // namespace gpu | 271 } // namespace gpu |
194 | 272 |
OLD | NEW |