[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 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 | |||||
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 5 | #include "gpu/config/gpu_info_collector.h" |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 6 | |
[email protected] | 33eeba7b9 | 2013-02-06 01:47:03 | [diff] [blame] | 7 | #include "base/android/build_info.h" |
[email protected] | f34ffdf2 | 2012-12-15 00:41:27 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 9 | #include "base/logging.h" |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 10 | #include "base/string_number_conversions.h" |
[email protected] | f34ffdf2 | 2012-12-15 00:41:27 | [diff] [blame] | 11 | #include "base/string_util.h" |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 13 | #include "base/strings/string_split.h" |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 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 [email protected] 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 | } | ||||
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 45 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 46 | namespace gpu { |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 47 | |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 48 | bool CollectContextGraphicsInfo(GPUInfo* gpu_info) { |
[email protected] | 289126f | 2013-05-17 00:12:38 | [diff] [blame] | 49 | return CollectBasicGraphicsInfo(gpu_info); |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 50 | } |
51 | |||||
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 52 | GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { |
[email protected] | 12e74bb | 2013-02-07 22:08:44 | [diff] [blame] | 53 | DCHECK(vendor_id && device_id); |
54 | *vendor_id = 0; | ||||
55 | *device_id = 0; | ||||
[email protected] | b4ede660 | 2013-05-15 16:46:55 | [diff] [blame] | 56 | return kGpuIDNotSupported; |
[email protected] | 12e74bb | 2013-02-07 22:08:44 | [diff] [blame] | 57 | } |
58 | |||||
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 59 | bool CollectBasicGraphicsInfo(GPUInfo* gpu_info) { |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 60 | gpu_info->can_lose_context = false; |
[email protected] | 289126f | 2013-05-17 00:12:38 | [diff] [blame] | 61 | gpu_info->finalized = true; |
62 | |||||
63 | gpu_info->machine_model = base::android::BuildInfo::GetInstance()->model(); | ||||
64 | |||||
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 65 | // Create a short-lived context on the UI thread to collect the GL strings. |
[email protected] | 289126f | 2013-05-17 00:12:38 | [diff] [blame] | 66 | return CollectGraphicsInfoGL(gpu_info); |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 67 | } |
68 | |||||
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 69 | bool CollectDriverInfoGL(GPUInfo* gpu_info) { |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 70 | gpu_info->driver_version = GetDriverVersionFromString( |
71 | gpu_info->gl_version_string); | ||||
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 72 | return true; |
73 | } | ||||
74 | |||||
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 75 | void MergeGPUInfo(GPUInfo* basic_gpu_info, |
76 | const GPUInfo& context_gpu_info) { | ||||
[email protected] | 4df0884f | 2012-12-17 21:10:09 | [diff] [blame] | 77 | MergeGPUInfoGL(basic_gpu_info, context_gpu_info); |
78 | } | ||||
79 | |||||
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame^] | 80 | } // namespace gpu |