forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu_info_collector_linux.cc
67 lines (53 loc) · 1.93 KB
/
gpu_info_collector_linux.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "base/trace_event/trace_event.h"
#include "gpu/config/gpu_info_collector.h"
#include "gpu/config/gpu_switches.h"
#include "third_party/angle/src/gpu_info_util/SystemInfo.h"
#include "third_party/re2/src/re2/re2.h"
namespace gpu {
bool CollectContextGraphicsInfo(GPUInfo* gpu_info) {
DCHECK(gpu_info);
TRACE_EVENT0("gpu", "gpu_info_collector::CollectGraphicsInfo");
return CollectGraphicsInfoGL(gpu_info);
}
bool CollectBasicGraphicsInfo(GPUInfo* gpu_info) {
DCHECK(gpu_info);
angle::SystemInfo system_info;
bool success = angle::GetSystemInfo(&system_info);
FillGPUInfoFromSystemInfo(gpu_info, &system_info);
return success;
}
void CollectDriverInfoGL(GPUInfo* gpu_info) {
DCHECK(gpu_info);
if (!gpu_info->driver_vendor.empty() && !gpu_info->driver_version.empty())
return;
std::string gl_version = gpu_info->gl_version;
std::vector<std::string> pieces = base::SplitString(
gl_version, base::kWhitespaceASCII, base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
// In linux, the gl version string might be in the format of
// GLVersion DriverVendor DriverVersion
if (pieces.size() < 3)
return;
// 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;
gpu_info->driver_vendor = *(++it);
gpu_info->driver_version = driver_version;
}
} // namespace gpu