gl_features.cc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2019 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 "ui/gl/gl_features.h"
  5. #include "base/command_line.h"
  6. #include "base/feature_list.h"
  7. #include "build/build_config.h"
  8. #include "build/chromecast_buildflags.h"
  9. #include "build/chromeos_buildflags.h"
  10. #include "ui/gl/gl_switches.h"
  11. #if BUILDFLAG(IS_MAC)
  12. #include "base/mac/mac_util.h"
  13. #endif
  14. #if BUILDFLAG(IS_ANDROID)
  15. #include "base/android/build_info.h"
  16. #include "base/metrics/field_trial_params.h"
  17. #include "base/strings/pattern.h"
  18. #include "base/strings/string_split.h"
  19. #include "ui/gfx/android/achoreographer_compat.h"
  20. #include "ui/gfx/android/android_surface_control_compat.h"
  21. #endif
  22. namespace features {
  23. namespace {
  24. const base::Feature kGpuVsync{"GpuVsync", base::FEATURE_ENABLED_BY_DEFAULT};
  25. #if BUILDFLAG(IS_ANDROID)
  26. const base::FeatureParam<std::string>
  27. kPassthroughCommandDecoderBlockListByBrand{
  28. &kDefaultPassthroughCommandDecoder, "BlockListByBrand", ""};
  29. const base::FeatureParam<std::string>
  30. kPassthroughCommandDecoderBlockListByDevice{
  31. &kDefaultPassthroughCommandDecoder, "BlockListByDevice", ""};
  32. const base::FeatureParam<std::string>
  33. kPassthroughCommandDecoderBlockListByAndroidBuildId{
  34. &kDefaultPassthroughCommandDecoder, "BlockListByAndroidBuildId", ""};
  35. const base::FeatureParam<std::string>
  36. kPassthroughCommandDecoderBlockListByManufacturer{
  37. &kDefaultPassthroughCommandDecoder, "BlockListByManufacturer", ""};
  38. const base::FeatureParam<std::string>
  39. kPassthroughCommandDecoderBlockListByModel{
  40. &kDefaultPassthroughCommandDecoder, "BlockListByModel", ""};
  41. const base::FeatureParam<std::string>
  42. kPassthroughCommandDecoderBlockListByBoard{
  43. &kDefaultPassthroughCommandDecoder, "BlockListByBoard", ""};
  44. const base::FeatureParam<std::string>
  45. kPassthroughCommandDecoderBlockListByAndroidBuildFP{
  46. &kDefaultPassthroughCommandDecoder, "BlockListByAndroidBuildFP", ""};
  47. bool IsDeviceBlocked(const char* field, const std::string& block_list) {
  48. auto disable_patterns = base::SplitString(
  49. block_list, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
  50. for (const auto& disable_pattern : disable_patterns) {
  51. if (base::MatchPattern(field, disable_pattern))
  52. return true;
  53. }
  54. return false;
  55. }
  56. #endif
  57. } // namespace
  58. #if BUILDFLAG(IS_ANDROID)
  59. const base::Feature kAndroidFrameDeadline{"AndroidFrameDeadline",
  60. base::FEATURE_DISABLED_BY_DEFAULT};
  61. #endif
  62. // Use the passthrough command decoder by default. This can be overridden with
  63. // the --use-cmd-decoder=passthrough or --use-cmd-decoder=validating flags.
  64. // Feature lives in ui/gl because it affects the GL binding initialization on
  65. // platforms that would otherwise not default to using EGL bindings.
  66. // Launched on Windows, still experimental on other platforms.
  67. const base::Feature kDefaultPassthroughCommandDecoder {
  68. "DefaultPassthroughCommandDecoder",
  69. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA) || \
  70. (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CASTOS)) || \
  71. BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC)
  72. base::FEATURE_ENABLED_BY_DEFAULT
  73. #else
  74. base::FEATURE_DISABLED_BY_DEFAULT
  75. #endif
  76. };
  77. bool UseGpuVsync() {
  78. return !base::CommandLine::ForCurrentProcess()->HasSwitch(
  79. switches::kDisableGpuVsync) &&
  80. base::FeatureList::IsEnabled(kGpuVsync);
  81. }
  82. bool IsAndroidFrameDeadlineEnabled() {
  83. #if BUILDFLAG(IS_ANDROID)
  84. static bool enabled =
  85. base::android::BuildInfo::GetInstance()->is_at_least_t() &&
  86. gfx::AChoreographerCompat33::Get().supported &&
  87. gfx::SurfaceControl::SupportsSetFrameTimeline() &&
  88. base::FeatureList::IsEnabled(kAndroidFrameDeadline);
  89. return enabled;
  90. #else
  91. return false;
  92. #endif
  93. }
  94. bool UsePassthroughCommandDecoder() {
  95. if (!base::FeatureList::IsEnabled(kDefaultPassthroughCommandDecoder))
  96. return false;
  97. #if BUILDFLAG(IS_ANDROID)
  98. // Check block list against build info.
  99. const auto* build_info = base::android::BuildInfo::GetInstance();
  100. if (IsDeviceBlocked(build_info->brand(),
  101. kPassthroughCommandDecoderBlockListByBrand.Get()))
  102. return false;
  103. if (IsDeviceBlocked(build_info->device(),
  104. kPassthroughCommandDecoderBlockListByDevice.Get()))
  105. return false;
  106. if (IsDeviceBlocked(
  107. build_info->android_build_id(),
  108. kPassthroughCommandDecoderBlockListByAndroidBuildId.Get()))
  109. return false;
  110. if (IsDeviceBlocked(build_info->manufacturer(),
  111. kPassthroughCommandDecoderBlockListByManufacturer.Get()))
  112. return false;
  113. if (IsDeviceBlocked(build_info->model(),
  114. kPassthroughCommandDecoderBlockListByModel.Get()))
  115. return false;
  116. if (IsDeviceBlocked(build_info->board(),
  117. kPassthroughCommandDecoderBlockListByBoard.Get()))
  118. return false;
  119. if (IsDeviceBlocked(
  120. build_info->android_build_fp(),
  121. kPassthroughCommandDecoderBlockListByAndroidBuildFP.Get()))
  122. return false;
  123. #endif // BUILDFLAG(IS_ANDROID)
  124. return true;
  125. }
  126. } // namespace features