Commit 2fcd98ef authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

SurfaceSynchronization support for Android WebView

Ensures that Android WebView works with SurfaceSynchronization enabled.

For WebView, SurfaceSynchronization is nearly a no-op, as only one
surface is ever in use. This change only does two real things:
- Ensures that WebView uses RenderFrameMetadata rather than
CompositorFrameMetadata where appropriate.
- Ensures that SurfaceIds are correctly sent to the renderer for
WebView, allowing for rendering to occur.

Also removes previous disabling of WebView in tests.

Bug: 881469
Change-Id: If01ebc3be54eb90ca3aa196a464de693ad69bed5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570136Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarSaman Sami <samans@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652709}
parent 479f1f91
......@@ -19,13 +19,8 @@ constexpr char kProvider[] = "provider";
constexpr char kDrawQuad[] = "draw_quad";
constexpr char kSurfaceLayer[] = "surface_layer";
#if defined(USE_AURA) || defined(OS_MACOSX)
const base::Feature kEnableSurfaceSynchronization{
"SurfaceSynchronization", base::FEATURE_ENABLED_BY_DEFAULT};
#else
const base::Feature kEnableSurfaceSynchronization{
"SurfaceSynchronization", base::FEATURE_DISABLED_BY_DEFAULT};
#endif
// Enables running the display compositor as part of the viz service in the GPU
// process. This is also referred to as out-of-process display compositor
......
......@@ -194,6 +194,12 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
// layer is managed by the DelegatedFrameHost.
view_.SetLayer(cc::Layer::Create());
view_.set_event_handler(this);
// If we're showing at creation time, we won't get a visibility change, so
// generate our initial LocalSurfaceId here.
if (is_showing_)
local_surface_id_allocator_.GenerateId();
if (using_browser_compositor_) {
delegated_frame_host_client_ =
std::make_unique<DelegatedFrameHostClientAndroid>(this);
......@@ -202,7 +208,6 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
delegated_frame_host_client_.get(), host()->GetFrameSinkId(),
features::IsSurfaceSynchronizationEnabled());
if (is_showing_) {
local_surface_id_allocator_.GenerateId();
delegated_frame_host_->WasShown(
local_surface_id_allocator_.GetCurrentLocalSurfaceIdAllocation()
.local_surface_id(),
......@@ -1039,22 +1044,27 @@ void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
if (!view_.parent())
return;
bool is_mobile_optimized = IsMobileOptimizedFrame(
metadata.page_scale_factor, metadata.min_page_scale_factor,
metadata.max_page_scale_factor, metadata.scrollable_viewport_size,
metadata.root_layer_size);
// With SurfaceSynchronization, this logic happens during RenderFrameMetadata
// processing.
// TODO(ericrk): Remove this once surface synchronization feature is no
// longer optional.
if (!features::IsSurfaceSynchronizationEnabled()) {
bool is_mobile_optimized = IsMobileOptimizedFrame(
metadata.page_scale_factor, metadata.min_page_scale_factor,
metadata.max_page_scale_factor, metadata.scrollable_viewport_size,
metadata.root_layer_size);
if (host() && host()->input_router())
host()->input_router()->NotifySiteIsMobileOptimized(is_mobile_optimized);
if (host() && host()->input_router()) {
host()->input_router()->NotifySiteIsMobileOptimized(is_mobile_optimized);
// This is a subset of OnSwapCompositorFrame() used in the synchronous
// compositor flow.
OnFrameMetadataUpdated(metadata.Clone(), false);
}
if (host() && metadata.frame_token)
host()->DidProcessFrame(metadata.frame_token);
// This is a subset of OnSwapCompositorFrame() used in the synchronous
// compositor flow.
OnFrameMetadataUpdated(metadata.Clone(), false);
// DevTools ScreenCast support for Android WebView.
RenderFrameHost* frame_host = RenderViewHost::From(host())->GetMainFrame();
if (frame_host) {
......@@ -2025,9 +2035,6 @@ RenderWidgetHostViewAndroid::GetTouchSelectionControllerClientManager() {
const viz::LocalSurfaceIdAllocation&
RenderWidgetHostViewAndroid::GetLocalSurfaceIdAllocation() const {
if (!delegated_frame_host_)
return viz::ParentLocalSurfaceIdAllocator::
InvalidLocalSurfaceIdAllocation();
return local_surface_id_allocator_.GetCurrentLocalSurfaceIdAllocation();
}
......
......@@ -2008,6 +2008,14 @@ void RenderThreadImpl::RequestNewLayerTreeFrameSink(
if (GetContentClient()->UsingSynchronousCompositing()) {
RenderWidget* widget = RenderWidget::FromRoutingID(widget_routing_id);
if (widget) {
// TODO(ericrk): Remove this check when SurfaceSynchronization is always
// enabled, and collapse with non-webview registration below.
if (features::IsSurfaceSynchronizationEnabled()) {
frame_sink_provider_->RegisterRenderFrameMetadataObserver(
widget_routing_id,
std::move(render_frame_metadata_observer_client_request),
std::move(render_frame_metadata_observer_ptr));
}
std::move(callback).Run(std::make_unique<SynchronousLayerTreeFrameSink>(
std::move(context_provider), std::move(worker_context_provider),
compositor_task_runner_, GetGpuMemoryBufferManager(),
......
......@@ -109,12 +109,12 @@ class PerfBenchmark(benchmark.Benchmark):
browser_options.AppendExtraBrowserArgs(
'--disable-gpu-process-for-dx12-vulkan-info-collection')
# TODO(crbug.com/881469): remove this once Webview support surface
# synchronization and viz.
# TODO(crbug.com/881469): remove this once Webview supports
# VizDisplayCompositor.
if (browser_options.browser_type and
'android-webview' in browser_options.browser_type):
browser_options.AppendExtraBrowserArgs(
'--disable-features=SurfaceSynchronization,VizDisplayCompositor')
'--disable-features=VizDisplayCompositor')
# Switch Chrome to use Perfetto instead of TraceLog as the tracing backend,
# needed until the feature gets turned on by default everywhere.
......
......@@ -46,11 +46,11 @@ def _OptionsForBrowser(browser_type, finder_options):
finder_options.browser_executable = None
finder_options.browser_options.browser_type = browser_type
# TODO(crbug.com/881469): remove this once Webview support surface
# synchronization and viz.
# TODO(crbug.com/881469): remove this once Webview supports
# VizDisplayCompositor.
if browser_type and 'android-webview' in browser_type:
finder_options.browser_options.AppendExtraBrowserArgs(
'--disable-features=SurfaceSynchronization,VizDisplayCompositor')
'--disable-features=VizDisplayCompositor')
return finder_options
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment