[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 | |
| 5 | #include "content/gpu/gpu_info_collector.h" |
| 6 | |
| 7 | #include "base/logging.h" |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame^] | 8 | #include "base/string_number_conversions.h" |
| 9 | #include "base/string_piece.h" |
| 10 | #include "base/string_split.h" |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | std::string GetDriverVersionFromString(const std::string& version_string) { |
| 15 | // Extract driver version from the second number in a string like: |
| 16 | // "OpenGL ES 2.0 [email protected] AU@ (CL@2946718)" |
| 17 | |
| 18 | // Exclude first "2.0". |
| 19 | size_t begin = version_string.find_first_of("0123456789"); |
| 20 | if (begin == std::string::npos) |
| 21 | return "0"; |
| 22 | size_t end = version_string.find_first_not_of("01234567890.", begin); |
| 23 | |
| 24 | // Extract number of the form "%d.%d" |
| 25 | begin = version_string.find_first_of("0123456789", end); |
| 26 | if (begin == std::string::npos) |
| 27 | return "0"; |
| 28 | end = version_string.find_first_not_of("01234567890.", begin); |
| 29 | std::string sub_string; |
| 30 | if (end != std::string::npos) |
| 31 | sub_string = version_string.substr(begin, end - begin); |
| 32 | else |
| 33 | sub_string = version_string.substr(begin); |
| 34 | std::vector<std::string> pieces; |
| 35 | base::SplitString(sub_string, '.', &pieces); |
| 36 | if (pieces.size() < 2) |
| 37 | return "0"; |
| 38 | return pieces[0] + "." + pieces[1]; |
| 39 | } |
| 40 | |
| 41 | } |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 42 | |
| 43 | namespace gpu_info_collector { |
| 44 | |
| 45 | bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
| 46 | // can_lose_context must be false to enable accelerated Canvas2D |
| 47 | gpu_info->can_lose_context = false; |
| 48 | gpu_info->finalized = true; |
| 49 | return CollectGraphicsInfoGL(gpu_info); |
| 50 | } |
| 51 | |
| 52 | bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame^] | 53 | gpu_info->can_lose_context = false; |
| 54 | // Create a short-lived context on the UI thread to collect the GL strings. |
| 55 | return CollectGraphicsInfoGL(gpu_info); |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame^] | 63 | gpu_info->driver_version = GetDriverVersionFromString( |
| 64 | gpu_info->gl_version_string); |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 65 | return true; |
| 66 | } |
| 67 | |
| 68 | } // namespace gpu_info_collector |