OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/compositor_frame.h" | 5 #include "cc/output/compositor_frame.h" |
6 #include "cc/output/delegated_frame_data.h" | 6 #include "cc/output/delegated_frame_data.h" |
7 #include "cc/quads/render_pass.h" | 7 #include "cc/quads/render_pass.h" |
8 #include "cc/quads/render_pass_draw_quad.h" | 8 #include "cc/quads/render_pass_draw_quad.h" |
9 #include "cc/quads/solid_color_draw_quad.h" | 9 #include "cc/quads/solid_color_draw_quad.h" |
10 #include "cc/quads/surface_draw_quad.h" | 10 #include "cc/quads/surface_draw_quad.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 60 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
61 SurfaceId one_id(7); | 61 SurfaceId one_id(7); |
62 factory_.Create(one_id, SurfaceSize()); | 62 factory_.Create(one_id, SurfaceSize()); |
63 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); | 63 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); |
64 EXPECT_FALSE(frame); | 64 EXPECT_FALSE(frame); |
65 factory_.Destroy(one_id); | 65 factory_.Destroy(one_id); |
66 } | 66 } |
67 | 67 |
68 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { | 68 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
69 public: | 69 public: |
70 SurfaceAggregatorValidSurfaceTest() : allocator_(1u) {} | 70 SurfaceAggregatorValidSurfaceTest() : allocator_(1u), child_allocator_(2u) {} |
71 | 71 |
72 virtual void SetUp() { | 72 virtual void SetUp() { |
73 SurfaceAggregatorTest::SetUp(); | 73 SurfaceAggregatorTest::SetUp(); |
74 root_surface_id_ = allocator_.GenerateId(); | 74 root_surface_id_ = allocator_.GenerateId(); |
75 factory_.Create(root_surface_id_, SurfaceSize()); | 75 factory_.Create(root_surface_id_, SurfaceSize()); |
76 } | 76 } |
77 | 77 |
78 virtual void TearDown() { | 78 virtual void TearDown() { |
79 factory_.Destroy(root_surface_id_); | 79 factory_.Destroy(root_surface_id_); |
80 SurfaceAggregatorTest::TearDown(); | 80 SurfaceAggregatorTest::TearDown(); |
81 } | 81 } |
82 | 82 |
83 void AggregateAndVerify(test::Pass* expected_passes, | 83 void AggregateAndVerify(test::Pass* expected_passes, |
84 size_t expected_pass_count, | 84 size_t expected_pass_count, |
85 SurfaceId* surface_ids, | 85 SurfaceId* surface_ids, |
86 size_t expected_surface_count) { | 86 size_t expected_surface_count) { |
87 scoped_ptr<CompositorFrame> aggregated_frame = | 87 scoped_ptr<CompositorFrame> aggregated_frame = |
88 aggregator_.Aggregate(root_surface_id_); | 88 aggregator_.Aggregate(root_surface_id_); |
89 | 89 |
90 ASSERT_TRUE(aggregated_frame); | 90 ASSERT_TRUE(aggregated_frame); |
91 ASSERT_TRUE(aggregated_frame->delegated_frame_data); | 91 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
92 | 92 |
93 DelegatedFrameData* frame_data = | 93 DelegatedFrameData* frame_data = |
94 aggregated_frame->delegated_frame_data.get(); | 94 aggregated_frame->delegated_frame_data.get(); |
95 | 95 |
96 TestPassesMatchExpectations( | 96 TestPassesMatchExpectations( |
97 expected_passes, expected_pass_count, &frame_data->render_pass_list); | 97 expected_passes, expected_pass_count, &frame_data->render_pass_list); |
98 | 98 |
| 99 // Ensure no duplicate pass ids output. |
| 100 std::set<RenderPassId> used_passes; |
| 101 for (auto* pass : frame_data->render_pass_list) { |
| 102 EXPECT_TRUE(used_passes.insert(pass->id).second); |
| 103 } |
| 104 |
99 EXPECT_EQ(expected_surface_count, | 105 EXPECT_EQ(expected_surface_count, |
100 aggregator_.previous_contained_surfaces().size()); | 106 aggregator_.previous_contained_surfaces().size()); |
101 for (size_t i = 0; i < expected_surface_count; i++) { | 107 for (size_t i = 0; i < expected_surface_count; i++) { |
102 EXPECT_TRUE( | 108 EXPECT_TRUE( |
103 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != | 109 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != |
104 aggregator_.previous_contained_surfaces().end()); | 110 aggregator_.previous_contained_surfaces().end()); |
105 } | 111 } |
106 } | 112 } |
107 | 113 |
108 void SubmitFrame(test::Pass* passes, | 114 void SubmitFrame(test::Pass* passes, |
(...skipping 17 matching lines...) Expand all Loading... |
126 | 132 |
127 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame); | 133 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame); |
128 child_frame->delegated_frame_data = delegated_frame_data.Pass(); | 134 child_frame->delegated_frame_data = delegated_frame_data.Pass(); |
129 | 135 |
130 factory_.SubmitFrame(surface_id, child_frame.Pass(), base::Closure()); | 136 factory_.SubmitFrame(surface_id, child_frame.Pass(), base::Closure()); |
131 } | 137 } |
132 | 138 |
133 protected: | 139 protected: |
134 SurfaceId root_surface_id_; | 140 SurfaceId root_surface_id_; |
135 SurfaceIdAllocator allocator_; | 141 SurfaceIdAllocator allocator_; |
| 142 SurfaceIdAllocator child_allocator_; |
136 }; | 143 }; |
137 | 144 |
138 // Tests that a very simple frame containing only two solid color quads makes it | 145 // Tests that a very simple frame containing only two solid color quads makes it |
139 // through the aggregator correctly. | 146 // through the aggregator correctly. |
140 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) { | 147 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) { |
141 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorRED), | 148 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorRED), |
142 test::Quad::SolidColorQuad(SK_ColorBLUE)}; | 149 test::Quad::SolidColorQuad(SK_ColorBLUE)}; |
143 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; | 150 test::Pass passes[] = {test::Pass(quads, arraysize(quads))}; |
144 | 151 |
145 SubmitFrame(passes, arraysize(passes), root_surface_id_); | 152 SubmitFrame(passes, arraysize(passes), root_surface_id_); |
146 | 153 |
147 SurfaceId ids[] = {root_surface_id_}; | 154 SurfaceId ids[] = {root_surface_id_}; |
148 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); | 155 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); |
149 } | 156 } |
150 | 157 |
151 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) { | 158 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) { |
152 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE), | 159 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE), |
153 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}, | 160 test::Quad::SolidColorQuad(SK_ColorLTGRAY)}, |
154 {test::Quad::SolidColorQuad(SK_ColorGRAY), | 161 {test::Quad::SolidColorQuad(SK_ColorGRAY), |
155 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}}; | 162 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}}; |
156 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0])), | 163 test::Pass passes[] = { |
157 test::Pass(quads[1], arraysize(quads[1]))}; | 164 test::Pass(quads[0], arraysize(quads[0]), RenderPassId(1, 1)), |
| 165 test::Pass(quads[1], arraysize(quads[1]), RenderPassId(1, 2))}; |
158 | 166 |
159 SubmitFrame(passes, arraysize(passes), root_surface_id_); | 167 SubmitFrame(passes, arraysize(passes), root_surface_id_); |
160 | 168 |
161 SurfaceId ids[] = {root_surface_id_}; | 169 SurfaceId ids[] = {root_surface_id_}; |
162 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); | 170 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids)); |
163 } | 171 } |
164 | 172 |
165 // This tests very simple embedding. root_surface has a frame containing a few | 173 // This tests very simple embedding. root_surface has a frame containing a few |
166 // solid color quads and a surface quad referencing embedded_surface. | 174 // solid color quads and a surface quad referencing embedded_surface. |
167 // embedded_surface has a frame containing only a solid color quad. The solid | 175 // embedded_surface has a frame containing only a solid color quad. The solid |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 original_frame->delegated_frame_data->render_pass_list; | 342 original_frame->delegated_frame_data->render_pass_list; |
335 ASSERT_EQ(2u, original_pass_list.size()); | 343 ASSERT_EQ(2u, original_pass_list.size()); |
336 DCHECK(original_pass_list[0]->copy_requests.empty()); | 344 DCHECK(original_pass_list[0]->copy_requests.empty()); |
337 DCHECK(original_pass_list[1]->copy_requests.empty()); | 345 DCHECK(original_pass_list[1]->copy_requests.empty()); |
338 | 346 |
339 factory_.Destroy(embedded_surface_id); | 347 factory_.Destroy(embedded_surface_id); |
340 } | 348 } |
341 | 349 |
342 // This tests referencing a surface that has multiple render passes. | 350 // This tests referencing a surface that has multiple render passes. |
343 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) { | 351 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) { |
344 SurfaceId embedded_surface_id = allocator_.GenerateId(); | 352 SurfaceId embedded_surface_id = child_allocator_.GenerateId(); |
345 factory_.Create(embedded_surface_id, SurfaceSize()); | 353 factory_.Create(embedded_surface_id, SurfaceSize()); |
346 | 354 |
347 RenderPassId pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2), | 355 RenderPassId pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2), |
348 RenderPassId(1, 3)}; | 356 RenderPassId(1, 3)}; |
349 | 357 |
350 test::Quad embedded_quads[][2] = { | 358 test::Quad embedded_quads[][2] = { |
351 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)}, | 359 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)}, |
352 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])}, | 360 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])}, |
353 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}}; | 361 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}}; |
354 test::Pass embedded_passes[] = { | 362 test::Pass embedded_passes[] = { |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 returned_ids[i] = client.returned_resources()[i].id; | 1238 returned_ids[i] = client.returned_resources()[i].id; |
1231 } | 1239 } |
1232 EXPECT_THAT(returned_ids, | 1240 EXPECT_THAT(returned_ids, |
1233 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1241 testing::WhenSorted(testing::ElementsAreArray(ids))); |
1234 factory.Destroy(surface_id); | 1242 factory.Destroy(surface_id); |
1235 } | 1243 } |
1236 | 1244 |
1237 } // namespace | 1245 } // namespace |
1238 } // namespace cc | 1246 } // namespace cc |
1239 | 1247 |
OLD | NEW |