OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/gpu/gpu_info_collector.h" | |
6 | |
7 #include "base/android/build_info.h" | |
8 #include "base/command_line.h" | |
9 #include "base/logging.h" | |
10 #include "base/string_number_conversions.h" | |
11 #include "base/string_util.h" | |
12 #include "base/strings/string_piece.h" | |
13 #include "base/strings/string_split.h" | |
14 | |
15 namespace { | |
16 | |
17 std::string GetDriverVersionFromString(const std::string& version_string) { | |
18 // Extract driver version from the second number in a string like: | |
19 // "OpenGL ES 2.0 V@6.0 AU@ (CL@2946718)" | |
20 | |
21 // Exclude first "2.0". | |
22 size_t begin = version_string.find_first_of("0123456789"); | |
23 if (begin == std::string::npos) | |
24 return "0"; | |
25 size_t end = version_string.find_first_not_of("01234567890.", begin); | |
26 | |
27 // Extract number of the form "%d.%d" | |
28 begin = version_string.find_first_of("0123456789", end); | |
29 if (begin == std::string::npos) | |
30 return "0"; | |
31 end = version_string.find_first_not_of("01234567890.", begin); | |
32 std::string sub_string; | |
33 if (end != std::string::npos) | |
34 sub_string = version_string.substr(begin, end - begin); | |
35 else | |
36 sub_string = version_string.substr(begin); | |
37 std::vector<std::string> pieces; | |
38 base::SplitString(sub_string, '.', &pieces); | |
39 if (pieces.size() < 2) | |
40 return "0"; | |
41 return pieces[0] + "." + pieces[1]; | |
42 } | |
43 | |
44 } | |
45 | |
46 namespace gpu_info_collector { | |
47 | |
48 bool CollectContextGraphicsInfo(content::GPUInfo* gpu_info) { | |
49 return CollectBasicGraphicsInfo(gpu_info); | |
50 } | |
51 | |
52 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { | |
53 DCHECK(vendor_id && device_id); | |
54 *vendor_id = 0; | |
55 *device_id = 0; | |
56 return kGpuIDNotSupported; | |
57 } | |
58 | |
59 bool CollectBasicGraphicsInfo(content::GPUInfo* gpu_info) { | |
60 gpu_info->can_lose_context = false; | |
61 gpu_info->finalized = true; | |
62 | |
63 gpu_info->machine_model = base::android::BuildInfo::GetInstance()->model(); | |
64 | |
65 // Create a short-lived context on the UI thread to collect the GL strings. | |
66 return CollectGraphicsInfoGL(gpu_info); | |
67 } | |
68 | |
69 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { | |
70 gpu_info->driver_version = GetDriverVersionFromString( | |
71 gpu_info->gl_version_string); | |
72 return true; | |
73 } | |
74 | |
75 void MergeGPUInfo(content::GPUInfo* basic_gpu_info, | |
76 const content::GPUInfo& context_gpu_info) { | |
77 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); | |
78 } | |
79 | |
80 } // namespace gpu_info_collector | |
OLD | NEW |