Commit 5479bee2 authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Surface Synchronization: Enable by default on Android

Surface synchronization has launched on desktop but has not shipped
on Android yet. We'd like to attempt to launch it soon. This CL turns
on surface sync by default on bots on Android.

Bug: 672962
Change-Id: I24e8eda65a090d16aa349167e7b805be924bae1d
Reviewed-on: https://chromium-review.googlesource.com/1162438
Commit-Queue: Fady Samuel <fsamuel@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586039}
parent c9437e66
......@@ -392,7 +392,7 @@ void RenderWidgetHostViewAndroid::OnRenderFrameMetadataChangedBeforeActivation(
float top_content_offset_dip = IsUseZoomForDSFEnabled()
? top_content_offset / dip_scale
: top_content_offset;
view_.UpdateFrameInfo({scrollable_viewport_size_dip, top_content_offset});
view_.UpdateFrameInfo({scrollable_viewport_size_dip, top_content_offset_dip});
bool controls_changed = UpdateControls(
view_.GetDipScale(), metadata.top_controls_height,
metadata.top_controls_shown_ratio, metadata.bottom_controls_height,
......@@ -888,7 +888,8 @@ void RenderWidgetHostViewAndroid::CopyFromSurface(
const gfx::Size& output_size,
base::OnceCallback<void(const SkBitmap&)> callback) {
TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromSurface");
if (!IsSurfaceAvailableForCopy()) {
if (!features::IsSurfaceSynchronizationEnabled() &&
!IsSurfaceAvailableForCopy()) {
std::move(callback).Run(SkBitmap());
return;
}
......
......@@ -4224,6 +4224,25 @@
]
}
],
"SurfaceSynchronization": [
{
"platforms": [
"linux",
"mac",
"windows",
"chromeos",
"android"
],
"experiments": [
{
"name": "Enabled",
"enable_features": [
"SurfaceSynchronization"
]
}
]
}
],
"TLS13Variant": [
{
"platforms": [
......
......@@ -6,6 +6,7 @@
#include "base/android/build_info.h"
#include "base/bind.h"
#include "base/debug/stack_trace.h"
#include "base/logging.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/surface_layer.h"
......@@ -121,54 +122,30 @@ void DelegatedFrameHostAndroid::CopyFromCompositingSurface(
const gfx::Rect& src_subrect,
const gfx::Size& output_size,
base::OnceCallback<void(const SkBitmap&)> callback) {
// TODO(vmpstr): We should defer this request until such time that this
// returns true. https://crbug.com/826097.
if (!CanCopyFromCompositingSurface()) {
std::move(callback).Run(SkBitmap());
return;
}
// TODO(samans): We shouldn't need a readback layer. https://crbug.com/841734
scoped_refptr<cc::Layer> readback_layer = CreateSurfaceLayer(
*content_layer_->fallback_surface_id(),
*content_layer_->fallback_surface_id(), content_layer_->bounds(),
cc::DeadlinePolicy::UseDefaultDeadline(), !has_transparent_background_);
readback_layer->SetHideLayerAndSubtree(true);
view_->GetWindowAndroid()->GetCompositor()->AttachLayerForReadback(
readback_layer);
std::unique_ptr<viz::CopyOutputRequest> request =
std::make_unique<viz::CopyOutputRequest>(
viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(
[](base::OnceCallback<void(const SkBitmap&)> callback,
scoped_refptr<cc::Layer> readback_layer,
std::unique_ptr<viz::CopyOutputResult> result) {
readback_layer->RemoveFromParent();
std::move(callback).Run(result->AsSkBitmap());
},
std::move(callback), std::move(readback_layer)));
if (src_subrect.IsEmpty()) {
request->set_area(gfx::Rect(content_layer_->bounds()));
} else {
request->set_area(
gfx::ConvertRectToPixel(view_->GetDipScale(), src_subrect));
}
std::move(callback)));
if (!output_size.IsEmpty()) {
if (request->area().IsEmpty()) {
// Viz would normally return an empty result for an empty source area.
// However, this guard here is still necessary to protect against setting
// an illegal scaling ratio.
return;
}
if (!src_subrect.IsEmpty())
request->set_area(src_subrect);
if (!output_size.IsEmpty())
request->set_result_selection(gfx::Rect(output_size));
request->SetScaleRatio(
gfx::Vector2d(request->area().width(), request->area().height()),
gfx::Vector2d(output_size.width(), output_size.height()));
// If there is enough information to populate the copy output request fields,
// then process it now. Otherwise, wait until the information becomes
// available.
if (CanCopyFromCompositingSurface() &&
active_local_surface_id_ == pending_local_surface_id_) {
ProcessCopyOutputRequest(std::move(request));
} else {
pending_first_frame_requests_.push_back(std::move(request));
}
host_frame_sink_manager_->RequestCopyOfOutput(
*content_layer_->fallback_surface_id(), std::move(request));
}
bool DelegatedFrameHostAndroid::CanCopyFromCompositingSurface() const {
......@@ -280,6 +257,7 @@ void DelegatedFrameHostAndroid::EmbedSurface(
pending_local_surface_id_ = new_pending_local_surface_id;
pending_surface_size_in_pixels_ = new_pending_size_in_pixels;
viz::SurfaceId current_primary_surface_id =
content_layer_->primary_surface_id();
......@@ -387,6 +365,10 @@ void DelegatedFrameHostAndroid::OnFirstSurfaceActivation(
content_layer_->SetFallbackSurfaceId(surface_info.id());
content_layer_->SetContentsOpaque(!has_transparent_background_);
content_layer_->SetBounds(surface_info.size_in_pixels());
active_local_surface_id_ = surface_info.id().local_surface_id();
pending_local_surface_id_ = active_local_surface_id_;
active_device_scale_factor_ = surface_info.device_scale_factor();
pending_surface_size_in_pixels_ = surface_info.size_in_pixels();
return;
}
......@@ -400,12 +382,21 @@ void DelegatedFrameHostAndroid::OnFirstSurfaceActivation(
}
content_layer_->SetFallbackSurfaceId(surface_info.id());
active_local_surface_id_ = surface_info.id().local_surface_id();
active_device_scale_factor_ = surface_info.device_scale_factor();
// TODO(fsamuel): "SwappedFrame" is a bad name. Also, this method doesn't
// really need to take in visiblity. FrameEvictor already has the latest
// visibility state.
frame_evictor_->SwappedFrame(frame_evictor_->visible());
// Note: the frame may have been evicted immediately.
if (!pending_first_frame_requests_.empty()) {
DCHECK(CanCopyFromCompositingSurface());
for (auto& request : pending_first_frame_requests_)
ProcessCopyOutputRequest(std::move(request));
pending_first_frame_requests_.clear();
}
}
void DelegatedFrameHostAndroid::OnFrameTokenChanged(uint32_t frame_token) {
......@@ -425,6 +416,33 @@ void DelegatedFrameHostAndroid::CreateNewCompositorFrameSinkSupport() {
this, frame_sink_id_, is_root, needs_sync_points);
}
void DelegatedFrameHostAndroid::ProcessCopyOutputRequest(
std::unique_ptr<viz::CopyOutputRequest> request) {
if (!request->has_area())
request->set_area(gfx::Rect(pending_surface_size_in_pixels_));
request->set_area(
gfx::ScaleToRoundedRect(request->area(), active_device_scale_factor_));
if (request->has_result_selection()) {
const gfx::Rect& area = request->area();
const gfx::Rect& result_selection = request->result_selection();
if (area.IsEmpty() || result_selection.IsEmpty()) {
// Viz would normally return an empty result for an empty selection.
// However, this guard here is still necessary to protect against setting
// an illegal scaling ratio.
return;
}
request->SetScaleRatio(
gfx::Vector2d(area.width(), area.height()),
gfx::Vector2d(result_selection.width(), result_selection.height()));
}
host_frame_sink_manager_->RequestCopyOfOutput(
viz::SurfaceId(frame_sink_id_, pending_local_surface_id_),
std::move(request));
}
viz::SurfaceId DelegatedFrameHostAndroid::SurfaceId() const {
return content_layer_->fallback_surface_id()
? *content_layer_->fallback_surface_id()
......
......@@ -163,6 +163,9 @@ class UI_ANDROID_EXPORT DelegatedFrameHostAndroid
void CreateNewCompositorFrameSinkSupport();
void ProcessCopyOutputRequest(
std::unique_ptr<viz::CopyOutputRequest> request);
const viz::FrameSinkId frame_sink_id_;
ViewAndroid* view_;
......@@ -199,6 +202,15 @@ class UI_ANDROID_EXPORT DelegatedFrameHostAndroid
viz::LocalSurfaceId first_local_surface_id_after_navigation_;
bool received_frame_after_navigation_ = false;
std::vector<std::unique_ptr<viz::CopyOutputRequest>>
pending_first_frame_requests_;
// The surface id that was most recently activated by
// OnFirstSurfaceActivation.
viz::LocalSurfaceId active_local_surface_id_;
// The scale factor of the above surface.
float active_device_scale_factor_ = 0.f;
// The local surface id as of the most recent call to
// EmbedSurface. This is the surface that we expect future frames to
// reference. This will eventually equal the active surface.
......
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