Commit 8bbd0e69 authored by Fady Samuel's avatar Fady Samuel Committed by Commit Bot

Surface Synchronization: Avoid unnecessary LocalSurfaceId allocations

LocalSurfaceId allocations are expensive because they force a commit
and draw and could increase memory usage. On Android, we were allocating
a new parent LocalSurfaceId every time the child LocalSurfaceId changed
and blocking UI on the new parent LocalSurfaceId which does not make any
sense. Instead, we accept the LocalSurfaceId provided by the child and
embed it in the parent.

This improves Surface synchronization performance on Android substantially.

Before: https://pinpoint-dot-chromeperf.appspot.com/job/14c43963240000

After: https://pinpoint-dot-chromeperf.appspot.com/job/14e7a563240000

Change-Id: I46a85c6d718b97163c371adb169bc4a9d896c68a
Reviewed-on: https://chromium-review.googlesource.com/1105019Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSaman Sami <samans@chromium.org>
Commit-Queue: Fady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568590}
parent e104d494
......@@ -266,12 +266,20 @@ void RenderWidgetHostViewAndroid::InitAsFullscreen(
NOTIMPLEMENTED();
}
bool RenderWidgetHostViewAndroid::SynchronizeVisualProperties() {
bool RenderWidgetHostViewAndroid::SynchronizeVisualProperties(
const cc::DeadlinePolicy& deadline_policy,
const base::Optional<viz::LocalSurfaceId>&
child_allocated_local_surface_id) {
if (child_allocated_local_surface_id) {
local_surface_id_allocator_.UpdateFromChild(
*child_allocated_local_surface_id);
} else {
local_surface_id_allocator_.GenerateId();
}
if (delegated_frame_host_) {
delegated_frame_host_->EmbedSurface(
local_surface_id_allocator_.GenerateId(),
GetCompositorViewportPixelSize(),
cc::DeadlinePolicy::UseDefaultDeadline());
local_surface_id_allocator_.GetCurrentLocalSurfaceId(),
GetCompositorViewportPixelSize(), deadline_policy);
// TODO(ericrk): This can be removed once surface synchronization is
// enabled. https://crbug.com/835102
......@@ -819,7 +827,8 @@ void RenderWidgetHostViewAndroid::CopyFromSurface(
void RenderWidgetHostViewAndroid::EnsureSurfaceSynchronizedForLayoutTest() {
++latest_capture_sequence_number_;
SynchronizeVisualProperties();
SynchronizeVisualProperties(cc::DeadlinePolicy::UseInfiniteDeadline(),
base::nullopt);
}
uint32_t RenderWidgetHostViewAndroid::GetCaptureSequenceNumber() const {
......@@ -951,7 +960,8 @@ void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
}
bool RenderWidgetHostViewAndroid::RequestRepaintForTesting() {
return SynchronizeVisualProperties();
return SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
......@@ -1268,12 +1278,8 @@ void RenderWidgetHostViewAndroid::OnDidUpdateVisualPropertiesComplete(
base::ScopedClosureRunner sync_visual_props_runner(base::BindOnce(
base::IgnoreResult(
&RenderWidgetHostViewAndroid::SynchronizeVisualProperties),
base::Unretained(this)));
if (!local_surface_id_allocator_.UpdateFromChild(
metadata.local_surface_id.value_or(viz::LocalSurfaceId()))) {
return;
}
base::Unretained(this), cc::DeadlinePolicy::UseDefaultDeadline(),
metadata.local_surface_id));
if (!features::IsSurfaceSynchronizationEnabled())
return;
......@@ -1370,7 +1376,8 @@ void RenderWidgetHostViewAndroid::ShowInternal() {
if (delegated_frame_host_ &&
delegated_frame_host_->IsPrimarySurfaceEvicted()) {
SynchronizeVisualProperties();
SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
host()->WasShown(false /* record_presentation_time */);
......@@ -1975,8 +1982,10 @@ void RenderWidgetHostViewAndroid::UpdateNativeViewTree(
if (is_showing_ && view_.GetWindowAndroid())
StartObservingRootWindow();
if (resize)
SynchronizeVisualProperties();
if (resize) {
SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
if (!touch_selection_controller_) {
ui::TouchSelectionControllerClient* client =
......@@ -2067,7 +2076,8 @@ void RenderWidgetHostViewAndroid::OnSizeChanged() {
void RenderWidgetHostViewAndroid::OnPhysicalBackingSizeChanged() {
EvictFrameIfNecessary();
SynchronizeVisualProperties();
SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) {
......@@ -2344,7 +2354,8 @@ void RenderWidgetHostViewAndroid::TakeFallbackContentFrom(
}
void RenderWidgetHostViewAndroid::OnSynchronizedDisplayPropertiesChanged() {
SynchronizeVisualProperties();
SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
base::Optional<SkColor> RenderWidgetHostViewAndroid::GetBackgroundColor()
......@@ -2358,8 +2369,16 @@ void RenderWidgetHostViewAndroid::DidNavigate() {
return;
}
SynchronizeVisualProperties();
if (is_first_navigation_) {
SynchronizeVisualProperties(
cc::DeadlinePolicy::UseExistingDeadline(),
local_surface_id_allocator_.GetCurrentLocalSurfaceId());
} else {
SynchronizeVisualProperties(cc::DeadlinePolicy::UseExistingDeadline(),
base::nullopt);
}
delegated_frame_host_->DidNavigate();
is_first_navigation_ = false;
}
viz::ScopedSurfaceIdAllocator
......
......@@ -292,7 +292,9 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
void SetDoubleTapSupportEnabled(bool enabled);
void SetMultiTouchZoomSupportEnabled(bool enabled);
bool SynchronizeVisualProperties();
bool SynchronizeVisualProperties(const cc::DeadlinePolicy& deadline_policy,
const base::Optional<viz::LocalSurfaceId>&
child_allocated_local_surface_id);
bool HasValidFrame() const;
......@@ -507,6 +509,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
uint32_t latest_capture_sequence_number_ = 0u;
viz::ParentLocalSurfaceIdAllocator local_surface_id_allocator_;
bool is_first_navigation_ = true;
base::WeakPtrFactory<RenderWidgetHostViewAndroid> weak_ptr_factory_;
......
......@@ -842,7 +842,8 @@ void WebContentsAndroid::OnScaleFactorChanged(
if (rwhva) {
// |SendScreenRects()| indirectly calls GetViewSize() that asks Java layer.
web_contents_->SendScreenRects();
rwhva->SynchronizeVisualProperties();
rwhva->SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
}
......
......@@ -590,7 +590,8 @@ void WebContentsViewAndroid::OnSizeChanged() {
auto* rwhv = GetRenderWidgetHostViewAndroid();
if (rwhv) {
web_contents_->SendScreenRects();
rwhv->SynchronizeVisualProperties();
rwhv->SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
base::nullopt);
}
}
......
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