Commit e7316d0a authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

android: Frame token with presentation feedback

Send frame token from viz display with the presentation feedback. This
is more inline with chrome's architecture where viz display service
sends this update.

There are other code paths that used to deliver CompositorFrameMetadata
and they have to call the new path for delivering frame tokens.
Eventually should remove CompositorFrameMetadata code paths.

SynchronousCompositorHost has to ensure tokens are delivered in order.
Previously this worked with metadata version. Now that it's independent,
need to explicitly make sure it's delivered in order.

For now, only call DidProcessFrame. Eventually should move devtools to
frame token and RenderFrameMetadata.

Bug: 881469
Change-Id: Ie49e97255d45ba7a7267cce87b37c29fadb302a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1576428Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652910}
parent 338a3551
......@@ -297,13 +297,14 @@ bool BrowserViewRenderer::DoUpdateParentDrawData() {
ParentCompositorDrawConstraints new_constraints;
viz::PresentationFeedbackMap new_presentation_feedbacks;
CompositorID id;
uint32_t frame_token = 0u;
current_compositor_frame_consumer_->TakeParentDrawDataOnUI(
&new_constraints, &id, &new_presentation_feedbacks);
&new_constraints, &id, &new_presentation_feedbacks, &frame_token);
content::SynchronousCompositor* compositor = FindCompositor(id);
if (compositor) {
compositor_->DidPresentCompositorFrames(
std::move(new_presentation_feedbacks));
std::move(new_presentation_feedbacks), frame_token);
}
if (external_draw_constraints_ == new_constraints)
......
......@@ -220,8 +220,9 @@ class TestAnimateInAndOutOfScreen : public RenderingTest {
ParentCompositorDrawConstraints constraints;
CompositorID id;
viz::PresentationFeedbackMap presentation_feedbacks;
uint32_t frame_token = 0u;
GetCompositorFrameConsumer()->TakeParentDrawDataOnUI(
&constraints, &id, &presentation_feedbacks);
&constraints, &id, &presentation_feedbacks, &frame_token);
switch (on_draw_count_) {
case 0u:
// This OnParentDrawDataUpdated is generated by
......
......@@ -34,7 +34,8 @@ class CompositorFrameConsumer {
virtual void TakeParentDrawDataOnUI(
ParentCompositorDrawConstraints* constraints,
CompositorID* compositor_id,
viz::PresentationFeedbackMap* presentation_feedbacks) = 0;
viz::PresentationFeedbackMap* presentation_feedbacks,
uint32_t* frame_token) = 0;
virtual ChildFrameQueue PassUncommittedFrameOnUI() = 0;
protected:
......
......@@ -57,7 +57,7 @@ HardwareRenderer::~HardwareRenderer() {
// Reset draw constraints.
render_thread_manager_->PostParentDrawDataToChildCompositorOnRT(
ParentCompositorDrawConstraints(), compositor_id_,
viz::PresentationFeedbackMap());
viz::PresentationFeedbackMap(), 0u);
for (auto& child_frame : child_frame_queue_) {
child_frame->WaitOnFutureIfNeeded();
ReturnChildFrame(std::move(child_frame));
......@@ -112,6 +112,7 @@ void HardwareRenderer::Draw(HardwareRendererDrawParams* params) {
}
bool submitted_new_frame = false;
uint32_t frame_token = 0u;
// SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it
// during "kModeSync" stage (which does not allow GL) might result in extra
// kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid
......@@ -143,6 +144,7 @@ void HardwareRenderer::Draw(HardwareRendererDrawParams* params) {
device_scale_factor_ = device_scale_factor;
}
frame_token = child_compositor_frame->metadata.frame_token;
support_->SubmitCompositorFrame(child_id_,
std::move(*child_compositor_frame));
submitted_new_frame = true;
......@@ -164,7 +166,7 @@ void HardwareRenderer::Draw(HardwareRendererDrawParams* params) {
// presentation feedback to return as well.
if (need_to_update_draw_constraints && !submitted_new_frame) {
render_thread_manager_->PostParentDrawDataToChildCompositorOnRT(
draw_constraints, compositor_id_, viz::PresentationFeedbackMap());
draw_constraints, compositor_id_, viz::PresentationFeedbackMap(), 0u);
}
if (!child_id_.is_valid())
......@@ -184,10 +186,9 @@ void HardwareRenderer::Draw(HardwareRendererDrawParams* params) {
device_scale_factor_, params->color_space);
viz::PresentationFeedbackMap feedbacks =
support_->TakePresentationFeedbacks();
if (submitted_new_frame &&
(need_to_update_draw_constraints || !feedbacks.empty())) {
if (submitted_new_frame) {
render_thread_manager_->PostParentDrawDataToChildCompositorOnRT(
draw_constraints, compositor_id_, std::move(feedbacks));
draw_constraints, compositor_id_, std::move(feedbacks), frame_token);
}
}
......
......@@ -109,7 +109,8 @@ ChildFrameQueue RenderThreadManager::PassUncommittedFrameOnUI() {
void RenderThreadManager::PostParentDrawDataToChildCompositorOnRT(
const ParentCompositorDrawConstraints& parent_draw_constraints,
const CompositorID& compositor_id,
viz::PresentationFeedbackMap presentation_feedbacks) {
viz::PresentationFeedbackMap presentation_feedbacks,
uint32_t frame_token) {
{
base::AutoLock lock(lock_);
parent_draw_constraints_ = parent_draw_constraints;
......@@ -117,6 +118,7 @@ void RenderThreadManager::PostParentDrawDataToChildCompositorOnRT(
// the middle of the sequence. This also means its ok to drop the feedbacks
// from early returned frames from WaitAndPruneFrameQueue as well.
presentation_feedbacks_ = std::move(presentation_feedbacks);
presented_frame_token_ = frame_token;
compositor_id_for_presentation_feedbacks_ = compositor_id;
}
......@@ -130,7 +132,8 @@ void RenderThreadManager::PostParentDrawDataToChildCompositorOnRT(
void RenderThreadManager::TakeParentDrawDataOnUI(
ParentCompositorDrawConstraints* constraints,
CompositorID* compositor_id,
viz::PresentationFeedbackMap* presentation_feedbacks) {
viz::PresentationFeedbackMap* presentation_feedbacks,
uint32_t* frame_token) {
DCHECK(ui_loop_->BelongsToCurrentThread());
DCHECK(presentation_feedbacks->empty());
CheckUiCallsAllowed();
......@@ -138,6 +141,7 @@ void RenderThreadManager::TakeParentDrawDataOnUI(
*constraints = parent_draw_constraints_;
*compositor_id = compositor_id_for_presentation_feedbacks_;
presentation_feedbacks_.swap(*presentation_feedbacks);
*frame_token = presented_frame_token_;
}
void RenderThreadManager::SetInsideHardwareRelease(bool inside) {
......
......@@ -40,7 +40,8 @@ class RenderThreadManager : public CompositorFrameConsumer {
void TakeParentDrawDataOnUI(
ParentCompositorDrawConstraints* constraints,
CompositorID* compositor_id,
viz::PresentationFeedbackMap* presentation_feedbacks) override;
viz::PresentationFeedbackMap* presentation_feedbacks,
uint32_t* frame_token) override;
ChildFrameQueue PassUncommittedFrameOnUI() override;
void RemoveFromCompositorFrameProducerOnUI();
......@@ -51,7 +52,8 @@ class RenderThreadManager : public CompositorFrameConsumer {
void PostParentDrawDataToChildCompositorOnRT(
const ParentCompositorDrawConstraints& parent_draw_constraints,
const CompositorID& compositor_id,
viz::PresentationFeedbackMap presentation_feedbacks);
viz::PresentationFeedbackMap presentation_feedbacks,
uint32_t frame_token);
void InsertReturnedResourcesOnRT(
const std::vector<viz::ReturnedResource>& resources,
const CompositorID& compositor_id,
......@@ -115,6 +117,7 @@ class RenderThreadManager : public CompositorFrameConsumer {
ParentCompositorDrawConstraints parent_draw_constraints_;
CompositorID compositor_id_for_presentation_feedbacks_;
viz::PresentationFeedbackMap presentation_feedbacks_;
uint32_t presented_frame_token_ = 0u;
base::WeakPtrFactory<RenderThreadManager> weak_factory_on_ui_thread_;
......
......@@ -233,6 +233,7 @@ void SynchronousCompositorHost::UpdateFrameMetaData(
return;
}
frame_metadata_version_ = version;
UpdatePresentedFrameToken(frame_metadata.frame_token);
rwhva_->SynchronousFrameMetadata(std::move(frame_metadata));
}
......@@ -413,8 +414,18 @@ void SynchronousCompositorHost::ReturnResources(
}
void SynchronousCompositorHost::DidPresentCompositorFrames(
viz::PresentationFeedbackMap feedbacks) {
viz::PresentationFeedbackMap feedbacks,
uint32_t frame_token) {
rwhva_->DidPresentCompositorFrames(feedbacks);
UpdatePresentedFrameToken(frame_token);
}
void SynchronousCompositorHost::UpdatePresentedFrameToken(
uint32_t frame_token) {
if (!viz::FrameTokenGT(frame_token, last_frame_token_))
return;
last_frame_token_ = frame_token;
rwhva_->FrameTokenChangedForSynchronousCompositor(frame_token);
}
void SynchronousCompositorHost::SetMemoryPolicy(size_t bytes_limit) {
......
......@@ -54,8 +54,8 @@ class SynchronousCompositorHost : public SynchronousCompositor,
void ReturnResources(
uint32_t layer_tree_frame_sink_id,
const std::vector<viz::ReturnedResource>& resources) override;
void DidPresentCompositorFrames(
viz::PresentationFeedbackMap feedbacks) override;
void DidPresentCompositorFrames(viz::PresentationFeedbackMap feedbacks,
uint32_t frame_token) override;
void SetMemoryPolicy(size_t bytes_limit) override;
void DidBecomeActive() override;
void DidChangeRootLayerScrollOffset(
......@@ -109,6 +109,7 @@ class SynchronousCompositorHost : public SynchronousCompositor,
// handle blocking calls.
bool IsReadyForSynchronousCall();
void UpdateRootLayerStateOnClient();
void UpdatePresentedFrameToken(uint32_t frame_token);
RenderWidgetHostViewAndroid* const rwhva_;
SynchronousCompositorClient* const client_;
......@@ -159,6 +160,9 @@ class SynchronousCompositorHost : public SynchronousCompositor,
float min_page_scale_factor_ = 0.f;
float max_page_scale_factor_ = 0.f;
// From viz display.
uint32_t last_frame_token_ = 0u;
scoped_refptr<SynchronousCompositorSyncCallBridge> bridge_;
DISALLOW_COPY_AND_ASSIGN(SynchronousCompositorHost);
......
......@@ -1062,9 +1062,6 @@ void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
OnFrameMetadataUpdated(metadata.Clone(), false);
}
if (host() && metadata.frame_token)
host()->DidProcessFrame(metadata.frame_token);
// DevTools ScreenCast support for Android WebView.
RenderFrameHost* frame_host = RenderViewHost::From(host())->GetMainFrame();
if (frame_host) {
......@@ -1073,6 +1070,12 @@ void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
}
}
void RenderWidgetHostViewAndroid::FrameTokenChangedForSynchronousCompositor(
uint32_t frame_token) {
if (host() && frame_token)
host()->DidProcessFrame(frame_token);
}
void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient(
SynchronousCompositorClient* client) {
synchronous_compositor_client_ = client;
......
......@@ -304,6 +304,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
int end_adjust);
void SynchronousFrameMetadata(viz::CompositorFrameMetadata frame_metadata);
void FrameTokenChangedForSynchronousCompositor(uint32_t frame_token);
void SetSynchronousCompositorClient(SynchronousCompositorClient* client);
......
......@@ -92,7 +92,8 @@ class CONTENT_EXPORT SynchronousCompositor {
const std::vector<viz::ReturnedResource>& resources) = 0;
virtual void DidPresentCompositorFrames(
viz::PresentationFeedbackMap feedbacks) = 0;
viz::PresentationFeedbackMap feedbacks,
uint32_t frame_token) = 0;
// "On demand" SW draw, into the supplied canvas (observing the transform
// and clip set there-in).
......
......@@ -30,8 +30,8 @@ class CONTENT_EXPORT TestSynchronousCompositor : public SynchronousCompositor {
void ReturnResources(
uint32_t layer_tree_frame_sink_id,
const std::vector<viz::ReturnedResource>& resources) override;
void DidPresentCompositorFrames(
viz::PresentationFeedbackMap feedbacks) override {}
void DidPresentCompositorFrames(viz::PresentationFeedbackMap feedbacks,
uint32_t frame_token) override {}
bool DemandDrawSw(SkCanvas* canvas) override;
void SetMemoryPolicy(size_t bytes_limit) override {}
void DidBecomeActive() override {}
......
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