gpu_finch_features.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. // Copyright 2017 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. #include "gpu/config/gpu_finch_features.h"
  5. #include "base/command_line.h"
  6. #include "build/build_config.h"
  7. #include "build/chromeos_buildflags.h"
  8. #include "gpu/config/gpu_switches.h"
  9. #include "ui/gl/gl_features.h"
  10. #include "ui/gl/gl_surface_egl.h"
  11. #include "ui/gl/gl_utils.h"
  12. #if BUILDFLAG(IS_ANDROID)
  13. #include "base/android/android_image_reader_compat.h"
  14. #include "base/android/build_info.h"
  15. #include "base/android/sys_utils.h"
  16. #include "base/metrics/field_trial_params.h"
  17. #include "base/strings/pattern.h"
  18. #include "base/strings/string_split.h"
  19. #include "base/strings/string_util.h"
  20. #include "ui/gfx/android/android_surface_control_compat.h"
  21. #endif
  22. namespace features {
  23. namespace {
  24. #if BUILDFLAG(IS_ANDROID)
  25. bool FieldIsInBlocklist(const char* current_value, std::string blocklist_str) {
  26. std::vector<std::string> blocklist = base::SplitString(
  27. blocklist_str, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  28. for (const std::string& blocklisted_value : blocklist) {
  29. if (base::StartsWith(current_value, blocklisted_value,
  30. base::CompareCase::INSENSITIVE_ASCII)) {
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. bool IsDeviceBlocked(const char* field, const std::string& block_list) {
  37. auto disable_patterns = base::SplitString(
  38. block_list, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
  39. for (const auto& disable_pattern : disable_patterns) {
  40. if (base::MatchPattern(field, disable_pattern))
  41. return true;
  42. }
  43. return false;
  44. }
  45. #endif
  46. } // namespace
  47. // Used to limit GL version to 2.0 for skia raster and compositing.
  48. const base::Feature kUseGles2ForOopR {
  49. "UseGles2ForOopR",
  50. #if BUILDFLAG(IS_ANDROID)
  51. base::FEATURE_DISABLED_BY_DEFAULT
  52. #else
  53. base::FEATURE_ENABLED_BY_DEFAULT
  54. #endif
  55. };
  56. #if BUILDFLAG(IS_ANDROID)
  57. // Use android SurfaceControl API for managing display compositor's buffer queue
  58. // and using overlays on Android. Also used by webview to disable surface
  59. // SurfaceControl.
  60. const base::Feature kAndroidSurfaceControl{"AndroidSurfaceControl",
  61. base::FEATURE_ENABLED_BY_DEFAULT};
  62. // https://crbug.com/1176185 List of devices on which SurfaceControl should be
  63. // disabled.
  64. const base::FeatureParam<std::string> kAndroidSurfaceControlDeviceBlocklist{
  65. &kAndroidSurfaceControl, "AndroidSurfaceControlDeviceBlocklist",
  66. "capri|caprip"};
  67. // List of models on which SurfaceControl should be disabled.
  68. const base::FeatureParam<std::string> kAndroidSurfaceControlModelBlocklist{
  69. &kAndroidSurfaceControl, "AndroidSurfaceControlModelBlocklist",
  70. "SM-F9*|SM-W202?|SCV44|SCG05|SCG11|SC-55B"};
  71. // Hardware Overlays for WebView.
  72. const base::Feature kWebViewSurfaceControl{"WebViewSurfaceControl",
  73. base::FEATURE_DISABLED_BY_DEFAULT};
  74. // Same as kWebViewSurfaceControl, but affects only Android T+, used for
  75. // targeting pre-release version.
  76. const base::Feature kWebViewSurfaceControlForT{
  77. "WebViewSurfaceControlForT", base::FEATURE_DISABLED_BY_DEFAULT};
  78. // Use thread-safe media path on WebView.
  79. const base::Feature kWebViewThreadSafeMedia{"WebViewThreadSafeMedia",
  80. base::FEATURE_DISABLED_BY_DEFAULT};
  81. // This is used as default state because it's different for webview and chrome.
  82. // WebView hardcodes this as enabled in AwMainDelegate.
  83. const base::Feature kWebViewThreadSafeMediaDefault{
  84. "WebViewThreadSafeMediaDefault", base::FEATURE_DISABLED_BY_DEFAULT};
  85. // Use AImageReader for MediaCodec and MediaPlyer on android.
  86. const base::Feature kAImageReader{"AImageReader",
  87. base::FEATURE_ENABLED_BY_DEFAULT};
  88. // If webview-draw-functor-uses-vulkan is set, use vulkan for composite and
  89. // raster.
  90. const base::Feature kWebViewVulkan{"WebViewVulkan",
  91. base::FEATURE_ENABLED_BY_DEFAULT};
  92. // Used to limit AImageReader max queue size to 1 since many devices especially
  93. // android Tv devices do not support more than 1 images.
  94. const base::Feature kLimitAImageReaderMaxSizeToOne{
  95. "LimitAImageReaderMaxSizeToOne", base::FEATURE_ENABLED_BY_DEFAULT};
  96. // List of devices on which to limit AImageReader max queue size to 1.
  97. const base::FeatureParam<std::string> kLimitAImageReaderMaxSizeToOneBlocklist{
  98. &kLimitAImageReaderMaxSizeToOne, "LimitAImageReaderMaxSizeToOneBlocklist",
  99. "MIBOX"};
  100. // Increase number of buffers and pipeline depth for high frame rate devices.
  101. const base::Feature kIncreaseBufferCountForHighFrameRate{
  102. "IncreaseBufferCountForHighFrameRate", base::FEATURE_ENABLED_BY_DEFAULT};
  103. const base::FeatureParam<std::string>
  104. kDisableIncreaseBufferCountForHighFrameRate{
  105. &kIncreaseBufferCountForHighFrameRate,
  106. "DisableIncreaseBufferCountForHighFrameRate", ""};
  107. #endif
  108. // Enable GPU Rasterization by default. This can still be overridden by
  109. // --enable-gpu-rasterization or --disable-gpu-rasterization.
  110. // DefaultEnableGpuRasterization has launched on Mac, Windows, ChromeOS,
  111. // Android and Linux.
  112. const base::Feature kDefaultEnableGpuRasterization{
  113. "DefaultEnableGpuRasterization",
  114. #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS) || \
  115. BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || BUILDFLAG(IS_LINUX)
  116. base::FEATURE_ENABLED_BY_DEFAULT
  117. #else
  118. base::FEATURE_DISABLED_BY_DEFAULT
  119. #endif
  120. };
  121. // Enables the use of out of process rasterization for canvas.
  122. const base::Feature kCanvasOopRasterization {
  123. "CanvasOopRasterization",
  124. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH) || \
  125. (BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)) || BUILDFLAG(IS_FUCHSIA)
  126. base::FEATURE_ENABLED_BY_DEFAULT
  127. #else
  128. base::FEATURE_DISABLED_BY_DEFAULT
  129. #endif
  130. };
  131. // Enables the use of MSAA in skia on Ice Lake and later intel architectures.
  132. const base::Feature kEnableMSAAOnNewIntelGPUs{
  133. "EnableMSAAOnNewIntelGPUs", base::FEATURE_DISABLED_BY_DEFAULT};
  134. // Enables the use of ANGLE validation for non-WebGL contexts.
  135. const base::Feature kDefaultEnableANGLEValidation{
  136. "DefaultEnableANGLEValidation", base::FEATURE_DISABLED_BY_DEFAULT};
  137. // Enables canvas to free its resources by default when it's running in
  138. // the background.
  139. const base::Feature kCanvasContextLostInBackground{
  140. "CanvasContextLostInBackground", base::FEATURE_DISABLED_BY_DEFAULT};
  141. #if BUILDFLAG(IS_WIN)
  142. // Use a high priority for GPU process on Windows.
  143. const base::Feature kGpuProcessHighPriorityWin{
  144. "GpuProcessHighPriorityWin", base::FEATURE_ENABLED_BY_DEFAULT};
  145. // Disable overlay promotion for clear video quads when their MPO quad would
  146. // move.
  147. const base::Feature kDisableVideoOverlayIfMoving{
  148. "DisableVideoOverlayIfMoving", base::FEATURE_DISABLED_BY_DEFAULT};
  149. #endif
  150. #if BUILDFLAG(IS_MAC)
  151. // Enable use of Metal for OOP rasterization.
  152. const base::Feature kMetal{"Metal", base::FEATURE_DISABLED_BY_DEFAULT};
  153. #if defined(ARCH_CPU_ARM64)
  154. const base::Feature kDisableFlushWorkaroundForMacCrash{
  155. "DisableFlushWorkaroundForMacCrash", base::FEATURE_DISABLED_BY_DEFAULT};
  156. #endif
  157. #endif
  158. // Causes us to use the SharedImageManager, removing support for the old
  159. // mailbox system. Any consumers of the GPU process using the old mailbox
  160. // system will experience undefined results.
  161. const base::Feature kSharedImageManager{"SharedImageManager",
  162. base::FEATURE_DISABLED_BY_DEFAULT};
  163. // Controls the decode acceleration of JPEG images (as opposed to camera
  164. // captures) in Chrome OS using the VA-API.
  165. // TODO(andrescj): remove or enable by default in Chrome OS once
  166. // https://crbug.com/868400 is resolved.
  167. const base::Feature kVaapiJpegImageDecodeAcceleration{
  168. "VaapiJpegImageDecodeAcceleration", base::FEATURE_DISABLED_BY_DEFAULT};
  169. // Controls the decode acceleration of WebP images in Chrome OS using the
  170. // VA-API.
  171. // TODO(gildekel): remove or enable by default in Chrome OS once
  172. // https://crbug.com/877694 is resolved.
  173. const base::Feature kVaapiWebPImageDecodeAcceleration{
  174. "VaapiWebPImageDecodeAcceleration", base::FEATURE_DISABLED_BY_DEFAULT};
  175. // Enable Vulkan graphics backend for compositing and rasterization. Defaults to
  176. // native implementation if --use-vulkan flag is not used. Otherwise
  177. // --use-vulkan will be followed.
  178. // Note Android WebView uses kWebViewVulkan instead of this.
  179. const base::Feature kVulkan {
  180. "Vulkan",
  181. #if BUILDFLAG(IS_ANDROID)
  182. base::FEATURE_ENABLED_BY_DEFAULT
  183. #else
  184. base::FEATURE_DISABLED_BY_DEFAULT
  185. #endif
  186. };
  187. const base::Feature kEnableDrDc {
  188. "EnableDrDc",
  189. #if BUILDFLAG(IS_ANDROID)
  190. base::FEATURE_ENABLED_BY_DEFAULT
  191. #else
  192. base::FEATURE_DISABLED_BY_DEFAULT
  193. #endif
  194. };
  195. const base::Feature kForceGpuMainThreadToNormalPriorityDrDc{
  196. "ForceGpuMainThreadToNormalPriorityDrDc",
  197. base::FEATURE_DISABLED_BY_DEFAULT};
  198. #if BUILDFLAG(IS_ANDROID)
  199. const base::Feature kEnableDrDcVulkan{"EnableDrDcVulkan",
  200. base::FEATURE_DISABLED_BY_DEFAULT};
  201. #endif // BUILDFLAG(IS_ANDROID)
  202. // Enable WebGPU on gpu service side only. This is used with origin trial and
  203. // enabled by default on supported platforms.
  204. const base::Feature kWebGPUService {
  205. "WebGPUService",
  206. #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH)
  207. base::FEATURE_ENABLED_BY_DEFAULT
  208. #else
  209. base::FEATURE_DISABLED_BY_DEFAULT
  210. #endif
  211. };
  212. #if BUILDFLAG(IS_ANDROID)
  213. const base::FeatureParam<std::string> kVulkanBlockListByHardware{
  214. &kVulkan, "BlockListByHardware", "mt*"};
  215. const base::FeatureParam<std::string> kVulkanBlockListByBrand{
  216. &kVulkan, "BlockListByBrand", "HONOR"};
  217. const base::FeatureParam<std::string> kVulkanBlockListByDevice{
  218. &kVulkan, "BlockListByDevice", "OP4863|OP4883"};
  219. const base::FeatureParam<std::string> kVulkanBlockListByAndroidBuildId{
  220. &kVulkan, "BlockListByAndroidBuildId", ""};
  221. const base::FeatureParam<std::string> kVulkanBlockListByManufacturer{
  222. &kVulkan, "BlockListByManufacturer", ""};
  223. const base::FeatureParam<std::string> kVulkanBlockListByModel{
  224. &kVulkan, "BlockListByModel", ""};
  225. const base::FeatureParam<std::string> kVulkanBlockListByBoard{
  226. &kVulkan, "BlockListByBoard",
  227. "RM67*|RM68*|k68*|mt6*|oppo67*|oppo68*|QM215|rk30sdk"};
  228. const base::FeatureParam<std::string> kVulkanBlockListByAndroidBuildFP{
  229. &kVulkan, "BlockListByAndroidBuildFP", ""};
  230. // Blocklists meant for DrDc.
  231. // crbug.com/1294648
  232. const base::FeatureParam<std::string> kDrDcBlockListByDevice{
  233. &kEnableDrDc, "BlockListByDevice", "LF9810_2GB"};
  234. // crbug.com/1340059, crbug.com/1340064
  235. const base::FeatureParam<std::string> kDrDcBlockListByModel{
  236. &kEnableDrDc, "BlockListByModel",
  237. "SM-J400M|SM-J415F|ONEPLUS A3003|OCTAStream*"};
  238. const base::FeatureParam<std::string> kDrDcBlockListByHardware{
  239. &kEnableDrDc, "BlockListByHardware", ""};
  240. const base::FeatureParam<std::string> kDrDcBlockListByBrand{
  241. &kEnableDrDc, "BlockListByBrand", "HONOR"};
  242. const base::FeatureParam<std::string> kDrDcBlockListByAndroidBuildId{
  243. &kEnableDrDc, "BlockListByAndroidBuildId", ""};
  244. const base::FeatureParam<std::string> kDrDcBlockListByManufacturer{
  245. &kEnableDrDc, "BlockListByManufacturer", ""};
  246. const base::FeatureParam<std::string> kDrDcBlockListByBoard{
  247. &kEnableDrDc, "BlockListByBoard", ""};
  248. const base::FeatureParam<std::string> kDrDcBlockListByAndroidBuildFP{
  249. &kEnableDrDc, "BlockListByAndroidBuildFP", ""};
  250. #endif // BUILDFLAG(IS_ANDROID)
  251. // Enable SkiaRenderer Dawn graphics backend. On Windows this will use D3D12,
  252. // and on Linux this will use Vulkan.
  253. const base::Feature kSkiaDawn{"SkiaDawn", base::FEATURE_DISABLED_BY_DEFAULT};
  254. // Enable GrShaderCache to use with Vulkan backend.
  255. const base::Feature kEnableGrShaderCacheForVulkan{
  256. "EnableGrShaderCacheForVulkan", base::FEATURE_ENABLED_BY_DEFAULT};
  257. // Enable persistent storage of VkPipelineCache data.
  258. const base::Feature kEnableVkPipelineCache{"EnableVkPipelineCache",
  259. base::FEATURE_DISABLED_BY_DEFAULT};
  260. // Enable Skia reduceOpsTaskSplitting to reduce render passes.
  261. const base::Feature kReduceOpsTaskSplitting{
  262. "ReduceOpsTaskSplitting", base::FEATURE_DISABLED_BY_DEFAULT};
  263. // Enabling this will make the GPU decode path use a mock implementation of
  264. // discardable memory.
  265. const base::Feature kNoDiscardableMemoryForGpuDecodePath{
  266. "NoDiscardableMemoryForGpuDecodePath", base::FEATURE_DISABLED_BY_DEFAULT};
  267. // Use a 100-command limit before forcing context switch per command buffer
  268. // instead of 20.
  269. const base::Feature kIncreasedCmdBufferParseSlice{
  270. "IncreasedCmdBufferParseSlice", base::FEATURE_DISABLED_BY_DEFAULT};
  271. bool UseGles2ForOopR() {
  272. #if BUILDFLAG(IS_ANDROID)
  273. // GLS3 + passthrough decoder break many tests on Android.
  274. // TODO(crbug.com/1044287): use GLES3 with passthrough decoder.
  275. if (gl::UsePassthroughCommandDecoder(base::CommandLine::ForCurrentProcess()))
  276. return true;
  277. #endif
  278. return base::FeatureList::IsEnabled(features::kUseGles2ForOopR);
  279. }
  280. bool IsUsingVulkan() {
  281. #if BUILDFLAG(IS_ANDROID)
  282. // Force on if Vulkan feature is enabled from command line.
  283. base::FeatureList* feature_list = base::FeatureList::GetInstance();
  284. if (feature_list &&
  285. feature_list->IsFeatureOverriddenFromCommandLine(
  286. features::kVulkan.name, base::FeatureList::OVERRIDE_ENABLE_FEATURE))
  287. return true;
  288. // WebView checks, which do not use (and disables) kVulkan.
  289. // Do this above the Android version check because there are test devices
  290. if (base::CommandLine::ForCurrentProcess()->HasSwitch(
  291. switches::kWebViewDrawFunctorUsesVulkan) &&
  292. base::FeatureList::IsEnabled(kWebViewVulkan)) {
  293. return true;
  294. }
  295. // No support for devices before Q -- exit before checking feature flags
  296. // so that devices are not counted in finch trials.
  297. if (base::android::BuildInfo::GetInstance()->sdk_int() <
  298. base::android::SDK_VERSION_Q)
  299. return false;
  300. if (!base::FeatureList::IsEnabled(kVulkan))
  301. return false;
  302. // Check block list against build info.
  303. const auto* build_info = base::android::BuildInfo::GetInstance();
  304. if (IsDeviceBlocked(build_info->hardware(), kVulkanBlockListByHardware.Get()))
  305. return false;
  306. if (IsDeviceBlocked(build_info->brand(), kVulkanBlockListByBrand.Get()))
  307. return false;
  308. if (IsDeviceBlocked(build_info->device(), kVulkanBlockListByDevice.Get()))
  309. return false;
  310. if (IsDeviceBlocked(build_info->android_build_id(),
  311. kVulkanBlockListByAndroidBuildId.Get()))
  312. return false;
  313. if (IsDeviceBlocked(build_info->manufacturer(),
  314. kVulkanBlockListByManufacturer.Get()))
  315. return false;
  316. if (IsDeviceBlocked(build_info->model(), kVulkanBlockListByModel.Get()))
  317. return false;
  318. if (IsDeviceBlocked(build_info->board(), kVulkanBlockListByBoard.Get()))
  319. return false;
  320. if (IsDeviceBlocked(build_info->android_build_fp(),
  321. kVulkanBlockListByAndroidBuildFP.Get()))
  322. return false;
  323. return true;
  324. #else
  325. return base::FeatureList::IsEnabled(kVulkan);
  326. #endif
  327. }
  328. bool IsDrDcEnabled() {
  329. #if BUILDFLAG(IS_ANDROID)
  330. // Enabled on android P+.
  331. if (base::android::BuildInfo::GetInstance()->sdk_int() <
  332. base::android::SDK_VERSION_P) {
  333. return false;
  334. }
  335. // DrDc is supported on android MediaPlayer and MCVD path only when
  336. // AImageReader is enabled. Also DrDc requires AImageReader max size to be
  337. // at least 2 for each gpu thread. Hence DrDc is disabled on devices which has
  338. // only 1 image.
  339. if (!IsAImageReaderEnabled() || LimitAImageReaderMaxSizeToOne())
  340. return false;
  341. // Check block list against build info.
  342. const auto* build_info = base::android::BuildInfo::GetInstance();
  343. if (IsDeviceBlocked(build_info->device(), kDrDcBlockListByDevice.Get()))
  344. return false;
  345. if (IsDeviceBlocked(build_info->model(), kDrDcBlockListByModel.Get()))
  346. return false;
  347. if (IsDeviceBlocked(build_info->hardware(), kDrDcBlockListByHardware.Get()))
  348. return false;
  349. if (IsDeviceBlocked(build_info->brand(), kDrDcBlockListByBrand.Get()))
  350. return false;
  351. if (IsDeviceBlocked(build_info->android_build_id(),
  352. kDrDcBlockListByAndroidBuildId.Get()))
  353. return false;
  354. if (IsDeviceBlocked(build_info->manufacturer(),
  355. kDrDcBlockListByManufacturer.Get()))
  356. return false;
  357. if (IsDeviceBlocked(build_info->board(), kDrDcBlockListByBoard.Get()))
  358. return false;
  359. if (IsDeviceBlocked(build_info->android_build_fp(),
  360. kDrDcBlockListByAndroidBuildFP.Get()))
  361. return false;
  362. if (!base::FeatureList::IsEnabled(kEnableDrDc))
  363. return false;
  364. return IsUsingVulkan() ? base::FeatureList::IsEnabled(kEnableDrDcVulkan)
  365. : true;
  366. #else
  367. return false;
  368. #endif
  369. }
  370. bool IsGpuMainThreadForcedToNormalPriorityDrDc() {
  371. // GPU main thread priority is forced to NORMAL only when DrDc is enabled. In
  372. // that case DrDc thread continues to use DISPLAY thread priority and hence
  373. // have higher thread priority than GPU main.
  374. return IsDrDcEnabled() &&
  375. base::FeatureList::IsEnabled(kForceGpuMainThreadToNormalPriorityDrDc);
  376. }
  377. bool IsUsingThreadSafeMediaForWebView() {
  378. #if BUILDFLAG(IS_ANDROID)
  379. // SurfaceTexture can't be thread-safe. Also thread safe media code currently
  380. // requires AImageReader max size to be at least 2 since one image could be
  381. // accessed by each gpu thread in webview.
  382. if (!IsAImageReaderEnabled() || LimitAImageReaderMaxSizeToOne())
  383. return false;
  384. // If the feature is overridden from command line or finch we will use its
  385. // value. If not we use kWebViewThreadSafeMediaDefault which is set in
  386. // AwMainDelegate for WebView.
  387. base::FeatureList* feature_list = base::FeatureList::GetInstance();
  388. if (feature_list &&
  389. feature_list->IsFeatureOverridden(kWebViewThreadSafeMedia.name))
  390. return base::FeatureList::IsEnabled(kWebViewThreadSafeMedia);
  391. return base::FeatureList::IsEnabled(kWebViewThreadSafeMediaDefault);
  392. #else
  393. return false;
  394. #endif
  395. }
  396. bool NeedThreadSafeAndroidMedia() {
  397. return IsDrDcEnabled() || IsUsingThreadSafeMediaForWebView();
  398. }
  399. bool IsANGLEValidationEnabled() {
  400. return base::FeatureList::IsEnabled(kDefaultEnableANGLEValidation) &&
  401. UsePassthroughCommandDecoder();
  402. }
  403. #if BUILDFLAG(IS_ANDROID)
  404. bool IsAImageReaderEnabled() {
  405. // Device Hammer_Energy_2 seems to be very crash with image reader during
  406. // gl::GLImageEGL::BindTexImage(). Disable image reader on that device for
  407. // now. crbug.com/1323921
  408. if (IsDeviceBlocked(base::android::BuildInfo::GetInstance()->device(),
  409. "Hammer_Energy_2")) {
  410. return false;
  411. }
  412. return base::FeatureList::IsEnabled(kAImageReader) &&
  413. base::android::AndroidImageReader::GetInstance().IsSupported();
  414. }
  415. bool IsAndroidSurfaceControlEnabled() {
  416. const auto* build_info = base::android::BuildInfo::GetInstance();
  417. if (IsDeviceBlocked(build_info->device(),
  418. kAndroidSurfaceControlDeviceBlocklist.Get()) ||
  419. IsDeviceBlocked(build_info->model(),
  420. kAndroidSurfaceControlModelBlocklist.Get())) {
  421. return false;
  422. }
  423. if (!gfx::SurfaceControl::IsSupported())
  424. return false;
  425. // We can use surface control only with AImageReader.
  426. if (!IsAImageReaderEnabled())
  427. return false;
  428. // SurfaceControl requires at least 3 frames in flight.
  429. if (LimitAImageReaderMaxSizeToOne())
  430. return false;
  431. // On WebView we require thread-safe media to use SurfaceControl
  432. if (IsUsingThreadSafeMediaForWebView()) {
  433. // If main feature is not overridden from command line and we're running T+
  434. // use kWebViewSurfaceControlForT to decide feature status instead so we
  435. // can target pre-release android to fish out platform side bugs.
  436. base::FeatureList* feature_list = base::FeatureList::GetInstance();
  437. if ((!feature_list || !feature_list->IsFeatureOverriddenFromCommandLine(
  438. features::kWebViewSurfaceControl.name)) &&
  439. build_info->is_at_least_t()) {
  440. return base::FeatureList::IsEnabled(kWebViewSurfaceControlForT);
  441. }
  442. return base::FeatureList::IsEnabled(kWebViewSurfaceControl);
  443. }
  444. return base::FeatureList::IsEnabled(kAndroidSurfaceControl);
  445. }
  446. // Many devices do not support more than 1 image to be acquired from the
  447. // AImageReader.(crbug.com/1051705). This method returns true for those
  448. // devices. Currently the list of device model names are sent from server side
  449. // via a finch config file. There is a known device MIBOX for which max size
  450. // should be 1 irrespecticve of the feature LimitAImageReaderMaxSizeToOne
  451. // enabled or not. Get() returns default value even if the feature is disabled.
  452. bool LimitAImageReaderMaxSizeToOne() {
  453. // Always limit image reader to 1 frame for Android TV. Many TVs doesn't work
  454. // with more than 1 frame and it's very hard to localize which models do.
  455. if (base::android::BuildInfo::GetInstance()->is_tv())
  456. return true;
  457. return (FieldIsInBlocklist(base::android::BuildInfo::GetInstance()->model(),
  458. kLimitAImageReaderMaxSizeToOneBlocklist.Get()));
  459. }
  460. bool IncreaseBufferCountForHighFrameRate() {
  461. // TODO(crbug.com/1211332): We don't have a way to dynamically adjust number
  462. // of buffers. So these checks, espeically the RAM one, is to limit the impact
  463. // of more buffers to devices that can handle them.
  464. // 8GB of ram with large margin for error.
  465. constexpr int RAM_8GB_CUTOFF = 7200 * 1024;
  466. static bool increase =
  467. base::android::BuildInfo::GetInstance()->sdk_int() >=
  468. base::android::SdkVersion::SDK_VERSION_R &&
  469. IsAndroidSurfaceControlEnabled() && IsAImageReaderEnabled() &&
  470. base::android::SysUtils::AmountOfPhysicalMemoryKB() > RAM_8GB_CUTOFF &&
  471. base::FeatureList::IsEnabled(kIncreaseBufferCountForHighFrameRate) &&
  472. !IsDeviceBlocked(base::android::BuildInfo::GetInstance()->device(),
  473. kDisableIncreaseBufferCountForHighFrameRate.Get());
  474. return increase;
  475. }
  476. #endif
  477. } // namespace features