| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/gpu/gpu_info_collector.h" | 5 #include "content/gpu/gpu_info_collector.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "cc/base/switches.h" | |
| 15 #include "content/public/common/content_switches.h" | |
| 16 #include "ui/gfx/android/device_display_info.h" | |
| 17 | 14 |
| 18 namespace { | 15 namespace { |
| 19 | 16 |
| 20 std::string GetDriverVersionFromString(const std::string& version_string) { | 17 std::string GetDriverVersionFromString(const std::string& version_string) { |
| 21 // Extract driver version from the second number in a string like: | 18 // Extract driver version from the second number in a string like: |
| 22 // "OpenGL ES 2.0 V@6.0 AU@ (CL@2946718)" | 19 // "OpenGL ES 2.0 V@6.0 AU@ (CL@2946718)" |
| 23 | 20 |
| 24 // Exclude first "2.0". | 21 // Exclude first "2.0". |
| 25 size_t begin = version_string.find_first_of("0123456789"); | 22 size_t begin = version_string.find_first_of("0123456789"); |
| 26 if (begin == std::string::npos) | 23 if (begin == std::string::npos) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 if (pieces.size() < 2) | 39 if (pieces.size() < 2) |
| 43 return "0"; | 40 return "0"; |
| 44 return pieces[0] + "." + pieces[1]; | 41 return pieces[0] + "." + pieces[1]; |
| 45 } | 42 } |
| 46 | 43 |
| 47 } | 44 } |
| 48 | 45 |
| 49 namespace gpu_info_collector { | 46 namespace gpu_info_collector { |
| 50 | 47 |
| 51 bool CollectContextGraphicsInfo(content::GPUInfo* gpu_info) { | 48 bool CollectContextGraphicsInfo(content::GPUInfo* gpu_info) { |
| 52 // can_lose_context must be false to enable accelerated Canvas2D | 49 return CollectBasicGraphicsInfo(gpu_info); |
| 53 gpu_info->can_lose_context = false; | |
| 54 gpu_info->finalized = true; | |
| 55 return CollectGraphicsInfoGL(gpu_info); | |
| 56 } | 50 } |
| 57 | 51 |
| 58 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { | 52 GpuIDResult CollectGpuID(uint32* vendor_id, uint32* device_id) { |
| 59 DCHECK(vendor_id && device_id); | 53 DCHECK(vendor_id && device_id); |
| 60 *vendor_id = 0; | 54 *vendor_id = 0; |
| 61 *device_id = 0; | 55 *device_id = 0; |
| 62 return kGpuIDNotSupported; | 56 return kGpuIDNotSupported; |
| 63 } | 57 } |
| 64 | 58 |
| 65 bool CollectBasicGraphicsInfo(content::GPUInfo* gpu_info) { | 59 bool CollectBasicGraphicsInfo(content::GPUInfo* gpu_info) { |
| 66 gpu_info->can_lose_context = false; | 60 gpu_info->can_lose_context = false; |
| 61 gpu_info->finalized = true; |
| 62 |
| 63 gpu_info->machine_model = base::android::BuildInfo::GetInstance()->model(); |
| 64 |
| 67 // Create a short-lived context on the UI thread to collect the GL strings. | 65 // Create a short-lived context on the UI thread to collect the GL strings. |
| 68 if (!CollectGraphicsInfoGL(gpu_info)) | 66 return CollectGraphicsInfoGL(gpu_info); |
| 69 return false; | |
| 70 | |
| 71 std::string vendor(StringToLowerASCII(gpu_info->gl_vendor)); | |
| 72 std::string renderer(StringToLowerASCII(gpu_info->gl_renderer)); | |
| 73 bool is_img = vendor.find("imagination") != std::string::npos; | |
| 74 bool is_arm = vendor.find("arm") != std::string::npos; | |
| 75 bool is_qualcomm = vendor.find("qualcomm") != std::string::npos; | |
| 76 bool is_mali_t604 = is_arm && renderer.find("mali-t604") != std::string::npos; | |
| 77 bool is_vivante = vendor.find("vivante") != std::string::npos; | |
| 78 is_vivante |= vendor.find("hisilicon") != std::string::npos; | |
| 79 | |
| 80 base::android::BuildInfo* build_info = | |
| 81 base::android::BuildInfo::GetInstance(); | |
| 82 std::string model = build_info->model(); | |
| 83 model = StringToLowerASCII(model); | |
| 84 bool is_nexus7 = model.find("nexus 7") != std::string::npos; | |
| 85 bool is_nexus10 = model.find("nexus 10") != std::string::npos; | |
| 86 | |
| 87 // IMG: avoid context switching perf problems, crashes with share groups | |
| 88 // Mali-T604: http://crbug.com/154715 | |
| 89 // QualComm, NVIDIA: Crashes with share groups | |
| 90 if (is_vivante || is_img || is_mali_t604 || is_nexus7 || is_qualcomm) { | |
| 91 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 92 switches::kEnableVirtualGLContexts); | |
| 93 } | |
| 94 | |
| 95 gfx::DeviceDisplayInfo info; | |
| 96 int default_tile_size = 256; | |
| 97 | |
| 98 // For very high resolution displays (eg. Nexus 10), set the default | |
| 99 // tile size to be 512. This should be removed in favour of a generic | |
| 100 // hueristic that works across all platforms and devices, once that | |
| 101 // exists: http://crbug.com/159524. This switches to 512 for screens | |
| 102 // containing 40 or more 256x256 tiles, such that 1080p devices do | |
| 103 // not use 512x512 tiles (eg. 1920x1280 requires 37.5 tiles) | |
| 104 int numTiles = (info.GetDisplayWidth() * | |
| 105 info.GetDisplayHeight()) / (256 * 256); | |
| 106 if (numTiles >= 40) | |
| 107 default_tile_size = 512; | |
| 108 | |
| 109 // IMG: Fast async texture uploads only work with non-power-of-two, | |
| 110 // but still multiple-of-eight sizes. | |
| 111 // http://crbug.com/168099 | |
| 112 if (is_img) | |
| 113 default_tile_size -= 8; | |
| 114 | |
| 115 // Set the command line if it isn't already set and we changed | |
| 116 // the default tile size. | |
| 117 if (default_tile_size != 256 && | |
| 118 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 119 switches::kDefaultTileWidth) && | |
| 120 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 121 switches::kDefaultTileHeight)) { | |
| 122 std::stringstream size; | |
| 123 size << default_tile_size; | |
| 124 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 125 switches::kDefaultTileWidth, size.str()); | |
| 126 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 127 switches::kDefaultTileHeight, size.str()); | |
| 128 } | |
| 129 | |
| 130 // Increase the resolution of low resolution tiles for Nexus tablets. | |
| 131 if ((is_nexus7 || is_nexus10) && | |
| 132 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 133 cc::switches::kLowResolutionContentsScaleFactor)) { | |
| 134 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 135 cc::switches::kLowResolutionContentsScaleFactor, "0.25"); | |
| 136 } | |
| 137 | |
| 138 return true; | |
| 139 } | 67 } |
| 140 | 68 |
| 141 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { | 69 bool CollectDriverInfoGL(content::GPUInfo* gpu_info) { |
| 142 gpu_info->driver_version = GetDriverVersionFromString( | 70 gpu_info->driver_version = GetDriverVersionFromString( |
| 143 gpu_info->gl_version_string); | 71 gpu_info->gl_version_string); |
| 144 return true; | 72 return true; |
| 145 } | 73 } |
| 146 | 74 |
| 147 void MergeGPUInfo(content::GPUInfo* basic_gpu_info, | 75 void MergeGPUInfo(content::GPUInfo* basic_gpu_info, |
| 148 const content::GPUInfo& context_gpu_info) { | 76 const content::GPUInfo& context_gpu_info) { |
| 149 MergeGPUInfoGL(basic_gpu_info, context_gpu_info); | 77 // CollectBasicGraphicsInfo collects all the needed info, |
| 78 // so no need to merge here. |
| 79 return; |
| 150 } | 80 } |
| 151 | 81 |
| 152 } // namespace gpu_info_collector | 82 } // namespace gpu_info_collector |
| OLD | NEW |