blob: 905fedf8d80157c0076ebb5fdf55cfff69681c09 [file] [log] [blame]
[email protected]3b7efa42012-02-08 19:41:441// 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]d7b5cc72013-05-23 20:05:005#include "gpu/config/gpu_info_collector.h"
[email protected]3b7efa42012-02-08 19:41:446
[email protected]33eeba7b92013-02-06 01:47:037#include "base/android/build_info.h"
[email protected]f34ffdf22012-12-15 00:41:278#include "base/command_line.h"
[email protected]3b7efa42012-02-08 19:41:449#include "base/logging.h"
[email protected]bd4d2f732012-11-19 22:19:3610#include "base/string_number_conversions.h"
[email protected]f34ffdf22012-12-15 00:41:2711#include "base/string_util.h"
[email protected]b9e7c479f2013-04-12 04:33:2412#include "base/strings/string_piece.h"
[email protected]27c05732013-02-15 21:55:4913#include "base/strings/string_split.h"
[email protected]bd4d2f732012-11-19 22:19:3614
15namespace {
16
17std::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]3b7efa42012-02-08 19:41:4445
[email protected]d7b5cc72013-05-23 20:05:0046namespace gpu {
[email protected]3b7efa42012-02-08 19:41:4447
[email protected]d7b5cc72013-05-23 20:05:0048bool CollectContextGraphicsInfo(GPUInfo* gpu_info) {
[email protected]289126f2013-05-17 00:12:3849 return CollectBasicGraphicsInfo(gpu_info);
[email protected]3b7efa42012-02-08 19:41:4450}
51
[email protected]b4ede6602013-05-15 16:46:5552GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) {
[email protected]12e74bb2013-02-07 22:08:4453 DCHECK(vendor_id && device_id);
54 *vendor_id = 0;
55 *device_id = 0;
[email protected]b4ede6602013-05-15 16:46:5556 return kGpuIDNotSupported;
[email protected]12e74bb2013-02-07 22:08:4457}
58
[email protected]d7b5cc72013-05-23 20:05:0059bool CollectBasicGraphicsInfo(GPUInfo* gpu_info) {
[email protected]bd4d2f732012-11-19 22:19:3660 gpu_info->can_lose_context = false;
[email protected]289126f2013-05-17 00:12:3861 gpu_info->finalized = true;
62
63 gpu_info->machine_model = base::android::BuildInfo::GetInstance()->model();
64
[email protected]bd4d2f732012-11-19 22:19:3665 // Create a short-lived context on the UI thread to collect the GL strings.
[email protected]289126f2013-05-17 00:12:3866 return CollectGraphicsInfoGL(gpu_info);
[email protected]3b7efa42012-02-08 19:41:4467}
68
[email protected]d7b5cc72013-05-23 20:05:0069bool CollectDriverInfoGL(GPUInfo* gpu_info) {
[email protected]bd4d2f732012-11-19 22:19:3670 gpu_info->driver_version = GetDriverVersionFromString(
71 gpu_info->gl_version_string);
[email protected]3b7efa42012-02-08 19:41:4472 return true;
73}
74
[email protected]d7b5cc72013-05-23 20:05:0075void MergeGPUInfo(GPUInfo* basic_gpu_info,
76 const GPUInfo& context_gpu_info) {
[email protected]4df0884f2012-12-17 21:10:0977 MergeGPUInfoGL(basic_gpu_info, context_gpu_info);
78}
79
[email protected]d7b5cc72013-05-23 20:05:0080} // namespace gpu