Skip to content

Commit

Permalink
Add CompositorFrameBuilder for tests.
Browse files Browse the repository at this point in the history
Add a class that helps build valid CompostiorFrames for tests. Also
convert some tests to use the builder and update existing helper
functions.

Bug: 758707
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I293ef25799d2db398e905f34e5eb0650a3525677
Reviewed-on: https://chromium-review.googlesource.com/796931
Reviewed-by: Timothy Dresser <tdresser@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Fady Samuel <fsamuel@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521774}
  • Loading branch information
kylechar authored and Commit Bot committed Dec 5, 2017
1 parent 6fd1cd6 commit 30a805f
Show file tree
Hide file tree
Showing 19 changed files with 506 additions and 350 deletions.
8 changes: 2 additions & 6 deletions android_webview/browser/test/rendering_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@ content::SynchronousCompositor* RenderingTest::ActiveCompositor() const {
}

std::unique_ptr<viz::CompositorFrame> RenderingTest::ConstructEmptyFrame() {
auto compositor_frame = std::make_unique<viz::CompositorFrame>(
viz::test::MakeEmptyCompositorFrame());
std::unique_ptr<viz::RenderPass> 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::CompositorFrame>(
viz::CompositorFrameBuilder().AddRenderPass(viewport, viewport).Build());
}

std::unique_ptr<viz::CompositorFrame> RenderingTest::ConstructFrame(
Expand Down
9 changes: 5 additions & 4 deletions components/viz/host/host_frame_sink_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ TEST_F(HostFrameSinkManagerLocalTest, CommunicateFrameToken) {
auto support =
CreateCompositorFrameSinkSupport(kParentFrameSink, true /* is_root */);

CompositorFrame compositor_frame(
test::MakeCompositorFrame({child_id1}, std::vector<SurfaceId>(),
std::vector<TransferableResource>()));
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));

Expand Down
109 changes: 56 additions & 53 deletions components/viz/service/display/display_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<RenderPass> render_pass2 = RenderPass::Create();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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));
Expand All @@ -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));

Expand Down
12 changes: 6 additions & 6 deletions components/viz/service/display/surface_aggregator_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextureDrawQuad>();
const gfx::Rect rect(0, 0, 1, 2);
Expand Down Expand Up @@ -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(
Expand All @@ -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<SurfaceDrawQuad>();
Expand All @@ -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));
Expand Down
Loading

0 comments on commit 30a805f

Please sign in to comment.