diff --git a/android_webview/browser/test/rendering_test.cc b/android_webview/browser/test/rendering_test.cc index 26aa0ec2eec1d1..d19aecb0c615bf 100644 --- a/android_webview/browser/test/rendering_test.cc +++ b/android_webview/browser/test/rendering_test.cc @@ -118,13 +118,9 @@ content::SynchronousCompositor* RenderingTest::ActiveCompositor() const { } std::unique_ptr RenderingTest::ConstructEmptyFrame() { - auto compositor_frame = std::make_unique( - viz::test::MakeEmptyCompositorFrame()); - std::unique_ptr root_pass(viz::RenderPass::Create()); gfx::Rect viewport(browser_view_renderer_->size()); - root_pass->SetNew(1, viewport, viewport, gfx::Transform()); - compositor_frame->render_pass_list.push_back(std::move(root_pass)); - return compositor_frame; + return std::make_unique( + viz::CompositorFrameBuilder().AddRenderPass(viewport, viewport).Build()); } std::unique_ptr RenderingTest::ConstructFrame( diff --git a/components/viz/host/host_frame_sink_manager_unittest.cc b/components/viz/host/host_frame_sink_manager_unittest.cc index 697c8b4f407579..372845b00c55c5 100644 --- a/components/viz/host/host_frame_sink_manager_unittest.cc +++ b/components/viz/host/host_frame_sink_manager_unittest.cc @@ -257,10 +257,11 @@ TEST_F(HostFrameSinkManagerLocalTest, CommunicateFrameToken) { auto support = CreateCompositorFrameSinkSupport(kParentFrameSink, true /* is_root */); - CompositorFrame compositor_frame( - test::MakeCompositorFrame({child_id1}, std::vector(), - std::vector())); - compositor_frame.metadata.frame_token = frame_token1; + CompositorFrame compositor_frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token1) + .SetActivationDependencies({child_id1}) + .Build(); support->SubmitCompositorFrame(parent_id1.local_surface_id(), std::move(compositor_frame)); diff --git a/components/viz/service/display/display_unittest.cc b/components/viz/service/display/display_unittest.cc index 09e11f67336a8e..4f376a7b063be6 100644 --- a/components/viz/service/display/display_unittest.cc +++ b/components/viz/service/display/display_unittest.cc @@ -153,8 +153,10 @@ class DisplayTest : public testing::Test { protected: void SubmitCompositorFrame(RenderPassList* pass_list, const LocalSurfaceId& local_surface_id) { - CompositorFrame frame = test::MakeCompositorFrame(); - pass_list->swap(frame.render_pass_list); + CompositorFrame frame = CompositorFrameBuilder() + .SetRenderPassList(std::move(*pass_list)) + .Build(); + pass_list->clear(); support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); } @@ -361,17 +363,14 @@ TEST_F(DisplayTest, DisplayDamaged) { // Pass has no damage, so shouldn't be swapped, but latency info should be // saved for next swap. { - pass = RenderPass::Create(); - pass->output_rect = gfx::Rect(0, 0, 100, 100); - pass->damage_rect = gfx::Rect(10, 10, 0, 0); - pass->id = 1u; - - pass_list.push_back(std::move(pass)); scheduler_->ResetDamageForTest(); - CompositorFrame frame = test::MakeCompositorFrame(); - pass_list.swap(frame.render_pass_list); - frame.metadata.latency_info.push_back(ui::LatencyInfo()); + constexpr gfx::Rect kOutputRect(0, 0, 100, 100); + constexpr gfx::Rect kDamageRect(10, 10, 0, 0); + CompositorFrame frame = CompositorFrameBuilder() + .AddRenderPass(kOutputRect, kDamageRect) + .AddLatencyInfo(ui::LatencyInfo()) + .Build(); support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); EXPECT_TRUE(scheduler_->damaged); @@ -392,17 +391,13 @@ TEST_F(DisplayTest, DisplayDamaged) { display_->Resize(gfx::Size(200, 200)); EXPECT_FALSE(scheduler_->swapped); EXPECT_EQ(4u, output_surface_->num_sent_frames()); - - pass = RenderPass::Create(); - pass->output_rect = gfx::Rect(0, 0, 200, 200); - pass->damage_rect = gfx::Rect(10, 10, 10, 10); - pass->id = 1u; - - pass_list.push_back(std::move(pass)); scheduler_->ResetDamageForTest(); - CompositorFrame frame = test::MakeCompositorFrame(); - pass_list.swap(frame.render_pass_list); + constexpr gfx::Rect kOutputRect(0, 0, 200, 200); + constexpr gfx::Rect kDamageRect(10, 10, 10, 10); + CompositorFrame frame = CompositorFrameBuilder() + .AddRenderPass(kOutputRect, kDamageRect) + .Build(); support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); EXPECT_TRUE(scheduler_->damaged); @@ -481,17 +476,14 @@ TEST_F(DisplayTest, MaxLatencyInfoCap) { // This is the same as LatencyInfo::kMaxLatencyInfoNumber. const size_t max_latency_info_count = 100; for (size_t i = 0; i <= max_latency_info_count; ++i) { - pass = RenderPass::Create(); - pass->output_rect = gfx::Rect(0, 0, 100, 100); - pass->damage_rect = gfx::Rect(10, 10, 0, 0); - pass->id = 1u; - - pass_list.push_back(std::move(pass)); scheduler_->ResetDamageForTest(); - CompositorFrame frame = test::MakeCompositorFrame(); - pass_list.swap(frame.render_pass_list); - frame.metadata.latency_info.push_back(ui::LatencyInfo()); + constexpr gfx::Rect kOutputRect(0, 0, 100, 100); + constexpr gfx::Rect kDamageRect(10, 10, 0, 0); + CompositorFrame frame = CompositorFrameBuilder() + .AddRenderPass(kOutputRect, kDamageRect) + .AddLatencyInfo(ui::LatencyInfo()) + .Build(); support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); @@ -671,7 +663,7 @@ TEST_F(DisplayTest, DrawOcclusionWithNonCoveringDrawQuad) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(50, 50, 100, 100); gfx::Rect rect3(25, 25, 50, 100); @@ -834,7 +826,7 @@ TEST_F(DisplayTest, CompositorFrameWithOverlapDrawQuad) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(25, 25, 50, 50); gfx::Rect rect3(50, 50, 50, 25); @@ -966,7 +958,7 @@ TEST_F(DisplayTest, CompositorFrameWithTransformer) { // Rect 2, 3, 4 are contained in rect 1 only after applying the scale matrix. // They are repetition of the test case above. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(25, 25, 100, 100); gfx::Rect rect3(50, 50, 100, 50); @@ -1145,7 +1137,7 @@ TEST_F(DisplayTest, CompositorFrameWithEpsilonScaleTransform) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect(0, 0, 100, 100); SkMScalar epsilon = float(0.000000001); @@ -1257,7 +1249,7 @@ TEST_F(DisplayTest, CompositorFrameWithNegativeScaleTransform) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect(0, 0, 100, 100); gfx::Transform negative_scale; @@ -1381,7 +1373,7 @@ TEST_F(DisplayTest, CompositorFrameWithRotation) { display_->Initialize(&client, manager_.surface_manager()); // rect 2 is inside rect 1 initially. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(75, 75, 10, 10); @@ -1455,7 +1447,7 @@ TEST_F(DisplayTest, CompositorFrameWithPerspective) { display_->Initialize(&client, manager_.surface_manager()); // rect 2 is inside rect 1 initially. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(10, 10, 1, 1); @@ -1528,7 +1520,7 @@ TEST_F(DisplayTest, CompositorFrameWithOpacityChange) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(25, 25, 10, 10); @@ -1593,7 +1585,7 @@ TEST_F(DisplayTest, CompositorFrameWithOpaquenessChange) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(25, 25, 10, 10); @@ -1659,7 +1651,7 @@ TEST_F(DisplayTest, CompositorFrameWithTranslateTransformer) { display_->Initialize(&client, manager_.surface_manager()); // rect 2 is outside rect 1 initially. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(120, 120, 10, 10); @@ -1735,7 +1727,7 @@ TEST_F(DisplayTest, CompositorFrameWithCombinedSharedQuadState) { display_->Initialize(&client, manager_.surface_manager()); // rect 3 is inside of combined rect of rect 1 and rect 2. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(100, 0, 60, 60); gfx::Rect rect3(10, 10, 120, 30); @@ -1798,7 +1790,7 @@ TEST_F(DisplayTest, CompositorFrameWithMultipleRenderPass) { display_->Initialize(&client, manager_.surface_manager()); // rect 3 is inside of combined rect of rect 1 and rect 2. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(100, 0, 60, 60); @@ -1872,7 +1864,7 @@ TEST_F(DisplayTest, CompositorFrameWithCoveredRenderPass) { display_->Initialize(&client, manager_.surface_manager()); // rect 3 is inside of combined rect of rect 1 and rect 2. - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); std::unique_ptr render_pass2 = RenderPass::Create(); @@ -1941,7 +1933,7 @@ TEST_F(DisplayTest, CompositorFrameWithClip) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(50, 50, 25, 25); gfx::Rect clip_rect(0, 0, 60, 60); @@ -2019,7 +2011,7 @@ TEST_F(DisplayTest, CompositorFrameWithCopyRequest) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(50, 50, 25, 25); @@ -2065,7 +2057,7 @@ TEST_F(DisplayTest, CompositorFrameWithRenderPass) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(50, 0, 100, 100); gfx::Rect rect3(0, 0, 25, 25); @@ -2243,7 +2235,7 @@ TEST_F(DisplayTest, CompositorFrameWithMultipleDrawQuadInSharedQuadState) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect(0, 0, 100, 100); gfx::Rect rect1(0, 0, 50, 50); gfx::Rect rect2(50, 0, 50, 50); @@ -2314,7 +2306,7 @@ TEST_F(DisplayTest, CompositorFrameWithNonInvertibleTransform) { StubDisplayClient client; display_->Initialize(&client, manager_.surface_manager()); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); gfx::Rect rect1(0, 0, 100, 100); gfx::Rect rect2(10, 10, 50, 50); gfx::Rect rect3(0, 0, 10, 10); @@ -2437,8 +2429,11 @@ TEST_F(DisplayTest, CompositorFrameWithPresentationToken) { const gfx::Size sub_surface_size(32, 32); { - CompositorFrame frame = test::MakeCompositorFrame(sub_surface_size); - frame.metadata.presentation_token = 1; + CompositorFrame frame = + CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(sub_surface_size), gfx::Rect()) + .SetPresentationToken(1) + .Build(); EXPECT_CALL(sub_client, DidReceiveCompositorFrameAck(_)).Times(1); // TODO(penghuang): Verify DidDiscardCompositorFrame() is called when // GLSurface presentation callback is implemented. @@ -2487,8 +2482,12 @@ TEST_F(DisplayTest, CompositorFrameWithPresentationToken) { } { - CompositorFrame frame = test::MakeCompositorFrame(sub_surface_size); - frame.metadata.presentation_token = 2; + CompositorFrame frame = + CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(sub_surface_size), gfx::Rect()) + .SetPresentationToken(2) + .Build(); + EXPECT_CALL(sub_client, DidReceiveCompositorFrameAck(_)).Times(1); EXPECT_CALL(sub_client, DidDiscardCompositorFrame(2)).Times(1); sub_support->SubmitCompositorFrame(sub_local_surface_id, std::move(frame)); @@ -2498,8 +2497,12 @@ TEST_F(DisplayTest, CompositorFrameWithPresentationToken) { } { - CompositorFrame frame = test::MakeCompositorFrame(sub_surface_size); - frame.metadata.presentation_token = 3; + CompositorFrame frame = + CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(sub_surface_size), gfx::Rect()) + .SetPresentationToken(3) + .Build(); + EXPECT_CALL(sub_client, DidReceiveCompositorFrameAck(_)).Times(1); sub_support->SubmitCompositorFrame(sub_local_surface_id, std::move(frame)); diff --git a/components/viz/service/display/surface_aggregator_perftest.cc b/components/viz/service/display/surface_aggregator_perftest.cc index db9a8e4c1ddc4a..294a68b619d48b 100644 --- a/components/viz/service/display/surface_aggregator_perftest.cc +++ b/components/viz/service/display/surface_aggregator_perftest.cc @@ -62,14 +62,14 @@ class SurfaceAggregatorPerfTest : public testing::Test { auto pass = RenderPass::Create(); pass->output_rect = gfx::Rect(0, 0, 1, 2); - CompositorFrame frame = test::MakeEmptyCompositorFrame(); + CompositorFrameBuilder frame_builder; auto* sqs = pass->CreateAndAppendSharedQuadState(); for (int j = 0; j < num_textures; j++) { TransferableResource resource; resource.id = j; resource.is_software = true; - frame.resource_list.push_back(resource); + frame_builder.AddTransferableResource(resource); auto* quad = pass->CreateAndAppendDrawQuad(); const gfx::Rect rect(0, 0, 1, 2); @@ -99,9 +99,9 @@ class SurfaceAggregatorPerfTest : public testing::Test { base::nullopt, SK_ColorWHITE, false); } - frame.render_pass_list.push_back(std::move(pass)); + frame_builder.AddRenderPass(std::move(pass)); child_supports[i]->SubmitCompositorFrame(local_surface_id, - std::move(frame)); + frame_builder.Build()); } auto root_support = CompositorFrameSinkSupport::Create( @@ -110,7 +110,6 @@ class SurfaceAggregatorPerfTest : public testing::Test { timer_.Reset(); do { auto pass = RenderPass::Create(); - CompositorFrame frame = test::MakeEmptyCompositorFrame(); auto* sqs = pass->CreateAndAppendSharedQuadState(); auto* surface_quad = pass->CreateAndAppendDrawQuad(); @@ -127,7 +126,8 @@ class SurfaceAggregatorPerfTest : public testing::Test { else pass->damage_rect = gfx::Rect(0, 0, 1, 1); - frame.render_pass_list.push_back(std::move(pass)); + CompositorFrame frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); root_support->SubmitCompositorFrame( LocalSurfaceId(num_surfaces + 1, kArbitraryToken), std::move(frame)); diff --git a/components/viz/service/display/surface_aggregator_pixeltest.cc b/components/viz/service/display/surface_aggregator_pixeltest.cc index 33b524677ff0bd..b9b1756b01c527 100644 --- a/components/viz/service/display/surface_aggregator_pixeltest.cc +++ b/components/viz/service/display/surface_aggregator_pixeltest.cc @@ -79,8 +79,8 @@ TEST_F(SurfaceAggregatorPixelTest, DrawSimpleFrame) { color_quad->SetNew(pass->shared_quad_state_list.back(), rect, rect, SK_ColorGREEN, force_anti_aliasing_off); - auto root_frame = test::MakeCompositorFrame(); - root_frame.render_pass_list.push_back(std::move(pass)); + auto root_frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); LocalSurfaceId root_local_surface_id = allocator_.GenerateId(); SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id); @@ -131,8 +131,8 @@ TEST_F(SurfaceAggregatorPixelTest, DrawSimpleAggregatedFrame) { color_quad->SetNew(pass->shared_quad_state_list.back(), rect, rect, SK_ColorYELLOW, force_anti_aliasing_off); - auto root_frame = test::MakeCompositorFrame(); - root_frame.render_pass_list.push_back(std::move(pass)); + auto root_frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); support_->SubmitCompositorFrame(root_local_surface_id, std::move(root_frame)); @@ -152,8 +152,8 @@ TEST_F(SurfaceAggregatorPixelTest, DrawSimpleAggregatedFrame) { color_quad->SetNew(pass->shared_quad_state_list.back(), rect, rect, SK_ColorBLUE, force_anti_aliasing_off); - auto child_frame = test::MakeCompositorFrame(); - child_frame.render_pass_list.push_back(std::move(pass)); + auto child_frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); child_support->SubmitCompositorFrame(child_local_surface_id, std::move(child_frame)); @@ -226,8 +226,8 @@ TEST_F(SurfaceAggregatorPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { right_child_id, base::nullopt, SK_ColorWHITE, false); - auto root_frame = test::MakeCompositorFrame(); - root_frame.render_pass_list.push_back(std::move(pass)); + auto root_frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); support_->SubmitCompositorFrame(root_local_surface_id, std::move(root_frame)); @@ -254,8 +254,8 @@ TEST_F(SurfaceAggregatorPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { pass->shared_quad_state_list.back(), gfx::Rect(0, 100, 100, 100), gfx::Rect(0, 100, 100, 100), SK_ColorBLUE, force_anti_aliasing_off); - auto child_frame = test::MakeCompositorFrame(); - child_frame.render_pass_list.push_back(std::move(pass)); + auto child_frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); left_support->SubmitCompositorFrame(left_child_local_id, std::move(child_frame)); @@ -282,8 +282,8 @@ TEST_F(SurfaceAggregatorPixelTest, DrawAggregatedFrameWithSurfaceTransforms) { pass->shared_quad_state_list.back(), gfx::Rect(0, 100, 100, 100), gfx::Rect(0, 100, 100, 100), SK_ColorGREEN, force_anti_aliasing_off); - auto child_frame = test::MakeCompositorFrame(); - child_frame.render_pass_list.push_back(std::move(pass)); + auto child_frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); right_support->SubmitCompositorFrame(right_child_local_id, std::move(child_frame)); diff --git a/components/viz/service/display/surface_aggregator_unittest.cc b/components/viz/service/display/surface_aggregator_unittest.cc index 4083eb5679256c..0c24ff5a158d3f 100644 --- a/components/viz/service/display/surface_aggregator_unittest.cc +++ b/components/viz/service/display/surface_aggregator_unittest.cc @@ -383,9 +383,11 @@ class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { const LocalSurfaceId& local_surface_id, RenderPassList* pass_list, float device_scale_factor) { - CompositorFrame frame = test::MakeEmptyCompositorFrame(); - frame.metadata.device_scale_factor = device_scale_factor; - pass_list->swap(frame.render_pass_list); + CompositorFrame frame = CompositorFrameBuilder() + .SetRenderPassList(std::move(*pass_list)) + .SetDeviceScaleFactor(device_scale_factor) + .Build(); + pass_list->clear(); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); } @@ -405,9 +407,10 @@ class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { const LocalSurfaceId& local_surface_id, float device_scale_factor, CompositorFrameSinkSupport* support) { - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); - child_frame.metadata.device_scale_factor = device_scale_factor; - child_frame.render_pass_list.push_back(std::move(pass)); + CompositorFrame child_frame = CompositorFrameBuilder() + .AddRenderPass(std::move(pass)) + .SetDeviceScaleFactor(device_scale_factor) + .Build(); support->SubmitCompositorFrame(local_surface_id, std::move(child_frame)); } @@ -756,8 +759,8 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, StretchContentToFillBounds) { solid_color_quad->SetNew(sqs, gfx::Rect(0, 0, 20, 20), gfx::Rect(0, 0, 20, 20), SK_ColorRED, false); - CompositorFrame frame = test::MakeEmptyCompositorFrame(); - frame.render_pass_list.push_back(std::move(pass)); + CompositorFrame frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); primary_child_support->SubmitCompositorFrame(primary_child_local_surface_id, std::move(frame)); @@ -972,7 +975,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, RootCopyRequest) { Pass(root_quads, arraysize(root_quads), 1, SurfaceSize()), Pass(root_quads2, arraysize(root_quads2), 2, SurfaceSize())}; { - CompositorFrame frame = test::MakeEmptyCompositorFrame(); + CompositorFrame frame = MakeEmptyCompositorFrame(); AddPasses(&frame.render_pass_list, root_passes, arraysize(root_passes)); frame.render_pass_list[0]->copy_requests.push_back(std::move(copy_request)); frame.render_pass_list[1]->copy_requests.push_back( @@ -1061,7 +1064,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, UnreferencedSurface) { Pass(parent_quads, arraysize(parent_quads), SurfaceSize())}; { - CompositorFrame frame = test::MakeEmptyCompositorFrame(); + CompositorFrame frame = MakeEmptyCompositorFrame(); AddPasses(&frame.render_pass_list, parent_passes, arraysize(parent_passes)); @@ -1076,7 +1079,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, UnreferencedSurface) { Pass root_passes[] = {Pass(root_quads, arraysize(root_quads), SurfaceSize())}; { - CompositorFrame frame = test::MakeEmptyCompositorFrame(); + CompositorFrame frame = MakeEmptyCompositorFrame(); AddPasses(&frame.render_pass_list, root_passes, arraysize(root_passes)); frame.metadata.referenced_surfaces.push_back(parent_surface_id); @@ -1691,7 +1694,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) { Pass(child_quads[1], arraysize(child_quads[1]), child_pass_id[1], SurfaceSize())}; - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); @@ -1723,7 +1726,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) { Pass(middle_quads, arraysize(middle_quads), SurfaceSize()), }; - CompositorFrame middle_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame middle_frame = MakeEmptyCompositorFrame(); AddPasses(&middle_frame.render_pass_list, middle_passes, arraysize(middle_passes)); @@ -1749,7 +1752,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) { Pass(secondary_quads, arraysize(secondary_quads), SurfaceSize()), Pass(root_quads, arraysize(root_quads), SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); root_frame.render_pass_list[0] @@ -1850,7 +1853,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { Pass child_passes[] = { Pass(child_quads, arraysize(child_quads), 1, SurfaceSize())}; - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); @@ -1872,7 +1875,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { // Parent surface is only used to test if the transform is applied correctly // to the child surface's damage. - CompositorFrame parent_surface_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame parent_surface_frame = MakeEmptyCompositorFrame(); AddPasses(&parent_surface_frame.render_pass_list, parent_surface_passes, arraysize(parent_surface_passes)); @@ -1892,7 +1895,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 2, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); root_frame.render_pass_list[0] @@ -1916,7 +1919,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { aggregated_pass_list[1]->damage_rect.Contains(gfx::Rect(SurfaceSize()))); { - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); @@ -1943,7 +1946,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { } { - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); @@ -1957,7 +1960,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) { } { - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); @@ -2021,7 +2024,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, SwitchSurfaceDamage) { arraysize(root_render_pass_quads), 2, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); root_frame.render_pass_list[0]->damage_rect = gfx::Rect(5, 5, 100, 100); @@ -2053,7 +2056,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, SwitchSurfaceDamage) { arraysize(root_render_pass_quads), 2, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); @@ -2447,7 +2450,7 @@ void SubmitCompositorFrameWithResources(ResourceId* resource_ids, SurfaceId child_id, CompositorFrameSinkSupport* support, SurfaceId surface_id) { - CompositorFrame frame = test::MakeEmptyCompositorFrame(); + CompositorFrame frame = MakeEmptyCompositorFrame(); auto pass = RenderPass::Create(); pass->SetNew(1, gfx::Rect(0, 0, 20, 20), gfx::Rect(), gfx::Transform()); auto* sqs = pass->CreateAndAppendSharedQuadState(); @@ -2568,13 +2571,16 @@ TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { LocalSurfaceId local_surface_id(7u, base::UnguessableToken::Create()); SurfaceId surface_id(support->frame_sink_id(), local_surface_id); - CompositorFrame frame = test::MakeCompositorFrame(); TransferableResource resource; resource.id = 11; // ResourceProvider is software but resource is not, so it should be // ignored. resource.is_software = false; - frame.resource_list.push_back(resource); + + CompositorFrame frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .AddTransferableResource(resource) + .Build(); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); CompositorFrame returned_frame = aggregator_->Aggregate(surface_id); @@ -2724,8 +2730,8 @@ TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { surface1_id, base::nullopt, SK_ColorWHITE, false); pass->copy_requests.push_back(CopyOutputRequest::CreateStubForTesting()); - CompositorFrame frame = test::MakeEmptyCompositorFrame(); - frame.render_pass_list.push_back(std::move(pass)); + CompositorFrame frame = + CompositorFrameBuilder().AddRenderPass(std::move(pass)).Build(); support2->SubmitCompositorFrame(local_frame2_id, std::move(frame)); } @@ -2803,7 +2809,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageByChangingChildSurface) { Pass child_surface_passes[] = {Pass( child_surface_quads, arraysize(child_surface_quads), 1, SurfaceSize())}; - CompositorFrame child_surface_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_surface_frame = MakeEmptyCompositorFrame(); AddPasses(&child_surface_frame.render_pass_list, child_surface_passes, arraysize(child_surface_passes)); @@ -2819,7 +2825,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageByChangingChildSurface) { Pass root_passes[] = {Pass(root_surface_quads, arraysize(root_surface_quads), 1, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id_); @@ -2839,7 +2845,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageByChangingChildSurface) { // Change child_frame with damage should set the flag. { - CompositorFrame child_surface_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_surface_frame = MakeEmptyCompositorFrame(); AddPasses(&child_surface_frame.render_pass_list, child_surface_passes, arraysize(child_surface_passes)); child_support_->SubmitCompositorFrame(child_local_surface_id, @@ -2853,7 +2859,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageByChangingChildSurface) { // Change child_frame without damage should not set the flag. { - CompositorFrame child_surface_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_surface_frame = MakeEmptyCompositorFrame(); AddPasses(&child_surface_frame.render_pass_list, child_surface_passes, arraysize(child_surface_passes)); child_surface_frame.render_pass_list[0]->damage_rect = gfx::Rect(); @@ -2879,7 +2885,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, Pass child_surface_passes[] = {Pass( child_surface_quads, arraysize(child_surface_quads), 1, SurfaceSize())}; - CompositorFrame child_surface_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_surface_frame = MakeEmptyCompositorFrame(); AddPasses(&child_surface_frame.render_pass_list, child_surface_passes, arraysize(child_surface_passes)); @@ -2895,7 +2901,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, Pass root_passes[] = {Pass(root_surface_quads, arraysize(root_surface_quads), 1, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); SurfaceId root_surface_id(support_->frame_sink_id(), root_local_surface_id_); @@ -2921,7 +2927,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, SurfaceId grand_child_surface_id(grand_child_support->frame_sink_id(), grand_child_local_surface_id); { - CompositorFrame grand_child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame grand_child_frame = MakeEmptyCompositorFrame(); AddPasses(&grand_child_frame.render_pass_list, grand_child_passes, arraysize(grand_child_passes)); @@ -2935,7 +2941,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, Pass new_child_surface_passes[] = {Pass(new_child_surface_quads, arraysize(new_child_surface_quads), 1, SurfaceSize())}; - child_surface_frame = test::MakeEmptyCompositorFrame(); + child_surface_frame = MakeEmptyCompositorFrame(); AddPasses(&child_surface_frame.render_pass_list, new_child_surface_passes, arraysize(new_child_surface_passes)); child_support_->SubmitCompositorFrame(child_local_surface_id, @@ -2956,7 +2962,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, // Change grand_child_frame with damage should set the flag. { - CompositorFrame grand_child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame grand_child_frame = MakeEmptyCompositorFrame(); AddPasses(&grand_child_frame.render_pass_list, grand_child_passes, arraysize(grand_child_passes)); grand_child_support->SubmitCompositorFrame(grand_child_local_surface_id, @@ -2970,7 +2976,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, // Change grand_child_frame without damage should not set the flag. { - CompositorFrame grand_child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame grand_child_frame = MakeEmptyCompositorFrame(); AddPasses(&grand_child_frame.render_pass_list, grand_child_passes, arraysize(grand_child_passes)); grand_child_frame.render_pass_list[0]->damage_rect = gfx::Rect(); @@ -2993,7 +2999,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageFromRenderPassQuads) { Pass child_passes[] = { Pass(child_quads, arraysize(child_quads), 1, SurfaceSize())}; - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); @@ -3013,7 +3019,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageFromRenderPassQuads) { Pass(root_render_pass_quads, arraysize(root_render_pass_quads), 2, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); support_->SubmitCompositorFrame(root_local_surface_id_, @@ -3039,7 +3045,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, HasDamageFromRenderPassQuads) { // Changing child_frame should damage both render_pass. { - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); child_support_->SubmitCompositorFrame(child_local_surface_id, @@ -3066,7 +3072,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, DamageRectOfCachedRenderPass) { Pass(root_quads[0], arraysize(root_quads[0]), pass_id[0], SurfaceSize()), Pass(root_quads[1], arraysize(root_quads[1]), pass_id[1], SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); support_->SubmitCompositorFrame(root_local_surface_id_, @@ -3088,7 +3094,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, DamageRectOfCachedRenderPass) { // For offscreen render pass, only the visible area is damaged. { - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); @@ -3114,7 +3120,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, DamageRectOfCachedRenderPass) { // For offscreen cached render pass, should have full damage. { - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); @@ -3154,7 +3160,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, Pass(child_quads[1], arraysize(child_quads[1]), pass_id[1], SurfaceSize())}; - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); @@ -3171,7 +3177,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, Pass root_passes[] = {Pass(root_surface_quads, arraysize(root_surface_quads), 1, SurfaceSize())}; - CompositorFrame root_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame root_frame = MakeEmptyCompositorFrame(); AddPasses(&root_frame.render_pass_list, root_passes, arraysize(root_passes)); support_->SubmitCompositorFrame(root_local_surface_id_, @@ -3193,7 +3199,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, // For offscreen render pass, only the visible area is damaged. { - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); @@ -3219,7 +3225,7 @@ TEST_F(SurfaceAggregatorValidSurfaceTest, // For offscreen cached render pass, should have full damage. { - CompositorFrame child_frame = test::MakeEmptyCompositorFrame(); + CompositorFrame child_frame = MakeEmptyCompositorFrame(); AddPasses(&child_frame.render_pass_list, child_passes, arraysize(child_passes)); diff --git a/components/viz/service/frame_sinks/compositor_frame_sink_support_unittest.cc b/components/viz/service/frame_sinks/compositor_frame_sink_support_unittest.cc index 8dd1b6902e64f1..3ff9bd40a67855 100644 --- a/components/viz/service/frame_sinks/compositor_frame_sink_support_unittest.cc +++ b/components/viz/service/frame_sinks/compositor_frame_sink_support_unittest.cc @@ -125,7 +125,7 @@ class CompositorFrameSinkSupportTest : public testing::Test { void SubmitCompositorFrameWithResources(ResourceId* resource_ids, size_t num_resource_ids) { - auto frame = test::MakeCompositorFrame(); + auto frame = MakeDefaultCompositorFrame(); for (size_t i = 0u; i < num_resource_ids; ++i) { TransferableResource resource; resource.id = resource_ids[i]; @@ -505,14 +505,15 @@ TEST_F(CompositorFrameSinkSupportTest, AddDuringEviction) { &mock_client, &manager_, kAnotherArbitraryFrameSinkId, kIsRoot, kNeedsSyncPoints); LocalSurfaceId local_surface_id(6, kArbitraryToken); - support->SubmitCompositorFrame(local_surface_id, test::MakeCompositorFrame()); + support->SubmitCompositorFrame(local_surface_id, + MakeDefaultCompositorFrame()); SurfaceManager* surface_manager = manager_.surface_manager(); EXPECT_CALL(mock_client, DidReceiveCompositorFrameAck(_)) .WillOnce(testing::InvokeWithoutArgs([&]() { LocalSurfaceId new_id(7, base::UnguessableToken::Create()); - support->SubmitCompositorFrame(new_id, test::MakeCompositorFrame()); + support->SubmitCompositorFrame(new_id, MakeDefaultCompositorFrame()); surface_manager->GarbageCollectSurfaces(); })) .WillRepeatedly(testing::Return()); @@ -535,8 +536,10 @@ TEST_F(CompositorFrameSinkSupportTest, EvictCurrentSurface) { TransferableResource resource; resource.id = 1; resource.mailbox_holder.texture_target = GL_TEXTURE_2D; - auto frame = test::MakeCompositorFrame(); - frame.resource_list.push_back(resource); + auto frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .AddTransferableResource(resource) + .Build(); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); EXPECT_EQ(surface_observer_.last_created_surface_id().local_surface_id(), local_surface_id); @@ -569,7 +572,7 @@ TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceWithTemporaryReference) { frame_sink_manager_client_.SetTemporaryReferenceToAssign( surface_id, parent_frame_sink_id); support_->SubmitCompositorFrame(local_surface_id, - test::MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify the temporary reference has prevented the surface from getting // destroyed. @@ -588,9 +591,11 @@ void CopyRequestTestCallback(bool* called, TEST_F(CompositorFrameSinkSupportTest, DuplicateCopyRequest) { { - auto frame = test::MakeCompositorFrame(); - frame.metadata.referenced_surfaces.push_back( - SurfaceId(support_->frame_sink_id(), local_surface_id_)); + const SurfaceId surface_id(support_->frame_sink_id(), local_surface_id_); + auto frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetReferencedSurfaces({surface_id}) + .Build(); support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); EXPECT_EQ(surface_observer_.last_created_surface_id().local_surface_id(), local_surface_id_); @@ -639,17 +644,11 @@ TEST_F(CompositorFrameSinkSupportTest, DuplicateCopyRequest) { // Check whether the SurfaceInfo object is created and populated correctly // after the frame submission. TEST_F(CompositorFrameSinkSupportTest, SurfaceInfo) { - auto frame = test::MakeCompositorFrame(); - - auto render_pass = RenderPass::Create(); - render_pass->SetNew(1, gfx::Rect(5, 6), gfx::Rect(), gfx::Transform()); - frame.render_pass_list.push_back(std::move(render_pass)); - - render_pass = RenderPass::Create(); - render_pass->SetNew(2, gfx::Rect(7, 8), gfx::Rect(), gfx::Transform()); - frame.render_pass_list.push_back(std::move(render_pass)); - - frame.metadata.device_scale_factor = 2.5f; + auto frame = CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(5, 6), gfx::Rect()) + .AddRenderPass(gfx::Rect(7, 8), gfx::Rect()) + .SetDeviceScaleFactor(2.5f) + .Build(); support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); SurfaceId expected_surface_id(support_->frame_sink_id(), local_surface_id_); @@ -663,8 +662,8 @@ TEST_F(CompositorFrameSinkSupportTest, SurfaceInfo) { // a Surface for it. TEST_F(CompositorFrameSinkSupportTest, ZeroFrameSize) { SurfaceId id(support_->frame_sink_id(), local_surface_id_); - auto frame = test::MakeEmptyCompositorFrame(); - frame.render_pass_list.push_back(RenderPass::Create()); + auto frame = + CompositorFrameBuilder().AddRenderPass(gfx::Rect(), gfx::Rect()).Build(); EXPECT_TRUE( support_->SubmitCompositorFrame(local_surface_id_, std::move(frame))); EXPECT_FALSE(GetSurfaceForId(id)); @@ -674,8 +673,10 @@ TEST_F(CompositorFrameSinkSupportTest, ZeroFrameSize) { // don't create a Surface for it. TEST_F(CompositorFrameSinkSupportTest, ZeroDeviceScaleFactor) { SurfaceId id(support_->frame_sink_id(), local_surface_id_); - auto frame = test::MakeCompositorFrame(); - frame.metadata.device_scale_factor = 0.f; + auto frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetDeviceScaleFactor(0.f) + .Build(); EXPECT_TRUE( support_->SubmitCompositorFrame(local_surface_id_, std::move(frame))); EXPECT_FALSE(GetSurfaceForId(id)); @@ -687,20 +688,18 @@ TEST_F(CompositorFrameSinkSupportTest, FrameSizeMismatch) { SurfaceId id(support_->frame_sink_id(), local_surface_id_); // Submit a frame with size (5,5). - auto frame = test::MakeEmptyCompositorFrame(); - auto pass = RenderPass::Create(); - pass->SetNew(1, gfx::Rect(5, 5), gfx::Rect(), gfx::Transform()); - frame.render_pass_list.push_back(std::move(pass)); + auto frame = CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(5, 5), gfx::Rect()) + .Build(); EXPECT_TRUE( support_->SubmitCompositorFrame(local_surface_id_, std::move(frame))); EXPECT_TRUE(GetSurfaceForId(id)); // Submit a frame with size (5,4). This frame should be rejected and the // surface should be destroyed. - frame = test::MakeEmptyCompositorFrame(); - pass = RenderPass::Create(); - pass->SetNew(1, gfx::Rect(5, 4), gfx::Rect(), gfx::Transform()); - frame.render_pass_list.push_back(std::move(pass)); + frame = CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(5, 4), gfx::Rect()) + .Build(); EXPECT_FALSE( support_->SubmitCompositorFrame(local_surface_id_, std::move(frame))); manager_.surface_manager()->GarbageCollectSurfaces(); @@ -714,16 +713,20 @@ TEST_F(CompositorFrameSinkSupportTest, DeviceScaleFactorMismatch) { SurfaceId id(support_->frame_sink_id(), local_surface_id_); // Submit a frame with device scale factor of 0.5. - auto frame = test::MakeCompositorFrame(); - frame.metadata.device_scale_factor = 0.5f; + auto frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetDeviceScaleFactor(0.5f) + .Build(); EXPECT_TRUE( support_->SubmitCompositorFrame(local_surface_id_, std::move(frame))); EXPECT_TRUE(GetSurfaceForId(id)); // Submit a frame with device scale factor of 0.4. This frame should be // rejected and the surface should be destroyed. - frame = test::MakeCompositorFrame(); - frame.metadata.device_scale_factor = 0.4f; + frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetDeviceScaleFactor(0.4f) + .Build(); EXPECT_FALSE( support_->SubmitCompositorFrame(local_surface_id_, std::move(frame))); manager_.surface_manager()->GarbageCollectSurfaces(); @@ -742,8 +745,10 @@ TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { // Check that the support and SurfaceManager forward the BeginFrameAck // attached to a CompositorFrame to the SurfaceObserver. BeginFrameAck ack(0, 1, true); - auto frame = test::MakeCompositorFrame(); - frame.metadata.begin_frame_ack = ack; + CompositorFrame frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetBeginFrameAck(ack) + .Build(); support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); EXPECT_EQ(ack, surface_observer_.last_ack()); @@ -768,14 +773,14 @@ TEST_F(CompositorFrameSinkSupportTest, FrameIndexCarriedOverToNewSurface) { // Submit a frame to |id1| and record the frame index. support_->SubmitCompositorFrame(local_surface_id1, - test::MakeCompositorFrame()); + MakeDefaultCompositorFrame()); Surface* surface1 = GetSurfaceForId(id1); uint64_t frame_index = surface1->GetActiveFrameIndex(); // Submit a frame to |id2| and verify that the new frame index is one more // than what we had before. support_->SubmitCompositorFrame(local_surface_id2, - test::MakeCompositorFrame()); + MakeDefaultCompositorFrame()); Surface* surface2 = GetSurfaceForId(id2); EXPECT_EQ(frame_index + 1, surface2->GetActiveFrameIndex()); } diff --git a/components/viz/service/frame_sinks/direct_layer_tree_frame_sink_unittest.cc b/components/viz/service/frame_sinks/direct_layer_tree_frame_sink_unittest.cc index f499652759e5a7..61daa5411401a0 100644 --- a/components/viz/service/frame_sinks/direct_layer_tree_frame_sink_unittest.cc +++ b/components/viz/service/frame_sinks/direct_layer_tree_frame_sink_unittest.cc @@ -101,13 +101,9 @@ class DirectLayerTreeFrameSinkTest : public testing::Test { } void SwapBuffersWithDamage(const gfx::Rect& damage_rect) { - auto render_pass = RenderPass::Create(); - render_pass->SetNew(1, display_rect_, damage_rect, gfx::Transform()); - - CompositorFrame frame = test::MakeEmptyCompositorFrame(); - frame.metadata.begin_frame_ack = BeginFrameAck(0, 1, true); - frame.render_pass_list.push_back(std::move(render_pass)); - + auto frame = CompositorFrameBuilder() + .AddRenderPass(display_rect_, damage_rect) + .Build(); layer_tree_frame_sink_->SubmitCompositorFrame(std::move(frame)); } diff --git a/components/viz/service/frame_sinks/surface_references_unittest.cc b/components/viz/service/frame_sinks/surface_references_unittest.cc index abbe38be422904..62aa6bd1ca6ae8 100644 --- a/components/viz/service/frame_sinks/surface_references_unittest.cc +++ b/components/viz/service/frame_sinks/surface_references_unittest.cc @@ -51,7 +51,7 @@ class SurfaceReferencesTest : public testing::Test { LocalSurfaceId local_surface_id(parent_id, base::UnguessableToken::Deserialize(0, 1u)); GetCompositorFrameSinkSupport(frame_sink_id) - .SubmitCompositorFrame(local_surface_id, MakeCompositorFrame()); + .SubmitCompositorFrame(local_surface_id, MakeDefaultCompositorFrame()); return SurfaceId(frame_sink_id, local_surface_id); } diff --git a/components/viz/service/frame_sinks/surface_synchronization_unittest.cc b/components/viz/service/frame_sinks/surface_synchronization_unittest.cc index a3ea60c229cd53..18eef5526b0d3a 100644 --- a/components/viz/service/frame_sinks/surface_synchronization_unittest.cc +++ b/components/viz/service/frame_sinks/surface_synchronization_unittest.cc @@ -14,7 +14,6 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -using viz::test::MakeCompositorFrame; using testing::_; using testing::Eq; using testing::IsEmpty; @@ -43,6 +42,18 @@ SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t parent_id) { LocalSurfaceId(parent_id, base::UnguessableToken::Deserialize(0, 1u))); } +CompositorFrame MakeCompositorFrame( + std::vector activation_dependencies, + std::vector referenced_surfaces, + std::vector resource_list) { + return CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetActivationDependencies(std::move(activation_dependencies)) + .SetReferencedSurfaces(std::move(referenced_surfaces)) + .SetTransferableResources(std::move(resource_list)) + .Build(); +} + } // namespace class FakeExternalBeginFrameSourceClient @@ -225,7 +236,7 @@ TEST_F(SurfaceSynchronizationTest, RootSurfaceReceivesReferences) { // Submit a CompositorFrame for the first display root surface. display_support().SubmitCompositorFrame(display_id_first.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // A surface reference from the top-level root is added and there shouldn't be // a temporary reference. @@ -236,7 +247,7 @@ TEST_F(SurfaceSynchronizationTest, RootSurfaceReceivesReferences) { // Submit a CompositorFrame for the second display root surface. display_support().SubmitCompositorFrame(display_id_second.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // A surface reference from the top-level root to |display_id_second| should // be added and the reference to |display_root_first| removed. @@ -272,7 +283,7 @@ TEST_F(SurfaceSynchronizationTest, BlockedOnTwo) { // Submit a CompositorFrame without any dependencies to |child_id1|. // parent_support should now only be blocked on |child_id2|. child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_TRUE(parent_surface()->has_deadline()); EXPECT_FALSE(parent_surface()->HasActiveFrame()); @@ -283,7 +294,7 @@ TEST_F(SurfaceSynchronizationTest, BlockedOnTwo) { // Submit a CompositorFrame without any dependencies to |child_id2|. // parent_support should be activated. child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(child_surface2()->has_deadline()); EXPECT_TRUE(parent_surface()->HasActiveFrame()); @@ -394,7 +405,7 @@ TEST_F(SurfaceSynchronizationTest, TwoBlockedOnOne) { // Submit a CompositorFrame without any dependencies to |child_id2|. // parent_support should be activated. child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(child_surface2()->has_deadline()); @@ -498,7 +509,7 @@ TEST_F(SurfaceSynchronizationTest, NewFrameOverridesOldDependencies) { // Submit a CompositorFrame that has no dependencies. parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify that the CompositorFrame has been activated. EXPECT_TRUE(parent_surface()->HasActiveFrame()); @@ -518,7 +529,7 @@ TEST_F(SurfaceSynchronizationTest, OnlyActiveFramesAffectSurfaceReferences) { // DidReceiveCompositorFrameAck should call on immediate activation. EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(1); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); testing::Mock::VerifyAndClearExpectations(&support_client_); // Verify that the child surface is not blocked. @@ -555,7 +566,7 @@ TEST_F(SurfaceSynchronizationTest, OnlyActiveFramesAffectSurfaceReferences) { // on activation. EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2); child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); testing::Mock::VerifyAndClearExpectations(&support_client_); // Verify that the child surface is not blocked. @@ -663,7 +674,7 @@ TEST_F(SurfaceSynchronizationTest, DropStaleReferencesAfterActivation) { // and once for the now active parent CompositorFrame. EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); testing::Mock::VerifyAndClearExpectations(&support_client_); // Verify that the child CompositorFrame activates immediately. @@ -712,7 +723,7 @@ TEST_F(SurfaceSynchronizationTest, DropStaleReferencesAfterActivation) { EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id1)); child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify that the parent Surface has activated and no longer has a // pending CompositorFrame. Also verify that |child_id1| is no longer a @@ -743,8 +754,10 @@ TEST_F(SurfaceSynchronizationTest, ui::LatencyInfo info; info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); - CompositorFrame frame = MakeCompositorFrame(); - frame.metadata.latency_info.push_back(info); + CompositorFrame frame = CompositorFrameBuilder() + .AddDefaultRenderPass() + .AddLatencyInfo(info) + .Build(); parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), std::move(frame)); @@ -760,8 +773,10 @@ TEST_F(SurfaceSynchronizationTest, ui::LatencyInfo info2; info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2); - CompositorFrame frame2 = MakeCompositorFrame(); - frame2.metadata.latency_info.push_back(info2); + CompositorFrame frame2 = CompositorFrameBuilder() + .AddDefaultRenderPass() + .AddLatencyInfo(info2) + .Build(); parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), std::move(frame2)); @@ -816,7 +831,7 @@ TEST_F(SurfaceSynchronizationTest, ui::LatencyInfo info; info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); - CompositorFrame frame = MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); frame.metadata.latency_info.push_back(info); parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), @@ -841,7 +856,7 @@ TEST_F(SurfaceSynchronizationTest, // Submit a frame with a new local surface id. parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify that the new surface has an active frame only. Surface* surface = GetSurfaceForId(parent_id2); @@ -894,7 +909,7 @@ TEST_F(SurfaceSynchronizationTest, ui::LatencyInfo info; info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1); - CompositorFrame frame = MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); frame.metadata.latency_info.push_back(info); parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), @@ -926,7 +941,7 @@ TEST_F(SurfaceSynchronizationTest, // Resolve the dependencies. The frame in parent's surface must become active. child_support1().SubmitCompositorFrame(child_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(surface->HasPendingFrame()); EXPECT_TRUE(surface->HasActiveFrame()); @@ -969,7 +984,7 @@ TEST_F(SurfaceSynchronizationTest, ReturnResourcesWithAck) { EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(Eq(returned_resources))); parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); } // Verifies that if a surface is marked destroyed and a new frame arrives for @@ -981,7 +996,7 @@ TEST_F(SurfaceSynchronizationTest, SurfaceResurrection) { // Create the child surface by submitting a frame to it. EXPECT_EQ(nullptr, GetSurfaceForId(child_id)); child_support1().SubmitCompositorFrame(child_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify that the child surface is created. Surface* surface = GetSurfaceForId(child_id); @@ -1004,7 +1019,7 @@ TEST_F(SurfaceSynchronizationTest, SurfaceResurrection) { // destroyed. surface_observer().Reset(); child_support1().SubmitCompositorFrame(child_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify that the surface that was marked destroyed is recovered and is being // used again. @@ -1022,7 +1037,7 @@ TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { // Submit the first frame. Creates the surface. child_support1().SubmitCompositorFrame(child_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_NE(nullptr, GetSurfaceForId(child_id)); // Add a reference from parent. @@ -1033,7 +1048,7 @@ TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { // Remove the reference from parant. This allows us to destroy the surface. parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Destroy the surface. child_support1().EvictCurrentSurface(); @@ -1044,7 +1059,7 @@ TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { // Submit another frame with the same local surface id. This should work fine // and a new surface must be created. child_support1().SubmitCompositorFrame(child_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_NE(nullptr, GetSurfaceForId(child_id)); } @@ -1103,7 +1118,7 @@ TEST_F(SurfaceSynchronizationTest, DependencyTrackingGarbageCollection) { // Submitting a CompositorFrame will trigger garbage collection of the // |parent_id1| subtree. This should not crash. child_support1().SubmitCompositorFrame(child_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); } // This test verifies that a crash does not occur if garbage collection is @@ -1189,7 +1204,7 @@ TEST_F(SurfaceSynchronizationTest, OnlyBlockOnEmbeddedSurfaces) { // Submitting a CompositorFrame with |parent_id2| so that the display // CompositorFrame can hold a reference to it. parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); display_support().SubmitCompositorFrame( display_id.local_surface_id(), @@ -1211,7 +1226,7 @@ TEST_F(SurfaceSynchronizationTest, OnlyBlockOnEmbeddedSurfaces) { // Submitting a CompositorFrame with |parent_id2| should unblock the // display CompositorFrame. parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(display_surface()->has_deadline()); EXPECT_FALSE(display_surface()->HasPendingFrame()); @@ -1400,12 +1415,12 @@ TEST_F(SurfaceSynchronizationTest, IndependentDeadlines) { const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(child_surface1()->HasPendingFrame()); EXPECT_TRUE(child_surface1()->HasActiveFrame()); child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(child_surface2()->HasPendingFrame()); EXPECT_TRUE(child_surface2()->HasActiveFrame()); @@ -1588,7 +1603,7 @@ TEST_F(SurfaceSynchronizationTest, FrameActivationAfterFrameSinkDestruction) { const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_FALSE(parent_surface()->has_deadline()); EXPECT_TRUE(parent_surface()->HasActiveFrame()); @@ -1640,7 +1655,7 @@ TEST_F(SurfaceSynchronizationTest, FrameActivationAfterFrameSinkDestruction) { // Submitting a new CompositorFrame to the display should free the parent. display_support().SubmitCompositorFrame(display_id.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); frame_sink_manager().surface_manager()->GarbageCollectSurfaces(); @@ -1744,9 +1759,9 @@ TEST_F(SurfaceSynchronizationTest, ActiveFrameIndex) { EXPECT_EQ(0u, parent_surface()->GetActiveFrameIndex()); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_TRUE(parent_surface()->HasActiveFrame()); EXPECT_EQ(3u, parent_surface()->GetActiveFrameIndex()); } @@ -1763,7 +1778,7 @@ TEST_F(SurfaceSynchronizationTest, LatestInFlightSurface) { const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink1, 2); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); parent_support().SubmitCompositorFrame( parent_id.local_surface_id(), @@ -1809,7 +1824,7 @@ TEST_F(SurfaceSynchronizationTest, LatestInFlightSurface) { // Submit a child CompositorFrame to a new SurfaceId and verify that // GetLatestInFlightSurface returns the right surface. child_support1().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Verify that there is a temporary reference for child_id2 and there is // a reference from the parent to child_id1. @@ -1844,7 +1859,7 @@ TEST_F(SurfaceSynchronizationTest, LatestInFlightSurfaceWithBogusFallback) { const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); parent_support().SubmitCompositorFrame( parent_id.local_surface_id(), @@ -1878,7 +1893,7 @@ TEST_F(SurfaceSynchronizationTest, LatestInFlightSurfaceDifferentFrameSinkIds) { const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); parent_support().SubmitCompositorFrame( parent_id.local_surface_id(), @@ -1889,13 +1904,13 @@ TEST_F(SurfaceSynchronizationTest, LatestInFlightSurfaceDifferentFrameSinkIds) { // that if the fallback and primary differ in FrameSinkId then // GetLatestInFlightSurface will always return the specified fallback. child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); // Submit a child CompositorFrame without a different FrameSinkId and verify // that if the fallback and primary differ in FrameSinkId then // GetLatestInFlightSurface will always return the specified fallback. child_support2().SubmitCompositorFrame(child_id2.local_surface_id(), - MakeCompositorFrame()); + MakeDefaultCompositorFrame()); EXPECT_EQ(GetSurfaceForId(child_id1), GetLatestInFlightSurface(parent_id.frame_sink_id(), child_id2, child_id1)); diff --git a/components/viz/service/frame_sinks/video_detector_unittest.cc b/components/viz/service/frame_sinks/video_detector_unittest.cc index 6562eba19ca8f9..10efc3d094a6c4 100644 --- a/components/viz/service/frame_sinks/video_detector_unittest.cc +++ b/components/viz/service/frame_sinks/video_detector_unittest.cc @@ -92,7 +92,7 @@ class VideoDetectorTest : public testing::Test { root_frame_sink_ = CreateFrameSink(); root_frame_sink_->SubmitCompositorFrame( - local_surface_id_allocator_.GenerateId(), test::MakeCompositorFrame()); + local_surface_id_allocator_.GenerateId(), MakeDefaultCompositorFrame()); } protected: @@ -120,7 +120,7 @@ class VideoDetectorTest : public testing::Test { } void SubmitRootFrame() { - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); RenderPass* render_pass = frame.render_pass_list.back().get(); SharedQuadState* shared_quad_state = render_pass->CreateAndAppendSharedQuadState(); @@ -182,10 +182,10 @@ class VideoDetectorTest : public testing::Test { private: CompositorFrame MakeDamagedCompositorFrame(const gfx::Rect& damage) { - constexpr gfx::Size kFrameSinkSize = gfx::Size(10000, 10000); - CompositorFrame frame = test::MakeCompositorFrame(kFrameSinkSize); - frame.render_pass_list.back()->damage_rect = damage; - return frame; + constexpr gfx::Rect kFrameSinkRect(10000, 10000); + return CompositorFrameBuilder() + .AddRenderPass(kFrameSinkRect, damage) + .Build(); } FrameSinkManagerImpl frame_sink_manager_; diff --git a/components/viz/service/surfaces/surface_hittest_unittest.cc b/components/viz/service/surfaces/surface_hittest_unittest.cc index 76f4825fcf2bd0..bedd0bf8563973 100644 --- a/components/viz/service/surfaces/surface_hittest_unittest.cc +++ b/components/viz/service/surfaces/surface_hittest_unittest.cc @@ -316,7 +316,7 @@ TEST_F(SurfaceHittestTest, Hittest_InvalidRenderPassDrawQuad) { TEST_F(SurfaceHittestTest, Hittest_RenderPassDrawQuad) { // Create a CompositorFrame with two RenderPasses. gfx::Rect root_rect(300, 300); - CompositorFrame root_frame = test::MakeCompositorFrame(); + CompositorFrame root_frame = MakeDefaultCompositorFrame(); RenderPassList& render_pass_list = root_frame.render_pass_list; // Create a child RenderPass. diff --git a/components/viz/service/surfaces/surface_unittest.cc b/components/viz/service/surfaces/surface_unittest.cc index 76cddb3f024036..600ad20b4f3edf 100644 --- a/components/viz/service/surfaces/surface_unittest.cc +++ b/components/viz/service/surfaces/surface_unittest.cc @@ -25,7 +25,8 @@ constexpr bool kIsRoot = true; constexpr bool kNeedsSyncPoints = true; TEST(SurfaceTest, PresentationCallback) { - const gfx::Size kSurfaceSize(300, 300); + constexpr gfx::Size kSurfaceSize(300, 300); + constexpr gfx::Rect kDamageRect(0, 0); const LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); FrameSinkManagerImpl frame_sink_manager; @@ -34,8 +35,11 @@ TEST(SurfaceTest, PresentationCallback) { &client, &frame_sink_manager, kArbitraryFrameSinkId, kIsRoot, kNeedsSyncPoints); { - CompositorFrame frame = test::MakeCompositorFrame(kSurfaceSize); - frame.metadata.presentation_token = 1; + CompositorFrame frame = + CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(kSurfaceSize), kDamageRect) + .SetPresentationToken(1) + .Build(); EXPECT_CALL(client, DidReceiveCompositorFrameAck(testing::_)).Times(1); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); } @@ -43,8 +47,11 @@ TEST(SurfaceTest, PresentationCallback) { { // Replaces previous frame. The previous frame with token 1 will be // discarded. - CompositorFrame frame = test::MakeCompositorFrame(kSurfaceSize); - frame.metadata.presentation_token = 2; + CompositorFrame frame = + CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(kSurfaceSize), kDamageRect) + .SetPresentationToken(2) + .Build(); EXPECT_CALL(client, DidDiscardCompositorFrame(1)).Times(1); EXPECT_CALL(client, DidReceiveCompositorFrameAck(testing::_)).Times(1); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); @@ -53,8 +60,10 @@ TEST(SurfaceTest, PresentationCallback) { { // Submits a frame with token 3 and different size. This frame with token 3 // will be discarded immediately. - CompositorFrame frame = test::MakeCompositorFrame(gfx::Size(400, 400)); - frame.metadata.presentation_token = 3; + CompositorFrame frame = CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(400, 400), kDamageRect) + .SetPresentationToken(3) + .Build(); EXPECT_CALL(client, DidDiscardCompositorFrame(3)).Times(1); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); } @@ -62,9 +71,12 @@ TEST(SurfaceTest, PresentationCallback) { { // Submits a frame with token 4 and different scale factor, this frame with // token 4 will be discarded immediately. - CompositorFrame frame = test::MakeCompositorFrame(kSurfaceSize); - frame.metadata.device_scale_factor = 2; - frame.metadata.presentation_token = 4; + CompositorFrame frame = + CompositorFrameBuilder() + .AddRenderPass(gfx::Rect(kSurfaceSize), kDamageRect) + .SetDeviceScaleFactor(2.f) + .SetPresentationToken(4) + .Build(); EXPECT_CALL(client, DidDiscardCompositorFrame(4)).Times(1); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); } @@ -85,7 +97,8 @@ TEST(SurfaceTest, SurfaceLifetime) { LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); - support->SubmitCompositorFrame(local_surface_id, test::MakeCompositorFrame()); + support->SubmitCompositorFrame(local_surface_id, + MakeDefaultCompositorFrame()); EXPECT_TRUE(surface_manager->GetSurfaceForId(surface_id)); support->EvictCurrentSurface(); frame_sink_manager.surface_manager()->GarbageCollectSurfaces(); @@ -118,7 +131,7 @@ TEST(SurfaceTest, CopyRequestLifetime) { LocalSurfaceId local_surface_id(6, base::UnguessableToken::Create()); SurfaceId surface_id(kArbitraryFrameSinkId, local_surface_id); - CompositorFrame frame = test::MakeCompositorFrame(); + CompositorFrame frame = MakeDefaultCompositorFrame(); support->SubmitCompositorFrame(local_surface_id, std::move(frame)); Surface* surface = surface_manager->GetSurfaceForId(surface_id); ASSERT_TRUE(!!surface); @@ -132,7 +145,7 @@ TEST(SurfaceTest, CopyRequestLifetime) { int max_frame = 3, start_id = 200; for (int i = 0; i < max_frame; ++i) { - CompositorFrame frame = test::MakeEmptyCompositorFrame(); + CompositorFrame frame = CompositorFrameBuilder().Build(); frame.render_pass_list.push_back(RenderPass::Create()); frame.render_pass_list.back()->id = i * 3 + start_id; frame.render_pass_list.push_back(RenderPass::Create()); diff --git a/components/viz/test/DEPS b/components/viz/test/DEPS index b722c7a6879be7..e631b91e008e8d 100644 --- a/components/viz/test/DEPS +++ b/components/viz/test/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+mojo/public/cpp/bindings", "+services/viz/privileged/interfaces", "+services/viz/public/interfaces", + "+ui/latency", ] specific_include_rules = { diff --git a/components/viz/test/compositor_frame_helpers.cc b/components/viz/test/compositor_frame_helpers.cc index fbd8a16180e7aa..3790bd3b7704b0 100644 --- a/components/viz/test/compositor_frame_helpers.cc +++ b/components/viz/test/compositor_frame_helpers.cc @@ -4,42 +4,126 @@ #include "components/viz/test/compositor_frame_helpers.h" -#include "components/viz/common/quads/compositor_frame.h" - namespace viz { -namespace test { +namespace { + +constexpr gfx::Rect kDefaultOutputRect(20, 20); +constexpr gfx::Rect kDefaultDamageRect(0, 0); + +} // namespace + +CompositorFrameBuilder::CompositorFrameBuilder() : frame_(base::in_place) { + frame_->metadata.begin_frame_ack = + BeginFrameAck(BeginFrameArgs::kManualSourceId, + BeginFrameArgs::kStartingFrameNumber, true); + frame_->metadata.device_scale_factor = 1.f; +} + +CompositorFrameBuilder::~CompositorFrameBuilder() = default; + +CompositorFrame CompositorFrameBuilder::Build() { + CompositorFrame temp_frame(std::move(frame_.value())); + frame_.reset(); + return temp_frame; +} + +CompositorFrameBuilder& CompositorFrameBuilder::AddDefaultRenderPass() { + return AddRenderPass(kDefaultOutputRect, kDefaultDamageRect); +} -CompositorFrame MakeCompositorFrame(const gfx::Size& size) { - CompositorFrame frame = MakeEmptyCompositorFrame(); +CompositorFrameBuilder& CompositorFrameBuilder::AddRenderPass( + const gfx::Rect& output_rect, + const gfx::Rect& damage_rect) { std::unique_ptr pass = RenderPass::Create(); - pass->SetNew(1, gfx::Rect(size), gfx::Rect(), gfx::Transform()); - frame.render_pass_list.push_back(std::move(pass)); - return frame; + pass->SetNew(next_render_pass_id_++, output_rect, damage_rect, + gfx::Transform()); + frame_->render_pass_list.push_back(std::move(pass)); + return *this; } -CompositorFrame MakeEmptyCompositorFrame() { - CompositorFrame frame; - frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId; - frame.metadata.begin_frame_ack.sequence_number = - BeginFrameArgs::kStartingFrameNumber; - frame.metadata.begin_frame_ack.has_damage = true; - frame.metadata.device_scale_factor = 1; - return frame; -} - -CompositorFrame MakeCompositorFrame( - std::vector activation_dependencies, - std::vector referenced_surfaces, +CompositorFrameBuilder& CompositorFrameBuilder::AddRenderPass( + std::unique_ptr render_pass) { + // Give the render pass a unique id if one hasn't been assigned. + if (render_pass->id == 0) + render_pass->id = next_render_pass_id_++; + frame_->render_pass_list.push_back(std::move(render_pass)); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetRenderPassList( + RenderPassList render_pass_list) { + DCHECK(frame_->render_pass_list.empty()); + frame_->render_pass_list = std::move(render_pass_list); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::AddTransferableResource( + TransferableResource resource) { + frame_->resource_list.push_back(std::move(resource)); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetTransferableResources( std::vector resource_list) { - CompositorFrame compositor_frame = test::MakeCompositorFrame(); - compositor_frame.metadata.begin_frame_ack = BeginFrameAck(0, 1, true); - compositor_frame.metadata.activation_dependencies = - std::move(activation_dependencies); - compositor_frame.metadata.referenced_surfaces = - std::move(referenced_surfaces); - compositor_frame.resource_list = std::move(resource_list); - return compositor_frame; + DCHECK(frame_->resource_list.empty()); + frame_->resource_list = std::move(resource_list); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetBeginFrameAck( + const BeginFrameAck& ack) { + frame_->metadata.begin_frame_ack = ack; + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetDeviceScaleFactor( + float device_scale_factor) { + frame_->metadata.device_scale_factor = device_scale_factor; + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::AddLatencyInfo( + ui::LatencyInfo latency_info) { + frame_->metadata.latency_info.push_back(std::move(latency_info)); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetActivationDependencies( + std::vector activation_dependencies) { + frame_->metadata.activation_dependencies = std::move(activation_dependencies); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetReferencedSurfaces( + std::vector referenced_surfaces) { + frame_->metadata.referenced_surfaces = std::move(referenced_surfaces); + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetFrameToken( + uint32_t frame_token) { + frame_->metadata.frame_token = frame_token; + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetContentSourceId( + uint32_t content_source_id) { + frame_->metadata.content_source_id = content_source_id; + return *this; +} + +CompositorFrameBuilder& CompositorFrameBuilder::SetPresentationToken( + uint32_t presentation_token) { + frame_->metadata.presentation_token = presentation_token; + return *this; +} + +CompositorFrame MakeDefaultCompositorFrame() { + return CompositorFrameBuilder().AddDefaultRenderPass().Build(); +} + +CompositorFrame MakeEmptyCompositorFrame() { + return CompositorFrameBuilder().Build(); } -} // namespace test } // namespace viz diff --git a/components/viz/test/compositor_frame_helpers.h b/components/viz/test/compositor_frame_helpers.h index a3ac800e80d4c7..0cf7ba71a0a734 100644 --- a/components/viz/test/compositor_frame_helpers.h +++ b/components/viz/test/compositor_frame_helpers.h @@ -7,27 +7,72 @@ #include +#include "base/optional.h" +#include "components/viz/common/quads/compositor_frame.h" +#include "components/viz/common/quads/render_pass.h" #include "components/viz/common/resources/transferable_resource.h" #include "components/viz/common/surfaces/surface_id.h" +#include "ui/latency/latency_info.h" namespace viz { -class CompositorFrame; -namespace test { +// A builder class for constructing CompositorFrames in tests. The initial +// CompositorFrame will have a valid BeginFrameAck and device_scale_factor of 1. +// At least one RenderPass must be added for the CompositorFrame to be valid. +class CompositorFrameBuilder { + public: + CompositorFrameBuilder(); + ~CompositorFrameBuilder(); -// Creates a valid CompositorFrame. -CompositorFrame MakeCompositorFrame(const gfx::Size& size = gfx::Size(20, 20)); + // Builds the CompositorFrame and leaves |this| in an invalid state. This can + // only be called once. + CompositorFrame Build(); + + // Adds a render pass with 20x20 output_rect and empty damage_rect. + CompositorFrameBuilder& AddDefaultRenderPass(); + // Adds a render pass with specified |output_rect| and |damage_rect|. + CompositorFrameBuilder& AddRenderPass(const gfx::Rect& output_rect, + const gfx::Rect& damage_rect); + CompositorFrameBuilder& AddRenderPass( + std::unique_ptr render_pass); + // Sets list of render passes. The list of render passes must be empty when + // this is called. + CompositorFrameBuilder& SetRenderPassList(RenderPassList render_pass_list); + + CompositorFrameBuilder& AddTransferableResource( + TransferableResource resource); + // Sets list of transferable resources. The list of transferable resources + // must be empty when this is called. + CompositorFrameBuilder& SetTransferableResources( + std::vector resource_list); + + // Sets the BeginFrameAck. This replaces the default BeginFrameAck. + CompositorFrameBuilder& SetBeginFrameAck(const BeginFrameAck& ack); + CompositorFrameBuilder& SetDeviceScaleFactor(float device_scale_factor); + CompositorFrameBuilder& AddLatencyInfo(ui::LatencyInfo latency_info); + CompositorFrameBuilder& SetReferencedSurfaces( + std::vector referenced_surfaces); + CompositorFrameBuilder& SetActivationDependencies( + std::vector activation_dependencies); + CompositorFrameBuilder& SetFrameToken(uint32_t frame_token); + CompositorFrameBuilder& SetContentSourceId(uint32_t content_source_id); + CompositorFrameBuilder& SetPresentationToken(uint32_t presentation_token); + + private: + base::Optional frame_; + uint64_t next_render_pass_id_ = 1; + + DISALLOW_COPY_AND_ASSIGN(CompositorFrameBuilder); +}; + +// Creates a CompositorFrame that has a render pass with 20x20 output_rect and +// empty damage_rect. This CompositorFrame is valid and can be sent over IPC. +CompositorFrame MakeDefaultCompositorFrame(); // Creates a CompositorFrame that will be valid once its render_pass_list is // initialized. CompositorFrame MakeEmptyCompositorFrame(); -CompositorFrame MakeCompositorFrame( - std::vector activation_dependencies, - std::vector referenced_surfaces, - std::vector resource_list); - -} // namespace test } // namespace viz #endif // COMPONENTS_VIZ_TEST_COMPOSITOR_FRAME_HELPERS_H_ diff --git a/components/viz/test/surface_hittest_test_helpers.cc b/components/viz/test/surface_hittest_test_helpers.cc index b6b97ec55017cf..8db686fefcc457 100644 --- a/components/viz/test/surface_hittest_test_helpers.cc +++ b/components/viz/test/surface_hittest_test_helpers.cc @@ -71,7 +71,7 @@ void CreateRenderPass(int render_pass_id, CompositorFrame CreateCompositorFrame(const gfx::Rect& root_rect, RenderPass** render_pass) { - CompositorFrame root_frame = MakeCompositorFrame(); + CompositorFrame root_frame = MakeDefaultCompositorFrame(); int root_id = 1; CreateRenderPass(root_id, root_rect, gfx::Transform(), &root_frame.render_pass_list); diff --git a/content/browser/renderer_host/offscreen_canvas_provider_impl_unittest.cc b/content/browser/renderer_host/offscreen_canvas_provider_impl_unittest.cc index fdc8db662818f2..a75960400adc89 100644 --- a/content/browser/renderer_host/offscreen_canvas_provider_impl_unittest.cc +++ b/content/browser/renderer_host/offscreen_canvas_provider_impl_unittest.cc @@ -14,6 +14,7 @@ #include "components/viz/common/quads/compositor_frame.h" #include "components/viz/host/host_frame_sink_manager.h" #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h" +#include "components/viz/test/compositor_frame_helpers.h" #include "components/viz/test/fake_host_frame_sink_client.h" #include "components/viz/test/mock_compositor_frame_sink_client.h" #include "content/browser/compositor/surface_utils.h" @@ -68,23 +69,6 @@ class StubOffscreenCanvasSurfaceClient DISALLOW_COPY_AND_ASSIGN(StubOffscreenCanvasSurfaceClient); }; -// Create a CompositorFrame suitable to send over IPC. -viz::CompositorFrame MakeCompositorFrame() { - viz::CompositorFrame frame; - frame.metadata.begin_frame_ack.source_id = - viz::BeginFrameArgs::kManualSourceId; - frame.metadata.begin_frame_ack.sequence_number = - viz::BeginFrameArgs::kStartingFrameNumber; - frame.metadata.device_scale_factor = 1.0f; - - auto render_pass = viz::RenderPass::Create(); - render_pass->id = 1; - render_pass->output_rect = gfx::Rect(100, 100); - frame.render_pass_list.push_back(std::move(render_pass)); - - return frame; -} - // Creates a closure that sets |error_variable| true when run. base::Closure ConnectionErrorClosure(bool* error_variable) { return base::Bind([](bool* error_variable) { *error_variable = true; }, @@ -180,7 +164,7 @@ TEST_F(OffscreenCanvasProviderImplTest, // Renderer submits a CompositorFrame with |local_id|. const viz::LocalSurfaceId local_id(1, base::UnguessableToken::Create()); compositor_frame_sink->SubmitCompositorFrame( - local_id, MakeCompositorFrame(), nullptr, + local_id, viz::MakeDefaultCompositorFrame(), nullptr, base::TimeTicks::Now().since_origin().InMicroseconds()); RunUntilIdle(); diff --git a/content/browser/renderer_host/render_widget_host_unittest.cc b/content/browser/renderer_host/render_widget_host_unittest.cc index 57954972a5b7df..9b9d8f972c58e3 100644 --- a/content/browser/renderer_host/render_widget_host_unittest.cc +++ b/content/browser/renderer_host/render_widget_host_unittest.cc @@ -20,6 +20,7 @@ #include "base/timer/timer.h" #include "build/build_config.h" #include "components/viz/test/begin_frame_args_test.h" +#include "components/viz/test/compositor_frame_helpers.h" #include "content/browser/gpu/compositor_util.h" #include "content/browser/renderer_host/input/legacy_input_router_impl.h" #include "content/browser/renderer_host/input/touch_emulator.h" @@ -260,22 +261,6 @@ class MockRenderWidgetHost : public RenderWidgetHostImpl { namespace { -viz::CompositorFrame MakeCompositorFrame(float scale_factor, gfx::Size size) { - viz::CompositorFrame frame; - frame.metadata.device_scale_factor = scale_factor; - frame.metadata.begin_frame_ack = viz::BeginFrameAck(0, 1, true); - - std::unique_ptr pass = viz::RenderPass::Create(); - pass->SetNew(1, gfx::Rect(size), gfx::Rect(), gfx::Transform()); - frame.render_pass_list.push_back(std::move(pass)); - if (!size.IsEmpty()) { - viz::TransferableResource resource; - resource.id = 1; - frame.resource_list.push_back(std::move(resource)); - } - return frame; -} - // RenderWidgetHostProcess ----------------------------------------------------- class RenderWidgetHostProcess : public MockRenderProcessHost { @@ -1733,7 +1718,6 @@ TEST_F(RenderWidgetHostTest, MultipleInputEvents) { // Test that the rendering timeout for newly loaded content fires // when enough time passes without receiving a new compositor frame. TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); @@ -1743,8 +1727,10 @@ TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { // Start the timer and immediately send a CompositorFrame with the // content_source_id of the new page. The timeout shouldn't fire. host_->StartNewContentRenderingTimeout(5); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.content_source_id = 5; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetContentSourceId(5) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), @@ -1757,8 +1743,10 @@ TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { // Start the timer but receive frames only from the old page. The timer // should fire. host_->StartNewContentRenderingTimeout(10); - frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.content_source_id = 9; + frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetContentSourceId(9) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), @@ -1770,8 +1758,10 @@ TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { // Send a CompositorFrame with content_source_id of the new page before we // attempt to start the timer. The timer shouldn't fire. - frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.content_source_id = 7; + frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetContentSourceId(7) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); host_->StartNewContentRenderingTimeout(7); base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( @@ -1795,7 +1785,6 @@ TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { // This tests that a compositor frame received with a stale content source ID // in its metadata is properly discarded. TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); @@ -1805,9 +1794,11 @@ TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { { // First swap a frame with an invalid ID. - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.begin_frame_ack = viz::BeginFrameAck(0, 1, true); - frame.metadata.content_source_id = 99; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetBeginFrameAck(viz::BeginFrameAck(0, 1, true)) + .SetContentSourceId(99) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_FALSE( @@ -1820,8 +1811,10 @@ TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { { // Test with a valid content ID as a control. - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.content_source_id = 100; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetContentSourceId(100) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_TRUE( @@ -1833,8 +1826,10 @@ TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { // We also accept frames with higher content IDs, to cover the case where // the browser process receives a compositor frame for a new page before // the corresponding DidCommitProvisionalLoad (it's a race). - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.content_source_id = 101; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetContentSourceId(101) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_TRUE( @@ -2707,7 +2702,6 @@ TEST_F(RenderWidgetHostTest, EventDispatchPostDetach) { // queue the messages until the frame arrives and then process them. TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { const uint32_t frame_token = 99; - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); std::vector messages; @@ -2721,8 +2715,10 @@ TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { EXPECT_EQ(1u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(1u, host_->processed_frame_messages_count()); @@ -2732,7 +2728,6 @@ TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { // messages immedtiately. TEST_F(RenderWidgetHostTest, FrameToken_FrameThenMessage) { const uint32_t frame_token = 99; - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); std::vector messages; @@ -2741,8 +2736,10 @@ TEST_F(RenderWidgetHostTest, FrameToken_FrameThenMessage) { EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); @@ -2758,7 +2755,6 @@ TEST_F(RenderWidgetHostTest, FrameToken_FrameThenMessage) { TEST_F(RenderWidgetHostTest, FrameToken_MultipleMessagesThenTokens) { const uint32_t frame_token1 = 99; const uint32_t frame_token2 = 100; - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); std::vector messages1; @@ -2779,14 +2775,18 @@ TEST_F(RenderWidgetHostTest, FrameToken_MultipleMessagesThenTokens) { EXPECT_EQ(2u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token1; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token1) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(1u, host_->queued_messages_.size()); EXPECT_EQ(1u, host_->processed_frame_messages_count()); - frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token2; + frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token2) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(2u, host_->processed_frame_messages_count()); @@ -2797,7 +2797,6 @@ TEST_F(RenderWidgetHostTest, FrameToken_MultipleMessagesThenTokens) { TEST_F(RenderWidgetHostTest, FrameToken_MultipleTokensThenMessages) { const uint32_t frame_token1 = 99; const uint32_t frame_token2 = 100; - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); std::vector messages1; @@ -2808,14 +2807,18 @@ TEST_F(RenderWidgetHostTest, FrameToken_MultipleTokensThenMessages) { EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token1; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token1) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token2; + frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token2) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); @@ -2836,7 +2839,6 @@ TEST_F(RenderWidgetHostTest, FrameToken_MultipleTokensThenMessages) { TEST_F(RenderWidgetHostTest, FrameToken_DroppedFrame) { const uint32_t frame_token1 = 99; const uint32_t frame_token2 = 100; - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); std::vector messages1; @@ -2857,8 +2859,10 @@ TEST_F(RenderWidgetHostTest, FrameToken_DroppedFrame) { EXPECT_EQ(2u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token2; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token2) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(2u, host_->processed_frame_messages_count()); @@ -2870,7 +2874,6 @@ TEST_F(RenderWidgetHostTest, FrameToken_RendererCrash) { const uint32_t frame_token1 = 99; const uint32_t frame_token2 = 50; const uint32_t frame_token3 = 30; - const gfx::Size frame_size(50, 50); const viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); std::vector messages1; @@ -2892,8 +2895,10 @@ TEST_F(RenderWidgetHostTest, FrameToken_RendererCrash) { EXPECT_EQ(0u, host_->processed_frame_messages_count()); host_->Init(); - viz::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token2; + auto frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token2) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); @@ -2909,8 +2914,10 @@ TEST_F(RenderWidgetHostTest, FrameToken_RendererCrash) { EXPECT_EQ(1u, host_->queued_messages_.size()); EXPECT_EQ(0u, host_->processed_frame_messages_count()); - frame = MakeCompositorFrame(1.f, frame_size); - frame.metadata.frame_token = frame_token3; + frame = viz::CompositorFrameBuilder() + .AddDefaultRenderPass() + .SetFrameToken(frame_token3) + .Build(); host_->SubmitCompositorFrame(local_surface_id, std::move(frame), nullptr, 0); EXPECT_EQ(0u, host_->queued_messages_.size()); EXPECT_EQ(1u, host_->processed_frame_messages_count());