Commit 8b8a9981 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

VideoSurfaceLayer: submit empty CompositorFrame before stopping frame submission.

This leads to better memory performance as the last frame will be discarded.

Bug: 829813
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I7bc753e7e8d74d80d8c8390bd0f33ed45003ed5a
Reviewed-on: https://chromium-review.googlesource.com/1141291
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576331}
parent 9a33e7f8
......@@ -71,6 +71,8 @@ void VideoFrameSubmitter::UpdateSubmissionStateInternal() {
compositor_frame_sink_->SetNeedsBeginFrame(is_rendering_ && should_submit_);
if (should_submit_)
SubmitSingleFrame();
else if (!frame_size_.IsEmpty())
SubmitEmptyFrame();
}
}
......@@ -194,11 +196,15 @@ void VideoFrameSubmitter::SubmitFrame(
if (!compositor_frame_sink_ || !should_submit_)
return;
// TODO(mlamouri): the `frame_size_` is expected to be consistent but seems to
// change in some cases. Ideally, it should be set when empty and a DCHECK
// should make sure it stays consistent.
frame_size_ = gfx::Rect(video_frame->coded_size());
viz::CompositorFrame compositor_frame;
std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
render_pass->SetNew(1, gfx::Rect(video_frame->coded_size()),
gfx::Rect(video_frame->coded_size()), gfx::Transform());
render_pass->SetNew(1, frame_size_, frame_size_, gfx::Transform());
render_pass->filters = cc::FilterOperations();
resource_provider_->AppendQuads(render_pass.get(), video_frame, rotation_);
compositor_frame.metadata.begin_frame_ack = begin_frame_ack;
......@@ -225,6 +231,28 @@ void VideoFrameSubmitter::SubmitFrame(
waiting_for_compositor_ack_ = true;
}
void VideoFrameSubmitter::SubmitEmptyFrame() {
TRACE_EVENT0("media", "VideoFrameSubmitter::SubmitEmptyFrame");
DCHECK_CALLED_ON_VALID_THREAD(media_thread_checker_);
DCHECK(compositor_frame_sink_ && !should_submit_);
DCHECK(!frame_size_.IsEmpty());
viz::CompositorFrame compositor_frame;
compositor_frame.metadata.begin_frame_ack =
viz::BeginFrameAck::CreateManualAckWithDamage();
compositor_frame.metadata.device_scale_factor = 1;
compositor_frame.metadata.may_contain_video = true;
std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
render_pass->SetNew(1, frame_size_, frame_size_, gfx::Transform());
compositor_frame.render_pass_list.push_back(std::move(render_pass));
compositor_frame_sink_->SubmitCompositorFrame(
surface_id_.local_surface_id(), std::move(compositor_frame), nullptr, 0);
waiting_for_compositor_ack_ = true;
}
void VideoFrameSubmitter::OnBeginFrame(const viz::BeginFrameArgs& args) {
TRACE_EVENT0("media", "VideoFrameSubmitter::OnBeginFrame");
DCHECK_CALLED_ON_VALID_THREAD(media_thread_checker_);
......
......@@ -92,6 +92,7 @@ class PLATFORM_EXPORT VideoFrameSubmitter
void StartSubmitting();
void UpdateSubmissionStateInternal();
void SubmitFrame(const viz::BeginFrameAck&, scoped_refptr<media::VideoFrame>);
void SubmitEmptyFrame();
// Pulls frame and submits it to compositor.
// Used in cases like PaintSingleFrame, which occurs before video rendering
......@@ -114,6 +115,11 @@ class PLATFORM_EXPORT VideoFrameSubmitter
bool should_submit_ = false;
media::VideoRotation rotation_;
// Size of the video frame being submitted. It is set the first time a frame
// is submitted and is expected to never change aftewards. Used to send an
// empty frame when the video is out of view.
gfx::Rect frame_size_;
THREAD_CHECKER(media_thread_checker_);
base::WeakPtrFactory<VideoFrameSubmitter> weak_ptr_factory_;
......
......@@ -287,7 +287,7 @@ TEST_F(VideoFrameSubmitterTest, ShouldSubmitPreventsSubmission) {
.WillOnce(Return(media::VideoFrame::CreateFrame(
media::PIXEL_FORMAT_YV12, gfx::Size(8, 8), gfx::Rect(gfx::Size(8, 8)),
gfx::Size(8, 8), base::TimeDelta())));
EXPECT_CALL(*sink_, DoSubmitCompositorFrame(_, _));
EXPECT_CALL(*sink_, DoSubmitCompositorFrame(_, _)).Times(1);
EXPECT_CALL(*provider_, PutCurrentFrame());
EXPECT_CALL(*resource_provider_, AppendQuads(_, _, _));
EXPECT_CALL(*resource_provider_, PrepareSendToParent(_, _));
......@@ -296,6 +296,8 @@ TEST_F(VideoFrameSubmitterTest, ShouldSubmitPreventsSubmission) {
scoped_task_environment_.RunUntilIdle();
EXPECT_CALL(*sink_, SetNeedsBeginFrame(false));
EXPECT_CALL(*sink_, DoSubmitCompositorFrame(_, _)).Times(1);
EXPECT_CALL(*provider_, GetCurrentFrame()).Times(0);
submitter_->UpdateSubmissionState(false);
scoped_task_environment_.RunUntilIdle();
......
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