Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: gpu/config/gpu_info_collector_linux.cc

Issue 2153373002: On Linux rework driver_version/vendor extraction from gl version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and only extract from gl_version if cannot use specifics Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_linux.h" 5 #include "gpu/config/gpu_info_collector_linux.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/string_tokenizer.h" 18 #include "base/strings/string_tokenizer.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
21 #include "gpu/config/gpu_info_collector.h" 21 #include "gpu/config/gpu_info_collector.h"
22 #include "third_party/re2/src/re2/re2.h"
22 #include "ui/gl/gl_bindings.h" 23 #include "ui/gl/gl_bindings.h"
23 #include "ui/gl/gl_context.h" 24 #include "ui/gl/gl_context.h"
24 #include "ui/gl/gl_implementation.h" 25 #include "ui/gl/gl_implementation.h"
25 #include "ui/gl/gl_surface.h" 26 #include "ui/gl/gl_surface.h"
26 #include "ui/gl/gl_switches.h" 27 #include "ui/gl/gl_switches.h"
27 28
28 #if defined(USE_LIBPCI) 29 #if defined(USE_LIBPCI)
29 #include "library_loaders/libpci.h" // nogncheck 30 #include "library_loaders/libpci.h" // nogncheck
30 #endif 31 #endif
31 32
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 break; 240 break;
240 } 241 }
241 242
242 gpu_info->basic_info_state = result; 243 gpu_info->basic_info_state = result;
243 return result; 244 return result;
244 } 245 }
245 246
246 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) { 247 CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) {
247 DCHECK(gpu_info); 248 DCHECK(gpu_info);
248 249
250 if (!gpu_info->driver_vendor.empty() && !gpu_info->driver_version.empty())
251 return kCollectInfoSuccess;
252
249 std::string gl_version = gpu_info->gl_version; 253 std::string gl_version = gpu_info->gl_version;
250 if (base::StartsWith(gl_version, "OpenGL ES", base::CompareCase::SENSITIVE))
251 gl_version = gl_version.substr(10);
252 std::vector<std::string> pieces = base::SplitString( 254 std::vector<std::string> pieces = base::SplitString(
253 gl_version, base::kWhitespaceASCII, base::KEEP_WHITESPACE, 255 gl_version, base::kWhitespaceASCII, base::KEEP_WHITESPACE,
254 base::SPLIT_WANT_NONEMPTY); 256 base::SPLIT_WANT_NONEMPTY);
255 // In linux, the gl version string might be in the format of 257 // In linux, the gl version string might be in the format of
256 // GLVersion DriverVendor DriverVersion 258 // GLVersion DriverVendor DriverVersion
257 if (pieces.size() < 3) 259 if (pieces.size() < 3)
258 return kCollectInfoNonFatalFailure; 260 return kCollectInfoNonFatalFailure;
259 261
260 std::string driver_version = pieces[2]; 262 // Search from the end for the first piece that starts with major.minor or
261 size_t pos = driver_version.find_first_not_of("0123456789."); 263 // major.minor.micro but assume the driver version cannot be in the first two
262 if (pos == 0) 264 // pieces.
265 re2::RE2 pattern("([\\d]+\\.[\\d]+(\\.[\\d]+)?).*");
266 std::string driver_version;
267 auto it = pieces.rbegin();
268 while (pieces.rend() - it > 2) {
269 bool parsed = re2::RE2::FullMatch(*it, pattern, &driver_version);
270 if (parsed)
271 break;
272 ++it;
273 }
274
275 if (driver_version.empty())
263 return kCollectInfoNonFatalFailure; 276 return kCollectInfoNonFatalFailure;
264 if (pos != std::string::npos)
265 driver_version = driver_version.substr(0, pos);
266 277
267 gpu_info->driver_vendor = pieces[1]; 278 gpu_info->driver_vendor = *(++it);
268 gpu_info->driver_version = driver_version; 279 gpu_info->driver_version = driver_version;
269 return kCollectInfoSuccess; 280 return kCollectInfoSuccess;
270 } 281 }
271 282
272 void MergeGPUInfo(GPUInfo* basic_gpu_info, 283 void MergeGPUInfo(GPUInfo* basic_gpu_info,
273 const GPUInfo& context_gpu_info) { 284 const GPUInfo& context_gpu_info) {
274 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); 285 MergeGPUInfoGL(basic_gpu_info, context_gpu_info);
275 } 286 }
276 287
277 } // namespace gpu 288 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698