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
3 // found in the LICENSE file.
5 #include "cc/output/compositor_frame.h"
6 #include "cc/output/delegated_frame_data.h"
7 #include "cc/quads/render_pass.h"
8 #include "cc/quads/render_pass_draw_quad.h"
9 #include "cc/quads/solid_color_draw_quad.h"
10 #include "cc/quads/surface_draw_quad.h"
11 #include "cc/quads/texture_draw_quad.h"
12 #include "cc/resources/shared_bitmap_manager.h"
13 #include "cc/surfaces/surface.h"
14 #include "cc/surfaces/surface_aggregator.h"
15 #include "cc/surfaces/surface_aggregator_test_helpers.h"
16 #include "cc/surfaces/surface_factory.h"
17 #include "cc/surfaces/surface_factory_client.h"
18 #include "cc/surfaces/surface_id_allocator.h"
19 #include "cc/surfaces/surface_manager.h"
20 #include "cc/test/fake_output_surface.h"
21 #include "cc/test/fake_output_surface_client.h"
22 #include "cc/test/fake_resource_provider.h"
23 #include "cc/test/render_pass_test_utils.h"
24 #include "cc/test/test_shared_bitmap_manager.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/skia/include/core/SkColor.h"
32 SurfaceId
InvalidSurfaceId() {
33 static SurfaceId invalid
;
34 invalid
.id
= static_cast<uint64_t>(-1);
38 gfx::Size
SurfaceSize() {
39 static gfx::Size
size(5, 5);
43 class EmptySurfaceFactoryClient
: public SurfaceFactoryClient
{
45 void ReturnResources(const ReturnedResourceArray
& resources
) override
{}
48 class SurfaceAggregatorTest
: public testing::Test
{
50 explicit SurfaceAggregatorTest(bool use_damage_rect
)
51 : factory_(&manager_
, &empty_client_
),
52 aggregator_(&manager_
, NULL
, use_damage_rect
) {}
54 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {}
57 SurfaceManager manager_
;
58 EmptySurfaceFactoryClient empty_client_
;
59 SurfaceFactory factory_
;
60 SurfaceAggregator aggregator_
;
63 TEST_F(SurfaceAggregatorTest
, ValidSurfaceNoFrame
) {
65 factory_
.Create(one_id
);
66 scoped_ptr
<CompositorFrame
> frame
= aggregator_
.Aggregate(one_id
);
68 factory_
.Destroy(one_id
);
71 class SurfaceAggregatorValidSurfaceTest
: public SurfaceAggregatorTest
{
73 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect
)
74 : SurfaceAggregatorTest(use_damage_rect
),
76 child_allocator_(2u) {}
77 SurfaceAggregatorValidSurfaceTest()
78 : SurfaceAggregatorValidSurfaceTest(false) {}
80 void SetUp() override
{
81 SurfaceAggregatorTest::SetUp();
82 root_surface_id_
= allocator_
.GenerateId();
83 factory_
.Create(root_surface_id_
);
86 void TearDown() override
{
87 factory_
.Destroy(root_surface_id_
);
88 SurfaceAggregatorTest::TearDown();
91 void AggregateAndVerify(test::Pass
* expected_passes
,
92 size_t expected_pass_count
,
93 SurfaceId
* surface_ids
,
94 size_t expected_surface_count
) {
95 scoped_ptr
<CompositorFrame
> aggregated_frame
=
96 aggregator_
.Aggregate(root_surface_id_
);
98 ASSERT_TRUE(aggregated_frame
);
99 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
101 DelegatedFrameData
* frame_data
=
102 aggregated_frame
->delegated_frame_data
.get();
104 TestPassesMatchExpectations(
105 expected_passes
, expected_pass_count
, &frame_data
->render_pass_list
);
107 // Ensure no duplicate pass ids output.
108 std::set
<RenderPassId
> used_passes
;
109 for (auto* pass
: frame_data
->render_pass_list
) {
110 EXPECT_TRUE(used_passes
.insert(pass
->id
).second
);
113 EXPECT_EQ(expected_surface_count
,
114 aggregator_
.previous_contained_surfaces().size());
115 for (size_t i
= 0; i
< expected_surface_count
; i
++) {
117 aggregator_
.previous_contained_surfaces().find(surface_ids
[i
]) !=
118 aggregator_
.previous_contained_surfaces().end());
122 void SubmitPassListAsFrame(SurfaceId surface_id
, RenderPassList
* pass_list
) {
123 scoped_ptr
<DelegatedFrameData
> frame_data(new DelegatedFrameData
);
124 pass_list
->swap(frame_data
->render_pass_list
);
126 scoped_ptr
<CompositorFrame
> frame(new CompositorFrame
);
127 frame
->delegated_frame_data
= frame_data
.Pass();
129 factory_
.SubmitFrame(surface_id
, frame
.Pass(),
130 SurfaceFactory::DrawCallback());
133 void SubmitFrame(test::Pass
* passes
,
135 SurfaceId surface_id
) {
136 RenderPassList pass_list
;
137 AddPasses(&pass_list
, gfx::Rect(SurfaceSize()), passes
, pass_count
);
138 SubmitPassListAsFrame(surface_id
, &pass_list
);
141 void QueuePassAsFrame(scoped_ptr
<RenderPass
> pass
, SurfaceId surface_id
) {
142 scoped_ptr
<DelegatedFrameData
> delegated_frame_data(new DelegatedFrameData
);
143 delegated_frame_data
->render_pass_list
.push_back(pass
.Pass());
145 scoped_ptr
<CompositorFrame
> child_frame(new CompositorFrame
);
146 child_frame
->delegated_frame_data
= delegated_frame_data
.Pass();
148 factory_
.SubmitFrame(surface_id
, child_frame
.Pass(),
149 SurfaceFactory::DrawCallback());
153 SurfaceId root_surface_id_
;
154 SurfaceIdAllocator allocator_
;
155 SurfaceIdAllocator child_allocator_
;
158 // Tests that a very simple frame containing only two solid color quads makes it
159 // through the aggregator correctly.
160 TEST_F(SurfaceAggregatorValidSurfaceTest
, SimpleFrame
) {
161 test::Quad quads
[] = {test::Quad::SolidColorQuad(SK_ColorRED
),
162 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
163 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
165 SubmitFrame(passes
, arraysize(passes
), root_surface_id_
);
167 SurfaceId ids
[] = {root_surface_id_
};
168 AggregateAndVerify(passes
, arraysize(passes
), ids
, arraysize(ids
));
171 TEST_F(SurfaceAggregatorValidSurfaceTest
, OpacityCopied
) {
172 SurfaceId embedded_surface_id
= allocator_
.GenerateId();
173 factory_
.Create(embedded_surface_id
);
175 test::Quad embedded_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
176 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
177 test::Pass embedded_passes
[] = {
178 test::Pass(embedded_quads
, arraysize(embedded_quads
))};
180 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), embedded_surface_id
);
182 test::Quad quads
[] = {test::Quad::SurfaceQuad(embedded_surface_id
, .5f
)};
183 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
185 SubmitFrame(passes
, arraysize(passes
), root_surface_id_
);
187 scoped_ptr
<CompositorFrame
> aggregated_frame
=
188 aggregator_
.Aggregate(root_surface_id_
);
190 ASSERT_TRUE(aggregated_frame
);
191 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
193 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
195 RenderPassList
& render_pass_list(frame_data
->render_pass_list
);
196 ASSERT_EQ(2u, render_pass_list
.size());
197 SharedQuadStateList
& shared_quad_state_list(
198 render_pass_list
[0]->shared_quad_state_list
);
199 ASSERT_EQ(2u, shared_quad_state_list
.size());
200 EXPECT_EQ(1.f
, shared_quad_state_list
.ElementAt(0)->opacity
);
201 EXPECT_EQ(1.f
, shared_quad_state_list
.ElementAt(1)->opacity
);
203 SharedQuadStateList
& shared_quad_state_list2(
204 render_pass_list
[1]->shared_quad_state_list
);
205 ASSERT_EQ(1u, shared_quad_state_list2
.size());
206 EXPECT_EQ(.5f
, shared_quad_state_list2
.ElementAt(0)->opacity
);
208 factory_
.Destroy(embedded_surface_id
);
211 TEST_F(SurfaceAggregatorValidSurfaceTest
, MultiPassSimpleFrame
) {
212 test::Quad quads
[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE
),
213 test::Quad::SolidColorQuad(SK_ColorLTGRAY
)},
214 {test::Quad::SolidColorQuad(SK_ColorGRAY
),
215 test::Quad::SolidColorQuad(SK_ColorDKGRAY
)}};
216 test::Pass passes
[] = {
217 test::Pass(quads
[0], arraysize(quads
[0]), RenderPassId(1, 1)),
218 test::Pass(quads
[1], arraysize(quads
[1]), RenderPassId(1, 2))};
220 SubmitFrame(passes
, arraysize(passes
), root_surface_id_
);
222 SurfaceId ids
[] = {root_surface_id_
};
223 AggregateAndVerify(passes
, arraysize(passes
), ids
, arraysize(ids
));
226 // This tests very simple embedding. root_surface has a frame containing a few
227 // solid color quads and a surface quad referencing embedded_surface.
228 // embedded_surface has a frame containing only a solid color quad. The solid
229 // color quad should be aggregated into the final frame.
230 TEST_F(SurfaceAggregatorValidSurfaceTest
, SimpleSurfaceReference
) {
231 SurfaceId embedded_surface_id
= allocator_
.GenerateId();
232 factory_
.Create(embedded_surface_id
);
234 test::Quad embedded_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
)};
235 test::Pass embedded_passes
[] = {
236 test::Pass(embedded_quads
, arraysize(embedded_quads
))};
238 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), embedded_surface_id
);
240 test::Quad root_quads
[] = {test::Quad::SolidColorQuad(SK_ColorWHITE
),
241 test::Quad::SurfaceQuad(embedded_surface_id
, 1.f
),
242 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
243 test::Pass root_passes
[] = {test::Pass(root_quads
, arraysize(root_quads
))};
245 SubmitFrame(root_passes
, arraysize(root_passes
), root_surface_id_
);
247 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorWHITE
),
248 test::Quad::SolidColorQuad(SK_ColorGREEN
),
249 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
250 test::Pass expected_passes
[] = {
251 test::Pass(expected_quads
, arraysize(expected_quads
))};
252 SurfaceId ids
[] = {root_surface_id_
, embedded_surface_id
};
254 expected_passes
, arraysize(expected_passes
), ids
, arraysize(ids
));
256 factory_
.Destroy(embedded_surface_id
);
259 TEST_F(SurfaceAggregatorValidSurfaceTest
, CopyRequest
) {
260 SurfaceId embedded_surface_id
= allocator_
.GenerateId();
261 factory_
.Create(embedded_surface_id
);
263 test::Quad embedded_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
)};
264 test::Pass embedded_passes
[] = {
265 test::Pass(embedded_quads
, arraysize(embedded_quads
))};
267 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), embedded_surface_id
);
268 scoped_ptr
<CopyOutputRequest
> copy_request(
269 CopyOutputRequest::CreateEmptyRequest());
270 CopyOutputRequest
* copy_request_ptr
= copy_request
.get();
271 factory_
.RequestCopyOfSurface(embedded_surface_id
, copy_request
.Pass());
273 test::Quad root_quads
[] = {test::Quad::SolidColorQuad(SK_ColorWHITE
),
274 test::Quad::SurfaceQuad(embedded_surface_id
, 1.f
),
275 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
276 test::Pass root_passes
[] = {test::Pass(root_quads
, arraysize(root_quads
))};
278 SubmitFrame(root_passes
, arraysize(root_passes
), root_surface_id_
);
280 scoped_ptr
<CompositorFrame
> aggregated_frame
=
281 aggregator_
.Aggregate(root_surface_id_
);
283 ASSERT_TRUE(aggregated_frame
);
284 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
286 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
288 test::Quad expected_quads
[] = {
289 test::Quad::SolidColorQuad(SK_ColorWHITE
),
290 test::Quad::RenderPassQuad(frame_data
->render_pass_list
[0]->id
),
291 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
292 test::Pass expected_passes
[] = {
293 test::Pass(embedded_quads
, arraysize(embedded_quads
)),
294 test::Pass(expected_quads
, arraysize(expected_quads
))};
295 TestPassesMatchExpectations(expected_passes
,
296 arraysize(expected_passes
),
297 &frame_data
->render_pass_list
);
298 ASSERT_EQ(2u, frame_data
->render_pass_list
.size());
299 ASSERT_EQ(1u, frame_data
->render_pass_list
[0]->copy_requests
.size());
300 DCHECK_EQ(copy_request_ptr
,
301 frame_data
->render_pass_list
[0]->copy_requests
[0]);
303 SurfaceId surface_ids
[] = {root_surface_id_
, embedded_surface_id
};
304 EXPECT_EQ(arraysize(surface_ids
),
305 aggregator_
.previous_contained_surfaces().size());
306 for (size_t i
= 0; i
< arraysize(surface_ids
); i
++) {
308 aggregator_
.previous_contained_surfaces().find(surface_ids
[i
]) !=
309 aggregator_
.previous_contained_surfaces().end());
312 factory_
.Destroy(embedded_surface_id
);
315 // Root surface may contain copy requests.
316 TEST_F(SurfaceAggregatorValidSurfaceTest
, RootCopyRequest
) {
317 SurfaceId embedded_surface_id
= allocator_
.GenerateId();
318 factory_
.Create(embedded_surface_id
);
320 test::Quad embedded_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
)};
321 test::Pass embedded_passes
[] = {
322 test::Pass(embedded_quads
, arraysize(embedded_quads
))};
324 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), embedded_surface_id
);
325 scoped_ptr
<CopyOutputRequest
> copy_request(
326 CopyOutputRequest::CreateEmptyRequest());
327 CopyOutputRequest
* copy_request_ptr
= copy_request
.get();
328 scoped_ptr
<CopyOutputRequest
> copy_request2(
329 CopyOutputRequest::CreateEmptyRequest());
330 CopyOutputRequest
* copy_request2_ptr
= copy_request2
.get();
332 test::Quad root_quads
[] = {test::Quad::SolidColorQuad(SK_ColorWHITE
),
333 test::Quad::SurfaceQuad(embedded_surface_id
, 1.f
),
334 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
335 test::Quad root_quads2
[] = {test::Quad::SolidColorQuad(SK_ColorRED
)};
336 test::Pass root_passes
[] = {
337 test::Pass(root_quads
, arraysize(root_quads
), RenderPassId(1, 1)),
338 test::Pass(root_quads2
, arraysize(root_quads2
), RenderPassId(1, 2))};
340 RenderPassList pass_list
;
341 AddPasses(&pass_list
,
342 gfx::Rect(SurfaceSize()),
344 arraysize(root_passes
));
345 pass_list
[0]->copy_requests
.push_back(copy_request
.Pass());
346 pass_list
[1]->copy_requests
.push_back(copy_request2
.Pass());
348 scoped_ptr
<DelegatedFrameData
> frame_data(new DelegatedFrameData
);
349 pass_list
.swap(frame_data
->render_pass_list
);
351 scoped_ptr
<CompositorFrame
> frame(new CompositorFrame
);
352 frame
->delegated_frame_data
= frame_data
.Pass();
354 factory_
.SubmitFrame(root_surface_id_
, frame
.Pass(),
355 SurfaceFactory::DrawCallback());
358 scoped_ptr
<CompositorFrame
> aggregated_frame
=
359 aggregator_
.Aggregate(root_surface_id_
);
361 ASSERT_TRUE(aggregated_frame
);
362 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
364 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
366 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorWHITE
),
367 test::Quad::SolidColorQuad(SK_ColorGREEN
),
368 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
369 test::Pass expected_passes
[] = {
370 test::Pass(expected_quads
, arraysize(expected_quads
)),
371 test::Pass(root_quads2
, arraysize(root_quads2
))};
372 TestPassesMatchExpectations(expected_passes
,
373 arraysize(expected_passes
),
374 &frame_data
->render_pass_list
);
375 ASSERT_EQ(2u, frame_data
->render_pass_list
.size());
376 ASSERT_EQ(1u, frame_data
->render_pass_list
[0]->copy_requests
.size());
377 DCHECK_EQ(copy_request_ptr
,
378 frame_data
->render_pass_list
[0]->copy_requests
[0]);
379 ASSERT_EQ(1u, frame_data
->render_pass_list
[1]->copy_requests
.size());
380 DCHECK_EQ(copy_request2_ptr
,
381 frame_data
->render_pass_list
[1]->copy_requests
[0]);
383 SurfaceId surface_ids
[] = {root_surface_id_
, embedded_surface_id
};
384 EXPECT_EQ(arraysize(surface_ids
),
385 aggregator_
.previous_contained_surfaces().size());
386 for (size_t i
= 0; i
< arraysize(surface_ids
); i
++) {
388 aggregator_
.previous_contained_surfaces().find(surface_ids
[i
]) !=
389 aggregator_
.previous_contained_surfaces().end());
392 // Ensure copy requests have been removed from root surface.
393 const CompositorFrame
* original_frame
=
394 manager_
.GetSurfaceForId(root_surface_id_
)->GetEligibleFrame();
395 RenderPassList
& original_pass_list
=
396 original_frame
->delegated_frame_data
->render_pass_list
;
397 ASSERT_EQ(2u, original_pass_list
.size());
398 DCHECK(original_pass_list
[0]->copy_requests
.empty());
399 DCHECK(original_pass_list
[1]->copy_requests
.empty());
401 factory_
.Destroy(embedded_surface_id
);
404 // This tests referencing a surface that has multiple render passes.
405 TEST_F(SurfaceAggregatorValidSurfaceTest
, MultiPassSurfaceReference
) {
406 SurfaceId embedded_surface_id
= child_allocator_
.GenerateId();
407 factory_
.Create(embedded_surface_id
);
409 RenderPassId pass_ids
[] = {RenderPassId(1, 1), RenderPassId(1, 2),
412 test::Quad embedded_quads
[][2] = {
413 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)},
414 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids
[0])},
415 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids
[1])}};
416 test::Pass embedded_passes
[] = {
417 test::Pass(embedded_quads
[0], arraysize(embedded_quads
[0]), pass_ids
[0]),
418 test::Pass(embedded_quads
[1], arraysize(embedded_quads
[1]), pass_ids
[1]),
419 test::Pass(embedded_quads
[2], arraysize(embedded_quads
[2]), pass_ids
[2])};
421 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), embedded_surface_id
);
423 test::Quad root_quads
[][2] = {
424 {test::Quad::SolidColorQuad(5), test::Quad::SolidColorQuad(6)},
425 {test::Quad::SurfaceQuad(embedded_surface_id
, 1.f
),
426 test::Quad::RenderPassQuad(pass_ids
[0])},
427 {test::Quad::SolidColorQuad(7), test::Quad::RenderPassQuad(pass_ids
[1])}};
428 test::Pass root_passes
[] = {
429 test::Pass(root_quads
[0], arraysize(root_quads
[0]), pass_ids
[0]),
430 test::Pass(root_quads
[1], arraysize(root_quads
[1]), pass_ids
[1]),
431 test::Pass(root_quads
[2], arraysize(root_quads
[2]), pass_ids
[2])};
433 SubmitFrame(root_passes
, arraysize(root_passes
), root_surface_id_
);
435 scoped_ptr
<CompositorFrame
> aggregated_frame
=
436 aggregator_
.Aggregate(root_surface_id_
);
438 ASSERT_TRUE(aggregated_frame
);
439 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
441 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
443 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
445 ASSERT_EQ(5u, aggregated_pass_list
.size());
446 RenderPassId actual_pass_ids
[] = {
447 aggregated_pass_list
[0]->id
, aggregated_pass_list
[1]->id
,
448 aggregated_pass_list
[2]->id
, aggregated_pass_list
[3]->id
,
449 aggregated_pass_list
[4]->id
};
450 for (size_t i
= 0; i
< 5; ++i
) {
451 for (size_t j
= 0; j
< i
; ++j
) {
452 EXPECT_NE(actual_pass_ids
[i
], actual_pass_ids
[j
]);
457 SCOPED_TRACE("First pass");
458 // The first pass will just be the first pass from the root surfaces quad
459 // with no render pass quads to remap.
460 TestPassMatchesExpectations(root_passes
[0], aggregated_pass_list
[0]);
464 SCOPED_TRACE("Second pass");
465 // The next two passes will be from the embedded surface since we have to
466 // draw those passes before they are referenced from the render pass draw
467 // quad embedded into the root surface's second pass.
468 // First, there's the first embedded pass which doesn't reference anything
470 TestPassMatchesExpectations(embedded_passes
[0], aggregated_pass_list
[1]);
474 SCOPED_TRACE("Third pass");
475 const QuadList
& third_pass_quad_list
= aggregated_pass_list
[2]->quad_list
;
476 ASSERT_EQ(2u, third_pass_quad_list
.size());
477 TestQuadMatchesExpectations(embedded_quads
[1][0],
478 third_pass_quad_list
.ElementAt(0));
480 // This render pass pass quad will reference the first pass from the
481 // embedded surface, which is the second pass in the aggregated frame.
482 ASSERT_EQ(DrawQuad::RENDER_PASS
,
483 third_pass_quad_list
.ElementAt(1)->material
);
484 const RenderPassDrawQuad
* third_pass_render_pass_draw_quad
=
485 RenderPassDrawQuad::MaterialCast(third_pass_quad_list
.ElementAt(1));
486 EXPECT_EQ(actual_pass_ids
[1],
487 third_pass_render_pass_draw_quad
->render_pass_id
);
491 SCOPED_TRACE("Fourth pass");
492 // The fourth pass will have aggregated quads from the root surface's second
493 // pass and the embedded surface's first pass.
494 const QuadList
& fourth_pass_quad_list
= aggregated_pass_list
[3]->quad_list
;
495 ASSERT_EQ(3u, fourth_pass_quad_list
.size());
497 // The first quad will be the yellow quad from the embedded surface's last
499 TestQuadMatchesExpectations(embedded_quads
[2][0],
500 fourth_pass_quad_list
.ElementAt(0));
502 // The next quad will be a render pass quad referencing the second pass from
503 // the embedded surface, which is the third pass in the aggregated frame.
504 ASSERT_EQ(DrawQuad::RENDER_PASS
,
505 fourth_pass_quad_list
.ElementAt(1)->material
);
506 const RenderPassDrawQuad
* fourth_pass_first_render_pass_draw_quad
=
507 RenderPassDrawQuad::MaterialCast(fourth_pass_quad_list
.ElementAt(1));
508 EXPECT_EQ(actual_pass_ids
[2],
509 fourth_pass_first_render_pass_draw_quad
->render_pass_id
);
511 // The last quad will be a render pass quad referencing the first pass from
512 // the root surface, which is the first pass overall.
513 ASSERT_EQ(DrawQuad::RENDER_PASS
,
514 fourth_pass_quad_list
.ElementAt(2)->material
);
515 const RenderPassDrawQuad
* fourth_pass_second_render_pass_draw_quad
=
516 RenderPassDrawQuad::MaterialCast(fourth_pass_quad_list
.ElementAt(2));
517 EXPECT_EQ(actual_pass_ids
[0],
518 fourth_pass_second_render_pass_draw_quad
->render_pass_id
);
522 SCOPED_TRACE("Fifth pass");
523 const QuadList
& fifth_pass_quad_list
= aggregated_pass_list
[4]->quad_list
;
524 ASSERT_EQ(2u, fifth_pass_quad_list
.size());
526 TestQuadMatchesExpectations(root_quads
[2][0],
527 fifth_pass_quad_list
.ElementAt(0));
529 // The last quad in the last pass will reference the second pass from the
530 // root surface, which after aggregating is the fourth pass in the overall
532 ASSERT_EQ(DrawQuad::RENDER_PASS
,
533 fifth_pass_quad_list
.ElementAt(1)->material
);
534 const RenderPassDrawQuad
* fifth_pass_render_pass_draw_quad
=
535 RenderPassDrawQuad::MaterialCast(fifth_pass_quad_list
.ElementAt(1));
536 EXPECT_EQ(actual_pass_ids
[3],
537 fifth_pass_render_pass_draw_quad
->render_pass_id
);
539 factory_
.Destroy(embedded_surface_id
);
542 // Tests an invalid surface reference in a frame. The surface quad should just
544 TEST_F(SurfaceAggregatorValidSurfaceTest
, InvalidSurfaceReference
) {
545 test::Quad quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
546 test::Quad::SurfaceQuad(InvalidSurfaceId(), 1.f
),
547 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
548 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
550 SubmitFrame(passes
, arraysize(passes
), root_surface_id_
);
552 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
553 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
554 test::Pass expected_passes
[] = {
555 test::Pass(expected_quads
, arraysize(expected_quads
))};
556 SurfaceId ids
[] = {root_surface_id_
, InvalidSurfaceId()};
558 expected_passes
, arraysize(expected_passes
), ids
, arraysize(ids
));
561 // Tests a reference to a valid surface with no submitted frame. This quad
562 // should also just be dropped.
563 TEST_F(SurfaceAggregatorValidSurfaceTest
, ValidSurfaceReferenceWithNoFrame
) {
564 SurfaceId surface_with_no_frame_id
= allocator_
.GenerateId();
565 factory_
.Create(surface_with_no_frame_id
);
566 test::Quad quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
567 test::Quad::SurfaceQuad(surface_with_no_frame_id
, 1.f
),
568 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
569 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
571 SubmitFrame(passes
, arraysize(passes
), root_surface_id_
);
573 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
574 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
575 test::Pass expected_passes
[] = {
576 test::Pass(expected_quads
, arraysize(expected_quads
))};
577 SurfaceId ids
[] = {root_surface_id_
, surface_with_no_frame_id
};
579 expected_passes
, arraysize(expected_passes
), ids
, arraysize(ids
));
580 factory_
.Destroy(surface_with_no_frame_id
);
583 // Tests a surface quad referencing itself, generating a trivial cycle.
584 // The quad creating the cycle should be dropped from the final frame.
585 TEST_F(SurfaceAggregatorValidSurfaceTest
, SimpleCyclicalReference
) {
586 test::Quad quads
[] = {test::Quad::SurfaceQuad(root_surface_id_
, 1.f
),
587 test::Quad::SolidColorQuad(SK_ColorYELLOW
)};
588 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
590 SubmitFrame(passes
, arraysize(passes
), root_surface_id_
);
592 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW
)};
593 test::Pass expected_passes
[] = {
594 test::Pass(expected_quads
, arraysize(expected_quads
))};
595 SurfaceId ids
[] = {root_surface_id_
};
597 expected_passes
, arraysize(expected_passes
), ids
, arraysize(ids
));
600 // Tests a more complex cycle with one intermediate surface.
601 TEST_F(SurfaceAggregatorValidSurfaceTest
, TwoSurfaceCyclicalReference
) {
602 SurfaceId child_surface_id
= allocator_
.GenerateId();
603 factory_
.Create(child_surface_id
);
605 test::Quad parent_quads
[] = {test::Quad::SolidColorQuad(SK_ColorBLUE
),
606 test::Quad::SurfaceQuad(child_surface_id
, 1.f
),
607 test::Quad::SolidColorQuad(SK_ColorCYAN
)};
608 test::Pass parent_passes
[] = {
609 test::Pass(parent_quads
, arraysize(parent_quads
))};
611 SubmitFrame(parent_passes
, arraysize(parent_passes
), root_surface_id_
);
613 test::Quad child_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
614 test::Quad::SurfaceQuad(root_surface_id_
, 1.f
),
615 test::Quad::SolidColorQuad(SK_ColorMAGENTA
)};
616 test::Pass child_passes
[] = {test::Pass(child_quads
, arraysize(child_quads
))};
618 SubmitFrame(child_passes
, arraysize(child_passes
), child_surface_id
);
620 // The child surface's reference to the root_surface_ will be dropped, so
621 // we'll end up with:
622 // SK_ColorBLUE from the parent
623 // SK_ColorGREEN from the child
624 // SK_ColorMAGENTA from the child
625 // SK_ColorCYAN from the parent
626 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorBLUE
),
627 test::Quad::SolidColorQuad(SK_ColorGREEN
),
628 test::Quad::SolidColorQuad(SK_ColorMAGENTA
),
629 test::Quad::SolidColorQuad(SK_ColorCYAN
)};
630 test::Pass expected_passes
[] = {
631 test::Pass(expected_quads
, arraysize(expected_quads
))};
632 SurfaceId ids
[] = {root_surface_id_
, child_surface_id
};
634 expected_passes
, arraysize(expected_passes
), ids
, arraysize(ids
));
635 factory_
.Destroy(child_surface_id
);
638 // Tests that we map render pass IDs from different surfaces into a unified
639 // namespace and update RenderPassDrawQuad's id references to match.
640 TEST_F(SurfaceAggregatorValidSurfaceTest
, RenderPassIdMapping
) {
641 SurfaceId child_surface_id
= allocator_
.GenerateId();
642 factory_
.Create(child_surface_id
);
644 RenderPassId child_pass_id
[] = {RenderPassId(1, 1), RenderPassId(1, 2)};
645 test::Quad child_quad
[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN
)},
646 {test::Quad::RenderPassQuad(child_pass_id
[0])}};
647 test::Pass surface_passes
[] = {
648 test::Pass(child_quad
[0], arraysize(child_quad
[0]), child_pass_id
[0]),
649 test::Pass(child_quad
[1], arraysize(child_quad
[1]), child_pass_id
[1])};
651 SubmitFrame(surface_passes
, arraysize(surface_passes
), child_surface_id
);
653 // Pass IDs from the parent surface may collide with ones from the child.
654 RenderPassId parent_pass_id
[] = {RenderPassId(2, 1), RenderPassId(1, 2)};
655 test::Quad parent_quad
[][1] = {
656 {test::Quad::SurfaceQuad(child_surface_id
, 1.f
)},
657 {test::Quad::RenderPassQuad(parent_pass_id
[0])}};
658 test::Pass parent_passes
[] = {
659 test::Pass(parent_quad
[0], arraysize(parent_quad
[0]), parent_pass_id
[0]),
660 test::Pass(parent_quad
[1], arraysize(parent_quad
[1]), parent_pass_id
[1])};
662 SubmitFrame(parent_passes
, arraysize(parent_passes
), root_surface_id_
);
663 scoped_ptr
<CompositorFrame
> aggregated_frame
=
664 aggregator_
.Aggregate(root_surface_id_
);
666 ASSERT_TRUE(aggregated_frame
);
667 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
669 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
671 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
673 ASSERT_EQ(3u, aggregated_pass_list
.size());
674 RenderPassId actual_pass_ids
[] = {aggregated_pass_list
[0]->id
,
675 aggregated_pass_list
[1]->id
,
676 aggregated_pass_list
[2]->id
};
677 // Make sure the aggregated frame's pass IDs are all unique.
678 for (size_t i
= 0; i
< 3; ++i
) {
679 for (size_t j
= 0; j
< i
; ++j
) {
680 EXPECT_NE(actual_pass_ids
[j
], actual_pass_ids
[i
]) << "pass ids " << i
685 // Make sure the render pass quads reference the remapped pass IDs.
686 DrawQuad
* render_pass_quads
[] = {aggregated_pass_list
[1]->quad_list
.front(),
687 aggregated_pass_list
[2]->quad_list
.front()};
688 ASSERT_EQ(render_pass_quads
[0]->material
, DrawQuad::RENDER_PASS
);
691 RenderPassDrawQuad::MaterialCast(render_pass_quads
[0])->render_pass_id
);
693 ASSERT_EQ(render_pass_quads
[1]->material
, DrawQuad::RENDER_PASS
);
696 RenderPassDrawQuad::MaterialCast(render_pass_quads
[1])->render_pass_id
);
697 factory_
.Destroy(child_surface_id
);
700 void AddSolidColorQuadWithBlendMode(const gfx::Size
& size
,
702 const SkXfermode::Mode blend_mode
) {
703 const gfx::Transform layer_to_target_transform
;
704 const gfx::Size
layer_bounds(size
);
705 const gfx::Rect
visible_layer_rect(size
);
706 const gfx::Rect
clip_rect(size
);
708 bool is_clipped
= false;
711 bool force_anti_aliasing_off
= false;
712 SharedQuadState
* sqs
= pass
->CreateAndAppendSharedQuadState();
713 sqs
->SetAll(layer_to_target_transform
, layer_bounds
, visible_layer_rect
,
714 clip_rect
, is_clipped
, opacity
, blend_mode
, 0);
716 SolidColorDrawQuad
* color_quad
=
717 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
718 color_quad
->SetNew(pass
->shared_quad_state_list
.back(), visible_layer_rect
,
719 visible_layer_rect
, SK_ColorGREEN
,
720 force_anti_aliasing_off
);
723 // This tests that we update shared quad state pointers correctly within
724 // aggregated passes. The shared quad state list on the aggregated pass will
725 // include the shared quad states from each pass in one list so the quads will
726 // end up pointed to shared quad state objects at different offsets. This test
727 // uses the blend_mode value stored on the shared quad state to track the shared
728 // quad state, but anything saved on the shared quad state would work.
730 // This test has 4 surfaces in the following structure:
731 // root_surface -> quad with kClear_Mode,
732 // [child_one_surface],
733 // quad with kDstOver_Mode,
734 // [child_two_surface],
735 // quad with kDstIn_Mode
736 // child_one_surface -> quad with kSrc_Mode,
737 // [grandchild_surface],
738 // quad with kSrcOver_Mode
739 // child_two_surface -> quad with kSrcIn_Mode
740 // grandchild_surface -> quad with kDst_Mode
742 // Resulting in the following aggregated pass:
743 // quad_root_0 - blend_mode kClear_Mode
744 // quad_child_one_0 - blend_mode kSrc_Mode
745 // quad_grandchild_0 - blend_mode kDst_Mode
746 // quad_child_one_1 - blend_mode kSrcOver_Mode
747 // quad_root_1 - blend_mode kDstOver_Mode
748 // quad_child_two_0 - blend_mode kSrcIn_Mode
749 // quad_root_2 - blend_mode kDstIn_Mode
750 TEST_F(SurfaceAggregatorValidSurfaceTest
, AggregateSharedQuadStateProperties
) {
751 const SkXfermode::Mode blend_modes
[] = {SkXfermode::kClear_Mode
, // 0
752 SkXfermode::kSrc_Mode
, // 1
753 SkXfermode::kDst_Mode
, // 2
754 SkXfermode::kSrcOver_Mode
, // 3
755 SkXfermode::kDstOver_Mode
, // 4
756 SkXfermode::kSrcIn_Mode
, // 5
757 SkXfermode::kDstIn_Mode
, // 6
760 RenderPassId
pass_id(1, 1);
761 SurfaceId grandchild_surface_id
= allocator_
.GenerateId();
762 factory_
.Create(grandchild_surface_id
);
763 scoped_ptr
<RenderPass
> grandchild_pass
= RenderPass::Create();
764 gfx::Rect
output_rect(SurfaceSize());
765 gfx::Rect
damage_rect(SurfaceSize());
766 gfx::Transform transform_to_root_target
;
767 grandchild_pass
->SetNew(
768 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
769 AddSolidColorQuadWithBlendMode(
770 SurfaceSize(), grandchild_pass
.get(), blend_modes
[2]);
771 QueuePassAsFrame(grandchild_pass
.Pass(), grandchild_surface_id
);
773 SurfaceId child_one_surface_id
= allocator_
.GenerateId();
774 factory_
.Create(child_one_surface_id
);
776 scoped_ptr
<RenderPass
> child_one_pass
= RenderPass::Create();
777 child_one_pass
->SetNew(
778 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
779 AddSolidColorQuadWithBlendMode(
780 SurfaceSize(), child_one_pass
.get(), blend_modes
[1]);
781 SurfaceDrawQuad
* grandchild_surface_quad
=
782 child_one_pass
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
783 grandchild_surface_quad
->SetNew(child_one_pass
->shared_quad_state_list
.back(),
784 gfx::Rect(SurfaceSize()),
785 gfx::Rect(SurfaceSize()),
786 grandchild_surface_id
);
787 AddSolidColorQuadWithBlendMode(
788 SurfaceSize(), child_one_pass
.get(), blend_modes
[3]);
789 QueuePassAsFrame(child_one_pass
.Pass(), child_one_surface_id
);
791 SurfaceId child_two_surface_id
= allocator_
.GenerateId();
792 factory_
.Create(child_two_surface_id
);
794 scoped_ptr
<RenderPass
> child_two_pass
= RenderPass::Create();
795 child_two_pass
->SetNew(
796 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
797 AddSolidColorQuadWithBlendMode(
798 SurfaceSize(), child_two_pass
.get(), blend_modes
[5]);
799 QueuePassAsFrame(child_two_pass
.Pass(), child_two_surface_id
);
801 scoped_ptr
<RenderPass
> root_pass
= RenderPass::Create();
803 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
805 AddSolidColorQuadWithBlendMode(
806 SurfaceSize(), root_pass
.get(), blend_modes
[0]);
807 SurfaceDrawQuad
* child_one_surface_quad
=
808 root_pass
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
809 child_one_surface_quad
->SetNew(root_pass
->shared_quad_state_list
.back(),
810 gfx::Rect(SurfaceSize()),
811 gfx::Rect(SurfaceSize()),
812 child_one_surface_id
);
813 AddSolidColorQuadWithBlendMode(
814 SurfaceSize(), root_pass
.get(), blend_modes
[4]);
815 SurfaceDrawQuad
* child_two_surface_quad
=
816 root_pass
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
817 child_two_surface_quad
->SetNew(root_pass
->shared_quad_state_list
.back(),
818 gfx::Rect(SurfaceSize()),
819 gfx::Rect(SurfaceSize()),
820 child_two_surface_id
);
821 AddSolidColorQuadWithBlendMode(
822 SurfaceSize(), root_pass
.get(), blend_modes
[6]);
824 QueuePassAsFrame(root_pass
.Pass(), root_surface_id_
);
826 scoped_ptr
<CompositorFrame
> aggregated_frame
=
827 aggregator_
.Aggregate(root_surface_id_
);
829 ASSERT_TRUE(aggregated_frame
);
830 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
832 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
834 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
836 ASSERT_EQ(1u, aggregated_pass_list
.size());
838 const QuadList
& aggregated_quad_list
= aggregated_pass_list
[0]->quad_list
;
840 ASSERT_EQ(7u, aggregated_quad_list
.size());
842 for (auto iter
= aggregated_quad_list
.cbegin();
843 iter
!= aggregated_quad_list
.cend();
845 EXPECT_EQ(blend_modes
[iter
.index()], iter
->shared_quad_state
->blend_mode
)
848 factory_
.Destroy(child_one_surface_id
);
849 factory_
.Destroy(child_two_surface_id
);
850 factory_
.Destroy(grandchild_surface_id
);
853 // This tests that when aggregating a frame with multiple render passes that we
854 // map the transforms for the root pass but do not modify the transform on child
857 // The root surface has one pass with a surface quad transformed by +10 in the y
860 // The middle surface has one pass with a surface quad scaled by 2 in the x
861 // and 3 in the y directions.
863 // The child surface has two passes. The first pass has a quad with a transform
864 // of +5 in the x direction. The second pass has a reference to the first pass'
865 // pass id and a transform of +8 in the x direction.
867 // After aggregation, the child surface's root pass quad should have all
868 // transforms concatenated for a total transform of +23 x, +10 y. The
869 // contributing render pass' transform in the aggregate frame should not be
871 TEST_F(SurfaceAggregatorValidSurfaceTest
, AggregateMultiplePassWithTransform
) {
872 // Innermost child surface.
873 SurfaceId child_surface_id
= allocator_
.GenerateId();
875 factory_
.Create(child_surface_id
);
876 RenderPassId child_pass_id
[] = {RenderPassId(1, 1), RenderPassId(1, 2)};
877 test::Quad child_quads
[][1] = {
878 {test::Quad::SolidColorQuad(SK_ColorGREEN
)},
879 {test::Quad::RenderPassQuad(child_pass_id
[0])},
881 test::Pass child_passes
[] = {
882 test::Pass(child_quads
[0], arraysize(child_quads
[0]), child_pass_id
[0]),
883 test::Pass(child_quads
[1], arraysize(child_quads
[1]),
886 RenderPassList child_pass_list
;
887 AddPasses(&child_pass_list
, gfx::Rect(SurfaceSize()), child_passes
,
888 arraysize(child_passes
));
890 RenderPass
* child_nonroot_pass
= child_pass_list
.at(0u);
891 child_nonroot_pass
->transform_to_root_target
.Translate(8, 0);
892 SharedQuadState
* child_nonroot_pass_sqs
=
893 child_nonroot_pass
->shared_quad_state_list
.front();
894 child_nonroot_pass_sqs
->quad_to_target_transform
.Translate(5, 0);
896 RenderPass
* child_root_pass
= child_pass_list
.at(1u);
897 SharedQuadState
* child_root_pass_sqs
=
898 child_root_pass
->shared_quad_state_list
.front();
899 child_root_pass_sqs
->quad_to_target_transform
.Translate(8, 0);
900 child_root_pass_sqs
->is_clipped
= true;
901 child_root_pass_sqs
->clip_rect
= gfx::Rect(0, 0, 5, 5);
903 scoped_ptr
<DelegatedFrameData
> child_frame_data(new DelegatedFrameData
);
904 child_pass_list
.swap(child_frame_data
->render_pass_list
);
906 scoped_ptr
<CompositorFrame
> child_frame(new CompositorFrame
);
907 child_frame
->delegated_frame_data
= child_frame_data
.Pass();
909 factory_
.SubmitFrame(child_surface_id
, child_frame
.Pass(),
910 SurfaceFactory::DrawCallback());
913 // Middle child surface.
914 SurfaceId middle_surface_id
= allocator_
.GenerateId();
916 factory_
.Create(middle_surface_id
);
917 test::Quad middle_quads
[] = {
918 test::Quad::SurfaceQuad(child_surface_id
, 1.f
)};
919 test::Pass middle_passes
[] = {
920 test::Pass(middle_quads
, arraysize(middle_quads
)),
923 RenderPassList middle_pass_list
;
924 AddPasses(&middle_pass_list
, gfx::Rect(SurfaceSize()), middle_passes
,
925 arraysize(middle_passes
));
927 RenderPass
* middle_root_pass
= middle_pass_list
.at(0u);
928 middle_root_pass
->quad_list
.ElementAt(0)->visible_rect
=
929 gfx::Rect(0, 1, 100, 7);
930 SharedQuadState
* middle_root_pass_sqs
=
931 middle_root_pass
->shared_quad_state_list
.front();
932 middle_root_pass_sqs
->quad_to_target_transform
.Scale(2, 3);
934 scoped_ptr
<DelegatedFrameData
> middle_frame_data(new DelegatedFrameData
);
935 middle_pass_list
.swap(middle_frame_data
->render_pass_list
);
937 scoped_ptr
<CompositorFrame
> middle_frame(new CompositorFrame
);
938 middle_frame
->delegated_frame_data
= middle_frame_data
.Pass();
940 factory_
.SubmitFrame(middle_surface_id
, middle_frame
.Pass(),
941 SurfaceFactory::DrawCallback());
945 test::Quad secondary_quads
[] = {
946 test::Quad::SolidColorQuad(1),
947 test::Quad::SurfaceQuad(middle_surface_id
, 1.f
)};
948 test::Quad root_quads
[] = {test::Quad::SolidColorQuad(1)};
949 test::Pass root_passes
[] = {
950 test::Pass(secondary_quads
, arraysize(secondary_quads
)),
951 test::Pass(root_quads
, arraysize(root_quads
))};
953 RenderPassList root_pass_list
;
954 AddPasses(&root_pass_list
,
955 gfx::Rect(SurfaceSize()),
957 arraysize(root_passes
));
960 ->shared_quad_state_list
.front()
961 ->quad_to_target_transform
.Translate(0, 7);
963 ->shared_quad_state_list
.ElementAt(1)
964 ->quad_to_target_transform
.Translate(0, 10);
965 root_pass_list
.at(0)->quad_list
.ElementAt(1)->visible_rect
=
966 gfx::Rect(0, 0, 8, 100);
968 root_pass_list
[0]->transform_to_root_target
.Translate(10, 5);
970 scoped_ptr
<DelegatedFrameData
> root_frame_data(new DelegatedFrameData
);
971 root_pass_list
.swap(root_frame_data
->render_pass_list
);
973 scoped_ptr
<CompositorFrame
> root_frame(new CompositorFrame
);
974 root_frame
->delegated_frame_data
= root_frame_data
.Pass();
976 factory_
.SubmitFrame(root_surface_id_
, root_frame
.Pass(),
977 SurfaceFactory::DrawCallback());
979 scoped_ptr
<CompositorFrame
> aggregated_frame
=
980 aggregator_
.Aggregate(root_surface_id_
);
982 ASSERT_TRUE(aggregated_frame
);
983 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
985 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
987 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
989 ASSERT_EQ(3u, aggregated_pass_list
.size());
991 ASSERT_EQ(1u, aggregated_pass_list
[0]->shared_quad_state_list
.size());
993 // The first pass should have one shared quad state for the one solid color
995 EXPECT_EQ(1u, aggregated_pass_list
[0]->shared_quad_state_list
.size());
996 // The second pass should have just two shared quad states. We'll
997 // verify the properties through the quads.
998 EXPECT_EQ(2u, aggregated_pass_list
[1]->shared_quad_state_list
.size());
1000 EXPECT_EQ(1u, aggregated_pass_list
[2]->shared_quad_state_list
.size());
1002 SharedQuadState
* aggregated_first_pass_sqs
=
1003 aggregated_pass_list
[0]->shared_quad_state_list
.front();
1005 // The first pass's transform should be unaffected by the embedding and still
1006 // be a translation by +5 in the x direction.
1007 gfx::Transform expected_aggregated_first_pass_sqs_transform
;
1008 expected_aggregated_first_pass_sqs_transform
.Translate(5, 0);
1009 EXPECT_EQ(expected_aggregated_first_pass_sqs_transform
.ToString(),
1010 aggregated_first_pass_sqs
->quad_to_target_transform
.ToString());
1012 // The first pass's transform to the root target should include the aggregated
1013 // transform, including the transform from the child pass to the root.
1014 gfx::Transform expected_first_pass_transform_to_root_target
;
1015 expected_first_pass_transform_to_root_target
.Translate(10, 5);
1016 expected_first_pass_transform_to_root_target
.Translate(0, 10);
1017 expected_first_pass_transform_to_root_target
.Scale(2, 3);
1018 expected_first_pass_transform_to_root_target
.Translate(8, 0);
1019 EXPECT_EQ(expected_first_pass_transform_to_root_target
.ToString(),
1020 aggregated_pass_list
[0]->transform_to_root_target
.ToString());
1022 ASSERT_EQ(2u, aggregated_pass_list
[1]->quad_list
.size());
1024 gfx::Transform expected_root_pass_quad_transforms
[2];
1025 // The first quad in the root pass is the solid color quad from the original
1026 // root surface. Its transform should be unaffected by the aggregation and
1027 // still be +7 in the y direction.
1028 expected_root_pass_quad_transforms
[0].Translate(0, 7);
1029 // The second quad in the root pass is aggregated from the child surface so
1030 // its transform should be the combination of its original translation
1031 // (0, 10), the middle surface draw quad's scale of (2, 3), and the
1032 // child surface draw quad's translation (8, 0).
1033 expected_root_pass_quad_transforms
[1].Translate(0, 10);
1034 expected_root_pass_quad_transforms
[1].Scale(2, 3);
1035 expected_root_pass_quad_transforms
[1].Translate(8, 0);
1037 for (auto iter
= aggregated_pass_list
[1]->quad_list
.cbegin();
1038 iter
!= aggregated_pass_list
[1]->quad_list
.cend();
1040 EXPECT_EQ(expected_root_pass_quad_transforms
[iter
.index()].ToString(),
1041 iter
->shared_quad_state
->quad_to_target_transform
.ToString())
1046 aggregated_pass_list
[1]->shared_quad_state_list
.ElementAt(1)->is_clipped
);
1048 // The second quad in the root pass is aggregated from the child, so its
1049 // clip rect must be transformed by the child's translation/scale and
1050 // clipped be the visible_rects for both children.
1051 EXPECT_EQ(gfx::Rect(0, 13, 8, 12).ToString(),
1052 aggregated_pass_list
[1]
1053 ->shared_quad_state_list
.ElementAt(1)
1054 ->clip_rect
.ToString());
1056 factory_
.Destroy(middle_surface_id
);
1057 factory_
.Destroy(child_surface_id
);
1060 // Tests that damage rects are aggregated correctly when surfaces change.
1061 TEST_F(SurfaceAggregatorValidSurfaceTest
, AggregateDamageRect
) {
1062 test::Quad child_quads
[] = {test::Quad::RenderPassQuad(RenderPassId(1, 1))};
1063 test::Pass child_passes
[] = {
1064 test::Pass(child_quads
, arraysize(child_quads
), RenderPassId(1, 1))};
1066 RenderPassList child_pass_list
;
1067 AddPasses(&child_pass_list
,
1068 gfx::Rect(SurfaceSize()),
1070 arraysize(child_passes
));
1072 RenderPass
* child_root_pass
= child_pass_list
.at(0u);
1073 SharedQuadState
* child_root_pass_sqs
=
1074 child_root_pass
->shared_quad_state_list
.front();
1075 child_root_pass_sqs
->quad_to_target_transform
.Translate(8, 0);
1077 scoped_ptr
<DelegatedFrameData
> child_frame_data(new DelegatedFrameData
);
1078 child_pass_list
.swap(child_frame_data
->render_pass_list
);
1080 scoped_ptr
<CompositorFrame
> child_frame(new CompositorFrame
);
1081 child_frame
->delegated_frame_data
= child_frame_data
.Pass();
1083 SurfaceId child_surface_id
= allocator_
.GenerateId();
1084 factory_
.Create(child_surface_id
);
1085 factory_
.SubmitFrame(child_surface_id
, child_frame
.Pass(),
1086 SurfaceFactory::DrawCallback());
1088 test::Quad parent_surface_quads
[] = {
1089 test::Quad::SurfaceQuad(child_surface_id
, 1.f
)};
1090 test::Pass parent_surface_passes
[] = {
1091 test::Pass(parent_surface_quads
, arraysize(parent_surface_quads
),
1092 RenderPassId(1, 1))};
1094 RenderPassList parent_surface_pass_list
;
1095 AddPasses(&parent_surface_pass_list
,
1096 gfx::Rect(SurfaceSize()),
1097 parent_surface_passes
,
1098 arraysize(parent_surface_passes
));
1100 // Parent surface is only used to test if the transform is applied correctly
1101 // to the child surface's damage.
1102 scoped_ptr
<DelegatedFrameData
> parent_surface_frame_data(
1103 new DelegatedFrameData
);
1104 parent_surface_pass_list
.swap(parent_surface_frame_data
->render_pass_list
);
1106 scoped_ptr
<CompositorFrame
> parent_surface_frame(new CompositorFrame
);
1107 parent_surface_frame
->delegated_frame_data
= parent_surface_frame_data
.Pass();
1109 SurfaceId parent_surface_id
= allocator_
.GenerateId();
1110 factory_
.Create(parent_surface_id
);
1111 factory_
.SubmitFrame(parent_surface_id
, parent_surface_frame
.Pass(),
1112 SurfaceFactory::DrawCallback());
1114 test::Quad root_surface_quads
[] = {
1115 test::Quad::SurfaceQuad(parent_surface_id
, 1.f
)};
1116 test::Quad root_render_pass_quads
[] = {
1117 test::Quad::RenderPassQuad(RenderPassId(1, 1))};
1119 test::Pass root_passes
[] = {
1120 test::Pass(root_surface_quads
, arraysize(root_surface_quads
),
1121 RenderPassId(1, 1)),
1122 test::Pass(root_render_pass_quads
, arraysize(root_render_pass_quads
),
1123 RenderPassId(2, 1))};
1125 RenderPassList root_pass_list
;
1126 AddPasses(&root_pass_list
,
1127 gfx::Rect(SurfaceSize()),
1129 arraysize(root_passes
));
1131 root_pass_list
.at(0)
1132 ->shared_quad_state_list
.front()
1133 ->quad_to_target_transform
.Translate(0, 10);
1134 root_pass_list
.at(0)->damage_rect
= gfx::Rect(5, 5, 10, 10);
1135 root_pass_list
.at(1)->damage_rect
= gfx::Rect(5, 5, 100, 100);
1137 scoped_ptr
<DelegatedFrameData
> root_frame_data(new DelegatedFrameData
);
1138 root_pass_list
.swap(root_frame_data
->render_pass_list
);
1140 scoped_ptr
<CompositorFrame
> root_frame(new CompositorFrame
);
1141 root_frame
->delegated_frame_data
= root_frame_data
.Pass();
1143 factory_
.SubmitFrame(root_surface_id_
, root_frame
.Pass(),
1144 SurfaceFactory::DrawCallback());
1146 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1147 aggregator_
.Aggregate(root_surface_id_
);
1149 ASSERT_TRUE(aggregated_frame
);
1150 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1152 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
1154 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1156 ASSERT_EQ(2u, aggregated_pass_list
.size());
1158 // Damage rect for first aggregation should contain entire root surface.
1160 aggregated_pass_list
[1]->damage_rect
.Contains(gfx::Rect(SurfaceSize())));
1163 AddPasses(&child_pass_list
,
1164 gfx::Rect(SurfaceSize()),
1166 arraysize(child_passes
));
1168 RenderPass
* child_root_pass
= child_pass_list
.at(0u);
1169 SharedQuadState
* child_root_pass_sqs
=
1170 child_root_pass
->shared_quad_state_list
.front();
1171 child_root_pass_sqs
->quad_to_target_transform
.Translate(8, 0);
1172 child_root_pass
->damage_rect
= gfx::Rect(10, 10, 10, 10);
1174 scoped_ptr
<DelegatedFrameData
> child_frame_data(new DelegatedFrameData
);
1175 child_pass_list
.swap(child_frame_data
->render_pass_list
);
1177 scoped_ptr
<CompositorFrame
> child_frame(new CompositorFrame
);
1178 child_frame
->delegated_frame_data
= child_frame_data
.Pass();
1180 factory_
.SubmitFrame(child_surface_id
, child_frame
.Pass(),
1181 SurfaceFactory::DrawCallback());
1183 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1184 aggregator_
.Aggregate(root_surface_id_
);
1186 ASSERT_TRUE(aggregated_frame
);
1187 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1189 DelegatedFrameData
* frame_data
=
1190 aggregated_frame
->delegated_frame_data
.get();
1192 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1194 ASSERT_EQ(2u, aggregated_pass_list
.size());
1196 // Outer surface didn't change, so transformed inner damage rect should be
1198 EXPECT_EQ(gfx::Rect(10, 20, 10, 10).ToString(),
1199 aggregated_pass_list
[1]->damage_rect
.ToString());
1203 RenderPassList root_pass_list
;
1204 AddPasses(&root_pass_list
,
1205 gfx::Rect(SurfaceSize()),
1207 arraysize(root_passes
));
1209 root_pass_list
.at(0)
1210 ->shared_quad_state_list
.front()
1211 ->quad_to_target_transform
.Translate(0, 10);
1212 root_pass_list
.at(0)->damage_rect
= gfx::Rect(0, 0, 1, 1);
1214 scoped_ptr
<DelegatedFrameData
> root_frame_data(new DelegatedFrameData
);
1215 root_pass_list
.swap(root_frame_data
->render_pass_list
);
1217 scoped_ptr
<CompositorFrame
> root_frame(new CompositorFrame
);
1218 root_frame
->delegated_frame_data
= root_frame_data
.Pass();
1220 factory_
.SubmitFrame(root_surface_id_
, root_frame
.Pass(),
1221 SurfaceFactory::DrawCallback());
1225 RenderPassList root_pass_list
;
1226 AddPasses(&root_pass_list
,
1227 gfx::Rect(SurfaceSize()),
1229 arraysize(root_passes
));
1231 root_pass_list
.at(0)
1232 ->shared_quad_state_list
.front()
1233 ->quad_to_target_transform
.Translate(0, 10);
1234 root_pass_list
.at(0)->damage_rect
= gfx::Rect(1, 1, 1, 1);
1236 scoped_ptr
<DelegatedFrameData
> root_frame_data(new DelegatedFrameData
);
1237 root_pass_list
.swap(root_frame_data
->render_pass_list
);
1239 scoped_ptr
<CompositorFrame
> root_frame(new CompositorFrame
);
1240 root_frame
->delegated_frame_data
= root_frame_data
.Pass();
1242 factory_
.SubmitFrame(root_surface_id_
, root_frame
.Pass(),
1243 SurfaceFactory::DrawCallback());
1245 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1246 aggregator_
.Aggregate(root_surface_id_
);
1248 ASSERT_TRUE(aggregated_frame
);
1249 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1251 DelegatedFrameData
* frame_data
=
1252 aggregated_frame
->delegated_frame_data
.get();
1254 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1256 ASSERT_EQ(2u, aggregated_pass_list
.size());
1258 // The root surface was enqueued without being aggregated once, so it should
1259 // be treated as completely damaged.
1260 EXPECT_TRUE(aggregated_pass_list
[1]->damage_rect
.Contains(
1261 gfx::Rect(SurfaceSize())));
1264 // No Surface changed, so no damage should be given.
1266 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1267 aggregator_
.Aggregate(root_surface_id_
);
1269 ASSERT_TRUE(aggregated_frame
);
1270 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1272 DelegatedFrameData
* frame_data
=
1273 aggregated_frame
->delegated_frame_data
.get();
1275 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1277 ASSERT_EQ(2u, aggregated_pass_list
.size());
1279 EXPECT_TRUE(aggregated_pass_list
[1]->damage_rect
.IsEmpty());
1282 // SetFullDamageRectForSurface should cause the entire output to be
1283 // marked as damaged.
1285 aggregator_
.SetFullDamageForSurface(root_surface_id_
);
1286 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1287 aggregator_
.Aggregate(root_surface_id_
);
1289 ASSERT_TRUE(aggregated_frame
);
1290 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1292 DelegatedFrameData
* frame_data
=
1293 aggregated_frame
->delegated_frame_data
.get();
1295 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1297 ASSERT_EQ(2u, aggregated_pass_list
.size());
1299 EXPECT_TRUE(aggregated_pass_list
[1]->damage_rect
.Contains(
1300 gfx::Rect(SurfaceSize())));
1303 factory_
.Destroy(child_surface_id
);
1306 class SurfaceAggregatorPartialSwapTest
1307 : public SurfaceAggregatorValidSurfaceTest
{
1309 SurfaceAggregatorPartialSwapTest()
1310 : SurfaceAggregatorValidSurfaceTest(true) {}
1313 // Tests that quads outside the damage rect are ignored.
1314 TEST_F(SurfaceAggregatorPartialSwapTest
, IgnoreOutside
) {
1315 SurfaceId child_surface_id
= allocator_
.GenerateId();
1316 factory_
.Create(child_surface_id
);
1317 // The child surface has two quads, one with a visible rect of 13,13 4x4 and
1318 // the other other with a visible rect of 10,10 2x2 (relative to root target
1321 RenderPassId child_pass_id
= RenderPassId(1, 1);
1322 test::Quad child_quads1
[] = {test::Quad::RenderPassQuad(child_pass_id
)};
1323 test::Quad child_quads2
[] = {test::Quad::RenderPassQuad(child_pass_id
)};
1324 test::Pass child_passes
[] = {
1325 test::Pass(child_quads1
, arraysize(child_quads1
), child_pass_id
),
1326 test::Pass(child_quads2
, arraysize(child_quads2
), child_pass_id
)};
1328 RenderPassList child_pass_list
;
1329 AddPasses(&child_pass_list
, gfx::Rect(SurfaceSize()), child_passes
,
1330 arraysize(child_passes
));
1332 child_pass_list
.at(0u)->quad_list
.ElementAt(0)->visible_rect
=
1333 gfx::Rect(1, 1, 2, 2);
1334 SharedQuadState
* child_sqs
=
1335 child_pass_list
.at(0u)->shared_quad_state_list
.ElementAt(0u);
1336 child_sqs
->quad_to_target_transform
.Translate(1, 1);
1337 child_sqs
->quad_to_target_transform
.Scale(2, 2);
1339 child_pass_list
.at(1u)->quad_list
.ElementAt(0)->visible_rect
=
1340 gfx::Rect(0, 0, 2, 2);
1342 SubmitPassListAsFrame(child_surface_id
, &child_pass_list
);
1346 test::Quad root_quads
[] = {test::Quad::SurfaceQuad(child_surface_id
, 1.f
)};
1348 test::Pass root_passes
[] = {test::Pass(root_quads
, arraysize(root_quads
))};
1350 RenderPassList root_pass_list
;
1351 AddPasses(&root_pass_list
, gfx::Rect(SurfaceSize()), root_passes
,
1352 arraysize(root_passes
));
1354 RenderPass
* root_pass
= root_pass_list
.at(0u);
1355 root_pass
->shared_quad_state_list
.front()
1356 ->quad_to_target_transform
.Translate(10, 10);
1357 root_pass
->damage_rect
= gfx::Rect(0, 0, 1, 1);
1359 SubmitPassListAsFrame(root_surface_id_
, &root_pass_list
);
1362 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1363 aggregator_
.Aggregate(root_surface_id_
);
1365 ASSERT_TRUE(aggregated_frame
);
1366 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1368 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
1370 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1372 ASSERT_EQ(2u, aggregated_pass_list
.size());
1374 // Damage rect for first aggregation should contain entire root surface.
1375 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), aggregated_pass_list
[1]->damage_rect
);
1376 EXPECT_EQ(1u, aggregated_pass_list
[0]->quad_list
.size());
1377 EXPECT_EQ(1u, aggregated_pass_list
[1]->quad_list
.size());
1379 // Create a root surface with a smaller damage rect.
1381 test::Quad root_quads
[] = {test::Quad::SurfaceQuad(child_surface_id
, 1.f
)};
1383 test::Pass root_passes
[] = {test::Pass(root_quads
, arraysize(root_quads
))};
1385 RenderPassList root_pass_list
;
1386 AddPasses(&root_pass_list
, gfx::Rect(SurfaceSize()), root_passes
,
1387 arraysize(root_passes
));
1389 RenderPass
* root_pass
= root_pass_list
.at(0u);
1390 root_pass
->shared_quad_state_list
.front()
1391 ->quad_to_target_transform
.Translate(10, 10);
1392 root_pass
->damage_rect
= gfx::Rect(10, 10, 2, 2);
1393 SubmitPassListAsFrame(root_surface_id_
, &root_pass_list
);
1397 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1398 aggregator_
.Aggregate(root_surface_id_
);
1400 ASSERT_TRUE(aggregated_frame
);
1401 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1403 DelegatedFrameData
* frame_data
=
1404 aggregated_frame
->delegated_frame_data
.get();
1406 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1408 ASSERT_EQ(2u, aggregated_pass_list
.size());
1410 // Only first quad from surface is inside damage rect and should be
1412 EXPECT_EQ(gfx::Rect(10, 10, 2, 2), aggregated_pass_list
[1]->damage_rect
);
1413 EXPECT_EQ(0u, aggregated_pass_list
[0]->quad_list
.size());
1414 EXPECT_EQ(1u, aggregated_pass_list
[1]->quad_list
.size());
1415 EXPECT_EQ(gfx::Rect(0, 0, 2, 2),
1416 aggregated_pass_list
[1]->quad_list
.back()->visible_rect
);
1419 // New child frame has same content and no damage, but has a
1420 // CopyOutputRequest.
1422 RenderPassId child_pass_id
= RenderPassId(1, 1);
1423 test::Quad child_quads1
[] = {test::Quad::RenderPassQuad(child_pass_id
)};
1424 test::Quad child_quads2
[] = {test::Quad::RenderPassQuad(child_pass_id
)};
1425 test::Pass child_passes
[] = {
1426 test::Pass(child_quads1
, arraysize(child_quads1
), child_pass_id
),
1427 test::Pass(child_quads2
, arraysize(child_quads2
), child_pass_id
)};
1429 RenderPassList child_pass_list
;
1430 AddPasses(&child_pass_list
, gfx::Rect(SurfaceSize()), child_passes
,
1431 arraysize(child_passes
));
1433 child_pass_list
.at(0u)->quad_list
.ElementAt(0)->visible_rect
=
1434 gfx::Rect(1, 1, 2, 2);
1435 SharedQuadState
* child_sqs
=
1436 child_pass_list
.at(0u)->shared_quad_state_list
.ElementAt(0u);
1437 child_sqs
->quad_to_target_transform
.Translate(1, 1);
1438 child_sqs
->quad_to_target_transform
.Scale(2, 2);
1440 child_pass_list
.at(1u)->quad_list
.ElementAt(0)->visible_rect
=
1441 gfx::Rect(0, 0, 2, 2);
1443 RenderPass
* child_root_pass
= child_pass_list
.at(1u);
1445 child_root_pass
->copy_requests
.push_back(
1446 CopyOutputRequest::CreateEmptyRequest());
1447 child_root_pass
->damage_rect
= gfx::Rect();
1448 SubmitPassListAsFrame(child_surface_id
, &child_pass_list
);
1452 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1453 aggregator_
.Aggregate(root_surface_id_
);
1455 ASSERT_TRUE(aggregated_frame
);
1456 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1458 DelegatedFrameData
* frame_data
=
1459 aggregated_frame
->delegated_frame_data
.get();
1461 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1463 // Output frame should have no damage, but all quads included.
1464 ASSERT_EQ(3u, aggregated_pass_list
.size());
1466 EXPECT_TRUE(aggregated_pass_list
[1]->damage_rect
.IsEmpty());
1467 ASSERT_EQ(1u, aggregated_pass_list
[0]->quad_list
.size());
1468 ASSERT_EQ(1u, aggregated_pass_list
[1]->quad_list
.size());
1469 EXPECT_EQ(gfx::Rect(1, 1, 2, 2),
1470 aggregated_pass_list
[0]->quad_list
.ElementAt(0)->visible_rect
);
1471 EXPECT_EQ(gfx::Rect(0, 0, 2, 2),
1472 aggregated_pass_list
[1]->quad_list
.ElementAt(0)->visible_rect
);
1476 scoped_ptr
<CompositorFrame
> aggregated_frame
=
1477 aggregator_
.Aggregate(root_surface_id_
);
1479 ASSERT_TRUE(aggregated_frame
);
1480 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
1482 DelegatedFrameData
* frame_data
=
1483 aggregated_frame
->delegated_frame_data
.get();
1485 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
1486 // There were no changes since last aggregation, so output should be empty
1487 // and have no damage.
1488 ASSERT_EQ(1u, aggregated_pass_list
.size());
1489 EXPECT_TRUE(aggregated_pass_list
[0]->damage_rect
.IsEmpty());
1490 ASSERT_EQ(0u, aggregated_pass_list
[0]->quad_list
.size());
1493 factory_
.Destroy(child_surface_id
);
1496 class SurfaceAggregatorWithResourcesTest
: public testing::Test
{
1498 void SetUp() override
{
1499 output_surface_
= FakeOutputSurface::CreateSoftware(
1500 make_scoped_ptr(new SoftwareOutputDevice
));
1501 output_surface_
->BindToClient(&output_surface_client_
);
1502 shared_bitmap_manager_
.reset(new TestSharedBitmapManager
);
1504 resource_provider_
= FakeResourceProvider::Create(
1505 output_surface_
.get(), shared_bitmap_manager_
.get());
1508 new SurfaceAggregator(&manager_
, resource_provider_
.get(), false));
1512 SurfaceManager manager_
;
1513 FakeOutputSurfaceClient output_surface_client_
;
1514 scoped_ptr
<OutputSurface
> output_surface_
;
1515 scoped_ptr
<SharedBitmapManager
> shared_bitmap_manager_
;
1516 scoped_ptr
<ResourceProvider
> resource_provider_
;
1517 scoped_ptr
<SurfaceAggregator
> aggregator_
;
1520 class ResourceTrackingSurfaceFactoryClient
: public SurfaceFactoryClient
{
1522 ResourceTrackingSurfaceFactoryClient() {}
1523 ~ResourceTrackingSurfaceFactoryClient() override
{}
1525 void ReturnResources(const ReturnedResourceArray
& resources
) override
{
1526 returned_resources_
= resources
;
1529 ReturnedResourceArray
returned_resources() const {
1530 return returned_resources_
;
1534 ReturnedResourceArray returned_resources_
;
1536 DISALLOW_COPY_AND_ASSIGN(ResourceTrackingSurfaceFactoryClient
);
1539 void SubmitFrameWithResources(ResourceId
* resource_ids
,
1540 size_t num_resource_ids
,
1543 SurfaceFactory
* factory
,
1544 SurfaceId surface_id
) {
1545 scoped_ptr
<DelegatedFrameData
> frame_data(new DelegatedFrameData
);
1546 scoped_ptr
<RenderPass
> pass
= RenderPass::Create();
1547 pass
->id
= RenderPassId(1, 1);
1548 SharedQuadState
* sqs
= pass
->CreateAndAppendSharedQuadState();
1550 if (!child_id
.is_null()) {
1551 SurfaceDrawQuad
* surface_quad
=
1552 pass
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
1553 surface_quad
->SetNew(sqs
, gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1),
1557 for (size_t i
= 0u; i
< num_resource_ids
; ++i
) {
1558 TransferableResource resource
;
1559 resource
.id
= resource_ids
[i
];
1560 // ResourceProvider is software, so only software resources are valid.
1561 resource
.is_software
= valid
;
1562 frame_data
->resource_list
.push_back(resource
);
1563 TextureDrawQuad
* quad
= pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
1564 const gfx::Rect rect
;
1565 const gfx::Rect opaque_rect
;
1566 const gfx::Rect visible_rect
;
1567 bool needs_blending
= false;
1568 bool premultiplied_alpha
= false;
1569 const gfx::PointF uv_top_left
;
1570 const gfx::PointF uv_bottom_right
;
1571 SkColor background_color
= SK_ColorGREEN
;
1572 const float vertex_opacity
[4] = {0.f
, 0.f
, 1.f
, 1.f
};
1573 bool flipped
= false;
1574 bool nearest_neighbor
= false;
1575 quad
->SetAll(sqs
, rect
, opaque_rect
, visible_rect
, needs_blending
,
1576 resource_ids
[i
], gfx::Size(), false, premultiplied_alpha
,
1577 uv_top_left
, uv_bottom_right
, background_color
, vertex_opacity
,
1578 flipped
, nearest_neighbor
);
1580 frame_data
->render_pass_list
.push_back(pass
.Pass());
1581 scoped_ptr
<CompositorFrame
> frame(new CompositorFrame
);
1582 frame
->delegated_frame_data
= frame_data
.Pass();
1583 factory
->SubmitFrame(surface_id
, frame
.Pass(),
1584 SurfaceFactory::DrawCallback());
1587 TEST_F(SurfaceAggregatorWithResourcesTest
, TakeResourcesOneSurface
) {
1588 ResourceTrackingSurfaceFactoryClient client
;
1589 SurfaceFactory
factory(&manager_
, &client
);
1590 SurfaceId
surface_id(7u);
1591 factory
.Create(surface_id
);
1593 ResourceId ids
[] = {11, 12, 13};
1594 SubmitFrameWithResources(ids
, arraysize(ids
), true, SurfaceId(), &factory
,
1597 scoped_ptr
<CompositorFrame
> frame
= aggregator_
->Aggregate(surface_id
);
1599 // Nothing should be available to be returned yet.
1600 EXPECT_TRUE(client
.returned_resources().empty());
1602 SubmitFrameWithResources(NULL
, 0u, true, SurfaceId(), &factory
, surface_id
);
1604 frame
= aggregator_
->Aggregate(surface_id
);
1606 ASSERT_EQ(3u, client
.returned_resources().size());
1607 ResourceId returned_ids
[3];
1608 for (size_t i
= 0; i
< 3; ++i
) {
1609 returned_ids
[i
] = client
.returned_resources()[i
].id
;
1611 EXPECT_THAT(returned_ids
,
1612 testing::WhenSorted(testing::ElementsAreArray(ids
)));
1613 factory
.Destroy(surface_id
);
1616 TEST_F(SurfaceAggregatorWithResourcesTest
, TakeInvalidResources
) {
1617 ResourceTrackingSurfaceFactoryClient client
;
1618 SurfaceFactory
factory(&manager_
, &client
);
1619 SurfaceId
surface_id(7u);
1620 factory
.Create(surface_id
);
1622 scoped_ptr
<DelegatedFrameData
> frame_data(new DelegatedFrameData
);
1623 scoped_ptr
<RenderPass
> pass
= RenderPass::Create();
1624 pass
->id
= RenderPassId(1, 1);
1625 TransferableResource resource
;
1627 // ResourceProvider is software but resource is not, so it should be
1629 resource
.is_software
= false;
1630 frame_data
->resource_list
.push_back(resource
);
1631 frame_data
->render_pass_list
.push_back(pass
.Pass());
1632 scoped_ptr
<CompositorFrame
> frame(new CompositorFrame
);
1633 frame
->delegated_frame_data
= frame_data
.Pass();
1634 factory
.SubmitFrame(surface_id
, frame
.Pass(), SurfaceFactory::DrawCallback());
1636 scoped_ptr
<CompositorFrame
> returned_frame
=
1637 aggregator_
->Aggregate(surface_id
);
1639 // Nothing should be available to be returned yet.
1640 EXPECT_TRUE(client
.returned_resources().empty());
1642 SubmitFrameWithResources(NULL
, 0, true, SurfaceId(), &factory
, surface_id
);
1643 ASSERT_EQ(1u, client
.returned_resources().size());
1644 EXPECT_EQ(11u, client
.returned_resources()[0].id
);
1646 factory
.Destroy(surface_id
);
1649 TEST_F(SurfaceAggregatorWithResourcesTest
, TwoSurfaces
) {
1650 ResourceTrackingSurfaceFactoryClient client
;
1651 SurfaceFactory
factory(&manager_
, &client
);
1652 SurfaceId
surface_id(7u);
1653 factory
.Create(surface_id
);
1654 SurfaceId
surface_id2(8u);
1655 factory
.Create(surface_id2
);
1657 ResourceId ids
[] = {11, 12, 13};
1658 SubmitFrameWithResources(ids
, arraysize(ids
), true, SurfaceId(), &factory
,
1660 ResourceId ids2
[] = {14, 15, 16};
1661 SubmitFrameWithResources(ids2
, arraysize(ids2
), true, SurfaceId(), &factory
,
1664 scoped_ptr
<CompositorFrame
> frame
= aggregator_
->Aggregate(surface_id
);
1666 SubmitFrameWithResources(NULL
, 0, true, SurfaceId(), &factory
, surface_id
);
1668 // Nothing should be available to be returned yet.
1669 EXPECT_TRUE(client
.returned_resources().empty());
1671 frame
= aggregator_
->Aggregate(surface_id2
);
1673 // surface_id wasn't referenced, so its resources should be returned.
1674 ASSERT_EQ(3u, client
.returned_resources().size());
1675 ResourceId returned_ids
[3];
1676 for (size_t i
= 0; i
< 3; ++i
) {
1677 returned_ids
[i
] = client
.returned_resources()[i
].id
;
1679 EXPECT_THAT(returned_ids
,
1680 testing::WhenSorted(testing::ElementsAreArray(ids
)));
1681 EXPECT_EQ(3u, resource_provider_
->num_resources());
1682 factory
.Destroy(surface_id
);
1683 factory
.Destroy(surface_id2
);
1686 // Ensure that aggregator completely ignores Surfaces that reference invalid
1688 TEST_F(SurfaceAggregatorWithResourcesTest
, InvalidChildSurface
) {
1689 ResourceTrackingSurfaceFactoryClient client
;
1690 SurfaceFactory
factory(&manager_
, &client
);
1691 SurfaceId
root_surface_id(7u);
1692 factory
.Create(root_surface_id
);
1693 SurfaceId
middle_surface_id(8u);
1694 factory
.Create(middle_surface_id
);
1695 SurfaceId
child_surface_id(9u);
1696 factory
.Create(child_surface_id
);
1698 ResourceId ids
[] = {14, 15, 16};
1699 SubmitFrameWithResources(ids
, arraysize(ids
), true, SurfaceId(), &factory
,
1702 ResourceId ids2
[] = {17, 18, 19};
1703 SubmitFrameWithResources(ids2
, arraysize(ids2
), false, child_surface_id
,
1704 &factory
, middle_surface_id
);
1706 ResourceId ids3
[] = {20, 21, 22};
1707 SubmitFrameWithResources(ids3
, arraysize(ids3
), true, middle_surface_id
,
1708 &factory
, root_surface_id
);
1710 scoped_ptr
<CompositorFrame
> frame
;
1711 frame
= aggregator_
->Aggregate(root_surface_id
);
1713 RenderPassList
* pass_list
= &frame
->delegated_frame_data
->render_pass_list
;
1714 ASSERT_EQ(1u, pass_list
->size());
1715 EXPECT_EQ(1u, pass_list
->back()->shared_quad_state_list
.size());
1716 EXPECT_EQ(3u, pass_list
->back()->quad_list
.size());
1718 SubmitFrameWithResources(ids2
, arraysize(ids
), true, child_surface_id
,
1719 &factory
, middle_surface_id
);
1721 frame
= aggregator_
->Aggregate(root_surface_id
);
1723 pass_list
= &frame
->delegated_frame_data
->render_pass_list
;
1724 ASSERT_EQ(1u, pass_list
->size());
1725 EXPECT_EQ(3u, pass_list
->back()->shared_quad_state_list
.size());
1726 EXPECT_EQ(9u, pass_list
->back()->quad_list
.size());
1728 factory
.Destroy(root_surface_id
);
1729 factory
.Destroy(child_surface_id
);
1730 factory
.Destroy(middle_surface_id
);