#include "gpu/config/gpu_finch_features.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "gpu/config/gpu_switches.h"
#include "ui/gl/gl_features.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/gl_utils.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/android_image_reader_compat.h"
#include "base/android/build_info.h"
#include "base/android/sys_utils.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/pattern.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "ui/gfx/android/android_surface_control_compat.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#include "base/system/sys_info.h"
#endif
namespace features {
namespace {
#if BUILDFLAG(IS_ANDROID)
bool IsDeviceBlocked(const char* field, const std::string& block_list) {
auto disable_patterns = base::SplitString(
block_list, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const auto& disable_pattern : disable_patterns) {
if (base::MatchPattern(field, disable_pattern))
return true;
}
return false;
}
#endif
}
BASE_FEATURE(…);
#if BUILDFLAG(IS_ANDROID)
BASE_FEATURE(kAndroidSurfaceControl,
"AndroidSurfaceControl",
base::FEATURE_ENABLED_BY_DEFAULT);
const base::FeatureParam<std::string> kAndroidSurfaceControlDeviceBlocklist{
&kAndroidSurfaceControl, "AndroidSurfaceControlDeviceBlocklist",
"capri|caprip"};
const base::FeatureParam<std::string> kAndroidSurfaceControlModelBlocklist{
&kAndroidSurfaceControl, "AndroidSurfaceControlModelBlocklist",
"SM-F9*|SM-W202?|SCV44|SCG05|SCG11|SC-55B"};
BASE_FEATURE(kWebViewSurfaceControl,
"WebViewSurfaceControl",
base::FEATURE_DISABLED_BY_DEFAULT);
BASE_FEATURE(kWebViewSurfaceControlForTV,
"WebViewSurfaceControlForTV",
base::FEATURE_DISABLED_BY_DEFAULT);
BASE_FEATURE(kWebViewThreadSafeMedia,
"WebViewThreadSafeMedia",
base::FEATURE_DISABLED_BY_DEFAULT);
BASE_FEATURE(kWebViewThreadSafeMediaDefault,
"WebViewThreadSafeMediaDefault",
base::FEATURE_DISABLED_BY_DEFAULT);
BASE_FEATURE(kAImageReader, "AImageReader", base::FEATURE_ENABLED_BY_DEFAULT);
BASE_FEATURE(kLimitAImageReaderMaxSizeToOne,
"LimitAImageReaderMaxSizeToOne",
base::FEATURE_ENABLED_BY_DEFAULT);
const base::FeatureParam<std::string> kLimitAImageReaderMaxSizeToOneBlocklist{
&kLimitAImageReaderMaxSizeToOne, "LimitAImageReaderMaxSizeToOneBlocklist",
"MIBOX|*ODROID*"};
BASE_FEATURE(kRelaxLimitAImageReaderMaxSizeToOne,
"RelaxLimitAImageReaderMaxSizeToOne",
base::FEATURE_ENABLED_BY_DEFAULT);
const base::FeatureParam<std::string>
kRelaxLimitAImageReaderMaxSizeToOneSoCBlocklist{
&kRelaxLimitAImageReaderMaxSizeToOne,
"RelaxLimitAImageReaderMaxSizeToOneSoCBlocklist", "*Broadcom*"};
const base::FeatureParam<std::string>
kRelaxLimitAImageReaderMaxSizeToOneManufacturerBlocklist{
&kRelaxLimitAImageReaderMaxSizeToOne,
"RelaxLimitAImageReaderMaxSizeToOneManufacturerBlocklist",
"*Broadcom*"};
const base::FeatureParam<std::string>
kRelaxLimitAImageReaderMaxSizeToOneDeviceBlocklist{
&kRelaxLimitAImageReaderMaxSizeToOne,
"RelaxLimitAImageReaderMaxSizeToOneDeviceBlocklist", ""};
const base::FeatureParam<std::string>
kRelaxLimitAImageReaderMaxSizeToOneModelBlocklist{
&kRelaxLimitAImageReaderMaxSizeToOne,
"RelaxLimitAImageReaderMaxSizeToOneModelBlocklist", ""};
BASE_FEATURE(kIncreaseBufferCountForHighFrameRate,
"IncreaseBufferCountForHighFrameRate",
base::FEATURE_ENABLED_BY_DEFAULT);
const base::FeatureParam<std::string>
kDisableIncreaseBufferCountForHighFrameRate{
&kIncreaseBufferCountForHighFrameRate,
"DisableIncreaseBufferCountForHighFrameRate", ""};
#endif
BASE_FEATURE(…);
#if !BUILDFLAG(IS_ANDROID)
BASE_FEATURE(…);
#endif
BASE_FEATURE(…);
BASE_FEATURE(…);
#if BUILDFLAG(IS_WIN)
BASE_FEATURE(kDisableVideoOverlayIfMoving,
"DisableVideoOverlayIfMoving",
base::FEATURE_ENABLED_BY_DEFAULT);
BASE_FEATURE(kNoUndamagedOverlayPromotion,
"NoUndamagedOverlayPromotion",
base::FEATURE_DISABLED_BY_DEFAULT);
#endif
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_IOS)
BASE_FEATURE(kAdjustGpuProcessPriority,
"AdjustGpuProcessPriority",
base::FEATURE_DISABLED_BY_DEFAULT);
#endif
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS) || \
BUILDFLAG(IS_ANDROID)
#define WEBGPU_ENABLED …
#else
#define WEBGPU_ENABLED …
#endif
BASE_FEATURE(…);
BASE_FEATURE(…);
#undef WEBGPU_ENABLED
const base::FeatureParam<std::string> kWebGPUUnsafeFeatures{ … };
const base::FeatureParam<std::string> kWGSLUnsafeFeatures{ … };
BASE_FEATURE(…);
BASE_FEATURE(…);
#if BUILDFLAG(IS_ANDROID)
const base::FeatureParam<std::string> kVulkanBlockListByHardware{
&kVulkan, "BlockListByHardware", ""};
const base::FeatureParam<std::string> kVulkanBlockListByBrand{
&kVulkan, "BlockListByBrand", ""};
const base::FeatureParam<std::string> kVulkanBlockListByDevice{
&kVulkan, "BlockListByDevice", ""};
const base::FeatureParam<std::string> kVulkanBlockListByAndroidBuildId{
&kVulkan, "BlockListByAndroidBuildId", ""};
const base::FeatureParam<std::string> kVulkanBlockListByManufacturer{
&kVulkan, "BlockListByManufacturer", ""};
const base::FeatureParam<std::string> kVulkanBlockListByModel{
&kVulkan, "BlockListByModel", ""};
const base::FeatureParam<std::string> kVulkanBlockListByBoard{
&kVulkan, "BlockListByBoard", ""};
const base::FeatureParam<std::string> kVulkanBlockListByAndroidBuildFP{
&kVulkan, "BlockListByAndroidBuildFP", ""};
const base::FeatureParam<std::string> kDrDcBlockListByDevice{
&kEnableDrDc, "BlockListByDevice",
"LF9810_2GB|amber|chopin|secret|a03|SO-51B|on7xelte|j7xelte|F41B|doha|"
"rk322x_box|a20s|HWMAR|HWSTK-HF|HWPOT-H|b2q|channel|galahad|a32|ellis|"
"dandelion|tonga|RMX3231|ASUS_I006D|ASUS_I004D|bacon"};
const base::FeatureParam<std::string> kDrDcBlockListByModel{
&kEnableDrDc, "BlockListByModel",
"SM-J400M|SM-J415F|ONEPLUS A3003|OCTAStream*"};
const base::FeatureParam<std::string> kDrDcBlockListByHardware{
&kEnableDrDc, "BlockListByHardware", ""};
const base::FeatureParam<std::string> kDrDcBlockListByBrand{
&kEnableDrDc, "BlockListByBrand", "HONOR"};
const base::FeatureParam<std::string> kDrDcBlockListByAndroidBuildId{
&kEnableDrDc, "BlockListByAndroidBuildId", ""};
const base::FeatureParam<std::string> kDrDcBlockListByManufacturer{
&kEnableDrDc, "BlockListByManufacturer", ""};
const base::FeatureParam<std::string> kDrDcBlockListByBoard{
&kEnableDrDc, "BlockListByBoard", ""};
const base::FeatureParam<std::string> kDrDcBlockListByAndroidBuildFP{
&kEnableDrDc, "BlockListByAndroidBuildFP", ""};
#endif
BASE_FEATURE(…);
BASE_FEATURE(…);
const base::FeatureParam<bool> kSkiaGraphiteDawnSkipValidation{ … };
const base::FeatureParam<bool> kSkiaGraphiteDawnBackendValidation{ … };
#if BUILDFLAG(IS_WIN)
BASE_FEATURE(kSkiaGraphiteDawnUseD3D12,
"SkiaGraphiteDawnUseD3D12",
base::FEATURE_DISABLED_BY_DEFAULT);
#endif
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
#if BUILDFLAG(IS_WIN)
BASE_FEATURE(kD3DBackingUploadWithUpdateSubresource,
"D3DBackingUploadWithUpdateSubresource",
base::FEATURE_ENABLED_BY_DEFAULT);
#endif
BASE_FEATURE(…);
bool UseGles2ForOopR() { … }
bool IsUsingVulkan() { … }
bool IsDrDcEnabled() { … }
bool IsUsingThreadSafeMediaForWebView() { … }
bool NeedThreadSafeAndroidMedia() { … }
namespace {
bool IsSkiaGraphiteSupportedByDevice(const base::CommandLine* command_line) { … }
}
bool IsSkiaGraphiteEnabled(const base::CommandLine* command_line) { … }
bool EnablePurgeGpuImageDecodeCache() { … }
bool EnablePruneOldTransferCacheEntries() { … }
bool IsCanvasOopRasterizationEnabled() { … }
#if BUILDFLAG(IS_ANDROID)
bool IsAImageReaderEnabled() {
if (IsDeviceBlocked(base::android::BuildInfo::GetInstance()->device(),
"Hammer_Energy_2")) {
return false;
}
return base::FeatureList::IsEnabled(kAImageReader) &&
base::android::EnableAndroidImageReader();
}
bool IsAndroidSurfaceControlEnabled() {
const auto* build_info = base::android::BuildInfo::GetInstance();
if (IsDeviceBlocked(build_info->device(),
kAndroidSurfaceControlDeviceBlocklist.Get()) ||
(IsDeviceBlocked(build_info->model(),
kAndroidSurfaceControlModelBlocklist.Get()) &&
build_info->sdk_int() <= base::android::SDK_VERSION_S)) {
return false;
}
if (!gfx::SurfaceControl::IsSupported())
return false;
if (!IsAImageReaderEnabled())
return false;
if (LimitAImageReaderMaxSizeToOne())
return false;
if (IsUsingThreadSafeMediaForWebView()) {
if (base::android::BuildInfo::GetInstance()->is_tv()) {
return base::FeatureList::IsEnabled(kWebViewSurfaceControlForTV);
} else {
return base::FeatureList::IsEnabled(kWebViewSurfaceControl);
}
}
return base::FeatureList::IsEnabled(kAndroidSurfaceControl);
}
bool LimitAImageReaderMaxSizeToOne() {
if (base::android::BuildInfo::GetInstance()->is_tv()) {
const auto* build_info = base::android::BuildInfo::GetInstance();
if (IsDeviceBlocked(
build_info->soc_manufacturer(),
kRelaxLimitAImageReaderMaxSizeToOneSoCBlocklist.Get())) {
return false;
}
if (IsDeviceBlocked(
build_info->manufacturer(),
kRelaxLimitAImageReaderMaxSizeToOneManufacturerBlocklist.Get())) {
return false;
}
if (IsDeviceBlocked(
build_info->device(),
kRelaxLimitAImageReaderMaxSizeToOneDeviceBlocklist.Get())) {
return false;
}
if (IsDeviceBlocked(
build_info->model(),
kRelaxLimitAImageReaderMaxSizeToOneModelBlocklist.Get())) {
return false;
}
return true;
}
return (IsDeviceBlocked(base::android::BuildInfo::GetInstance()->model(),
kLimitAImageReaderMaxSizeToOneBlocklist.Get()));
}
bool IncreaseBufferCountForHighFrameRate() {
constexpr int RAM_8GB_CUTOFF = 7200 * 1024;
static bool increase =
base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SdkVersion::SDK_VERSION_R &&
IsAndroidSurfaceControlEnabled() && IsAImageReaderEnabled() &&
base::android::SysUtils::AmountOfPhysicalMemoryKB() > RAM_8GB_CUTOFF &&
base::FeatureList::IsEnabled(kIncreaseBufferCountForHighFrameRate) &&
!IsDeviceBlocked(base::android::BuildInfo::GetInstance()->device(),
kDisableIncreaseBufferCountForHighFrameRate.Get());
return increase;
}
#endif
BASE_FEATURE(…);
bool IsSyncPointGraphValidationEnabled() { … }
}