1 // Copyright 2013 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/trees/layer_tree_host.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/thread.h"
12 #include "base/time/time.h"
13 #include "cc/layers/delegated_renderer_layer.h"
14 #include "cc/layers/delegated_renderer_layer_client.h"
15 #include "cc/layers/delegated_renderer_layer_impl.h"
16 #include "cc/output/compositor_frame.h"
17 #include "cc/output/compositor_frame_ack.h"
18 #include "cc/output/delegated_frame_data.h"
19 #include "cc/quads/render_pass_draw_quad.h"
20 #include "cc/quads/shared_quad_state.h"
21 #include "cc/quads/texture_draw_quad.h"
22 #include "cc/resources/returned_resource.h"
23 #include "cc/test/fake_delegated_renderer_layer.h"
24 #include "cc/test/fake_delegated_renderer_layer_impl.h"
25 #include "cc/test/fake_output_surface.h"
26 #include "cc/test/layer_tree_test.h"
27 #include "cc/trees/layer_tree_impl.h"
28 #include "gpu/GLES2/gl2extchromium.h"
29 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
34 bool ReturnedResourceLower(const ReturnedResource
& a
,
35 const ReturnedResource
& b
) {
39 // Tests if the list of resources matches an expectation, modulo the order.
40 bool ResourcesMatch(ReturnedResourceArray actual
,
42 size_t expected_count
) {
43 std::sort(actual
.begin(), actual
.end(), ReturnedResourceLower
);
44 std::sort(expected
, expected
+ expected_count
);
45 size_t actual_index
= 0;
47 // for each element of the expected array, count off one of the actual array
48 // (after checking it matches).
49 for (size_t expected_index
= 0; expected_index
< expected_count
;
51 EXPECT_LT(actual_index
, actual
.size());
52 if (actual_index
>= actual
.size())
54 EXPECT_EQ(actual
[actual_index
].id
, expected
[expected_index
]);
55 if (actual
[actual_index
].id
!= expected
[expected_index
])
57 EXPECT_GT(actual
[actual_index
].count
, 0);
58 if (actual
[actual_index
].count
<= 0) {
61 --actual
[actual_index
].count
;
62 if (actual
[actual_index
].count
== 0)
66 EXPECT_EQ(actual_index
, actual
.size());
67 return actual_index
== actual
.size();
70 #define EXPECT_RESOURCES(expected, actual) \
71 EXPECT_TRUE(ResourcesMatch(actual, expected, arraysize(expected)));
73 // These tests deal with delegated renderer layers.
74 class LayerTreeHostDelegatedTest
: public LayerTreeTest
{
76 scoped_ptr
<DelegatedFrameData
> CreateFrameData(gfx::Rect root_output_rect
,
77 gfx::Rect root_damage_rect
) {
78 scoped_ptr
<DelegatedFrameData
> frame(new DelegatedFrameData
);
80 scoped_ptr
<RenderPass
> root_pass(RenderPass::Create());
81 root_pass
->SetNew(RenderPass::Id(1, 1),
85 frame
->render_pass_list
.push_back(root_pass
.Pass());
89 scoped_ptr
<DelegatedFrameData
> CreateInvalidFrameData(
90 gfx::Rect root_output_rect
,
91 gfx::Rect root_damage_rect
) {
92 scoped_ptr
<DelegatedFrameData
> frame(new DelegatedFrameData
);
94 scoped_ptr
<RenderPass
> root_pass(RenderPass::Create());
95 root_pass
->SetNew(RenderPass::Id(1, 1),
100 scoped_ptr
<SharedQuadState
> shared_quad_state
= SharedQuadState::Create();
102 gfx::Rect rect
= root_output_rect
;
103 gfx::Rect opaque_rect
= root_output_rect
;
104 // An invalid resource id! The resource isn't part of the frame.
105 unsigned resource_id
= 5;
106 bool premultiplied_alpha
= false;
107 gfx::PointF uv_top_left
= gfx::PointF(0.f
, 0.f
);
108 gfx::PointF uv_bottom_right
= gfx::PointF(1.f
, 1.f
);
109 SkColor background_color
= 0;
110 float vertex_opacity
[4] = {1.f
, 1.f
, 1.f
, 1.f
};
111 bool flipped
= false;
113 scoped_ptr
<TextureDrawQuad
> invalid_draw_quad
= TextureDrawQuad::Create();
114 invalid_draw_quad
->SetNew(shared_quad_state
.get(),
124 root_pass
->quad_list
.push_back(invalid_draw_quad
.PassAs
<DrawQuad
>());
126 root_pass
->shared_quad_state_list
.push_back(shared_quad_state
.Pass());
128 frame
->render_pass_list
.push_back(root_pass
.Pass());
132 void AddTransferableResource(DelegatedFrameData
* frame
,
133 ResourceProvider::ResourceId resource_id
) {
134 TransferableResource resource
;
135 resource
.id
= resource_id
;
136 frame
->resource_list
.push_back(resource
);
139 void AddTextureQuad(DelegatedFrameData
* frame
,
140 ResourceProvider::ResourceId resource_id
) {
141 scoped_ptr
<SharedQuadState
> sqs
= SharedQuadState::Create();
142 scoped_ptr
<TextureDrawQuad
> quad
= TextureDrawQuad::Create();
143 float vertex_opacity
[4] = { 1.f
, 1.f
, 1.f
, 1.f
};
144 quad
->SetNew(sqs
.get(),
145 gfx::Rect(0, 0, 10, 10),
146 gfx::Rect(0, 0, 10, 10),
149 gfx::PointF(0.f
, 0.f
),
150 gfx::PointF(1.f
, 1.f
),
154 frame
->render_pass_list
[0]->shared_quad_state_list
.push_back(sqs
.Pass());
155 frame
->render_pass_list
[0]->quad_list
.push_back(quad
.PassAs
<DrawQuad
>());
158 void AddRenderPass(DelegatedFrameData
* frame
,
160 gfx::Rect output_rect
,
161 gfx::Rect damage_rect
,
162 const FilterOperations
& filters
,
163 const FilterOperations
& background_filters
) {
164 for (size_t i
= 0; i
< frame
->render_pass_list
.size(); ++i
)
165 DCHECK(id
!= frame
->render_pass_list
[i
]->id
);
167 scoped_ptr
<RenderPass
> pass(RenderPass::Create());
172 frame
->render_pass_list
.push_back(pass
.Pass());
174 scoped_ptr
<SharedQuadState
> sqs
= SharedQuadState::Create();
175 scoped_ptr
<RenderPassDrawQuad
> quad
= RenderPassDrawQuad::Create();
177 quad
->SetNew(sqs
.get(),
181 0, // mask_resource_id
183 gfx::Rect(0, 0, 1, 1), // mask_uv_rect
185 skia::RefPtr
<SkImageFilter
>(),
187 frame
->render_pass_list
[0]->shared_quad_state_list
.push_back(sqs
.Pass());
188 frame
->render_pass_list
[0]->quad_list
.push_back(quad
.PassAs
<DrawQuad
>());
191 scoped_ptr
<DelegatedFrameData
> CreateEmptyFrameData() {
192 scoped_ptr
<DelegatedFrameData
> frame(new DelegatedFrameData
);
197 static ResourceProvider::ResourceId
AppendResourceId(
198 std::vector
<ResourceProvider::ResourceId
>* resources_in_last_sent_frame
,
199 ResourceProvider::ResourceId resource_id
) {
200 resources_in_last_sent_frame
->push_back(resource_id
);
204 void ReturnUnusedResourcesFromParent(LayerTreeHostImpl
* host_impl
) {
205 DelegatedFrameData
* delegated_frame_data
=
206 output_surface()->last_sent_frame().delegated_frame_data
.get();
207 if (!delegated_frame_data
)
210 std::vector
<ResourceProvider::ResourceId
> resources_in_last_sent_frame
;
211 for (size_t i
= 0; i
< delegated_frame_data
->render_pass_list
.size(); ++i
) {
212 RenderPass
* pass
= delegated_frame_data
->render_pass_list
.at(i
);
213 for (size_t j
= 0; j
< pass
->quad_list
.size(); ++j
) {
214 DrawQuad
* quad
= pass
->quad_list
[j
];
215 quad
->IterateResources(base::Bind(&AppendResourceId
,
216 &resources_in_last_sent_frame
));
220 std::vector
<ResourceProvider::ResourceId
> resources_to_return
;
222 const TransferableResourceArray
& resources_held_by_parent
=
223 output_surface()->resources_held_by_parent();
224 for (size_t i
= 0; i
< resources_held_by_parent
.size(); ++i
) {
225 ResourceProvider::ResourceId resource_in_parent
=
226 resources_held_by_parent
[i
].id
;
227 bool resource_in_parent_is_not_part_of_frame
=
228 std::find(resources_in_last_sent_frame
.begin(),
229 resources_in_last_sent_frame
.end(),
230 resource_in_parent
) == resources_in_last_sent_frame
.end();
231 if (resource_in_parent_is_not_part_of_frame
)
232 resources_to_return
.push_back(resource_in_parent
);
235 if (resources_to_return
.empty())
238 CompositorFrameAck ack
;
239 for (size_t i
= 0; i
< resources_to_return
.size(); ++i
)
240 output_surface()->ReturnResource(resources_to_return
[i
], &ack
);
241 host_impl
->ReclaimResources(&ack
);
242 host_impl
->OnSwapBuffersComplete();
246 class LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
247 : public LayerTreeHostDelegatedTest
,
248 public DelegatedRendererLayerClient
{
250 virtual void SetupTree() OVERRIDE
{
251 root_
= Layer::Create();
252 root_
->SetAnchorPoint(gfx::PointF());
253 root_
->SetBounds(gfx::Size(10, 10));
255 delegated_
= FakeDelegatedRendererLayer::Create(this);
256 delegated_
->SetAnchorPoint(gfx::PointF());
257 delegated_
->SetBounds(gfx::Size(10, 10));
258 delegated_
->SetIsDrawable(true);
260 root_
->AddChild(delegated_
);
261 layer_tree_host()->SetRootLayer(root_
);
262 LayerTreeHostDelegatedTest::SetupTree();
265 virtual void BeginTest() OVERRIDE
{
266 PostSetNeedsCommitToMainThread();
269 virtual void AfterTest() OVERRIDE
{}
271 virtual void DidCommitFrameData() OVERRIDE
{}
274 scoped_refptr
<Layer
> root_
;
275 scoped_refptr
<DelegatedRendererLayer
> delegated_
;
278 class LayerTreeHostDelegatedTestClientDidCommitCallback
279 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
281 LayerTreeHostDelegatedTestClientDidCommitCallback()
282 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(),
283 num_did_commit_frame_data_(0) {}
285 virtual void DidCommit() OVERRIDE
{
289 EXPECT_EQ(1, num_did_commit_frame_data_
);
293 virtual void BeginTest() OVERRIDE
{
294 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1),
295 gfx::Rect(0, 0, 1, 1)));
296 PostSetNeedsCommitToMainThread();
299 virtual void DidCommitFrameData() OVERRIDE
{
300 num_did_commit_frame_data_
++;
304 int num_did_commit_frame_data_
;
307 SINGLE_AND_MULTI_THREAD_TEST_F(
308 LayerTreeHostDelegatedTestClientDidCommitCallback
);
310 class LayerTreeHostDelegatedTestCreateChildId
311 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
313 LayerTreeHostDelegatedTestCreateChildId()
314 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(),
316 did_reset_child_id_(false) {}
318 virtual void DidCommit() OVERRIDE
{
321 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1),
322 gfx::Rect(0, 0, 1, 1)));
325 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
326 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
327 FakeDelegatedRendererLayerImpl
* delegated_impl
=
328 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
330 ContextProvider
* context_provider
=
331 host_impl
->output_surface()->context_provider();
334 switch (num_activates_
) {
336 EXPECT_TRUE(delegated_impl
->ChildId());
337 EXPECT_FALSE(did_reset_child_id_
);
339 context_provider
->Context3d()->loseContextCHROMIUM(
340 GL_GUILTY_CONTEXT_RESET_ARB
,
341 GL_INNOCENT_CONTEXT_RESET_ARB
);
344 EXPECT_TRUE(delegated_impl
->ChildId());
345 EXPECT_TRUE(did_reset_child_id_
);
351 virtual void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
352 bool success
) OVERRIDE
{
353 EXPECT_TRUE(success
);
355 if (num_activates_
< 2)
358 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
359 FakeDelegatedRendererLayerImpl
* delegated_impl
=
360 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
362 EXPECT_EQ(2, num_activates_
);
363 EXPECT_FALSE(delegated_impl
->ChildId());
364 did_reset_child_id_
= true;
367 virtual void AfterTest() OVERRIDE
{}
371 bool did_reset_child_id_
;
374 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCreateChildId
);
376 class LayerTreeHostDelegatedTestOffscreenContext_NoFilters
377 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
379 virtual void BeginTest() OVERRIDE
{
380 scoped_ptr
<DelegatedFrameData
> frame
=
381 CreateFrameData(gfx::Rect(0, 0, 1, 1),
382 gfx::Rect(0, 0, 1, 1));
383 delegated_
->SetFrameData(frame
.Pass());
385 PostSetNeedsCommitToMainThread();
388 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
389 EXPECT_FALSE(host_impl
->offscreen_context_provider());
393 virtual void AfterTest() OVERRIDE
{}
396 SINGLE_AND_MULTI_THREAD_TEST_F(
397 LayerTreeHostDelegatedTestOffscreenContext_NoFilters
);
399 class LayerTreeHostDelegatedTestOffscreenContext_Filters
400 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
402 virtual void BeginTest() OVERRIDE
{
403 scoped_ptr
<DelegatedFrameData
> frame
=
404 CreateFrameData(gfx::Rect(0, 0, 1, 1),
405 gfx::Rect(0, 0, 1, 1));
407 FilterOperations filters
;
408 filters
.Append(FilterOperation::CreateGrayscaleFilter(0.5f
));
409 AddRenderPass(frame
.get(),
410 RenderPass::Id(2, 1),
411 gfx::Rect(0, 0, 1, 1),
412 gfx::Rect(0, 0, 1, 1),
415 delegated_
->SetFrameData(frame
.Pass());
417 PostSetNeedsCommitToMainThread();
420 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
421 bool expect_context
= !delegating_renderer();
422 EXPECT_EQ(expect_context
, !!host_impl
->offscreen_context_provider());
426 virtual void AfterTest() OVERRIDE
{}
429 SINGLE_AND_MULTI_THREAD_TEST_F(
430 LayerTreeHostDelegatedTestOffscreenContext_Filters
);
432 class LayerTreeHostDelegatedTestOffscreenContext_BackgroundFilters
433 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
435 virtual void BeginTest() OVERRIDE
{
436 scoped_ptr
<DelegatedFrameData
> frame
=
437 CreateFrameData(gfx::Rect(0, 0, 1, 1),
438 gfx::Rect(0, 0, 1, 1));
440 FilterOperations filters
;
441 filters
.Append(FilterOperation::CreateGrayscaleFilter(0.5f
));
442 AddRenderPass(frame
.get(),
443 RenderPass::Id(2, 1),
444 gfx::Rect(0, 0, 1, 1),
445 gfx::Rect(0, 0, 1, 1),
448 delegated_
->SetFrameData(frame
.Pass());
450 PostSetNeedsCommitToMainThread();
453 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
454 bool expect_context
= !delegating_renderer();
455 EXPECT_EQ(expect_context
, !!host_impl
->offscreen_context_provider());
459 virtual void AfterTest() OVERRIDE
{}
462 SINGLE_AND_MULTI_THREAD_TEST_F(
463 LayerTreeHostDelegatedTestOffscreenContext_BackgroundFilters
);
465 class LayerTreeHostDelegatedTestOffscreenContext_Filters_AddedToTree
466 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
468 virtual void BeginTest() OVERRIDE
{
469 scoped_ptr
<DelegatedFrameData
> frame
=
470 CreateFrameData(gfx::Rect(0, 0, 1, 1),
471 gfx::Rect(0, 0, 1, 1));
473 FilterOperations filters
;
474 filters
.Append(FilterOperation::CreateGrayscaleFilter(0.5f
));
475 AddRenderPass(frame
.get(),
476 RenderPass::Id(2, 1),
477 gfx::Rect(0, 0, 1, 1),
478 gfx::Rect(0, 0, 1, 1),
482 delegated_
->RemoveFromParent();
483 delegated_
->SetFrameData(frame
.Pass());
484 layer_tree_host()->root_layer()->AddChild(delegated_
);
486 PostSetNeedsCommitToMainThread();
489 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
490 bool expect_context
= !delegating_renderer();
491 EXPECT_EQ(expect_context
, !!host_impl
->offscreen_context_provider());
495 virtual void AfterTest() OVERRIDE
{}
498 SINGLE_AND_MULTI_THREAD_TEST_F(
499 LayerTreeHostDelegatedTestOffscreenContext_Filters_AddedToTree
);
501 class LayerTreeHostDelegatedTestLayerUsesFrameDamage
502 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
504 LayerTreeHostDelegatedTestLayerUsesFrameDamage()
505 : LayerTreeHostDelegatedTestCaseSingleDelegatedLayer(),
506 first_draw_for_source_frame_(true) {}
508 virtual void DidCommit() OVERRIDE
{
509 int next_source_frame_number
= layer_tree_host()->source_frame_number();
510 switch (next_source_frame_number
) {
512 // The first time the layer gets a frame the whole layer should be
514 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 1, 1),
515 gfx::Rect(0, 0, 1, 1)));
518 // Should create a total amount of gfx::Rect(2, 2, 10, 6) damage.
519 // The frame size is 20x20 while the layer is 10x10, so this should
520 // produce a gfx::Rect(1, 1, 5, 3) damage rect.
521 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 20, 20),
522 gfx::Rect(2, 2, 5, 5)));
523 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 20, 20),
524 gfx::Rect(7, 2, 5, 6)));
527 // Should create zero damage.
528 layer_tree_host()->SetNeedsCommit();
531 // Should damage the full viewport.
532 delegated_
->SetBounds(gfx::Size(2, 2));
535 // Should create zero damage.
536 layer_tree_host()->SetNeedsCommit();
539 // Should damage the full layer.
540 delegated_
->SetBounds(gfx::Size(6, 6));
541 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 5, 5),
542 gfx::Rect(1, 1, 2, 2)));
545 // Should create zero damage.
546 layer_tree_host()->SetNeedsCommit();
549 // Should damage the full layer.
550 delegated_
->SetDisplaySize(gfx::Size(10, 10));
553 // Should create zero damage.
554 layer_tree_host()->SetNeedsCommit();
557 // Setting an empty frame should damage the whole layer the
559 delegated_
->SetFrameData(CreateEmptyFrameData());
562 // Setting an empty frame shouldn't damage anything after the
564 delegated_
->SetFrameData(CreateEmptyFrameData());
567 // Having valid content to display agains should damage the whole layer.
568 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 10, 10),
569 gfx::Rect(5, 5, 1, 1)));
572 // An invalid frame isn't used, so it should not cause damage.
573 delegated_
->SetFrameData(CreateInvalidFrameData(gfx::Rect(0, 0, 10, 10),
574 gfx::Rect(5, 5, 1, 1)));
577 // Should create gfx::Rect(1, 1, 2, 2) of damage. The frame size is
578 // 5x5 and the display size is now set to 10x10, so this should result
579 // in a gfx::Rect(2, 2, 4, 4) damage rect.
580 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 5, 5),
581 gfx::Rect(1, 1, 2, 2)));
584 // Should create zero damage.
585 layer_tree_host()->SetNeedsCommit();
588 // Moving the layer out of the tree and back in will damage the whole
590 delegated_
->RemoveFromParent();
591 layer_tree_host()->root_layer()->AddChild(delegated_
);
594 // Make a larger frame with lots of damage. Then a frame smaller than
595 // the first frame's damage. The entire layer should be damaged, but
597 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 10, 10),
598 gfx::Rect(0, 0, 10, 10)));
599 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 5, 5),
600 gfx::Rect(1, 1, 2, 2)));
603 // Make a frame with lots of damage. Then replace it with an empty
604 // frame. The entire layer should be damaged, but nothing more.
605 delegated_
->SetFrameData(CreateFrameData(gfx::Rect(0, 0, 10, 10),
606 gfx::Rect(0, 0, 10, 10)));
607 delegated_
->SetFrameData(CreateEmptyFrameData());
610 first_draw_for_source_frame_
= true;
613 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
614 LayerTreeHostImpl::FrameData
* frame
,
615 bool result
) OVERRIDE
{
618 if (!first_draw_for_source_frame_
)
621 gfx::RectF damage_rect
;
622 if (!frame
->has_no_damage
) {
623 damage_rect
= frame
->render_passes
.back()->damage_rect
;
625 // If there is no damage, then we have no render passes to send.
626 EXPECT_TRUE(frame
->render_passes
.empty());
629 switch (host_impl
->active_tree()->source_frame_number()) {
631 // First frame is damaged because of viewport resize.
632 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 10.f
, 10.f
).ToString(),
633 damage_rect
.ToString());
636 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 10.f
, 10.f
).ToString(),
637 damage_rect
.ToString());
640 EXPECT_EQ(gfx::RectF(1.f
, 1.f
, 5.f
, 3.f
).ToString(),
641 damage_rect
.ToString());
644 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
645 damage_rect
.ToString());
648 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 10.f
, 10.f
).ToString(),
649 damage_rect
.ToString());
652 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
653 damage_rect
.ToString());
656 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
657 damage_rect
.ToString());
660 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
661 damage_rect
.ToString());
664 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
665 damage_rect
.ToString());
668 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
669 damage_rect
.ToString());
672 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
673 damage_rect
.ToString());
676 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
677 damage_rect
.ToString());
680 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
681 damage_rect
.ToString());
684 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
685 damage_rect
.ToString());
688 EXPECT_EQ(gfx::RectF(2.f
, 2.f
, 4.f
, 4.f
).ToString(),
689 damage_rect
.ToString());
692 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 0.f
, 0.f
).ToString(),
693 damage_rect
.ToString());
696 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
697 damage_rect
.ToString());
700 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
701 damage_rect
.ToString());
704 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 6.f
, 6.f
).ToString(),
705 damage_rect
.ToString());
714 bool first_draw_for_source_frame_
;
717 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestLayerUsesFrameDamage
);
719 class LayerTreeHostDelegatedTestMergeResources
720 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
722 virtual void BeginTest() OVERRIDE
{
723 // Push two frames to the delegated renderer layer with no commit between.
725 // The first frame has resource 999.
726 scoped_ptr
<DelegatedFrameData
> frame1
=
727 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
728 AddTextureQuad(frame1
.get(), 999);
729 AddTransferableResource(frame1
.get(), 999);
730 delegated_
->SetFrameData(frame1
.Pass());
732 // The second frame uses resource 999 still, but also adds 555.
733 scoped_ptr
<DelegatedFrameData
> frame2
=
734 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
735 AddTextureQuad(frame2
.get(), 999);
736 AddTransferableResource(frame2
.get(), 999);
737 AddTextureQuad(frame2
.get(), 555);
738 AddTransferableResource(frame2
.get(), 555);
739 delegated_
->SetFrameData(frame2
.Pass());
741 // The resource 999 from frame1 is returned since it is still on the main
743 ReturnedResourceArray returned_resources
;
744 delegated_
->TakeUnusedResourcesForChildCompositor(&returned_resources
);
746 unsigned expected
[] = {999};
747 EXPECT_RESOURCES(expected
, returned_resources
);
750 PostSetNeedsCommitToMainThread();
753 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
754 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
755 FakeDelegatedRendererLayerImpl
* delegated_impl
=
756 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
758 const ResourceProvider::ResourceIdMap
& map
=
759 host_impl
->resource_provider()->GetChildToParentMap(
760 delegated_impl
->ChildId());
762 // Both frames' resources should be in the parent's resource provider.
763 EXPECT_EQ(2u, map
.size());
764 EXPECT_EQ(1u, map
.count(999));
765 EXPECT_EQ(1u, map
.count(555));
767 EXPECT_EQ(2u, delegated_impl
->Resources().size());
768 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
769 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
774 virtual void AfterTest() OVERRIDE
{}
777 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestMergeResources
);
779 class LayerTreeHostDelegatedTestRemapResourcesInQuads
780 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
782 virtual void BeginTest() OVERRIDE
{
783 // Generate a frame with two resources in it.
784 scoped_ptr
<DelegatedFrameData
> frame
=
785 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
786 AddTextureQuad(frame
.get(), 999);
787 AddTransferableResource(frame
.get(), 999);
788 AddTextureQuad(frame
.get(), 555);
789 AddTransferableResource(frame
.get(), 555);
790 delegated_
->SetFrameData(frame
.Pass());
792 PostSetNeedsCommitToMainThread();
795 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
796 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
797 FakeDelegatedRendererLayerImpl
* delegated_impl
=
798 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
800 const ResourceProvider::ResourceIdMap
& map
=
801 host_impl
->resource_provider()->GetChildToParentMap(
802 delegated_impl
->ChildId());
804 // The frame's resource should be in the parent's resource provider.
805 EXPECT_EQ(2u, map
.size());
806 EXPECT_EQ(1u, map
.count(999));
807 EXPECT_EQ(1u, map
.count(555));
809 ResourceProvider::ResourceId parent_resource_id1
= map
.find(999)->second
;
810 EXPECT_NE(parent_resource_id1
, 999u);
811 ResourceProvider::ResourceId parent_resource_id2
= map
.find(555)->second
;
812 EXPECT_NE(parent_resource_id2
, 555u);
814 // The resources in the quads should be remapped to the parent's namespace.
815 const TextureDrawQuad
* quad1
= TextureDrawQuad::MaterialCast(
816 delegated_impl
->RenderPassesInDrawOrder()[0]->quad_list
[0]);
817 EXPECT_EQ(parent_resource_id1
, quad1
->resource_id
);
818 const TextureDrawQuad
* quad2
= TextureDrawQuad::MaterialCast(
819 delegated_impl
->RenderPassesInDrawOrder()[0]->quad_list
[1]);
820 EXPECT_EQ(parent_resource_id2
, quad2
->resource_id
);
825 virtual void AfterTest() OVERRIDE
{}
828 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestRemapResourcesInQuads
);
830 class LayerTreeHostDelegatedTestReturnUnusedResources
831 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
833 virtual void BeginTest() OVERRIDE
{
834 PostSetNeedsCommitToMainThread();
837 virtual void DidCommitAndDrawFrame() OVERRIDE
{
838 scoped_ptr
<DelegatedFrameData
> frame
;
839 ReturnedResourceArray resources
;
841 int next_source_frame_number
= layer_tree_host()->source_frame_number();
842 switch (next_source_frame_number
) {
844 // Generate a frame with two resources in it.
845 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
846 AddTextureQuad(frame
.get(), 999);
847 AddTransferableResource(frame
.get(), 999);
848 AddTextureQuad(frame
.get(), 555);
849 AddTransferableResource(frame
.get(), 555);
850 delegated_
->SetFrameData(frame
.Pass());
853 // Retrieve unused resources to the main thread.
854 // TODO(danakj): Shouldn't need to commit to get resources.
855 layer_tree_host()->SetNeedsCommit();
858 // All of the resources are in use.
859 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
860 EXPECT_EQ(0u, resources
.size());
862 // Keep using 999 but stop using 555.
863 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
864 AddTextureQuad(frame
.get(), 999);
865 AddTextureQuad(frame
.get(), 444);
866 AddTransferableResource(frame
.get(), 444);
867 delegated_
->SetFrameData(frame
.Pass());
870 // Retrieve unused resources to the main thread.
871 // TODO(danakj): Shouldn't need to commit to get resources.
872 layer_tree_host()->SetNeedsCommit();
875 // 555 is no longer in use.
876 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
878 unsigned expected
[] = {555};
879 EXPECT_RESOURCES(expected
, resources
);
882 // Stop using any resources.
883 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
884 delegated_
->SetFrameData(frame
.Pass());
887 // Postpone collecting resources for a frame. They should still be there
889 layer_tree_host()->SetNeedsCommit();
892 // 444 and 999 are no longer in use.
893 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
895 unsigned expected
[] = {444, 999};
896 EXPECT_RESOURCES(expected
, resources
);
902 // Resource are never immediately released.
903 ReturnedResourceArray empty_resources
;
904 delegated_
->TakeUnusedResourcesForChildCompositor(&empty_resources
);
905 EXPECT_TRUE(empty_resources
.empty());
908 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
909 bool result
) OVERRIDE
{
910 ReturnUnusedResourcesFromParent(host_impl
);
913 virtual void AfterTest() OVERRIDE
{}
916 SINGLE_AND_MULTI_THREAD_TEST_F(
917 LayerTreeHostDelegatedTestReturnUnusedResources
);
919 class LayerTreeHostDelegatedTestReusedResources
920 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
922 virtual void BeginTest() OVERRIDE
{
923 PostSetNeedsCommitToMainThread();
926 virtual void DidCommitAndDrawFrame() OVERRIDE
{
927 scoped_ptr
<DelegatedFrameData
> frame
;
928 ReturnedResourceArray resources
;
930 int next_source_frame_number
= layer_tree_host()->source_frame_number();
931 switch (next_source_frame_number
) {
933 // Generate a frame with some resources in it.
934 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
935 AddTextureQuad(frame
.get(), 999);
936 AddTransferableResource(frame
.get(), 999);
937 AddTextureQuad(frame
.get(), 555);
938 AddTransferableResource(frame
.get(), 555);
939 AddTextureQuad(frame
.get(), 444);
940 AddTransferableResource(frame
.get(), 444);
941 delegated_
->SetFrameData(frame
.Pass());
944 // Retrieve unused resources to the main thread.
945 // TODO(danakj): Shouldn't need to commit to get resources.
946 layer_tree_host()->SetNeedsCommit();
949 // All of the resources are in use.
950 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
951 EXPECT_EQ(0u, resources
.size());
953 // Keep using 999 but stop using 555 and 444.
954 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
955 AddTextureQuad(frame
.get(), 999);
956 delegated_
->SetFrameData(frame
.Pass());
958 // Resource are not immediately released.
959 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
960 EXPECT_EQ(0u, resources
.size());
962 // Now using 555 and 444 again, but not 999.
963 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
964 AddTextureQuad(frame
.get(), 555);
965 AddTextureQuad(frame
.get(), 444);
966 delegated_
->SetFrameData(frame
.Pass());
969 // Retrieve unused resources to the main thread.
970 // TODO(danakj): Shouldn't need to commit to get resources.
971 layer_tree_host()->SetNeedsCommit();
974 // The 999 resource is the only unused one.
975 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
977 unsigned expected
[] = {999};
978 EXPECT_RESOURCES(expected
, resources
);
985 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
986 bool result
) OVERRIDE
{
987 ReturnUnusedResourcesFromParent(host_impl
);
990 virtual void AfterTest() OVERRIDE
{}
993 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestReusedResources
);
995 class LayerTreeHostDelegatedTestFrameBeforeAck
996 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
998 virtual void BeginTest() OVERRIDE
{
999 PostSetNeedsCommitToMainThread();
1002 virtual void DidCommitAndDrawFrame() OVERRIDE
{
1003 scoped_ptr
<DelegatedFrameData
> frame
;
1004 ReturnedResourceArray resources
;
1006 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1007 switch (next_source_frame_number
) {
1009 // Generate a frame with some resources in it.
1010 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1011 AddTextureQuad(frame
.get(), 999);
1012 AddTransferableResource(frame
.get(), 999);
1013 AddTextureQuad(frame
.get(), 555);
1014 AddTransferableResource(frame
.get(), 555);
1015 AddTextureQuad(frame
.get(), 444);
1016 AddTransferableResource(frame
.get(), 444);
1017 delegated_
->SetFrameData(frame
.Pass());
1020 // Retrieve unused resources to the main thread.
1021 // TODO(danakj): Shouldn't need to commit to get resources.
1022 layer_tree_host()->SetNeedsCommit();
1025 // All of the resources are in use.
1026 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1027 EXPECT_EQ(0u, resources
.size());
1029 // Keep using 999 but stop using 555 and 444.
1030 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1031 AddTextureQuad(frame
.get(), 999);
1032 delegated_
->SetFrameData(frame
.Pass());
1034 // Resource are not immediately released.
1035 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1036 EXPECT_EQ(0u, resources
.size());
1038 // The parent compositor (this one) does a commit.
1041 // Retrieve unused resources to the main thread.
1042 // TODO(danakj): Shouldn't need to commit to get resources.
1043 layer_tree_host()->SetNeedsCommit();
1046 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1048 unsigned expected
[] = {444, 555};
1049 EXPECT_RESOURCES(expected
, resources
);
1052 // The child compositor sends a frame before receiving an for the
1053 // second frame. It uses 999, 444, and 555 again.
1054 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1055 AddTextureQuad(frame
.get(), 999);
1056 AddTextureQuad(frame
.get(), 555);
1057 AddTextureQuad(frame
.get(), 444);
1058 delegated_
->SetFrameData(frame
.Pass());
1063 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
1064 if (host_impl
->active_tree()->source_frame_number() != 5)
1067 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1068 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1069 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1071 const ResourceProvider::ResourceIdMap
& map
=
1072 host_impl
->resource_provider()->GetChildToParentMap(
1073 delegated_impl
->ChildId());
1075 // The bad frame should be dropped. So we should only have one quad (the
1076 // one with resource 999) on the impl tree. And only 999 will be present
1077 // in the parent's resource provider.
1078 EXPECT_EQ(1u, map
.size());
1079 EXPECT_EQ(1u, map
.count(999));
1081 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1082 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1084 const RenderPass
* pass
= delegated_impl
->RenderPassesInDrawOrder()[0];
1085 EXPECT_EQ(1u, pass
->quad_list
.size());
1086 const TextureDrawQuad
* quad
= TextureDrawQuad::MaterialCast(
1087 pass
->quad_list
[0]);
1088 EXPECT_EQ(map
.find(999)->second
, quad
->resource_id
);
1093 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
1094 bool result
) OVERRIDE
{
1095 ReturnUnusedResourcesFromParent(host_impl
);
1098 virtual void AfterTest() OVERRIDE
{}
1101 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestFrameBeforeAck
);
1103 class LayerTreeHostDelegatedTestFrameBeforeTakeResources
1104 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1106 virtual void BeginTest() OVERRIDE
{
1107 PostSetNeedsCommitToMainThread();
1110 virtual void DidCommitAndDrawFrame() OVERRIDE
{
1111 scoped_ptr
<DelegatedFrameData
> frame
;
1112 ReturnedResourceArray resources
;
1114 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1115 switch (next_source_frame_number
) {
1117 // Generate a frame with some resources in it.
1118 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1119 AddTextureQuad(frame
.get(), 999);
1120 AddTransferableResource(frame
.get(), 999);
1121 AddTextureQuad(frame
.get(), 555);
1122 AddTransferableResource(frame
.get(), 555);
1123 AddTextureQuad(frame
.get(), 444);
1124 AddTransferableResource(frame
.get(), 444);
1125 delegated_
->SetFrameData(frame
.Pass());
1128 // Retrieve unused resources to the main thread.
1129 // TODO(danakj): Shouldn't need to commit to get resources.
1130 layer_tree_host()->SetNeedsCommit();
1133 // All of the resources are in use.
1134 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1135 EXPECT_EQ(0u, resources
.size());
1137 // Keep using 999 but stop using 555 and 444.
1138 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1139 AddTextureQuad(frame
.get(), 999);
1140 AddTransferableResource(frame
.get(), 999);
1141 delegated_
->SetFrameData(frame
.Pass());
1143 // Resource are not immediately released.
1144 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1145 EXPECT_EQ(0u, resources
.size());
1147 // The parent compositor (this one) does a commit.
1150 // Retrieve unused resources to the main thread.
1151 // TODO(danakj): Shouldn't need to commit to get resources.
1152 layer_tree_host()->SetNeedsCommit();
1155 // The child compositor sends a frame before taking resources back
1156 // from the previous commit. This frame makes use of the resources 555
1157 // and 444, which were just released during commit.
1158 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1159 AddTextureQuad(frame
.get(), 999);
1160 AddTransferableResource(frame
.get(), 999);
1161 AddTextureQuad(frame
.get(), 555);
1162 AddTransferableResource(frame
.get(), 555);
1163 AddTextureQuad(frame
.get(), 444);
1164 AddTransferableResource(frame
.get(), 444);
1165 delegated_
->SetFrameData(frame
.Pass());
1167 // The resources are used by the new frame but are returned anyway since
1168 // we passed them again.
1169 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1171 unsigned expected
[] = {444, 555};
1172 EXPECT_RESOURCES(expected
, resources
);
1176 // Retrieve unused resources to the main thread.
1177 // TODO(danakj): Shouldn't need to commit to get resources.
1178 layer_tree_host()->SetNeedsCommit();
1181 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1182 EXPECT_EQ(0u, resources
.size());
1188 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
1189 if (host_impl
->active_tree()->source_frame_number() != 5)
1192 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1193 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1194 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1196 const ResourceProvider::ResourceIdMap
& map
=
1197 host_impl
->resource_provider()->GetChildToParentMap(
1198 delegated_impl
->ChildId());
1200 // The third frame has all of the resources in it again, the delegated
1201 // renderer layer should continue to own the resources for it.
1202 EXPECT_EQ(3u, map
.size());
1203 EXPECT_EQ(1u, map
.count(999));
1204 EXPECT_EQ(1u, map
.count(555));
1205 EXPECT_EQ(1u, map
.count(444));
1207 EXPECT_EQ(3u, delegated_impl
->Resources().size());
1208 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1209 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1210 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(444)->second
));
1212 const RenderPass
* pass
= delegated_impl
->RenderPassesInDrawOrder()[0];
1213 EXPECT_EQ(3u, pass
->quad_list
.size());
1214 const TextureDrawQuad
* quad1
= TextureDrawQuad::MaterialCast(
1215 pass
->quad_list
[0]);
1216 EXPECT_EQ(map
.find(999)->second
, quad1
->resource_id
);
1217 const TextureDrawQuad
* quad2
= TextureDrawQuad::MaterialCast(
1218 pass
->quad_list
[1]);
1219 EXPECT_EQ(map
.find(555)->second
, quad2
->resource_id
);
1220 const TextureDrawQuad
* quad3
= TextureDrawQuad::MaterialCast(
1221 pass
->quad_list
[2]);
1222 EXPECT_EQ(map
.find(444)->second
, quad3
->resource_id
);
1225 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
1226 bool result
) OVERRIDE
{
1227 ReturnUnusedResourcesFromParent(host_impl
);
1230 virtual void AfterTest() OVERRIDE
{}
1233 SINGLE_AND_MULTI_THREAD_TEST_F(
1234 LayerTreeHostDelegatedTestFrameBeforeTakeResources
);
1236 class LayerTreeHostDelegatedTestBadFrame
1237 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1239 virtual void BeginTest() OVERRIDE
{
1240 PostSetNeedsCommitToMainThread();
1243 virtual void DidCommitAndDrawFrame() OVERRIDE
{
1244 scoped_ptr
<DelegatedFrameData
> frame
;
1245 ReturnedResourceArray resources
;
1247 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1248 switch (next_source_frame_number
) {
1250 // Generate a frame with some resources in it.
1251 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1252 AddTextureQuad(frame
.get(), 999);
1253 AddTransferableResource(frame
.get(), 999);
1254 AddTextureQuad(frame
.get(), 555);
1255 AddTransferableResource(frame
.get(), 555);
1256 delegated_
->SetFrameData(frame
.Pass());
1259 // Retrieve unused resources to the main thread.
1260 // TODO(danakj): Shouldn't need to commit to get resources.
1261 layer_tree_host()->SetNeedsCommit();
1264 // All of the resources are in use.
1265 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1266 EXPECT_EQ(0u, resources
.size());
1268 // Generate a bad frame with a resource the layer doesn't have. The
1269 // 885 and 775 resources are unknown, while ownership of the legit 444
1270 // resource is passed in here. The bad frame does not use any of the
1271 // previous resources, 999 or 555.
1272 // A bad quad is present both before and after the good quad.
1273 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1274 AddTextureQuad(frame
.get(), 885);
1275 AddTextureQuad(frame
.get(), 444);
1276 AddTransferableResource(frame
.get(), 444);
1277 AddTextureQuad(frame
.get(), 775);
1278 delegated_
->SetFrameData(frame
.Pass());
1280 // The parent compositor (this one) does a commit.
1283 // Retrieve unused resources to the main thread.
1284 // TODO(danakj): Shouldn't need to commit to get resources.
1285 layer_tree_host()->SetNeedsCommit();
1288 // The bad frame's resource is given back to the child compositor.
1289 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1291 unsigned expected
[] = {444};
1292 EXPECT_RESOURCES(expected
, resources
);
1295 // Now send a good frame with 999 again.
1296 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1297 AddTextureQuad(frame
.get(), 999);
1298 delegated_
->SetFrameData(frame
.Pass());
1301 // Retrieve unused resources to the main thread.
1302 // TODO(danakj): Shouldn't need to commit to get resources.
1303 layer_tree_host()->SetNeedsCommit();
1306 // The unused 555 from the last good frame is now released.
1307 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1309 unsigned expected
[] = {555};
1310 EXPECT_RESOURCES(expected
, resources
);
1318 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
1319 bool result
) OVERRIDE
{
1320 if (host_impl
->active_tree()->source_frame_number() < 1)
1323 ReturnUnusedResourcesFromParent(host_impl
);
1325 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1326 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1327 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1329 const ResourceProvider::ResourceIdMap
& map
=
1330 host_impl
->resource_provider()->GetChildToParentMap(
1331 delegated_impl
->ChildId());
1333 switch (host_impl
->active_tree()->source_frame_number()) {
1335 // We have the first good frame with just 990 and 555 in it.
1337 EXPECT_EQ(2u, map
.size());
1338 EXPECT_EQ(1u, map
.count(999));
1339 EXPECT_EQ(1u, map
.count(555));
1341 EXPECT_EQ(2u, delegated_impl
->Resources().size());
1342 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1343 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1345 const RenderPass
* pass
= delegated_impl
->RenderPassesInDrawOrder()[0];
1346 EXPECT_EQ(2u, pass
->quad_list
.size());
1347 const TextureDrawQuad
* quad1
= TextureDrawQuad::MaterialCast(
1348 pass
->quad_list
[0]);
1349 EXPECT_EQ(map
.find(999)->second
, quad1
->resource_id
);
1350 const TextureDrawQuad
* quad2
= TextureDrawQuad::MaterialCast(
1351 pass
->quad_list
[1]);
1352 EXPECT_EQ(map
.find(555)->second
, quad2
->resource_id
);
1356 // We only keep resources from the last valid frame.
1357 EXPECT_EQ(2u, map
.size());
1358 EXPECT_EQ(1u, map
.count(999));
1359 EXPECT_EQ(1u, map
.count(555));
1361 EXPECT_EQ(2u, delegated_impl
->Resources().size());
1362 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1363 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1365 // The bad frame is dropped though, we still have the frame with 999 and
1367 const RenderPass
* pass
= delegated_impl
->RenderPassesInDrawOrder()[0];
1368 EXPECT_EQ(2u, pass
->quad_list
.size());
1369 const TextureDrawQuad
* quad1
= TextureDrawQuad::MaterialCast(
1370 pass
->quad_list
[0]);
1371 EXPECT_EQ(map
.find(999)->second
, quad1
->resource_id
);
1372 const TextureDrawQuad
* quad2
= TextureDrawQuad::MaterialCast(
1373 pass
->quad_list
[1]);
1374 EXPECT_EQ(map
.find(555)->second
, quad2
->resource_id
);
1378 // Resources given to our parent compositor will be returned now, but
1379 // the DelegatedRendererLayerImpl doesn't know about it until the next
1381 // TODO(danakj): Shouldn't need a commit to return resources to the
1382 // DelegatedRendererLayerImpl or to the main thread.
1385 // We have the new good frame with just 999 in it.
1386 EXPECT_EQ(1u, map
.size());
1387 EXPECT_EQ(1u, map
.count(999));
1389 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1390 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1392 const RenderPass
* pass
= delegated_impl
->RenderPassesInDrawOrder()[0];
1393 EXPECT_EQ(1u, pass
->quad_list
.size());
1394 const TextureDrawQuad
* quad1
= TextureDrawQuad::MaterialCast(
1395 pass
->quad_list
[0]);
1396 EXPECT_EQ(map
.find(999)->second
, quad1
->resource_id
);
1402 virtual void AfterTest() OVERRIDE
{}
1405 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestBadFrame
);
1407 class LayerTreeHostDelegatedTestUnnamedResource
1408 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1410 virtual void BeginTest() OVERRIDE
{
1411 PostSetNeedsCommitToMainThread();
1414 virtual void DidCommit() OVERRIDE
{
1415 scoped_ptr
<DelegatedFrameData
> frame
;
1416 ReturnedResourceArray resources
;
1418 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1419 switch (next_source_frame_number
) {
1421 // This frame includes two resources in it, but only uses one.
1422 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1423 AddTransferableResource(frame
.get(), 999);
1424 AddTextureQuad(frame
.get(), 555);
1425 AddTransferableResource(frame
.get(), 555);
1426 delegated_
->SetFrameData(frame
.Pass());
1429 // The unused resource should be returned.
1430 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1432 unsigned expected
[] = {999};
1433 EXPECT_RESOURCES(expected
, resources
);
1441 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
1442 if (host_impl
->active_tree()->source_frame_number() != 1)
1445 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1446 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1447 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1449 const ResourceProvider::ResourceIdMap
& map
=
1450 host_impl
->resource_provider()->GetChildToParentMap(
1451 delegated_impl
->ChildId());
1453 // The layer only held on to the resource that was used.
1454 EXPECT_EQ(1u, map
.size());
1455 EXPECT_EQ(1u, map
.count(555));
1457 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1458 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1461 virtual void AfterTest() OVERRIDE
{}
1464 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestUnnamedResource
);
1466 class LayerTreeHostDelegatedTestDontLeakResource
1467 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1469 virtual void BeginTest() OVERRIDE
{
1470 PostSetNeedsCommitToMainThread();
1473 virtual void DidCommit() OVERRIDE
{
1474 scoped_ptr
<DelegatedFrameData
> frame
;
1475 ReturnedResourceArray resources
;
1477 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1478 switch (next_source_frame_number
) {
1480 // This frame includes two resources in it.
1481 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1482 AddTextureQuad(frame
.get(), 999);
1483 AddTransferableResource(frame
.get(), 999);
1484 AddTextureQuad(frame
.get(), 555);
1485 AddTransferableResource(frame
.get(), 555);
1486 delegated_
->SetFrameData(frame
.Pass());
1488 // But then we immediately stop using 999.
1489 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1490 AddTextureQuad(frame
.get(), 555);
1491 AddTransferableResource(frame
.get(), 555);
1492 delegated_
->SetFrameData(frame
.Pass());
1495 // The unused resources should be returned. 555 is still used, but it's
1496 // returned once to account for the first frame.
1497 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1499 unsigned expected
[] = {555, 999};
1500 EXPECT_RESOURCES(expected
, resources
);
1502 // Send a frame with no resources in it.
1503 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1504 delegated_
->SetFrameData(frame
.Pass());
1507 // The impl side will get back the resource at some point.
1508 // TODO(piman): The test should work without this.
1509 layer_tree_host()->SetNeedsCommit();
1512 // The now unused resource 555 should be returned.
1514 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1516 unsigned expected
[] = {555};
1517 EXPECT_RESOURCES(expected
, resources
);
1524 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
1525 if (host_impl
->active_tree()->source_frame_number() != 1)
1528 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1529 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1530 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1532 const ResourceProvider::ResourceIdMap
& map
=
1533 host_impl
->resource_provider()->GetChildToParentMap(
1534 delegated_impl
->ChildId());
1536 // The layer only held on to the resource that was used.
1537 EXPECT_EQ(1u, map
.size());
1538 EXPECT_EQ(1u, map
.count(555));
1540 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1541 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1544 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
1545 bool result
) OVERRIDE
{
1546 ReturnUnusedResourcesFromParent(host_impl
);
1549 virtual void AfterTest() OVERRIDE
{}
1552 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestDontLeakResource
);
1554 class LayerTreeHostDelegatedTestResourceSentToParent
1555 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1557 virtual void DidCommitAndDrawFrame() OVERRIDE
{
1558 scoped_ptr
<DelegatedFrameData
> frame
;
1559 ReturnedResourceArray resources
;
1561 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1562 switch (next_source_frame_number
) {
1564 // This frame includes two resources in it.
1565 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1566 AddTextureQuad(frame
.get(), 999);
1567 AddTransferableResource(frame
.get(), 999);
1568 AddTextureQuad(frame
.get(), 555);
1569 AddTransferableResource(frame
.get(), 555);
1570 delegated_
->SetFrameData(frame
.Pass());
1573 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1574 EXPECT_EQ(0u, resources
.size());
1576 // 999 is in use in the grandparent compositor, generate a frame without
1578 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1579 AddTextureQuad(frame
.get(), 555);
1580 delegated_
->SetFrameData(frame
.Pass());
1583 // Since 999 is in the grandparent it is not returned.
1584 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1585 EXPECT_EQ(0u, resources
.size());
1587 // The impl side will get back the resource at some point.
1588 // TODO(danakj): The test should work without this.
1589 layer_tree_host()->SetNeedsCommit();
1592 // 999 was returned from the grandparent and could be released.
1593 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1595 unsigned expected
[] = {999};
1596 EXPECT_RESOURCES(expected
, resources
);
1604 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
1605 if (host_impl
->active_tree()->source_frame_number() < 1)
1608 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1609 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1610 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1612 const ResourceProvider::ResourceIdMap
& map
=
1613 host_impl
->resource_provider()->GetChildToParentMap(
1614 delegated_impl
->ChildId());
1616 switch (host_impl
->active_tree()->source_frame_number()) {
1618 EXPECT_EQ(2u, map
.size());
1619 EXPECT_EQ(1u, map
.count(999));
1620 EXPECT_EQ(1u, map
.count(555));
1622 EXPECT_EQ(2u, delegated_impl
->Resources().size());
1623 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1624 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1626 // The 999 resource will be sent to a grandparent compositor.
1630 EXPECT_EQ(2u, map
.size());
1631 EXPECT_EQ(1u, map
.count(999));
1632 EXPECT_EQ(1u, map
.count(555));
1634 // 999 is in the parent, so not held by delegated renderer layer.
1635 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1636 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1638 // Receive 999 back from the grandparent.
1639 CompositorFrameAck ack
;
1640 output_surface()->ReturnResource(map
.find(999)->second
, &ack
);
1641 host_impl
->ReclaimResources(&ack
);
1642 host_impl
->OnSwapBuffersComplete();
1646 // 999 should be released.
1647 EXPECT_EQ(1u, map
.size());
1648 EXPECT_EQ(1u, map
.count(555));
1650 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1651 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1656 virtual void AfterTest() OVERRIDE
{}
1658 TransferableResource resource_in_grandparent
;
1661 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
1662 LayerTreeHostDelegatedTestResourceSentToParent
);
1664 class LayerTreeHostDelegatedTestCommitWithoutTake
1665 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1667 virtual void BeginTest() OVERRIDE
{
1668 // Prevent drawing with resources that are sent to the grandparent.
1669 layer_tree_host()->SetViewportSize(gfx::Size());
1670 PostSetNeedsCommitToMainThread();
1673 virtual void DidCommit() OVERRIDE
{
1674 scoped_ptr
<DelegatedFrameData
> frame
;
1675 ReturnedResourceArray resources
;
1677 int next_source_frame_number
= layer_tree_host()->source_frame_number();
1678 switch (next_source_frame_number
) {
1680 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1681 AddTextureQuad(frame
.get(), 999);
1682 AddTransferableResource(frame
.get(), 999);
1683 AddTextureQuad(frame
.get(), 555);
1684 AddTransferableResource(frame
.get(), 555);
1685 AddTextureQuad(frame
.get(), 444);
1686 AddTransferableResource(frame
.get(), 444);
1687 delegated_
->SetFrameData(frame
.Pass());
1690 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1691 EXPECT_EQ(0u, resources
.size());
1693 // Stop using 999 and 444 in this frame and commit.
1694 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1695 AddTextureQuad(frame
.get(), 555);
1696 AddTransferableResource(frame
.get(), 555);
1697 delegated_
->SetFrameData(frame
.Pass());
1698 // 999 and 444 will be returned for frame 1, but not 555 since it's in
1699 // the current frame.
1702 // Don't take resources here, but set a new frame that uses 999 again.
1703 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1704 AddTextureQuad(frame
.get(), 999);
1705 AddTransferableResource(frame
.get(), 999);
1706 AddTextureQuad(frame
.get(), 555);
1707 AddTransferableResource(frame
.get(), 555);
1708 delegated_
->SetFrameData(frame
.Pass());
1711 // 555 from frame 1 and 2 isn't returned since it's still in use. 999
1712 // from frame 1 is returned though.
1713 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1715 unsigned expected
[] = {444, 999};
1716 EXPECT_RESOURCES(expected
, resources
);
1719 frame
= CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1720 delegated_
->SetFrameData(frame
.Pass());
1721 // 555 will be returned 3 times for frames 1 2 and 3, and 999 will be
1722 // returned once for frame 3.
1725 delegated_
->TakeUnusedResourcesForChildCompositor(&resources
);
1727 unsigned expected
[] = {555, 555, 555, 999};
1728 EXPECT_RESOURCES(expected
, resources
);
1736 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
1737 if (host_impl
->active_tree()->source_frame_number() < 1)
1740 LayerImpl
* root_impl
= host_impl
->active_tree()->root_layer();
1741 FakeDelegatedRendererLayerImpl
* delegated_impl
=
1742 static_cast<FakeDelegatedRendererLayerImpl
*>(root_impl
->children()[0]);
1744 const ResourceProvider::ResourceIdMap
& map
=
1745 host_impl
->resource_provider()->GetChildToParentMap(
1746 delegated_impl
->ChildId());
1748 switch (host_impl
->active_tree()->source_frame_number()) {
1750 EXPECT_EQ(3u, map
.size());
1751 EXPECT_EQ(1u, map
.count(999));
1752 EXPECT_EQ(1u, map
.count(555));
1753 EXPECT_EQ(1u, map
.count(444));
1755 EXPECT_EQ(3u, delegated_impl
->Resources().size());
1756 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1757 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1758 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(444)->second
));
1761 EXPECT_EQ(1u, map
.size());
1762 EXPECT_EQ(1u, map
.count(555));
1764 EXPECT_EQ(1u, delegated_impl
->Resources().size());
1765 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1768 EXPECT_EQ(2u, map
.size());
1769 EXPECT_EQ(1u, map
.count(999));
1770 EXPECT_EQ(1u, map
.count(555));
1772 EXPECT_EQ(2u, delegated_impl
->Resources().size());
1773 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(999)->second
));
1774 EXPECT_EQ(1u, delegated_impl
->Resources().count(map
.find(555)->second
));
1778 virtual void AfterTest() OVERRIDE
{}
1781 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake
);
1783 class DelegatedFrameIsActivatedDuringCommit
1784 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer
{
1786 DelegatedFrameIsActivatedDuringCommit()
1787 : wait_thread_("WAIT"),
1788 wait_event_(false, false) {
1789 wait_thread_
.Start();
1792 virtual void BeginTest() OVERRIDE
{
1793 activate_count_
= 0;
1795 scoped_ptr
<DelegatedFrameData
> frame
=
1796 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1797 AddTextureQuad(frame
.get(), 999);
1798 AddTransferableResource(frame
.get(), 999);
1799 delegated_
->SetFrameData(frame
.Pass());
1801 PostSetNeedsCommitToMainThread();
1804 virtual void WillActivateTreeOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
1805 // Slow down activation so the main thread DidCommit() will run if
1807 wait_thread_
.message_loop()->PostDelayedTask(
1809 base::Bind(&base::WaitableEvent::Signal
,
1810 base::Unretained(&wait_event_
)),
1811 base::TimeDelta::FromMilliseconds(10));
1814 base::AutoLock
lock(activate_lock_
);
1818 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
1819 // The main thread is awake now, and will run DidCommit() immediately.
1820 // Run DidActivate() afterwards by posting it now.
1821 proxy()->MainThreadTaskRunner()->PostTask(
1823 base::Bind(&DelegatedFrameIsActivatedDuringCommit::DidActivate
,
1824 base::Unretained(this)));
1827 void DidActivate() {
1828 base::AutoLock
lock(activate_lock_
);
1829 switch (activate_count_
) {
1831 // The first frame has been activated. Set a new frame, and
1832 // expect the next commit to finish *after* it is activated.
1833 scoped_ptr
<DelegatedFrameData
> frame
=
1834 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1835 AddTextureQuad(frame
.get(), 555);
1836 AddTransferableResource(frame
.get(), 555);
1837 delegated_
->SetFrameData(frame
.Pass());
1838 // So this commit number should complete after the second activate.
1839 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
1843 // The second frame has been activated. Remove the layer from
1844 // the tree to cause another commit/activation. The commit should
1845 // finish *after* the layer is removed from the active tree.
1846 delegated_
->RemoveFromParent();
1847 // So this commit number should complete after the third activate.
1848 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
1856 virtual void DidCommit() OVERRIDE
{
1857 switch (layer_tree_host()->source_frame_number()) {
1859 // The activate for the 2nd frame should have happened before now.
1860 base::AutoLock
lock(activate_lock_
);
1861 EXPECT_EQ(2, activate_count_
);
1865 // The activate to remove the layer should have happened before now.
1866 base::AutoLock
lock(activate_lock_
);
1867 EXPECT_EQ(3, activate_count_
);
1874 virtual void AfterTest() OVERRIDE
{}
1876 base::Thread wait_thread_
;
1877 base::WaitableEvent wait_event_
;
1878 base::Lock activate_lock_
;
1879 int activate_count_
;
1882 SINGLE_AND_MULTI_THREAD_TEST_F(
1883 DelegatedFrameIsActivatedDuringCommit
);