Disable WebContentsObserverAndroidTest#testDidFirstVisuallyNonEmptyPaint
[chromium-blink-merge.git] / cc / surfaces / surface_aggregator_unittest.cc
blob3a6d19ff5eb8b80949fc8d12bf0883f126fbe8b5
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/render_pass_test_common.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"
29 namespace cc {
30 namespace {
32 SurfaceId InvalidSurfaceId() {
33 static SurfaceId invalid;
34 invalid.id = static_cast<uint64_t>(-1);
35 return invalid;
38 gfx::Size SurfaceSize() {
39 static gfx::Size size(5, 5);
40 return size;
43 class EmptySurfaceFactoryClient : public SurfaceFactoryClient {
44 public:
45 virtual void ReturnResources(
46 const ReturnedResourceArray& resources) OVERRIDE {}
49 class SurfaceAggregatorTest : public testing::Test {
50 public:
51 SurfaceAggregatorTest()
52 : factory_(&manager_, &empty_client_), aggregator_(&manager_, NULL) {}
54 protected:
55 SurfaceManager manager_;
56 EmptySurfaceFactoryClient empty_client_;
57 SurfaceFactory factory_;
58 SurfaceAggregator aggregator_;
61 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) {
62 SurfaceId one_id(7);
63 factory_.Create(one_id, SurfaceSize());
64 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id);
65 EXPECT_FALSE(frame);
66 factory_.Destroy(one_id);
69 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest {
70 public:
71 SurfaceAggregatorValidSurfaceTest() : allocator_(1u) {}
73 virtual void SetUp() {
74 SurfaceAggregatorTest::SetUp();
75 root_surface_id_ = allocator_.GenerateId();
76 factory_.Create(root_surface_id_, SurfaceSize());
79 virtual void TearDown() {
80 factory_.Destroy(root_surface_id_);
81 SurfaceAggregatorTest::TearDown();
84 void AggregateAndVerify(test::Pass* expected_passes,
85 size_t expected_pass_count,
86 SurfaceId* surface_ids,
87 size_t expected_surface_count) {
88 scoped_ptr<CompositorFrame> aggregated_frame =
89 aggregator_.Aggregate(root_surface_id_);
91 ASSERT_TRUE(aggregated_frame);
92 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
94 DelegatedFrameData* frame_data =
95 aggregated_frame->delegated_frame_data.get();
97 TestPassesMatchExpectations(
98 expected_passes, expected_pass_count, &frame_data->render_pass_list);
100 EXPECT_EQ(expected_surface_count,
101 aggregator_.previous_contained_surfaces().size());
102 for (size_t i = 0; i < expected_surface_count; i++) {
103 EXPECT_TRUE(
104 aggregator_.previous_contained_surfaces().find(surface_ids[i]) !=
105 aggregator_.previous_contained_surfaces().end());
109 void SubmitFrame(test::Pass* passes,
110 size_t pass_count,
111 SurfaceId surface_id) {
112 RenderPassList pass_list;
113 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count);
115 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
116 pass_list.swap(frame_data->render_pass_list);
118 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
119 frame->delegated_frame_data = frame_data.Pass();
121 factory_.SubmitFrame(surface_id, frame.Pass(), base::Closure());
124 void QueuePassAsFrame(scoped_ptr<RenderPass> pass, SurfaceId surface_id) {
125 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
126 delegated_frame_data->render_pass_list.push_back(pass.Pass());
128 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
129 child_frame->delegated_frame_data = delegated_frame_data.Pass();
131 factory_.SubmitFrame(surface_id, child_frame.Pass(), base::Closure());
134 protected:
135 SurfaceId root_surface_id_;
136 SurfaceIdAllocator allocator_;
139 // Tests that a very simple frame containing only two solid color quads makes it
140 // through the aggregator correctly.
141 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleFrame) {
142 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorRED),
143 test::Quad::SolidColorQuad(SK_ColorBLUE)};
144 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
146 SubmitFrame(passes, arraysize(passes), root_surface_id_);
148 SurfaceId ids[] = {root_surface_id_};
149 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
152 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSimpleFrame) {
153 test::Quad quads[][2] = {{test::Quad::SolidColorQuad(SK_ColorWHITE),
154 test::Quad::SolidColorQuad(SK_ColorLTGRAY)},
155 {test::Quad::SolidColorQuad(SK_ColorGRAY),
156 test::Quad::SolidColorQuad(SK_ColorDKGRAY)}};
157 test::Pass passes[] = {test::Pass(quads[0], arraysize(quads[0])),
158 test::Pass(quads[1], arraysize(quads[1]))};
160 SubmitFrame(passes, arraysize(passes), root_surface_id_);
162 SurfaceId ids[] = {root_surface_id_};
163 AggregateAndVerify(passes, arraysize(passes), ids, arraysize(ids));
166 // This tests very simple embedding. root_surface has a frame containing a few
167 // solid color quads and a surface quad referencing embedded_surface.
168 // embedded_surface has a frame containing only a solid color quad. The solid
169 // color quad should be aggregated into the final frame.
170 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleSurfaceReference) {
171 SurfaceId embedded_surface_id = allocator_.GenerateId();
172 factory_.Create(embedded_surface_id, SurfaceSize());
174 test::Quad embedded_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN)};
175 test::Pass embedded_passes[] = {
176 test::Pass(embedded_quads, arraysize(embedded_quads))};
178 SubmitFrame(embedded_passes, arraysize(embedded_passes), embedded_surface_id);
180 test::Quad root_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
181 test::Quad::SurfaceQuad(embedded_surface_id),
182 test::Quad::SolidColorQuad(SK_ColorBLACK)};
183 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
185 SubmitFrame(root_passes, arraysize(root_passes), root_surface_id_);
187 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorWHITE),
188 test::Quad::SolidColorQuad(SK_ColorGREEN),
189 test::Quad::SolidColorQuad(SK_ColorBLACK)};
190 test::Pass expected_passes[] = {
191 test::Pass(expected_quads, arraysize(expected_quads))};
192 SurfaceId ids[] = {root_surface_id_, embedded_surface_id};
193 AggregateAndVerify(
194 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
196 factory_.Destroy(embedded_surface_id);
199 // This tests referencing a surface that has multiple render passes.
200 TEST_F(SurfaceAggregatorValidSurfaceTest, MultiPassSurfaceReference) {
201 SurfaceId embedded_surface_id = allocator_.GenerateId();
202 factory_.Create(embedded_surface_id, SurfaceSize());
204 RenderPassId pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2),
205 RenderPassId(1, 3)};
207 test::Quad embedded_quads[][2] = {
208 {test::Quad::SolidColorQuad(1), test::Quad::SolidColorQuad(2)},
209 {test::Quad::SolidColorQuad(3), test::Quad::RenderPassQuad(pass_ids[0])},
210 {test::Quad::SolidColorQuad(4), test::Quad::RenderPassQuad(pass_ids[1])}};
211 test::Pass embedded_passes[] = {
212 test::Pass(embedded_quads[0], arraysize(embedded_quads[0]), pass_ids[0]),
213 test::Pass(embedded_quads[1], arraysize(embedded_quads[1]), pass_ids[1]),
214 test::Pass(embedded_quads[2], arraysize(embedded_quads[2]), pass_ids[2])};
216 SubmitFrame(embedded_passes, arraysize(embedded_passes), embedded_surface_id);
218 test::Quad root_quads[][2] = {
219 {test::Quad::SolidColorQuad(5), test::Quad::SolidColorQuad(6)},
220 {test::Quad::SurfaceQuad(embedded_surface_id),
221 test::Quad::RenderPassQuad(pass_ids[0])},
222 {test::Quad::SolidColorQuad(7), test::Quad::RenderPassQuad(pass_ids[1])}};
223 test::Pass root_passes[] = {
224 test::Pass(root_quads[0], arraysize(root_quads[0]), pass_ids[0]),
225 test::Pass(root_quads[1], arraysize(root_quads[1]), pass_ids[1]),
226 test::Pass(root_quads[2], arraysize(root_quads[2]), pass_ids[2])};
228 SubmitFrame(root_passes, arraysize(root_passes), root_surface_id_);
230 scoped_ptr<CompositorFrame> aggregated_frame =
231 aggregator_.Aggregate(root_surface_id_);
233 ASSERT_TRUE(aggregated_frame);
234 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
236 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get();
238 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
240 ASSERT_EQ(5u, aggregated_pass_list.size());
241 RenderPassId actual_pass_ids[] = {
242 aggregated_pass_list[0]->id, aggregated_pass_list[1]->id,
243 aggregated_pass_list[2]->id, aggregated_pass_list[3]->id,
244 aggregated_pass_list[4]->id};
245 for (size_t i = 0; i < 5; ++i) {
246 for (size_t j = 0; j < i; ++j) {
247 EXPECT_NE(actual_pass_ids[i], actual_pass_ids[j]);
252 SCOPED_TRACE("First pass");
253 // The first pass will just be the first pass from the root surfaces quad
254 // with no render pass quads to remap.
255 TestPassMatchesExpectations(root_passes[0], aggregated_pass_list[0]);
259 SCOPED_TRACE("Second pass");
260 // The next two passes will be from the embedded surface since we have to
261 // draw those passes before they are referenced from the render pass draw
262 // quad embedded into the root surface's second pass.
263 // First, there's the first embedded pass which doesn't reference anything
264 // else.
265 TestPassMatchesExpectations(embedded_passes[0], aggregated_pass_list[1]);
269 SCOPED_TRACE("Third pass");
270 const QuadList& third_pass_quad_list = aggregated_pass_list[2]->quad_list;
271 ASSERT_EQ(2u, third_pass_quad_list.size());
272 TestQuadMatchesExpectations(embedded_quads[1][0],
273 third_pass_quad_list.at(0u));
275 // This render pass pass quad will reference the first pass from the
276 // embedded surface, which is the second pass in the aggregated frame.
277 ASSERT_EQ(DrawQuad::RENDER_PASS, third_pass_quad_list.at(1u)->material);
278 const RenderPassDrawQuad* third_pass_render_pass_draw_quad =
279 RenderPassDrawQuad::MaterialCast(third_pass_quad_list.at(1u));
280 EXPECT_EQ(actual_pass_ids[1],
281 third_pass_render_pass_draw_quad->render_pass_id);
285 SCOPED_TRACE("Fourth pass");
286 // The fourth pass will have aggregated quads from the root surface's second
287 // pass and the embedded surface's first pass.
288 const QuadList& fourth_pass_quad_list = aggregated_pass_list[3]->quad_list;
289 ASSERT_EQ(3u, fourth_pass_quad_list.size());
291 // The first quad will be the yellow quad from the embedded surface's last
292 // pass.
293 TestQuadMatchesExpectations(embedded_quads[2][0],
294 fourth_pass_quad_list.at(0u));
296 // The next quad will be a render pass quad referencing the second pass from
297 // the embedded surface, which is the third pass in the aggregated frame.
298 ASSERT_EQ(DrawQuad::RENDER_PASS, fourth_pass_quad_list.at(1u)->material);
299 const RenderPassDrawQuad* fourth_pass_first_render_pass_draw_quad =
300 RenderPassDrawQuad::MaterialCast(fourth_pass_quad_list.at(1u));
301 EXPECT_EQ(actual_pass_ids[2],
302 fourth_pass_first_render_pass_draw_quad->render_pass_id);
304 // The last quad will be a render pass quad referencing the first pass from
305 // the root surface, which is the first pass overall.
306 ASSERT_EQ(DrawQuad::RENDER_PASS, fourth_pass_quad_list.at(2u)->material);
307 const RenderPassDrawQuad* fourth_pass_second_render_pass_draw_quad =
308 RenderPassDrawQuad::MaterialCast(fourth_pass_quad_list.at(2u));
309 EXPECT_EQ(actual_pass_ids[0],
310 fourth_pass_second_render_pass_draw_quad->render_pass_id);
314 SCOPED_TRACE("Fifth pass");
315 const QuadList& fifth_pass_quad_list = aggregated_pass_list[4]->quad_list;
316 ASSERT_EQ(2u, fifth_pass_quad_list.size());
318 TestQuadMatchesExpectations(root_quads[2][0], fifth_pass_quad_list.at(0));
320 // The last quad in the last pass will reference the second pass from the
321 // root surface, which after aggregating is the fourth pass in the overall
322 // list.
323 ASSERT_EQ(DrawQuad::RENDER_PASS, fifth_pass_quad_list.at(1u)->material);
324 const RenderPassDrawQuad* fifth_pass_render_pass_draw_quad =
325 RenderPassDrawQuad::MaterialCast(fifth_pass_quad_list.at(1u));
326 EXPECT_EQ(actual_pass_ids[3],
327 fifth_pass_render_pass_draw_quad->render_pass_id);
329 factory_.Destroy(embedded_surface_id);
332 // Tests an invalid surface reference in a frame. The surface quad should just
333 // be dropped.
334 TEST_F(SurfaceAggregatorValidSurfaceTest, InvalidSurfaceReference) {
335 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
336 test::Quad::SurfaceQuad(InvalidSurfaceId()),
337 test::Quad::SolidColorQuad(SK_ColorBLUE)};
338 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
340 SubmitFrame(passes, arraysize(passes), root_surface_id_);
342 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
343 test::Quad::SolidColorQuad(SK_ColorBLUE)};
344 test::Pass expected_passes[] = {
345 test::Pass(expected_quads, arraysize(expected_quads))};
346 SurfaceId ids[] = {root_surface_id_, InvalidSurfaceId()};
347 AggregateAndVerify(
348 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
351 // Tests a reference to a valid surface with no submitted frame. This quad
352 // should also just be dropped.
353 TEST_F(SurfaceAggregatorValidSurfaceTest, ValidSurfaceReferenceWithNoFrame) {
354 SurfaceId surface_with_no_frame_id = allocator_.GenerateId();
355 factory_.Create(surface_with_no_frame_id, gfx::Size(5, 5));
356 test::Quad quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
357 test::Quad::SurfaceQuad(surface_with_no_frame_id),
358 test::Quad::SolidColorQuad(SK_ColorBLUE)};
359 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
361 SubmitFrame(passes, arraysize(passes), root_surface_id_);
363 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
364 test::Quad::SolidColorQuad(SK_ColorBLUE)};
365 test::Pass expected_passes[] = {
366 test::Pass(expected_quads, arraysize(expected_quads))};
367 SurfaceId ids[] = {root_surface_id_, surface_with_no_frame_id};
368 AggregateAndVerify(
369 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
370 factory_.Destroy(surface_with_no_frame_id);
373 // Tests a surface quad referencing itself, generating a trivial cycle.
374 // The quad creating the cycle should be dropped from the final frame.
375 TEST_F(SurfaceAggregatorValidSurfaceTest, SimpleCyclicalReference) {
376 test::Quad quads[] = {test::Quad::SurfaceQuad(root_surface_id_),
377 test::Quad::SolidColorQuad(SK_ColorYELLOW)};
378 test::Pass passes[] = {test::Pass(quads, arraysize(quads))};
380 SubmitFrame(passes, arraysize(passes), root_surface_id_);
382 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorYELLOW)};
383 test::Pass expected_passes[] = {
384 test::Pass(expected_quads, arraysize(expected_quads))};
385 SurfaceId ids[] = {root_surface_id_};
386 AggregateAndVerify(
387 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
390 // Tests a more complex cycle with one intermediate surface.
391 TEST_F(SurfaceAggregatorValidSurfaceTest, TwoSurfaceCyclicalReference) {
392 SurfaceId child_surface_id = allocator_.GenerateId();
393 factory_.Create(child_surface_id, SurfaceSize());
395 test::Quad parent_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE),
396 test::Quad::SurfaceQuad(child_surface_id),
397 test::Quad::SolidColorQuad(SK_ColorCYAN)};
398 test::Pass parent_passes[] = {
399 test::Pass(parent_quads, arraysize(parent_quads))};
401 SubmitFrame(parent_passes, arraysize(parent_passes), root_surface_id_);
403 test::Quad child_quads[] = {test::Quad::SolidColorQuad(SK_ColorGREEN),
404 test::Quad::SurfaceQuad(root_surface_id_),
405 test::Quad::SolidColorQuad(SK_ColorMAGENTA)};
406 test::Pass child_passes[] = {test::Pass(child_quads, arraysize(child_quads))};
408 SubmitFrame(child_passes, arraysize(child_passes), child_surface_id);
410 // The child surface's reference to the root_surface_ will be dropped, so
411 // we'll end up with:
412 // SK_ColorBLUE from the parent
413 // SK_ColorGREEN from the child
414 // SK_ColorMAGENTA from the child
415 // SK_ColorCYAN from the parent
416 test::Quad expected_quads[] = {test::Quad::SolidColorQuad(SK_ColorBLUE),
417 test::Quad::SolidColorQuad(SK_ColorGREEN),
418 test::Quad::SolidColorQuad(SK_ColorMAGENTA),
419 test::Quad::SolidColorQuad(SK_ColorCYAN)};
420 test::Pass expected_passes[] = {
421 test::Pass(expected_quads, arraysize(expected_quads))};
422 SurfaceId ids[] = {root_surface_id_, child_surface_id};
423 AggregateAndVerify(
424 expected_passes, arraysize(expected_passes), ids, arraysize(ids));
425 factory_.Destroy(child_surface_id);
428 // Tests that we map render pass IDs from different surfaces into a unified
429 // namespace and update RenderPassDrawQuad's id references to match.
430 TEST_F(SurfaceAggregatorValidSurfaceTest, RenderPassIdMapping) {
431 SurfaceId child_surface_id = allocator_.GenerateId();
432 factory_.Create(child_surface_id, SurfaceSize());
434 RenderPassId child_pass_id[] = {RenderPassId(1, 1), RenderPassId(1, 2)};
435 test::Quad child_quad[][1] = {{test::Quad::SolidColorQuad(SK_ColorGREEN)},
436 {test::Quad::RenderPassQuad(child_pass_id[0])}};
437 test::Pass surface_passes[] = {
438 test::Pass(child_quad[0], arraysize(child_quad[0]), child_pass_id[0]),
439 test::Pass(child_quad[1], arraysize(child_quad[1]), child_pass_id[1])};
441 SubmitFrame(surface_passes, arraysize(surface_passes), child_surface_id);
443 // Pass IDs from the parent surface may collide with ones from the child.
444 RenderPassId parent_pass_id[] = {RenderPassId(2, 1), RenderPassId(1, 2)};
445 test::Quad parent_quad[][1] = {
446 {test::Quad::SurfaceQuad(child_surface_id)},
447 {test::Quad::RenderPassQuad(parent_pass_id[0])}};
448 test::Pass parent_passes[] = {
449 test::Pass(parent_quad[0], arraysize(parent_quad[0]), parent_pass_id[0]),
450 test::Pass(parent_quad[1], arraysize(parent_quad[1]), parent_pass_id[1])};
452 SubmitFrame(parent_passes, arraysize(parent_passes), root_surface_id_);
453 scoped_ptr<CompositorFrame> aggregated_frame =
454 aggregator_.Aggregate(root_surface_id_);
456 ASSERT_TRUE(aggregated_frame);
457 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
459 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get();
461 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
463 ASSERT_EQ(3u, aggregated_pass_list.size());
464 RenderPassId actual_pass_ids[] = {aggregated_pass_list[0]->id,
465 aggregated_pass_list[1]->id,
466 aggregated_pass_list[2]->id};
467 // Make sure the aggregated frame's pass IDs are all unique.
468 for (size_t i = 0; i < 3; ++i) {
469 for (size_t j = 0; j < i; ++j) {
470 EXPECT_NE(actual_pass_ids[j], actual_pass_ids[i]) << "pass ids " << i
471 << " and " << j;
475 // Make sure the render pass quads reference the remapped pass IDs.
476 DrawQuad* render_pass_quads[] = {aggregated_pass_list[1]->quad_list[0],
477 aggregated_pass_list[2]->quad_list[0]};
478 ASSERT_EQ(render_pass_quads[0]->material, DrawQuad::RENDER_PASS);
479 EXPECT_EQ(
480 actual_pass_ids[0],
481 RenderPassDrawQuad::MaterialCast(render_pass_quads[0])->render_pass_id);
483 ASSERT_EQ(render_pass_quads[1]->material, DrawQuad::RENDER_PASS);
484 EXPECT_EQ(
485 actual_pass_ids[1],
486 RenderPassDrawQuad::MaterialCast(render_pass_quads[1])->render_pass_id);
487 factory_.Destroy(child_surface_id);
490 void AddSolidColorQuadWithBlendMode(const gfx::Size& size,
491 RenderPass* pass,
492 const SkXfermode::Mode blend_mode) {
493 const gfx::Transform content_to_target_transform;
494 const gfx::Size content_bounds(size);
495 const gfx::Rect visible_content_rect(size);
496 const gfx::Rect clip_rect(size);
498 bool is_clipped = false;
499 float opacity = 1.f;
501 bool force_anti_aliasing_off = false;
502 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
503 sqs->SetAll(content_to_target_transform,
504 content_bounds,
505 visible_content_rect,
506 clip_rect,
507 is_clipped,
508 opacity,
509 blend_mode,
512 SolidColorDrawQuad* color_quad =
513 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
514 color_quad->SetNew(pass->shared_quad_state_list.back(),
515 visible_content_rect,
516 visible_content_rect,
517 SK_ColorGREEN,
518 force_anti_aliasing_off);
521 // This tests that we update shared quad state pointers correctly within
522 // aggregated passes. The shared quad state list on the aggregated pass will
523 // include the shared quad states from each pass in one list so the quads will
524 // end up pointed to shared quad state objects at different offsets. This test
525 // uses the blend_mode value stored on the shared quad state to track the shared
526 // quad state, but anything saved on the shared quad state would work.
528 // This test has 4 surfaces in the following structure:
529 // root_surface -> quad with kClear_Mode,
530 // [child_one_surface],
531 // quad with kDstOver_Mode,
532 // [child_two_surface],
533 // quad with kDstIn_Mode
534 // child_one_surface -> quad with kSrc_Mode,
535 // [grandchild_surface],
536 // quad with kSrcOver_Mode
537 // child_two_surface -> quad with kSrcIn_Mode
538 // grandchild_surface -> quad with kDst_Mode
540 // Resulting in the following aggregated pass:
541 // quad_root_0 - blend_mode kClear_Mode
542 // quad_child_one_0 - blend_mode kSrc_Mode
543 // quad_grandchild_0 - blend_mode kDst_Mode
544 // quad_child_one_1 - blend_mode kSrcOver_Mode
545 // quad_root_1 - blend_mode kDstOver_Mode
546 // quad_child_two_0 - blend_mode kSrcIn_Mode
547 // quad_root_2 - blend_mode kDstIn_Mode
548 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateSharedQuadStateProperties) {
549 const SkXfermode::Mode blend_modes[] = {SkXfermode::kClear_Mode, // 0
550 SkXfermode::kSrc_Mode, // 1
551 SkXfermode::kDst_Mode, // 2
552 SkXfermode::kSrcOver_Mode, // 3
553 SkXfermode::kDstOver_Mode, // 4
554 SkXfermode::kSrcIn_Mode, // 5
555 SkXfermode::kDstIn_Mode, // 6
558 RenderPassId pass_id(1, 1);
559 SurfaceId grandchild_surface_id = allocator_.GenerateId();
560 factory_.Create(grandchild_surface_id, SurfaceSize());
561 scoped_ptr<RenderPass> grandchild_pass = RenderPass::Create();
562 gfx::Rect output_rect(SurfaceSize());
563 gfx::Rect damage_rect(SurfaceSize());
564 gfx::Transform transform_to_root_target;
565 grandchild_pass->SetNew(
566 pass_id, output_rect, damage_rect, transform_to_root_target);
567 AddSolidColorQuadWithBlendMode(
568 SurfaceSize(), grandchild_pass.get(), blend_modes[2]);
569 QueuePassAsFrame(grandchild_pass.Pass(), grandchild_surface_id);
571 SurfaceId child_one_surface_id = allocator_.GenerateId();
572 factory_.Create(child_one_surface_id, SurfaceSize());
574 scoped_ptr<RenderPass> child_one_pass = RenderPass::Create();
575 child_one_pass->SetNew(
576 pass_id, output_rect, damage_rect, transform_to_root_target);
577 AddSolidColorQuadWithBlendMode(
578 SurfaceSize(), child_one_pass.get(), blend_modes[1]);
579 SurfaceDrawQuad* grandchild_surface_quad =
580 child_one_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
581 grandchild_surface_quad->SetNew(child_one_pass->shared_quad_state_list.back(),
582 gfx::Rect(SurfaceSize()),
583 gfx::Rect(SurfaceSize()),
584 grandchild_surface_id);
585 AddSolidColorQuadWithBlendMode(
586 SurfaceSize(), child_one_pass.get(), blend_modes[3]);
587 QueuePassAsFrame(child_one_pass.Pass(), child_one_surface_id);
589 SurfaceId child_two_surface_id = allocator_.GenerateId();
590 factory_.Create(child_two_surface_id, SurfaceSize());
592 scoped_ptr<RenderPass> child_two_pass = RenderPass::Create();
593 child_two_pass->SetNew(
594 pass_id, output_rect, damage_rect, transform_to_root_target);
595 AddSolidColorQuadWithBlendMode(
596 SurfaceSize(), child_two_pass.get(), blend_modes[5]);
597 QueuePassAsFrame(child_two_pass.Pass(), child_two_surface_id);
599 scoped_ptr<RenderPass> root_pass = RenderPass::Create();
600 root_pass->SetNew(
601 pass_id, output_rect, damage_rect, transform_to_root_target);
603 AddSolidColorQuadWithBlendMode(
604 SurfaceSize(), root_pass.get(), blend_modes[0]);
605 SurfaceDrawQuad* child_one_surface_quad =
606 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
607 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
608 gfx::Rect(SurfaceSize()),
609 gfx::Rect(SurfaceSize()),
610 child_one_surface_id);
611 AddSolidColorQuadWithBlendMode(
612 SurfaceSize(), root_pass.get(), blend_modes[4]);
613 SurfaceDrawQuad* child_two_surface_quad =
614 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
615 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
616 gfx::Rect(SurfaceSize()),
617 gfx::Rect(SurfaceSize()),
618 child_two_surface_id);
619 AddSolidColorQuadWithBlendMode(
620 SurfaceSize(), root_pass.get(), blend_modes[6]);
622 QueuePassAsFrame(root_pass.Pass(), root_surface_id_);
624 scoped_ptr<CompositorFrame> aggregated_frame =
625 aggregator_.Aggregate(root_surface_id_);
627 ASSERT_TRUE(aggregated_frame);
628 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
630 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get();
632 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
634 ASSERT_EQ(1u, aggregated_pass_list.size());
636 const QuadList& aggregated_quad_list = aggregated_pass_list[0]->quad_list;
638 ASSERT_EQ(7u, aggregated_quad_list.size());
640 for (size_t i = 0; i < aggregated_quad_list.size(); ++i) {
641 DrawQuad* quad = aggregated_quad_list[i];
642 EXPECT_EQ(blend_modes[i], quad->shared_quad_state->blend_mode) << i;
644 factory_.Destroy(child_one_surface_id);
645 factory_.Destroy(child_two_surface_id);
646 factory_.Destroy(grandchild_surface_id);
649 // This tests that when aggregating a frame with multiple render passes that we
650 // map the transforms for the root pass but do not modify the transform on child
651 // passes.
653 // The root surface has one pass with a surface quad transformed by +10 in the y
654 // direction.
656 // The child surface has two passes. The first pass has a quad with a transform
657 // of +5 in the x direction. The second pass has a reference to the first pass'
658 // pass id and a transform of +8 in the x direction.
660 // After aggregation, the child surface's root pass quad should have both
661 // transforms concatenated for a total transform of +8 x, +10 y. The
662 // contributing render pass' transform in the aggregate frame should not be
663 // affected.
664 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateMultiplePassWithTransform) {
665 SurfaceId child_surface_id = allocator_.GenerateId();
666 factory_.Create(child_surface_id, SurfaceSize());
667 RenderPassId child_pass_id[] = {RenderPassId(1, 1), RenderPassId(1, 2)};
668 test::Quad child_quads[][1] = {
669 {test::Quad::SolidColorQuad(SK_ColorGREEN)},
670 {test::Quad::RenderPassQuad(child_pass_id[0])}};
671 test::Pass child_passes[] = {
672 test::Pass(child_quads[0], arraysize(child_quads[0]), child_pass_id[0]),
673 test::Pass(child_quads[1], arraysize(child_quads[1]), child_pass_id[1])};
675 RenderPassList child_pass_list;
676 AddPasses(&child_pass_list,
677 gfx::Rect(SurfaceSize()),
678 child_passes,
679 arraysize(child_passes));
681 RenderPass* child_nonroot_pass = child_pass_list.at(0u);
682 child_nonroot_pass->transform_to_root_target.Translate(8, 0);
683 SharedQuadState* child_nonroot_pass_sqs =
684 child_nonroot_pass->shared_quad_state_list[0];
685 child_nonroot_pass_sqs->content_to_target_transform.Translate(5, 0);
687 RenderPass* child_root_pass = child_pass_list.at(1u);
688 SharedQuadState* child_root_pass_sqs =
689 child_root_pass->shared_quad_state_list[0];
690 child_root_pass_sqs->content_to_target_transform.Translate(8, 0);
691 child_root_pass_sqs->is_clipped = true;
692 child_root_pass_sqs->clip_rect = gfx::Rect(0, 0, 5, 5);
694 scoped_ptr<DelegatedFrameData> child_frame_data(new DelegatedFrameData);
695 child_pass_list.swap(child_frame_data->render_pass_list);
697 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
698 child_frame->delegated_frame_data = child_frame_data.Pass();
700 factory_.SubmitFrame(child_surface_id, child_frame.Pass(), base::Closure());
702 test::Quad root_quads[] = {test::Quad::SolidColorQuad(1),
703 test::Quad::SurfaceQuad(child_surface_id)};
704 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
706 RenderPassList root_pass_list;
707 AddPasses(&root_pass_list,
708 gfx::Rect(SurfaceSize()),
709 root_passes,
710 arraysize(root_passes));
712 root_pass_list.at(0)
713 ->shared_quad_state_list[0]
714 ->content_to_target_transform.Translate(0, 7);
715 root_pass_list.at(0)
716 ->shared_quad_state_list[1]
717 ->content_to_target_transform.Translate(0, 10);
719 scoped_ptr<DelegatedFrameData> root_frame_data(new DelegatedFrameData);
720 root_pass_list.swap(root_frame_data->render_pass_list);
722 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
723 root_frame->delegated_frame_data = root_frame_data.Pass();
725 factory_.SubmitFrame(root_surface_id_, root_frame.Pass(), base::Closure());
727 scoped_ptr<CompositorFrame> aggregated_frame =
728 aggregator_.Aggregate(root_surface_id_);
730 ASSERT_TRUE(aggregated_frame);
731 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
733 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get();
735 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
737 ASSERT_EQ(2u, aggregated_pass_list.size());
739 ASSERT_EQ(1u, aggregated_pass_list[0]->shared_quad_state_list.size());
741 // The first pass should have one shared quad state for the one solid color
742 // quad.
743 EXPECT_EQ(1u, aggregated_pass_list[0]->shared_quad_state_list.size());
744 // The second (root) pass should have just two shared quad states. We'll
745 // verify the properties through the quads.
746 EXPECT_EQ(2u, aggregated_pass_list[1]->shared_quad_state_list.size());
748 SharedQuadState* aggregated_first_pass_sqs =
749 aggregated_pass_list[0]->shared_quad_state_list.front();
751 // The first pass's transform should be unaffected by the embedding and still
752 // be a translation by +5 in the x direction.
753 gfx::Transform expected_aggregated_first_pass_sqs_transform;
754 expected_aggregated_first_pass_sqs_transform.Translate(5, 0);
755 EXPECT_EQ(expected_aggregated_first_pass_sqs_transform.ToString(),
756 aggregated_first_pass_sqs->content_to_target_transform.ToString());
758 // The first pass's transform to the root target should include the aggregated
759 // transform.
760 gfx::Transform expected_first_pass_transform_to_root_target;
761 expected_first_pass_transform_to_root_target.Translate(8, 10);
762 EXPECT_EQ(expected_first_pass_transform_to_root_target.ToString(),
763 aggregated_pass_list[0]->transform_to_root_target.ToString());
765 ASSERT_EQ(2u, aggregated_pass_list[1]->quad_list.size());
767 gfx::Transform expected_root_pass_quad_transforms[2];
768 // The first quad in the root pass is the solid color quad from the original
769 // root surface. Its transform should be unaffected by the aggregation and
770 // still be +7 in the y direction.
771 expected_root_pass_quad_transforms[0].Translate(0, 7);
772 // The second quad in the root pass is aggregated from the child surface so
773 // its transform should be the combination of its original translation (0, 10)
774 // and the child surface draw quad's translation (8, 0).
775 expected_root_pass_quad_transforms[1].Translate(8, 10);
777 for (size_t i = 0; i < 2; ++i) {
778 DrawQuad* quad = aggregated_pass_list[1]->quad_list.at(i);
779 EXPECT_EQ(expected_root_pass_quad_transforms[i].ToString(),
780 quad->quadTransform().ToString())
781 << i;
784 EXPECT_EQ(true,
785 aggregated_pass_list[1]->shared_quad_state_list[1]->is_clipped);
787 // The second quad in the root pass is aggregated from the child, so its
788 // clip rect must be transformed by the child's translation.
789 EXPECT_EQ(
790 gfx::Rect(0, 10, 5, 5).ToString(),
791 aggregated_pass_list[1]->shared_quad_state_list[1]->clip_rect.ToString());
793 factory_.Destroy(child_surface_id);
796 // Tests that damage rects are aggregated correctly when surfaces change.
797 TEST_F(SurfaceAggregatorValidSurfaceTest, AggregateDamageRect) {
798 SurfaceId child_surface_id = allocator_.GenerateId();
799 factory_.Create(child_surface_id, SurfaceSize());
800 RenderPassId child_pass_id = RenderPassId(1, 1);
801 test::Quad child_quads[] = {test::Quad::RenderPassQuad(child_pass_id)};
802 test::Pass child_passes[] = {
803 test::Pass(child_quads, arraysize(child_quads), child_pass_id)};
805 RenderPassList child_pass_list;
806 AddPasses(&child_pass_list,
807 gfx::Rect(SurfaceSize()),
808 child_passes,
809 arraysize(child_passes));
811 RenderPass* child_root_pass = child_pass_list.at(0u);
812 SharedQuadState* child_root_pass_sqs =
813 child_root_pass->shared_quad_state_list[0];
814 child_root_pass_sqs->content_to_target_transform.Translate(8, 0);
816 scoped_ptr<DelegatedFrameData> child_frame_data(new DelegatedFrameData);
817 child_pass_list.swap(child_frame_data->render_pass_list);
819 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
820 child_frame->delegated_frame_data = child_frame_data.Pass();
822 factory_.SubmitFrame(child_surface_id, child_frame.Pass(), base::Closure());
824 test::Quad root_quads[] = {test::Quad::SurfaceQuad(child_surface_id)};
825 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))};
827 RenderPassList root_pass_list;
828 AddPasses(&root_pass_list,
829 gfx::Rect(SurfaceSize()),
830 root_passes,
831 arraysize(root_passes));
833 root_pass_list.at(0)
834 ->shared_quad_state_list[0]
835 ->content_to_target_transform.Translate(0, 10);
836 root_pass_list.at(0)->damage_rect = gfx::Rect(5, 5, 10, 10);
838 scoped_ptr<DelegatedFrameData> root_frame_data(new DelegatedFrameData);
839 root_pass_list.swap(root_frame_data->render_pass_list);
841 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
842 root_frame->delegated_frame_data = root_frame_data.Pass();
844 factory_.SubmitFrame(root_surface_id_, root_frame.Pass(), base::Closure());
846 scoped_ptr<CompositorFrame> aggregated_frame =
847 aggregator_.Aggregate(root_surface_id_);
849 ASSERT_TRUE(aggregated_frame);
850 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
852 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get();
854 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
856 ASSERT_EQ(1u, aggregated_pass_list.size());
858 // Damage rect for first aggregation should contain entire root surface.
859 EXPECT_TRUE(
860 aggregated_pass_list[0]->damage_rect.Contains(gfx::Rect(SurfaceSize())));
863 AddPasses(&child_pass_list,
864 gfx::Rect(SurfaceSize()),
865 child_passes,
866 arraysize(child_passes));
868 RenderPass* child_root_pass = child_pass_list.at(0u);
869 SharedQuadState* child_root_pass_sqs =
870 child_root_pass->shared_quad_state_list[0];
871 child_root_pass_sqs->content_to_target_transform.Translate(8, 0);
872 child_root_pass->damage_rect = gfx::Rect(10, 10, 10, 10);
874 scoped_ptr<DelegatedFrameData> child_frame_data(new DelegatedFrameData);
875 child_pass_list.swap(child_frame_data->render_pass_list);
877 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame);
878 child_frame->delegated_frame_data = child_frame_data.Pass();
880 factory_.SubmitFrame(child_surface_id, child_frame.Pass(), base::Closure());
882 scoped_ptr<CompositorFrame> aggregated_frame =
883 aggregator_.Aggregate(root_surface_id_);
885 ASSERT_TRUE(aggregated_frame);
886 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
888 DelegatedFrameData* frame_data =
889 aggregated_frame->delegated_frame_data.get();
891 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
893 ASSERT_EQ(1u, aggregated_pass_list.size());
895 // Outer surface didn't change, so transformed inner damage rect should be
896 // used.
897 EXPECT_EQ(gfx::Rect(10, 20, 10, 10).ToString(),
898 aggregated_pass_list[0]->damage_rect.ToString());
902 RenderPassList root_pass_list;
903 AddPasses(&root_pass_list,
904 gfx::Rect(SurfaceSize()),
905 root_passes,
906 arraysize(root_passes));
908 root_pass_list.at(0)
909 ->shared_quad_state_list[0]
910 ->content_to_target_transform.Translate(0, 10);
911 root_pass_list.at(0)->damage_rect = gfx::Rect(0, 0, 1, 1);
913 scoped_ptr<DelegatedFrameData> root_frame_data(new DelegatedFrameData);
914 root_pass_list.swap(root_frame_data->render_pass_list);
916 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
917 root_frame->delegated_frame_data = root_frame_data.Pass();
919 factory_.SubmitFrame(root_surface_id_, root_frame.Pass(), base::Closure());
923 RenderPassList root_pass_list;
924 AddPasses(&root_pass_list,
925 gfx::Rect(SurfaceSize()),
926 root_passes,
927 arraysize(root_passes));
929 root_pass_list.at(0)
930 ->shared_quad_state_list[0]
931 ->content_to_target_transform.Translate(0, 10);
932 root_pass_list.at(0)->damage_rect = gfx::Rect(1, 1, 1, 1);
934 scoped_ptr<DelegatedFrameData> root_frame_data(new DelegatedFrameData);
935 root_pass_list.swap(root_frame_data->render_pass_list);
937 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame);
938 root_frame->delegated_frame_data = root_frame_data.Pass();
940 factory_.SubmitFrame(root_surface_id_, root_frame.Pass(), base::Closure());
942 scoped_ptr<CompositorFrame> aggregated_frame =
943 aggregator_.Aggregate(root_surface_id_);
945 ASSERT_TRUE(aggregated_frame);
946 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
948 DelegatedFrameData* frame_data =
949 aggregated_frame->delegated_frame_data.get();
951 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list;
953 ASSERT_EQ(1u, aggregated_pass_list.size());
955 // The root surface was enqueued without being aggregated once, so it should
956 // be treated as completely damaged.
957 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.Contains(
958 gfx::Rect(SurfaceSize())));
961 factory_.Destroy(child_surface_id);
964 class SurfaceAggregatorWithResourcesTest : public testing::Test {
965 public:
966 virtual void SetUp() {
967 output_surface_ = FakeOutputSurface::CreateSoftware(
968 make_scoped_ptr(new SoftwareOutputDevice));
969 output_surface_->BindToClient(&output_surface_client_);
970 shared_bitmap_manager_.reset(new TestSharedBitmapManager);
972 resource_provider_ = ResourceProvider::Create(output_surface_.get(),
973 shared_bitmap_manager_.get(),
974 NULL,
976 false,
978 false);
980 aggregator_.reset(
981 new SurfaceAggregator(&manager_, resource_provider_.get()));
984 protected:
985 SurfaceManager manager_;
986 FakeOutputSurfaceClient output_surface_client_;
987 scoped_ptr<OutputSurface> output_surface_;
988 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
989 scoped_ptr<ResourceProvider> resource_provider_;
990 scoped_ptr<SurfaceAggregator> aggregator_;
993 class ResourceTrackingSurfaceFactoryClient : public SurfaceFactoryClient {
994 public:
995 ResourceTrackingSurfaceFactoryClient() {}
996 virtual ~ResourceTrackingSurfaceFactoryClient() {}
998 virtual void ReturnResources(
999 const ReturnedResourceArray& resources) OVERRIDE {
1000 returned_resources_ = resources;
1003 ReturnedResourceArray returned_resources() const {
1004 return returned_resources_;
1007 private:
1008 ReturnedResourceArray returned_resources_;
1010 DISALLOW_COPY_AND_ASSIGN(ResourceTrackingSurfaceFactoryClient);
1013 void SubmitFrameWithResources(ResourceProvider::ResourceId* resource_ids,
1014 size_t num_resource_ids,
1015 SurfaceFactory* factory,
1016 SurfaceId surface_id) {
1017 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
1018 scoped_ptr<RenderPass> pass = RenderPass::Create();
1019 pass->id = RenderPassId(1, 1);
1020 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
1021 for (size_t i = 0u; i < num_resource_ids; ++i) {
1022 TransferableResource resource;
1023 resource.id = resource_ids[i];
1024 resource.is_software = true;
1025 frame_data->resource_list.push_back(resource);
1026 TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
1027 const gfx::Rect rect;
1028 const gfx::Rect opaque_rect;
1029 const gfx::Rect visible_rect;
1030 bool needs_blending = false;
1031 bool premultiplied_alpha = false;
1032 const gfx::PointF uv_top_left;
1033 const gfx::PointF uv_bottom_right;
1034 SkColor background_color = SK_ColorGREEN;
1035 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f};
1036 bool flipped = false;
1037 quad->SetAll(sqs,
1038 rect,
1039 opaque_rect,
1040 visible_rect,
1041 needs_blending,
1042 resource_ids[i],
1043 premultiplied_alpha,
1044 uv_top_left,
1045 uv_bottom_right,
1046 background_color,
1047 vertex_opacity,
1048 flipped);
1050 quad->shared_quad_state = sqs;
1052 frame_data->render_pass_list.push_back(pass.Pass());
1053 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
1054 frame->delegated_frame_data = frame_data.Pass();
1055 factory->SubmitFrame(surface_id, frame.Pass(), base::Closure());
1058 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) {
1059 ResourceTrackingSurfaceFactoryClient client;
1060 SurfaceFactory factory(&manager_, &client);
1061 SurfaceId surface_id(7u);
1062 factory.Create(surface_id, SurfaceSize());
1064 ResourceProvider::ResourceId ids[] = {11, 12, 13};
1065 SubmitFrameWithResources(ids, arraysize(ids), &factory, surface_id);
1067 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id);
1069 // Nothing should be available to be returned yet.
1070 EXPECT_TRUE(client.returned_resources().empty());
1072 SubmitFrameWithResources(NULL, 0u, &factory, surface_id);
1074 frame = aggregator_->Aggregate(surface_id);
1076 ASSERT_EQ(3u, client.returned_resources().size());
1077 ResourceProvider::ResourceId returned_ids[3];
1078 for (size_t i = 0; i < 3; ++i) {
1079 returned_ids[i] = client.returned_resources()[i].id;
1081 EXPECT_THAT(returned_ids,
1082 testing::WhenSorted(testing::ElementsAreArray(ids)));
1083 factory.Destroy(surface_id);
1086 } // namespace
1087 } // namespace cc