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/surfaces/surface.h"
12 #include "cc/surfaces/surface_aggregator.h"
13 #include "cc/surfaces/surface_aggregator_test_helpers.h"
14 #include "cc/surfaces/surface_manager.h"
15 #include "cc/test/render_pass_test_common.h"
16 #include "cc/test/render_pass_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkColor.h"
22 const int kInvalidSurfaceId
= -1;
24 class SurfaceAggregatorTest
: public testing::Test
{
26 SurfaceAggregatorTest() : aggregator_(&manager_
) {}
29 SurfaceManager manager_
;
30 SurfaceAggregator aggregator_
;
33 TEST_F(SurfaceAggregatorTest
, InvalidSurfaceId
) {
34 scoped_ptr
<CompositorFrame
> frame
= aggregator_
.Aggregate(kInvalidSurfaceId
);
38 TEST_F(SurfaceAggregatorTest
, ValidSurfaceNoFrame
) {
39 Surface
one(&manager_
, NULL
, gfx::Size(5, 5));
40 scoped_ptr
<CompositorFrame
> frame
= aggregator_
.Aggregate(one
.surface_id());
44 class SurfaceAggregatorValidSurfaceTest
: public SurfaceAggregatorTest
{
46 SurfaceAggregatorValidSurfaceTest()
47 : root_surface_(&manager_
, NULL
, gfx::Size(5, 5)) {}
49 void AggregateAndVerify(test::Pass
* expected_passes
,
50 size_t expected_pass_count
) {
51 scoped_ptr
<CompositorFrame
> aggregated_frame
=
52 aggregator_
.Aggregate(root_surface_
.surface_id());
54 ASSERT_TRUE(aggregated_frame
);
55 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
57 DelegatedFrameData
* frame_data
=
58 aggregated_frame
->delegated_frame_data
.get();
60 TestPassesMatchExpectations(
61 expected_passes
, expected_pass_count
, &frame_data
->render_pass_list
);
65 Surface root_surface_
;
68 // Tests that a very simple frame containing only two solid color quads makes it
69 // through the aggregator correctly.
70 TEST_F(SurfaceAggregatorValidSurfaceTest
, SimpleFrame
) {
71 test::Quad quads
[] = {test::Quad::SolidColorQuad(SK_ColorRED
),
72 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
73 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
75 SubmitFrame(passes
, arraysize(passes
), &root_surface_
);
77 AggregateAndVerify(passes
, arraysize(passes
));
80 TEST_F(SurfaceAggregatorValidSurfaceTest
, MultiPassSimpleFrame
) {
81 test::Quad quads
[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE
),
82 test::Quad::SolidColorQuad(SK_ColorLTGRAY
)},
83 {test::Quad::SolidColorQuad(SK_ColorGRAY
),
84 test::Quad::SolidColorQuad(SK_ColorDKGRAY
)}};
85 test::Pass passes
[] = {test::Pass(quads
[0], arraysize(quads
[0])),
86 test::Pass(quads
[1], arraysize(quads
[1]))};
88 SubmitFrame(passes
, arraysize(passes
), &root_surface_
);
90 AggregateAndVerify(passes
, arraysize(passes
));
93 // This tests very simple embedding. root_surface has a frame containing a few
94 // solid color quads and a surface quad referencing embedded_surface.
95 // embedded_surface has a frame containing only a solid color quad. The solid
96 // color quad should be aggregated into the final frame.
97 TEST_F(SurfaceAggregatorValidSurfaceTest
, SimpleSurfaceReference
) {
98 gfx::Size
surface_size(5, 5);
100 Surface
embedded_surface(&manager_
, NULL
, surface_size
);
102 test::Quad embedded_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
)};
103 test::Pass embedded_passes
[] = {
104 test::Pass(embedded_quads
, arraysize(embedded_quads
))};
106 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), &embedded_surface
);
108 test::Quad root_quads
[] = {
109 test::Quad::SolidColorQuad(SK_ColorWHITE
),
110 test::Quad::SurfaceQuad(embedded_surface
.surface_id()),
111 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
112 test::Pass root_passes
[] = {test::Pass(root_quads
, arraysize(root_quads
))};
114 SubmitFrame(root_passes
, arraysize(root_passes
), &root_surface_
);
116 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorWHITE
),
117 test::Quad::SolidColorQuad(SK_ColorGREEN
),
118 test::Quad::SolidColorQuad(SK_ColorBLACK
)};
119 test::Pass expected_passes
[] = {
120 test::Pass(expected_quads
, arraysize(expected_quads
))};
121 AggregateAndVerify(expected_passes
, arraysize(expected_passes
));
124 // This tests referencing a surface that has multiple render passes.
125 TEST_F(SurfaceAggregatorValidSurfaceTest
, MultiPassSurfaceReference
) {
126 gfx::Size
surface_size(5, 5);
128 Surface
embedded_surface(&manager_
, NULL
, surface_size
);
130 RenderPass::Id pass_ids
[] = {RenderPass::Id(1, 1), RenderPass::Id(1, 2),
131 RenderPass::Id(1, 3)};
133 test::Quad embedded_quads
[][2] = {
134 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)},
135 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids
[0])},
136 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids
[1])}};
137 test::Pass embedded_passes
[] = {
138 test::Pass(embedded_quads
[0], arraysize(embedded_quads
[0]), pass_ids
[0]),
139 test::Pass(embedded_quads
[1], arraysize(embedded_quads
[1]), pass_ids
[1]),
140 test::Pass(embedded_quads
[2], arraysize(embedded_quads
[2]), pass_ids
[2])};
142 SubmitFrame(embedded_passes
, arraysize(embedded_passes
), &embedded_surface
);
144 test::Quad root_quads
[][2] = {
145 {test::Quad::SolidColorQuad(5), test::Quad::SolidColorQuad(6)},
146 {test::Quad::SurfaceQuad(embedded_surface
.surface_id()),
147 test::Quad::RenderPassQuad(pass_ids
[0])},
148 {test::Quad::SolidColorQuad(7), test::Quad::RenderPassQuad(pass_ids
[1])}};
149 test::Pass root_passes
[] = {
150 test::Pass(root_quads
[0], arraysize(root_quads
[0]), pass_ids
[0]),
151 test::Pass(root_quads
[1], arraysize(root_quads
[1]), pass_ids
[1]),
152 test::Pass(root_quads
[2], arraysize(root_quads
[2]), pass_ids
[2])};
154 SubmitFrame(root_passes
, arraysize(root_passes
), &root_surface_
);
156 scoped_ptr
<CompositorFrame
> aggregated_frame
=
157 aggregator_
.Aggregate(root_surface_
.surface_id());
159 ASSERT_TRUE(aggregated_frame
);
160 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
162 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
164 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
166 ASSERT_EQ(5u, aggregated_pass_list
.size());
167 RenderPass::Id actual_pass_ids
[] = {
168 aggregated_pass_list
[0]->id
, aggregated_pass_list
[1]->id
,
169 aggregated_pass_list
[2]->id
, aggregated_pass_list
[3]->id
,
170 aggregated_pass_list
[4]->id
};
171 for (size_t i
= 0; i
< 5; ++i
) {
172 for (size_t j
= 0; j
< i
; ++j
) {
173 EXPECT_NE(actual_pass_ids
[i
], actual_pass_ids
[j
]);
178 SCOPED_TRACE("First pass");
179 // The first pass will just be the first pass from the root surfaces quad
180 // with no render pass quads to remap.
181 TestPassMatchesExpectations(root_passes
[0], aggregated_pass_list
[0]);
185 SCOPED_TRACE("Second pass");
186 // The next two passes will be from the embedded surface since we have to
187 // draw those passes before they are referenced from the render pass draw
188 // quad embedded into the root surface's second pass.
189 // First, there's the first embedded pass which doesn't reference anything
191 TestPassMatchesExpectations(embedded_passes
[0], aggregated_pass_list
[1]);
195 SCOPED_TRACE("Third pass");
196 const QuadList
& third_pass_quad_list
= aggregated_pass_list
[2]->quad_list
;
197 ASSERT_EQ(2u, third_pass_quad_list
.size());
198 TestQuadMatchesExpectations(embedded_quads
[1][0],
199 third_pass_quad_list
.at(0u));
201 // This render pass pass quad will reference the first pass from the
202 // embedded surface, which is the second pass in the aggregated frame.
203 ASSERT_EQ(DrawQuad::RENDER_PASS
, third_pass_quad_list
.at(1u)->material
);
204 const RenderPassDrawQuad
* third_pass_render_pass_draw_quad
=
205 RenderPassDrawQuad::MaterialCast(third_pass_quad_list
.at(1u));
206 EXPECT_EQ(actual_pass_ids
[1],
207 third_pass_render_pass_draw_quad
->render_pass_id
);
211 SCOPED_TRACE("Fourth pass");
212 // The fourth pass will have aggregated quads from the root surface's second
213 // pass and the embedded surface's first pass.
214 const QuadList
& fourth_pass_quad_list
= aggregated_pass_list
[3]->quad_list
;
215 ASSERT_EQ(3u, fourth_pass_quad_list
.size());
217 // The first quad will be the yellow quad from the embedded surface's last
219 TestQuadMatchesExpectations(embedded_quads
[2][0],
220 fourth_pass_quad_list
.at(0u));
222 // The next quad will be a render pass quad referencing the second pass from
223 // the embedded surface, which is the third pass in the aggregated frame.
224 ASSERT_EQ(DrawQuad::RENDER_PASS
, fourth_pass_quad_list
.at(1u)->material
);
225 const RenderPassDrawQuad
* fourth_pass_first_render_pass_draw_quad
=
226 RenderPassDrawQuad::MaterialCast(fourth_pass_quad_list
.at(1u));
227 EXPECT_EQ(actual_pass_ids
[2],
228 fourth_pass_first_render_pass_draw_quad
->render_pass_id
);
230 // The last quad will be a render pass quad referencing the first pass from
231 // the root surface, which is the first pass overall.
232 ASSERT_EQ(DrawQuad::RENDER_PASS
, fourth_pass_quad_list
.at(2u)->material
);
233 const RenderPassDrawQuad
* fourth_pass_second_render_pass_draw_quad
=
234 RenderPassDrawQuad::MaterialCast(fourth_pass_quad_list
.at(2u));
235 EXPECT_EQ(actual_pass_ids
[0],
236 fourth_pass_second_render_pass_draw_quad
->render_pass_id
);
240 SCOPED_TRACE("Fifth pass");
241 const QuadList
& fifth_pass_quad_list
= aggregated_pass_list
[4]->quad_list
;
242 ASSERT_EQ(2u, fifth_pass_quad_list
.size());
244 TestQuadMatchesExpectations(root_quads
[2][0], fifth_pass_quad_list
.at(0));
246 // The last quad in the last pass will reference the second pass from the
247 // root surface, which after aggregating is the fourth pass in the overall
249 ASSERT_EQ(DrawQuad::RENDER_PASS
, fifth_pass_quad_list
.at(1u)->material
);
250 const RenderPassDrawQuad
* fifth_pass_render_pass_draw_quad
=
251 RenderPassDrawQuad::MaterialCast(fifth_pass_quad_list
.at(1u));
252 EXPECT_EQ(actual_pass_ids
[3],
253 fifth_pass_render_pass_draw_quad
->render_pass_id
);
257 // Tests an invalid surface reference in a frame. The surface quad should just
259 TEST_F(SurfaceAggregatorValidSurfaceTest
, InvalidSurfaceReference
) {
260 test::Quad quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
261 test::Quad::SurfaceQuad(kInvalidSurfaceId
),
262 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
263 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
265 SubmitFrame(passes
, arraysize(passes
), &root_surface_
);
267 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
268 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
269 test::Pass expected_passes
[] = {
270 test::Pass(expected_quads
, arraysize(expected_quads
))};
271 AggregateAndVerify(expected_passes
, arraysize(expected_passes
));
274 // Tests a reference to a valid surface with no submitted frame. This quad
275 // should also just be dropped.
276 TEST_F(SurfaceAggregatorValidSurfaceTest
, ValidSurfaceReferenceWithNoFrame
) {
277 Surface
surface_with_no_frame(&manager_
, NULL
, gfx::Size(5, 5));
278 test::Quad quads
[] = {
279 test::Quad::SolidColorQuad(SK_ColorGREEN
),
280 test::Quad::SurfaceQuad(surface_with_no_frame
.surface_id()),
281 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
282 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
284 SubmitFrame(passes
, arraysize(passes
), &root_surface_
);
286 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorGREEN
),
287 test::Quad::SolidColorQuad(SK_ColorBLUE
)};
288 test::Pass expected_passes
[] = {
289 test::Pass(expected_quads
, arraysize(expected_quads
))};
290 AggregateAndVerify(expected_passes
, arraysize(expected_passes
));
293 // Tests a surface quad referencing itself, generating a trivial cycle.
294 // The quad creating the cycle should be dropped from the final frame.
295 TEST_F(SurfaceAggregatorValidSurfaceTest
, SimpleCyclicalReference
) {
296 test::Quad quads
[] = {test::Quad::SurfaceQuad(root_surface_
.surface_id()),
297 test::Quad::SolidColorQuad(SK_ColorYELLOW
)};
298 test::Pass passes
[] = {test::Pass(quads
, arraysize(quads
))};
300 SubmitFrame(passes
, arraysize(passes
), &root_surface_
);
302 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW
)};
303 test::Pass expected_passes
[] = {
304 test::Pass(expected_quads
, arraysize(expected_quads
))};
305 AggregateAndVerify(expected_passes
, arraysize(expected_passes
));
308 // Tests a more complex cycle with one intermediate surface.
309 TEST_F(SurfaceAggregatorValidSurfaceTest
, TwoSurfaceCyclicalReference
) {
310 gfx::Size
surface_size(5, 5);
312 Surface
child_surface(&manager_
, NULL
, surface_size
);
314 test::Quad parent_quads
[] = {
315 test::Quad::SolidColorQuad(SK_ColorBLUE
),
316 test::Quad::SurfaceQuad(child_surface
.surface_id()),
317 test::Quad::SolidColorQuad(SK_ColorCYAN
)};
318 test::Pass parent_passes
[] = {
319 test::Pass(parent_quads
, arraysize(parent_quads
))};
321 SubmitFrame(parent_passes
, arraysize(parent_passes
), &root_surface_
);
323 test::Quad child_quads
[] = {
324 test::Quad::SolidColorQuad(SK_ColorGREEN
),
325 test::Quad::SurfaceQuad(root_surface_
.surface_id()),
326 test::Quad::SolidColorQuad(SK_ColorMAGENTA
)};
327 test::Pass child_passes
[] = {test::Pass(child_quads
, arraysize(child_quads
))};
329 SubmitFrame(child_passes
, arraysize(child_passes
), &child_surface
);
331 // The child surface's reference to the root_surface_ will be dropped, so
332 // we'll end up with:
333 // SK_ColorBLUE from the parent
334 // SK_ColorGREEN from the child
335 // SK_ColorMAGENTA from the child
336 // SK_ColorCYAN from the parent
337 test::Quad expected_quads
[] = {test::Quad::SolidColorQuad(SK_ColorBLUE
),
338 test::Quad::SolidColorQuad(SK_ColorGREEN
),
339 test::Quad::SolidColorQuad(SK_ColorMAGENTA
),
340 test::Quad::SolidColorQuad(SK_ColorCYAN
)};
341 test::Pass expected_passes
[] = {
342 test::Pass(expected_quads
, arraysize(expected_quads
))};
343 AggregateAndVerify(expected_passes
, arraysize(expected_passes
));
346 // Tests that we map render pass IDs from different surfaces into a unified
347 // namespace and update RenderPassDrawQuad's id references to match.
348 TEST_F(SurfaceAggregatorValidSurfaceTest
, RenderPassIdMapping
) {
349 gfx::Size
surface_size(5, 5);
351 Surface
child_surface(&manager_
, NULL
, surface_size
);
353 RenderPass::Id child_pass_id
[] = {RenderPass::Id(1, 1), RenderPass::Id(1, 2)};
354 test::Quad child_quad
[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN
)},
355 {test::Quad::RenderPassQuad(child_pass_id
[0])}};
356 test::Pass surface_passes
[] = {
357 test::Pass(child_quad
[0], arraysize(child_quad
[0]), child_pass_id
[0]),
358 test::Pass(child_quad
[1], arraysize(child_quad
[1]), child_pass_id
[1])};
360 SubmitFrame(surface_passes
, arraysize(surface_passes
), &child_surface
);
362 // Pass IDs from the parent surface may collide with ones from the child.
363 RenderPass::Id parent_pass_id
[] = {RenderPass::Id(2, 1),
364 RenderPass::Id(1, 2)};
365 test::Quad parent_quad
[][1] = {
366 {test::Quad::SurfaceQuad(child_surface
.surface_id())},
367 {test::Quad::RenderPassQuad(parent_pass_id
[0])}};
368 test::Pass parent_passes
[] = {
369 test::Pass(parent_quad
[0], arraysize(parent_quad
[0]), parent_pass_id
[0]),
370 test::Pass(parent_quad
[1], arraysize(parent_quad
[1]), parent_pass_id
[1])};
372 SubmitFrame(parent_passes
, arraysize(parent_passes
), &root_surface_
);
373 scoped_ptr
<CompositorFrame
> aggregated_frame
=
374 aggregator_
.Aggregate(root_surface_
.surface_id());
376 ASSERT_TRUE(aggregated_frame
);
377 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
379 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
381 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
383 ASSERT_EQ(3u, aggregated_pass_list
.size());
384 RenderPass::Id actual_pass_ids
[] = {aggregated_pass_list
[0]->id
,
385 aggregated_pass_list
[1]->id
,
386 aggregated_pass_list
[2]->id
};
387 // Make sure the aggregated frame's pass IDs are all unique.
388 for (size_t i
= 0; i
< 3; ++i
) {
389 for (size_t j
= 0; j
< i
; ++j
) {
390 EXPECT_NE(actual_pass_ids
[j
], actual_pass_ids
[i
]) << "pass ids " << i
395 // Make sure the render pass quads reference the remapped pass IDs.
396 DrawQuad
* render_pass_quads
[] = {aggregated_pass_list
[1]->quad_list
[0],
397 aggregated_pass_list
[2]->quad_list
[0]};
398 ASSERT_EQ(render_pass_quads
[0]->material
, DrawQuad::RENDER_PASS
);
401 RenderPassDrawQuad::MaterialCast(render_pass_quads
[0])->render_pass_id
);
403 ASSERT_EQ(render_pass_quads
[1]->material
, DrawQuad::RENDER_PASS
);
406 RenderPassDrawQuad::MaterialCast(render_pass_quads
[1])->render_pass_id
);
409 void AddSolidColorQuadWithBlendMode(const gfx::Size
& size
,
411 const SkXfermode::Mode blend_mode
) {
412 const gfx::Transform content_to_target_transform
;
413 const gfx::Size
content_bounds(size
);
414 const gfx::Rect
visible_content_rect(size
);
415 const gfx::Rect
clip_rect(size
);
417 bool is_clipped
= false;
420 bool force_anti_aliasing_off
= false;
421 scoped_ptr
<SharedQuadState
> sqs
= SharedQuadState::Create();
422 sqs
->SetAll(content_to_target_transform
,
424 visible_content_rect
,
429 pass
->shared_quad_state_list
.push_back(sqs
.Pass());
431 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
432 color_quad
->SetNew(pass
->shared_quad_state_list
.back(),
433 visible_content_rect
,
435 force_anti_aliasing_off
);
436 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
439 // This tests that we update shared quad state pointers correctly within
440 // aggregated passes. The shared quad state list on the aggregated pass will
441 // include the shared quad states from each pass in one list so the quads will
442 // end up pointed to shared quad state objects at different offsets. This test
443 // uses the blend_mode value stored on the shared quad state to track the shared
444 // quad state, but anything saved on the shared quad state would work.
446 // This test has 4 surfaces in the following structure:
447 // root_surface -> quad with kClear_Mode,
448 // [child_one_surface],
449 // quad with kDstOver_Mode,
450 // [child_two_surface],
451 // quad with kDstIn_Mode
452 // child_one_surface -> quad with kSrc_Mode,
453 // [grandchild_surface],
454 // quad with kSrcOver_Mode
455 // child_two_surface -> quad with kSrcIn_Mode
456 // grandchild_surface -> quad with kDst_Mode
458 // Resulting in the following aggregated pass:
459 // quad_root_0 - blend_mode kClear_Mode
460 // quad_child_one_0 - blend_mode kSrc_Mode
461 // quad_grandchild_0 - blend_mode kDst_Mode
462 // quad_child_one_1 - blend_mode kSrcOver_Mode
463 // quad_root_1 - blend_mode kDstOver_Mode
464 // quad_child_two_0 - blend_mode kSrcIn_Mode
465 // quad_root_2 - blend_mode kDstIn_Mode
466 TEST_F(SurfaceAggregatorValidSurfaceTest
, AggregateSharedQuadStateProperties
) {
467 gfx::Size
surface_size(5, 5);
469 const SkXfermode::Mode blend_modes
[] = {SkXfermode::kClear_Mode
, // 0
470 SkXfermode::kSrc_Mode
, // 1
471 SkXfermode::kDst_Mode
, // 2
472 SkXfermode::kSrcOver_Mode
, // 3
473 SkXfermode::kDstOver_Mode
, // 4
474 SkXfermode::kSrcIn_Mode
, // 5
475 SkXfermode::kDstIn_Mode
, // 6
478 RenderPass::Id
pass_id(1, 1);
479 Surface
grandchild_surface(&manager_
, NULL
, surface_size
);
480 scoped_ptr
<RenderPass
> grandchild_pass
= RenderPass::Create();
481 gfx::Rect
output_rect(surface_size
);
482 gfx::RectF
damage_rect(surface_size
);
483 gfx::Transform transform_to_root_target
;
484 grandchild_pass
->SetNew(
485 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
486 AddSolidColorQuadWithBlendMode(
487 surface_size
, grandchild_pass
.get(), blend_modes
[2]);
488 test::QueuePassAsFrame(grandchild_pass
.Pass(), &grandchild_surface
);
490 Surface
child_one_surface(&manager_
, NULL
, surface_size
);
492 scoped_ptr
<RenderPass
> child_one_pass
= RenderPass::Create();
493 child_one_pass
->SetNew(
494 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
495 AddSolidColorQuadWithBlendMode(
496 surface_size
, child_one_pass
.get(), blend_modes
[1]);
497 scoped_ptr
<SurfaceDrawQuad
> grandchild_surface_quad
=
498 SurfaceDrawQuad::Create();
499 grandchild_surface_quad
->SetNew(child_one_pass
->shared_quad_state_list
.back(),
500 gfx::Rect(surface_size
),
501 grandchild_surface
.surface_id());
502 child_one_pass
->quad_list
.push_back(
503 grandchild_surface_quad
.PassAs
<DrawQuad
>());
504 AddSolidColorQuadWithBlendMode(
505 surface_size
, child_one_pass
.get(), blend_modes
[3]);
506 test::QueuePassAsFrame(child_one_pass
.Pass(), &child_one_surface
);
508 Surface
child_two_surface(&manager_
, NULL
, surface_size
);
510 scoped_ptr
<RenderPass
> child_two_pass
= RenderPass::Create();
511 child_two_pass
->SetNew(
512 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
513 AddSolidColorQuadWithBlendMode(
514 surface_size
, child_two_pass
.get(), blend_modes
[5]);
515 test::QueuePassAsFrame(child_two_pass
.Pass(), &child_two_surface
);
517 scoped_ptr
<RenderPass
> root_pass
= RenderPass::Create();
519 pass_id
, output_rect
, damage_rect
, transform_to_root_target
);
521 AddSolidColorQuadWithBlendMode(surface_size
, root_pass
.get(), blend_modes
[0]);
522 scoped_ptr
<SurfaceDrawQuad
> child_one_surface_quad
=
523 SurfaceDrawQuad::Create();
524 child_one_surface_quad
->SetNew(root_pass
->shared_quad_state_list
.back(),
525 gfx::Rect(surface_size
),
526 child_one_surface
.surface_id());
527 root_pass
->quad_list
.push_back(child_one_surface_quad
.PassAs
<DrawQuad
>());
528 AddSolidColorQuadWithBlendMode(surface_size
, root_pass
.get(), blend_modes
[4]);
529 scoped_ptr
<SurfaceDrawQuad
> child_two_surface_quad
=
530 SurfaceDrawQuad::Create();
531 child_two_surface_quad
->SetNew(root_pass
->shared_quad_state_list
.back(),
532 gfx::Rect(surface_size
),
533 child_two_surface
.surface_id());
534 root_pass
->quad_list
.push_back(child_two_surface_quad
.PassAs
<DrawQuad
>());
535 AddSolidColorQuadWithBlendMode(surface_size
, root_pass
.get(), blend_modes
[6]);
537 test::QueuePassAsFrame(root_pass
.Pass(), &root_surface_
);
539 scoped_ptr
<CompositorFrame
> aggregated_frame
=
540 aggregator_
.Aggregate(root_surface_
.surface_id());
542 ASSERT_TRUE(aggregated_frame
);
543 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
545 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
547 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
549 ASSERT_EQ(1u, aggregated_pass_list
.size());
551 const QuadList
& aggregated_quad_list
= aggregated_pass_list
[0]->quad_list
;
553 ASSERT_EQ(7u, aggregated_quad_list
.size());
555 for (size_t i
= 0; i
< aggregated_quad_list
.size(); ++i
) {
556 DrawQuad
* quad
= aggregated_quad_list
[i
];
557 EXPECT_EQ(blend_modes
[i
], quad
->shared_quad_state
->blend_mode
) << i
;
561 // This tests that when aggregating a frame with multiple render passes that we
562 // map the transforms for the root pass but do not modify the transform on child
565 // The root surface has one pass with a surface quad transformed by +10 in the y
568 // The child surface has two passes. The first pass has a quad with a transform
569 // of +5 in the x direction. The second pass has a reference to the first pass'
570 // pass id and a transform of +8 in the x direction.
572 // After aggregation, the child surface's root pass quad should have both
573 // transforms concatenated for a total transform of +8 x, +10 y. The
574 // contributing render pass' transform in the aggregate frame should not be
576 TEST_F(SurfaceAggregatorValidSurfaceTest
, AggregateMultiplePassWithTransform
) {
577 gfx::Size
surface_size(5, 5);
579 Surface
child_surface(&manager_
, NULL
, surface_size
);
580 RenderPass::Id child_pass_id
[] = {RenderPass::Id(1, 1), RenderPass::Id(1, 2)};
581 test::Quad child_quads
[][1] = {
582 {test::Quad::SolidColorQuad(SK_ColorGREEN
)},
583 {test::Quad::RenderPassQuad(child_pass_id
[0])}};
584 test::Pass child_passes
[] = {
585 test::Pass(child_quads
[0], arraysize(child_quads
[0]), child_pass_id
[0]),
586 test::Pass(child_quads
[1], arraysize(child_quads
[1]), child_pass_id
[1])};
588 RenderPassList child_pass_list
;
589 AddPasses(&child_pass_list
,
590 gfx::Rect(surface_size
),
592 arraysize(child_passes
));
594 RenderPass
* child_nonroot_pass
= child_pass_list
.at(0u);
595 child_nonroot_pass
->transform_to_root_target
.Translate(8, 0);
596 SharedQuadState
* child_nonroot_pass_sqs
=
597 child_nonroot_pass
->shared_quad_state_list
[0];
598 child_nonroot_pass_sqs
->content_to_target_transform
.Translate(5, 0);
600 RenderPass
* child_root_pass
= child_pass_list
.at(1u);
601 SharedQuadState
* child_root_pass_sqs
=
602 child_root_pass
->shared_quad_state_list
[0];
603 child_root_pass_sqs
->content_to_target_transform
.Translate(8, 0);
605 scoped_ptr
<DelegatedFrameData
> child_frame_data(new DelegatedFrameData
);
606 child_pass_list
.swap(child_frame_data
->render_pass_list
);
608 scoped_ptr
<CompositorFrame
> child_frame(new CompositorFrame
);
609 child_frame
->delegated_frame_data
= child_frame_data
.Pass();
611 child_surface
.QueueFrame(child_frame
.Pass());
613 test::Quad root_quads
[] = {
614 test::Quad::SolidColorQuad(1),
615 test::Quad::SurfaceQuad(child_surface
.surface_id())};
616 test::Pass root_passes
[] = {test::Pass(root_quads
, arraysize(root_quads
))};
618 RenderPassList root_pass_list
;
619 AddPasses(&root_pass_list
,
620 gfx::Rect(surface_size
),
622 arraysize(root_passes
));
625 ->shared_quad_state_list
[0]
626 ->content_to_target_transform
.Translate(0, 7);
628 ->shared_quad_state_list
[1]
629 ->content_to_target_transform
.Translate(0, 10);
631 scoped_ptr
<DelegatedFrameData
> root_frame_data(new DelegatedFrameData
);
632 root_pass_list
.swap(root_frame_data
->render_pass_list
);
634 scoped_ptr
<CompositorFrame
> root_frame(new CompositorFrame
);
635 root_frame
->delegated_frame_data
= root_frame_data
.Pass();
637 root_surface_
.QueueFrame(root_frame
.Pass());
639 scoped_ptr
<CompositorFrame
> aggregated_frame
=
640 aggregator_
.Aggregate(root_surface_
.surface_id());
642 ASSERT_TRUE(aggregated_frame
);
643 ASSERT_TRUE(aggregated_frame
->delegated_frame_data
);
645 DelegatedFrameData
* frame_data
= aggregated_frame
->delegated_frame_data
.get();
647 const RenderPassList
& aggregated_pass_list
= frame_data
->render_pass_list
;
649 ASSERT_EQ(2u, aggregated_pass_list
.size());
651 ASSERT_EQ(1u, aggregated_pass_list
[0]->shared_quad_state_list
.size());
653 // The first pass should have one shared quad state for the one solid color
655 EXPECT_EQ(1u, aggregated_pass_list
[0]->shared_quad_state_list
.size());
656 // The second (root) pass should have just two shared quad states. We'll
657 // verify the properties through the quads.
658 EXPECT_EQ(2u, aggregated_pass_list
[1]->shared_quad_state_list
.size());
660 SharedQuadState
* aggregated_first_pass_sqs
=
661 aggregated_pass_list
[0]->shared_quad_state_list
.front();
663 // The first pass's transform should be unaffected by the embedding and still
664 // be a translation by +5 in the x direction.
665 gfx::Transform expected_aggregated_first_pass_sqs_transform
;
666 expected_aggregated_first_pass_sqs_transform
.Translate(5, 0);
667 EXPECT_EQ(expected_aggregated_first_pass_sqs_transform
.ToString(),
668 aggregated_first_pass_sqs
->content_to_target_transform
.ToString());
670 // The first pass's transform to the root target should include the aggregated
672 gfx::Transform expected_first_pass_transform_to_root_target
;
673 expected_first_pass_transform_to_root_target
.Translate(8, 10);
674 EXPECT_EQ(expected_first_pass_transform_to_root_target
.ToString(),
675 aggregated_pass_list
[0]->transform_to_root_target
.ToString());
677 ASSERT_EQ(2u, aggregated_pass_list
[1]->quad_list
.size());
679 gfx::Transform expected_root_pass_quad_transforms
[2];
680 // The first quad in the root pass is the solid color quad from the original
681 // root surface. Its transform should be unaffected by the aggregation and
682 // still be +7 in the y direction.
683 expected_root_pass_quad_transforms
[0].Translate(0, 7);
684 // The second quad in the root pass is aggregated from the child surface so
685 // its transform should be the combination of its original translation (0, 10)
686 // and the child surface draw quad's translation (8, 0).
687 expected_root_pass_quad_transforms
[1].Translate(8, 10);
689 for (size_t i
= 0; i
< 2; ++i
) {
690 DrawQuad
* quad
= aggregated_pass_list
[1]->quad_list
.at(i
);
691 EXPECT_EQ(expected_root_pass_quad_transforms
[i
].ToString(),
692 quad
->quadTransform().ToString())