0

Enable/disable WebView's ADPF usage based on device's SOC

We already do this for the Chrome app - let's make WebView consistent with the app.

Change-Id: I0c1a0cd9acd9af4f92dbb1b8d5dc195a6ba7b9c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5982572
Reviewed-by: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Reviewed-by: Bo Liu <boliu@chromium.org>
Commit-Queue: Igor Kraskevich <kraskevich@google.com>
Cr-Commit-Position: refs/heads/main@{#1391558}
This commit is contained in:
Igor Kraskevich
2024-12-04 10:07:41 +00:00
committed by Chromium LUCI CQ
parent 6f5df798f3
commit 8e90373bb8
5 changed files with 59 additions and 20 deletions
android_webview/browser/gfx
components/viz
common
service
performance_hint

@ -30,6 +30,7 @@
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/system/sys_info.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/features.h"
@ -609,11 +610,19 @@ HardwareRenderer::HardwareRenderer(RenderThreadManager* state,
AwVulkanContextProvider* context_provider)
: render_thread_manager_(state),
last_egl_context_(eglGetCurrentContext()),
output_surface_provider_(context_provider),
report_rendering_threads_(
base::FeatureList::IsEnabled(::features::kWebViewEnableADPF)) {
output_surface_provider_(context_provider) {
DCHECK_CALLED_ON_VALID_THREAD(render_thread_checker_);
if (base::FeatureList::IsEnabled(::features::kWebViewEnableADPF)) {
std::string soc_allowlist =
::features::kWebViewADPFSocManufacturerAllowlist.Get();
std::string soc_blocklist =
::features::kWebViewADPFSocManufacturerBlocklist.Get();
std::string soc = base::SysInfo::SocManufacturer();
report_rendering_threads_ =
::features::ShouldUseAdpfForSoc(soc_allowlist, soc_blocklist, soc);
}
VizCompositorThreadRunnerWebView::GetInstance()->ScheduleOnVizAndBlock(
base::BindOnce(&HardwareRenderer::InitializeOnViz, base::Unretained(this),
std::move(root_frame_sink_getter)));

@ -154,7 +154,7 @@ class HardwareRenderer {
// These are accessed on the viz thread.
std::unique_ptr<OnViz> on_viz_;
const bool report_rendering_threads_;
bool report_rendering_threads_ = false;
base::TimeDelta preferred_frame_interval_;
};

@ -6,11 +6,13 @@
#include <algorithm>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_split.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "components/viz/common/switches.h"
@ -174,12 +176,23 @@ BASE_FEATURE(kWebViewNewInvalidateHeuristic,
"WebViewNewInvalidateHeuristic",
base::FEATURE_DISABLED_BY_DEFAULT);
// If enabled, WebView reports the set of threads involved in frame production
// to HWUI, and they're included in the HWUI ADPF session.
// If enabled and the device's SOC manufacturer satisifes the allowlist and
// blocklist rules, WebView reports the set of threads involved in frame
// production to HWUI, and they're included in the HWUI ADPF session.
// If disabled, WebView never uses ADPF.
// The allowlist takes precedence - i.e. if the allowlist is non-empty, the
// soc must be in the allowlist for WebView to use ADPF, and the blocklist is
// ignored. If there's no allowlist, the soc must be absent from the blocklist.
BASE_FEATURE(kWebViewEnableADPF,
"WebViewEnableADPF",
base::FEATURE_DISABLED_BY_DEFAULT);
const base::FeatureParam<std::string> kWebViewADPFSocManufacturerAllowlist{
&kWebViewEnableADPF, "webview_soc_manufacturer_allowlist", "Google"};
const base::FeatureParam<std::string> kWebViewADPFSocManufacturerBlocklist{
&kWebViewEnableADPF, "webview_soc_manufacturer_blocklist", ""};
// If enabled, Renderer Main is included in the set of threads reported to the
// HWUI. This feature works only when WebViewEnableADPF is enabled, otherwise
// this is a no-op.
@ -672,6 +685,23 @@ bool IsBcivBottomControlsEnabled() {
bool IsBrowserControlsInVizEnabled() {
return base::FeatureList::IsEnabled(features::kAndroidBrowserControlsInViz);
}
bool ShouldUseAdpfForSoc(std::string_view soc_allowlist,
std::string_view soc_blocklist,
std::string_view soc) {
std::vector<std::string_view> allowlist = base::SplitStringPiece(
soc_allowlist, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
std::string blocklist_param = features::kADPFSocManufacturerBlocklist.Get();
std::vector<std::string_view> blocklist = base::SplitStringPiece(
soc_blocklist, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
// If there's no allowlist, soc must be absent from the blocklist.
if (allowlist.empty()) {
return !base::Contains(blocklist, soc);
}
// If there's an allowlist, soc must be in the allowlist.
// Blocklist is ignored in this case.
return base::Contains(allowlist, soc);
}
#endif // BUILDFLAG(IS_ANDROID)
} // namespace features

@ -73,6 +73,10 @@ VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kWebViewVulkanIntermediateBuffer);
#if BUILDFLAG(IS_ANDROID)
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kUseSurfaceLayerForVideoDefault);
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kWebViewEnableADPF);
VIZ_COMMON_EXPORT extern const base::FeatureParam<std::string>
kWebViewADPFSocManufacturerAllowlist;
VIZ_COMMON_EXPORT extern const base::FeatureParam<std::string>
kWebViewADPFSocManufacturerBlocklist;
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kWebViewEnableADPFRendererMain);
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kWebViewEnableADPFGpuMain);
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kWebViewFrameRateHints);
@ -181,6 +185,13 @@ VIZ_COMMON_EXPORT bool IsCrosContentAdjustedRefreshRateEnabled();
#if BUILDFLAG(IS_ANDROID)
VIZ_COMMON_EXPORT bool IsBcivBottomControlsEnabled();
VIZ_COMMON_EXPORT bool IsBrowserControlsInVizEnabled();
// If the allowlist is non-empty, the soc must be in the allowlist. Blocklist
// is ignored in this case.
// If the allowlist is empty, soc must be absent from the blocklist.
VIZ_COMMON_EXPORT bool ShouldUseAdpfForSoc(std::string_view soc_allowlist,
std::string_view soc_blocklist,
std::string_view soc);
#endif // BUILDFLAG(IS_ANDROID)
} // namespace features

@ -10,7 +10,6 @@
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_split.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "build/build_config.h"
@ -315,20 +314,10 @@ bool IsAdpfEnabled() {
return false;
}
std::string allowlist_param = features::kADPFSocManufacturerAllowlist.Get();
std::vector<std::string_view> allowlist = base::SplitStringPiece(
allowlist_param, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
std::string blocklist_param = features::kADPFSocManufacturerBlocklist.Get();
std::vector<std::string_view> blocklist = base::SplitStringPiece(
blocklist_param, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
std::string soc_allowlist = features::kADPFSocManufacturerAllowlist.Get();
std::string soc_blocklist = features::kADPFSocManufacturerBlocklist.Get();
std::string soc = base::SysInfo::SocManufacturer();
// If there's no allowlist, soc must be absent from the blocklist.
if (allowlist.empty()) {
return !base::Contains(blocklist, soc);
}
// If there's an allowlist, soc must be in the allowlist.
// Blocklist is ignored in this case.
return base::Contains(allowlist, soc);
return features::ShouldUseAdpfForSoc(soc_allowlist, soc_blocklist, soc);
}
} // namespace