[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 | |
[email protected] | f34ffdf2 | 2012-12-15 00:41:27 | [diff] [blame^] | 7 | #include "base/command_line.h" |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 8 | #include "base/logging.h" |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 9 | #include "base/string_number_conversions.h" |
| 10 | #include "base/string_piece.h" |
| 11 | #include "base/string_split.h" |
[email protected] | f34ffdf2 | 2012-12-15 00:41:27 | [diff] [blame^] | 12 | #include "base/string_util.h" |
| 13 | #include "content/public/common/content_switches.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 | |
| 46 | namespace gpu_info_collector { |
| 47 | |
| 48 | bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
| 49 | // can_lose_context must be false to enable accelerated Canvas2D |
| 50 | gpu_info->can_lose_context = false; |
| 51 | gpu_info->finalized = true; |
| 52 | return CollectGraphicsInfoGL(gpu_info); |
| 53 | } |
| 54 | |
| 55 | bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 56 | gpu_info->can_lose_context = false; |
| 57 | // Create a short-lived context on the UI thread to collect the GL strings. |
[email protected] | f34ffdf2 | 2012-12-15 00:41:27 | [diff] [blame^] | 58 | if (!CollectGraphicsInfoGL(gpu_info)) |
| 59 | return false; |
| 60 | |
| 61 | std::string vendor(StringToLowerASCII(gpu_info->gl_vendor)); |
| 62 | std::string renderer(StringToLowerASCII(gpu_info->gl_renderer)); |
| 63 | bool is_img = vendor.find("imagination") != std::string::npos; |
| 64 | bool is_arm = vendor.find("arm") != std::string::npos; |
| 65 | bool is_mali_t604 = is_arm && renderer.find("mali-t604") != std::string::npos; |
| 66 | |
| 67 | // IMG: avoid context switching perf problems, crashes with share groups |
| 68 | // Mali-T604: http://crbug.com/154715 |
| 69 | if (is_img || is_mali_t604) { |
| 70 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 71 | switches::kEnableVirtualGLContexts); |
| 72 | } |
| 73 | return true; |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { |
[email protected] | bd4d2f73 | 2012-11-19 22:19:36 | [diff] [blame] | 81 | gpu_info->driver_version = GetDriverVersionFromString( |
| 82 | gpu_info->gl_version_string); |
[email protected] | 3b7efa4 | 2012-02-08 19:41:44 | [diff] [blame] | 83 | return true; |
| 84 | } |
| 85 | |
| 86 | } // namespace gpu_info_collector |