Index: gpu/config/gpu_info_collector_linux.cc |
diff --git a/gpu/config/gpu_info_collector_linux.cc b/gpu/config/gpu_info_collector_linux.cc |
index 050c33d246d391afb8edea0fbd0ed753fdd4c8ee..1f380474f792e134d7f7589418e34ebc9a65e220 100644 |
--- a/gpu/config/gpu_info_collector_linux.cc |
+++ b/gpu/config/gpu_info_collector_linux.cc |
@@ -19,6 +19,8 @@ |
#include "base/strings/string_util.h" |
#include "base/trace_event/trace_event.h" |
#include "gpu/config/gpu_info_collector.h" |
+#include "gpu/config/gpu_switches.h" |
+#include "third_party/re2/src/re2/re2.h" |
#include "ui/gl/gl_bindings.h" |
#include "ui/gl/gl_context.h" |
#include "ui/gl/gl_implementation.h" |
@@ -246,9 +248,15 @@ CollectInfoResult CollectBasicGraphicsInfo(GPUInfo* gpu_info) { |
CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) { |
DCHECK(gpu_info); |
+ // Driver vendor and version are always expected to be extracted from the |
+ // testing gl version. |
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kGpuTestingGLVersion) && |
+ !gpu_info->driver_vendor.empty() && !gpu_info->driver_version.empty()) { |
+ return kCollectInfoSuccess; |
+ } |
+ |
std::string gl_version = gpu_info->gl_version; |
- if (base::StartsWith(gl_version, "OpenGL ES", base::CompareCase::SENSITIVE)) |
- gl_version = gl_version.substr(10); |
std::vector<std::string> pieces = base::SplitString( |
gl_version, base::kWhitespaceASCII, base::KEEP_WHITESPACE, |
base::SPLIT_WANT_NONEMPTY); |
@@ -257,14 +265,23 @@ CollectInfoResult CollectDriverInfoGL(GPUInfo* gpu_info) { |
if (pieces.size() < 3) |
return kCollectInfoNonFatalFailure; |
- std::string driver_version = pieces[2]; |
- size_t pos = driver_version.find_first_not_of("0123456789."); |
- if (pos == 0) |
+ // Search from the end for the first piece that starts with major.minor or |
+ // major.minor.micro but assume the driver version cannot be in the first two |
+ // pieces. |
+ re2::RE2 pattern("([\\d]+\\.[\\d]+(\\.[\\d]+)?).*"); |
+ std::string driver_version; |
+ auto it = pieces.rbegin(); |
+ while (pieces.rend() - it > 2) { |
+ bool parsed = re2::RE2::FullMatch(*it, pattern, &driver_version); |
+ if (parsed) |
+ break; |
+ ++it; |
+ } |
+ |
+ if (driver_version.empty()) |
return kCollectInfoNonFatalFailure; |
- if (pos != std::string::npos) |
- driver_version = driver_version.substr(0, pos); |
- gpu_info->driver_vendor = pieces[1]; |
+ gpu_info->driver_vendor = *(++it); |
gpu_info->driver_version = driver_version; |
return kCollectInfoSuccess; |
} |