1 // Copyright 2011 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"
9 #include "base/auto_reset.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/lock.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "cc/animation/timing_function.h"
15 #include "cc/debug/frame_rate_counter.h"
16 #include "cc/layers/content_layer_client.h"
17 #include "cc/layers/io_surface_layer.h"
18 #include "cc/layers/layer_impl.h"
19 #include "cc/layers/painted_scrollbar_layer.h"
20 #include "cc/layers/picture_layer.h"
21 #include "cc/layers/solid_color_layer.h"
22 #include "cc/layers/video_layer.h"
23 #include "cc/output/begin_frame_args.h"
24 #include "cc/output/compositor_frame_ack.h"
25 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h"
27 #include "cc/output/output_surface.h"
28 #include "cc/output/swap_promise.h"
29 #include "cc/quads/draw_quad.h"
30 #include "cc/quads/io_surface_draw_quad.h"
31 #include "cc/quads/render_pass_draw_quad.h"
32 #include "cc/quads/tile_draw_quad.h"
33 #include "cc/test/fake_content_layer_client.h"
34 #include "cc/test/fake_layer_tree_host_client.h"
35 #include "cc/test/fake_output_surface.h"
36 #include "cc/test/fake_painted_scrollbar_layer.h"
37 #include "cc/test/fake_picture_layer.h"
38 #include "cc/test/fake_picture_layer_impl.h"
39 #include "cc/test/fake_picture_pile.h"
40 #include "cc/test/fake_proxy.h"
41 #include "cc/test/fake_scoped_ui_resource.h"
42 #include "cc/test/fake_video_frame_provider.h"
43 #include "cc/test/geometry_test_utils.h"
44 #include "cc/test/layer_tree_test.h"
45 #include "cc/test/test_shared_bitmap_manager.h"
46 #include "cc/test/test_web_graphics_context_3d.h"
47 #include "cc/trees/layer_tree_host_impl.h"
48 #include "cc/trees/layer_tree_impl.h"
49 #include "cc/trees/single_thread_proxy.h"
50 #include "cc/trees/thread_proxy.h"
51 #include "gpu/GLES2/gl2extchromium.h"
52 #include "skia/ext/refptr.h"
53 #include "testing/gmock/include/gmock/gmock.h"
54 #include "third_party/khronos/GLES2/gl2.h"
55 #include "third_party/khronos/GLES2/gl2ext.h"
56 #include "third_party/skia/include/core/SkPicture.h"
57 #include "ui/gfx/geometry/point_conversions.h"
58 #include "ui/gfx/geometry/size_conversions.h"
59 #include "ui/gfx/geometry/vector2d_conversions.h"
62 using testing::AnyNumber
;
63 using testing::AtLeast
;
69 class LayerTreeHostTest
: public LayerTreeTest
{};
71 class LayerTreeHostTestHasImplThreadTest
: public LayerTreeHostTest
{
73 LayerTreeHostTestHasImplThreadTest() : threaded_(false) {}
75 void RunTest(bool threaded
, bool delegating_renderer
) override
{
77 LayerTreeHostTest::RunTest(threaded
, delegating_renderer
);
80 void BeginTest() override
{
81 EXPECT_EQ(threaded_
, HasImplThread());
85 void AfterTest() override
{ EXPECT_EQ(threaded_
, HasImplThread()); }
91 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHasImplThreadTest
);
93 class LayerTreeHostTestSetNeedsCommitInsideLayout
: public LayerTreeHostTest
{
95 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
97 void Layout() override
{
98 // This shouldn't cause a second commit to happen.
99 layer_tree_host()->SetNeedsCommit();
102 void DidCommit() override
{
103 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
107 void AfterTest() override
{}
110 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommitInsideLayout
);
112 class LayerTreeHostTestSetNeedsUpdateInsideLayout
: public LayerTreeHostTest
{
114 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
116 void Layout() override
{
117 // This shouldn't cause a second commit to happen.
118 layer_tree_host()->SetNeedsUpdateLayers();
121 void DidCommit() override
{
122 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
126 void AfterTest() override
{}
129 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsUpdateInsideLayout
);
131 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
132 // when no raster tasks get scheduled.
133 class LayerTreeHostTestReadyToActivateEmpty
: public LayerTreeHostTest
{
135 LayerTreeHostTestReadyToActivateEmpty()
136 : did_notify_ready_to_activate_(false),
137 all_tiles_required_for_activation_are_ready_to_draw_(false),
138 required_for_activation_count_(0) {}
140 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
142 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
143 const std::vector
<PictureLayerImpl
*>& layers
=
144 impl
->sync_tree()->picture_layers();
145 required_for_activation_count_
= 0;
146 for (const auto& layer
: layers
) {
147 FakePictureLayerImpl
* fake_layer
=
148 static_cast<FakePictureLayerImpl
*>(layer
);
149 required_for_activation_count_
+=
150 fake_layer
->CountTilesRequiredForActivation();
154 void NotifyReadyToActivateOnThread(LayerTreeHostImpl
* impl
) override
{
155 did_notify_ready_to_activate_
= true;
156 all_tiles_required_for_activation_are_ready_to_draw_
=
157 impl
->tile_manager()->IsReadyToActivate();
161 void AfterTest() override
{
162 EXPECT_TRUE(did_notify_ready_to_activate_
);
163 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_
);
164 EXPECT_EQ(size_t(0), required_for_activation_count_
);
168 bool did_notify_ready_to_activate_
;
169 bool all_tiles_required_for_activation_are_ready_to_draw_
;
170 size_t required_for_activation_count_
;
173 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateEmpty
);
175 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
176 // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled.
177 class LayerTreeHostTestReadyToActivateNonEmpty
178 : public LayerTreeHostTestReadyToActivateEmpty
{
180 void SetupTree() override
{
181 client_
.set_fill_with_nonsolid_color(true);
182 scoped_refptr
<FakePictureLayer
> root_layer
=
183 FakePictureLayer::Create(layer_settings(), &client_
);
184 root_layer
->SetBounds(gfx::Size(1024, 1024));
185 root_layer
->SetIsDrawable(true);
187 layer_tree_host()->SetRootLayer(root_layer
);
188 LayerTreeHostTest::SetupTree();
191 void AfterTest() override
{
192 EXPECT_TRUE(did_notify_ready_to_activate_
);
193 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_
);
194 EXPECT_LE(size_t(1), required_for_activation_count_
);
198 FakeContentLayerClient client_
;
201 // Multi-thread only because in single thread the commit goes directly to the
202 // active tree, so notify ready to activate is skipped.
203 MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty
);
205 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
206 // no raster tasks get scheduled.
207 class LayerTreeHostTestReadyToDrawEmpty
: public LayerTreeHostTest
{
209 LayerTreeHostTestReadyToDrawEmpty()
210 : did_notify_ready_to_draw_(false),
211 all_tiles_required_for_draw_are_ready_to_draw_(false),
212 required_for_draw_count_(0) {}
214 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
216 void NotifyReadyToDrawOnThread(LayerTreeHostImpl
* impl
) override
{
217 did_notify_ready_to_draw_
= true;
218 const std::vector
<PictureLayerImpl
*>& layers
=
219 impl
->active_tree()->picture_layers();
220 all_tiles_required_for_draw_are_ready_to_draw_
=
221 impl
->tile_manager()->IsReadyToDraw();
222 for (const auto& layer
: layers
) {
223 FakePictureLayerImpl
* fake_layer
=
224 static_cast<FakePictureLayerImpl
*>(layer
);
225 required_for_draw_count_
+= fake_layer
->CountTilesRequiredForDraw();
231 void AfterTest() override
{
232 EXPECT_TRUE(did_notify_ready_to_draw_
);
233 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_
);
234 EXPECT_EQ(size_t(0), required_for_draw_count_
);
238 bool did_notify_ready_to_draw_
;
239 bool all_tiles_required_for_draw_are_ready_to_draw_
;
240 size_t required_for_draw_count_
;
243 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToDrawEmpty
);
245 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
246 // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled.
247 class LayerTreeHostTestReadyToDrawNonEmpty
248 : public LayerTreeHostTestReadyToDrawEmpty
{
250 void SetupTree() override
{
251 client_
.set_fill_with_nonsolid_color(true);
252 scoped_refptr
<FakePictureLayer
> root_layer
=
253 FakePictureLayer::Create(layer_settings(), &client_
);
254 root_layer
->SetBounds(gfx::Size(1024, 1024));
255 root_layer
->SetIsDrawable(true);
257 layer_tree_host()->SetRootLayer(root_layer
);
258 LayerTreeHostTest::SetupTree();
261 void AfterTest() override
{
262 EXPECT_TRUE(did_notify_ready_to_draw_
);
263 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_
);
264 EXPECT_LE(size_t(1), required_for_draw_count_
);
268 FakeContentLayerClient client_
;
271 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
272 // single threaded mode.
273 SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty
);
275 class LayerTreeHostFreeWorkerContextResourcesTest
: public LayerTreeHostTest
{
277 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
278 auto output_surface
= make_scoped_ptr(new testing::StrictMock
<
279 MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface
>(
280 delegating_renderer()));
282 // At init, we expect one call to set visibility to true.
283 testing::Expectation visibility_true
=
284 EXPECT_CALL(*output_surface
,
285 SetWorkerContextShouldAggressivelyFreeResources(false))
288 // After running, we should get exactly one call to
289 // FreeWorkerContextGpuResources.
290 EXPECT_CALL(*output_surface
,
291 SetWorkerContextShouldAggressivelyFreeResources(true))
292 .After(visibility_true
)
293 .WillOnce(testing::Invoke([this](bool is_visible
) { EndTest(); }));
294 return output_surface
.Pass();
297 void InitializeSettings(LayerTreeSettings
* settings
) override
{
298 settings
->gpu_rasterization_enabled
= true;
299 settings
->gpu_rasterization_forced
= true;
302 void BeginTest() override
{
303 // Logic is handled in InitializedRendererOnThread to ensure that our
304 // LTHI is fully set up.
307 void AfterTest() override
{
308 // Expectations handled via mock.
312 class MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface
313 : public FakeOutputSurface
{
315 ~MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface() {}
316 explicit MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface(
317 bool delegated_rendering
)
318 : FakeOutputSurface(TestContextProvider::Create(),
319 TestContextProvider::Create(),
320 delegated_rendering
) {}
321 MOCK_METHOD1(SetWorkerContextShouldAggressivelyFreeResources
,
322 void(bool is_visible
));
326 // Test if the LTH successfully frees resources on the worker context when
327 // visibility is set to false.
328 class LayerTreeHostFreeWorkerContextResourcesOnInvisible
329 : public LayerTreeHostFreeWorkerContextResourcesTest
{
331 void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
332 bool success
) override
{
333 PostSetVisibleToMainThread(false);
337 SINGLE_AND_MULTI_THREAD_TEST_F(
338 LayerTreeHostFreeWorkerContextResourcesOnInvisible
);
340 // Test if the LTH successfully frees resources on the worker context when
341 // hard memory limit is set to zero.
342 class LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit
343 : public LayerTreeHostFreeWorkerContextResourcesTest
{
345 void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
346 bool success
) override
{
347 ManagedMemoryPolicy
zero_policy(
348 0, gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING
, 0);
349 host_impl
->SetMemoryPolicy(zero_policy
);
353 SINGLE_AND_MULTI_THREAD_TEST_F(
354 LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit
);
356 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
357 // draw with frame 0.
358 class LayerTreeHostTestSetNeedsCommit1
: public LayerTreeHostTest
{
360 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
362 void BeginTest() override
{
363 PostSetNeedsCommitToMainThread();
364 PostSetNeedsCommitToMainThread();
367 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
369 if (!impl
->active_tree()->source_frame_number())
373 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
377 void AfterTest() override
{
378 EXPECT_LE(1, num_commits_
);
379 EXPECT_LE(1, num_draws_
);
387 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1
);
389 // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that
390 // first committed frame draws should lead to another commit.
391 class LayerTreeHostTestSetNeedsCommit2
: public LayerTreeHostTest
{
393 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {}
395 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
397 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{ ++num_draws_
; }
399 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
401 switch (num_commits_
) {
403 PostSetNeedsCommitToMainThread();
413 void AfterTest() override
{
414 EXPECT_EQ(2, num_commits_
);
415 EXPECT_LE(1, num_draws_
);
423 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2
);
425 // Verify that we pass property values in PushPropertiesTo.
426 class LayerTreeHostTestPushPropertiesTo
: public LayerTreeHostTest
{
428 void SetupTree() override
{
429 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
430 root
->CreateRenderSurface();
431 root
->SetBounds(gfx::Size(10, 10));
432 layer_tree_host()->SetRootLayer(root
);
433 LayerTreeHostTest::SetupTree();
439 HIDE_LAYER_AND_SUBTREE
,
444 void BeginTest() override
{
446 PostSetNeedsCommitToMainThread();
449 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
450 VerifyAfterValues(impl
->active_tree()->root_layer());
453 void DidCommitAndDrawFrame() override
{
454 SetBeforeValues(layer_tree_host()->root_layer());
455 VerifyBeforeValues(layer_tree_host()->root_layer());
458 if (index_
== DONE
) {
463 SetAfterValues(layer_tree_host()->root_layer());
466 void AfterTest() override
{}
468 void VerifyBeforeValues(Layer
* layer
) {
469 EXPECT_EQ(gfx::Size(10, 10).ToString(), layer
->bounds().ToString());
470 EXPECT_FALSE(layer
->hide_layer_and_subtree());
471 EXPECT_FALSE(layer
->DrawsContent());
474 void SetBeforeValues(Layer
* layer
) {
475 layer
->SetBounds(gfx::Size(10, 10));
476 layer
->SetHideLayerAndSubtree(false);
477 layer
->SetIsDrawable(false);
480 void VerifyAfterValues(LayerImpl
* layer
) {
481 switch (static_cast<Properties
>(index_
)) {
486 EXPECT_EQ(gfx::Size(20, 20).ToString(), layer
->bounds().ToString());
488 case HIDE_LAYER_AND_SUBTREE
:
489 EXPECT_TRUE(layer
->hide_layer_and_subtree());
492 EXPECT_TRUE(layer
->DrawsContent());
497 void SetAfterValues(Layer
* layer
) {
498 switch (static_cast<Properties
>(index_
)) {
503 layer
->SetBounds(gfx::Size(20, 20));
505 case HIDE_LAYER_AND_SUBTREE
:
506 layer
->SetHideLayerAndSubtree(true);
509 layer
->SetIsDrawable(true);
517 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo
);
519 // 1 setNeedsRedraw after the first commit has completed should lead to 1
521 class LayerTreeHostTestSetNeedsRedraw
: public LayerTreeHostTest
{
523 LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {}
525 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
527 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
528 EXPECT_EQ(0, impl
->active_tree()->source_frame_number());
530 // Redraw again to verify that the second redraw doesn't commit.
531 PostSetNeedsRedrawToMainThread();
538 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
539 EXPECT_EQ(0, num_draws_
);
543 void AfterTest() override
{
544 EXPECT_GE(2, num_draws_
);
545 EXPECT_EQ(1, num_commits_
);
553 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw
);
555 // After setNeedsRedrawRect(invalid_rect) the final damage_rect
556 // must contain invalid_rect.
557 class LayerTreeHostTestSetNeedsRedrawRect
: public LayerTreeHostTest
{
559 LayerTreeHostTestSetNeedsRedrawRect()
560 : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {}
562 void BeginTest() override
{
563 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
564 root_layer_
->SetIsDrawable(true);
565 root_layer_
->SetBounds(bounds_
);
566 layer_tree_host()->SetRootLayer(root_layer_
);
567 layer_tree_host()->SetViewportSize(bounds_
);
568 PostSetNeedsCommitToMainThread();
571 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
572 LayerTreeHostImpl::FrameData
* frame_data
,
573 DrawResult draw_result
) override
{
574 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
576 gfx::RectF root_damage_rect
;
577 if (!frame_data
->render_passes
.empty())
578 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
581 // If this is the first frame, expect full frame damage.
582 EXPECT_EQ(root_damage_rect
, gfx::Rect(bounds_
));
584 // Check that invalid_rect_ is indeed repainted.
585 EXPECT_TRUE(root_damage_rect
.Contains(invalid_rect_
));
591 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
593 PostSetNeedsRedrawRectToMainThread(invalid_rect_
);
600 void AfterTest() override
{ EXPECT_EQ(2, num_draws_
); }
604 const gfx::Size bounds_
;
605 const gfx::Rect invalid_rect_
;
606 FakeContentLayerClient client_
;
607 scoped_refptr
<FakePictureLayer
> root_layer_
;
610 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect
);
612 // Ensure the texture size of the pending and active trees are identical when a
613 // layer is not in the viewport and a resize happens on the viewport
614 class LayerTreeHostTestGpuRasterDeviceSizeChanged
: public LayerTreeHostTest
{
616 LayerTreeHostTestGpuRasterDeviceSizeChanged()
617 : num_draws_(0), bounds_(500, 64), invalid_rect_(10, 10, 20, 20) {}
619 void BeginTest() override
{
620 client_
.set_fill_with_nonsolid_color(true);
621 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
622 root_layer_
->SetIsDrawable(true);
623 gfx::Transform transform
;
624 // Translate the layer out of the viewport to force it to not update its
625 // tile size via PushProperties.
626 transform
.Translate(10000.0, 10000.0);
627 root_layer_
->SetTransform(transform
);
628 root_layer_
->SetBounds(bounds_
);
629 layer_tree_host()->SetRootLayer(root_layer_
);
630 layer_tree_host()->SetViewportSize(bounds_
);
632 PostSetNeedsCommitToMainThread();
635 void InitializeSettings(LayerTreeSettings
* settings
) override
{
636 settings
->gpu_rasterization_enabled
= true;
637 settings
->gpu_rasterization_forced
= true;
640 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
641 // Perform 2 commits.
643 PostSetNeedsRedrawRectToMainThread(invalid_rect_
);
650 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
651 if (num_draws_
== 2) {
652 auto pending_tree
= host_impl
->pending_tree();
653 auto pending_layer_impl
=
654 static_cast<FakePictureLayerImpl
*>(pending_tree
->root_layer());
655 EXPECT_NE(pending_layer_impl
, nullptr);
657 auto active_tree
= host_impl
->pending_tree();
658 auto active_layer_impl
=
659 static_cast<FakePictureLayerImpl
*>(active_tree
->root_layer());
660 EXPECT_NE(pending_layer_impl
, nullptr);
662 auto active_tiling_set
= active_layer_impl
->picture_layer_tiling_set();
663 auto active_tiling
= active_tiling_set
->tiling_at(0);
664 auto pending_tiling_set
= pending_layer_impl
->picture_layer_tiling_set();
665 auto pending_tiling
= pending_tiling_set
->tiling_at(0);
667 pending_tiling
->TilingDataForTesting().max_texture_size().width(),
668 active_tiling
->TilingDataForTesting().max_texture_size().width());
672 void DidCommitAndDrawFrame() override
{
673 // On the second commit, resize the viewport.
674 if (num_draws_
== 1) {
675 layer_tree_host()->SetViewportSize(gfx::Size(400, 64));
679 void AfterTest() override
{}
683 const gfx::Size bounds_
;
684 const gfx::Rect invalid_rect_
;
685 FakeContentLayerClient client_
;
686 scoped_refptr
<FakePictureLayer
> root_layer_
;
689 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterDeviceSizeChanged
);
691 class LayerTreeHostTestNoExtraCommitFromInvalidate
: public LayerTreeHostTest
{
693 void InitializeSettings(LayerTreeSettings
* settings
) override
{
694 settings
->layer_transforms_should_scale_layer_contents
= true;
697 void SetupTree() override
{
698 root_layer_
= Layer::Create(layer_settings());
699 root_layer_
->SetBounds(gfx::Size(10, 20));
700 root_layer_
->CreateRenderSurface();
702 scaled_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
703 scaled_layer_
->SetBounds(gfx::Size(1, 1));
704 root_layer_
->AddChild(scaled_layer_
);
706 layer_tree_host()->SetRootLayer(root_layer_
);
707 LayerTreeHostTest::SetupTree();
710 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
712 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
713 if (host_impl
->active_tree()->source_frame_number() == 1)
717 void DidCommit() override
{
718 switch (layer_tree_host()->source_frame_number()) {
720 // SetBounds grows the layer and exposes new content.
721 scaled_layer_
->SetBounds(gfx::Size(4, 4));
725 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
729 void AfterTest() override
{
730 EXPECT_EQ(gfx::Size(4, 4).ToString(), scaled_layer_
->bounds().ToString());
734 FakeContentLayerClient client_
;
735 scoped_refptr
<Layer
> root_layer_
;
736 scoped_refptr
<Layer
> scaled_layer_
;
739 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate
);
741 class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate
742 : public LayerTreeHostTest
{
744 void InitializeSettings(LayerTreeSettings
* settings
) override
{
745 settings
->layer_transforms_should_scale_layer_contents
= true;
748 void SetupTree() override
{
749 root_layer_
= Layer::Create(layer_settings());
750 root_layer_
->SetBounds(gfx::Size(10, 20));
751 root_layer_
->CreateRenderSurface();
753 bool paint_scrollbar
= true;
754 bool has_thumb
= false;
755 scrollbar_
= FakePaintedScrollbarLayer::Create(
756 layer_settings(), paint_scrollbar
, has_thumb
, root_layer_
->id());
757 scrollbar_
->SetPosition(gfx::Point(0, 10));
758 scrollbar_
->SetBounds(gfx::Size(10, 10));
760 root_layer_
->AddChild(scrollbar_
);
762 layer_tree_host()->SetRootLayer(root_layer_
);
763 LayerTreeHostTest::SetupTree();
766 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
768 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
769 if (host_impl
->active_tree()->source_frame_number() == 1)
773 void DidCommit() override
{
774 switch (layer_tree_host()->source_frame_number()) {
776 // Changing the device scale factor causes a commit. It also changes
777 // the content bounds of |scrollbar_|, which should not generate
778 // a second commit as a result.
779 layer_tree_host()->SetDeviceScaleFactor(4.f
);
783 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
788 void AfterTest() override
{
792 FakeContentLayerClient client_
;
793 scoped_refptr
<Layer
> root_layer_
;
794 scoped_refptr
<FakePaintedScrollbarLayer
> scrollbar_
;
797 SINGLE_AND_MULTI_THREAD_TEST_F(
798 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate
);
800 class LayerTreeHostTestSetNextCommitForcesRedraw
: public LayerTreeHostTest
{
802 LayerTreeHostTestSetNextCommitForcesRedraw()
803 : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {}
805 void BeginTest() override
{
806 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
807 root_layer_
->SetIsDrawable(true);
808 root_layer_
->SetBounds(bounds_
);
809 layer_tree_host()->SetRootLayer(root_layer_
);
810 layer_tree_host()->SetViewportSize(bounds_
);
811 PostSetNeedsCommitToMainThread();
814 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
816 host_impl
->SetNeedsRedrawRect(invalid_rect_
);
819 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
820 LayerTreeHostImpl::FrameData
* frame_data
,
821 DrawResult draw_result
) override
{
822 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
824 gfx::RectF root_damage_rect
;
825 if (!frame_data
->render_passes
.empty())
826 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
828 switch (num_draws_
) {
830 EXPECT_EQ(gfx::Rect(bounds_
), root_damage_rect
);
834 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect
);
837 EXPECT_EQ(invalid_rect_
, root_damage_rect
);
840 EXPECT_EQ(gfx::Rect(bounds_
), root_damage_rect
);
849 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
850 switch (num_draws_
) {
853 // Cycle through a couple of empty commits to ensure we're observing the
855 PostSetNeedsCommitToMainThread();
858 // Should force full frame damage on the next commit
859 PostSetNextCommitForcesRedrawToMainThread();
860 PostSetNeedsCommitToMainThread();
861 host_impl
->BlockNotifyReadyToActivateForTesting(true);
864 host_impl
->BlockNotifyReadyToActivateForTesting(false);
873 void AfterTest() override
{ EXPECT_EQ(5, num_draws_
); }
877 const gfx::Size bounds_
;
878 const gfx::Rect invalid_rect_
;
879 FakeContentLayerClient client_
;
880 scoped_refptr
<FakePictureLayer
> root_layer_
;
883 // This test blocks activation which is not supported for single thread mode.
884 MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw
);
886 // Tests that if a layer is not drawn because of some reason in the parent then
887 // its damage is preserved until the next time it is drawn.
888 class LayerTreeHostTestUndrawnLayersDamageLater
: public LayerTreeHostTest
{
890 void InitializeSettings(LayerTreeSettings
* settings
) override
{
891 // If we don't set the minimum contents scale, it's harder to verify whether
892 // the damage we get is correct. For other scale amounts, please see
893 // LayerTreeHostTestDamageWithScale.
894 settings
->minimum_contents_scale
= 1.f
;
897 void SetupTree() override
{
898 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
899 root_layer_
->SetIsDrawable(true);
900 root_layer_
->SetBounds(gfx::Size(50, 50));
901 layer_tree_host()->SetRootLayer(root_layer_
);
903 // The initially transparent layer has a larger child layer, which is
904 // not initially drawn because of the this (parent) layer.
905 parent_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
906 parent_layer_
->SetBounds(gfx::Size(15, 15));
907 parent_layer_
->SetOpacity(0.0f
);
908 root_layer_
->AddChild(parent_layer_
);
910 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
911 child_layer_
->SetBounds(gfx::Size(25, 25));
912 parent_layer_
->AddChild(child_layer_
);
914 LayerTreeHostTest::SetupTree();
917 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
919 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
920 LayerTreeHostImpl::FrameData
* frame_data
,
921 DrawResult draw_result
) override
{
922 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
924 gfx::RectF root_damage_rect
;
925 if (!frame_data
->render_passes
.empty())
926 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
928 // The first time, the whole view needs be drawn.
929 // Afterwards, just the opacity of surface_layer1 is changed a few times,
930 // and each damage should be the bounding box of it and its child. If this
931 // was working improperly, the damage might not include its childs bounding
933 switch (host_impl
->active_tree()->source_frame_number()) {
935 EXPECT_EQ(gfx::Rect(root_layer_
->bounds()), root_damage_rect
);
940 EXPECT_EQ(gfx::Rect(child_layer_
->bounds()), root_damage_rect
);
949 void DidCommitAndDrawFrame() override
{
950 switch (layer_tree_host()->source_frame_number()) {
952 // Test not owning the surface.
953 parent_layer_
->SetOpacity(1.0f
);
956 parent_layer_
->SetOpacity(0.0f
);
959 // Test owning the surface.
960 parent_layer_
->SetOpacity(0.5f
);
961 parent_layer_
->SetForceRenderSurface(true);
971 void AfterTest() override
{}
974 FakeContentLayerClient client_
;
975 scoped_refptr
<FakePictureLayer
> root_layer_
;
976 scoped_refptr
<FakePictureLayer
> parent_layer_
;
977 scoped_refptr
<FakePictureLayer
> child_layer_
;
980 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater
);
982 // Tests that if a layer is not drawn because of some reason in the parent then
983 // its damage is preserved until the next time it is drawn.
984 class LayerTreeHostTestDamageWithScale
: public LayerTreeHostTest
{
986 LayerTreeHostTestDamageWithScale() {}
988 void SetupTree() override
{
989 client_
.set_fill_with_nonsolid_color(true);
991 scoped_ptr
<FakePicturePile
> pile(
992 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
993 LayerTreeSettings().default_tile_grid_size
));
994 root_layer_
= FakePictureLayer::CreateWithRecordingSource(
995 layer_settings(), &client_
, pile
.Pass());
996 root_layer_
->SetBounds(gfx::Size(50, 50));
998 pile
.reset(new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
999 LayerTreeSettings().default_tile_grid_size
));
1000 child_layer_
= FakePictureLayer::CreateWithRecordingSource(
1001 layer_settings(), &client_
, pile
.Pass());
1002 child_layer_
->SetBounds(gfx::Size(25, 25));
1003 child_layer_
->SetIsDrawable(true);
1004 child_layer_
->SetContentsOpaque(true);
1005 root_layer_
->AddChild(child_layer_
);
1007 layer_tree_host()->SetRootLayer(root_layer_
);
1008 LayerTreeHostTest::SetupTree();
1011 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
1012 // Force the layer to have a tiling at 1.3f scale. Note that if we simply
1013 // add tiling, it will be gone by the time we draw because of aggressive
1014 // cleanup. AddTilingUntilNextDraw ensures that it remains there during
1015 // damage calculation.
1016 FakePictureLayerImpl
* child_layer_impl
= static_cast<FakePictureLayerImpl
*>(
1017 host_impl
->active_tree()->LayerById(child_layer_
->id()));
1018 child_layer_impl
->AddTilingUntilNextDraw(1.3f
);
1021 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1023 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
1024 LayerTreeHostImpl::FrameData
* frame_data
,
1025 DrawResult draw_result
) override
{
1026 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
1028 gfx::RectF root_damage_rect
;
1029 if (!frame_data
->render_passes
.empty())
1030 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
1032 // The first time, the whole view needs be drawn.
1033 // Afterwards, just the opacity of surface_layer1 is changed a few times,
1034 // and each damage should be the bounding box of it and its child. If this
1035 // was working improperly, the damage might not include its childs bounding
1037 switch (host_impl
->active_tree()->source_frame_number()) {
1039 EXPECT_EQ(gfx::Rect(root_layer_
->bounds()), root_damage_rect
);
1042 FakePictureLayerImpl
* child_layer_impl
=
1043 static_cast<FakePictureLayerImpl
*>(
1044 host_impl
->active_tree()->LayerById(child_layer_
->id()));
1045 // We remove tilings pretty aggressively if they are not ideal. Add this
1046 // back in so that we can compare
1047 // child_layer_impl->GetEnclosingRectInTargetSpace to the damage.
1048 child_layer_impl
->AddTilingUntilNextDraw(1.3f
);
1050 EXPECT_EQ(gfx::Rect(26, 26), root_damage_rect
);
1051 EXPECT_EQ(child_layer_impl
->GetEnclosingRectInTargetSpace(),
1053 EXPECT_TRUE(child_layer_impl
->GetEnclosingRectInTargetSpace().Contains(
1054 gfx::Rect(child_layer_
->bounds())));
1064 void DidCommitAndDrawFrame() override
{
1065 switch (layer_tree_host()->source_frame_number()) {
1067 // Test not owning the surface.
1068 child_layer_
->SetOpacity(0.5f
);
1079 void AfterTest() override
{}
1082 FakeContentLayerClient client_
;
1083 scoped_refptr
<Layer
> root_layer_
;
1084 scoped_refptr
<Layer
> child_layer_
;
1087 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDamageWithScale
);
1089 // This test verifies that properties on the layer tree host are commited
1090 // to the impl side.
1091 class LayerTreeHostTestCommit
: public LayerTreeHostTest
{
1093 LayerTreeHostTestCommit() {}
1095 void BeginTest() override
{
1096 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1097 layer_tree_host()->set_background_color(SK_ColorGRAY
);
1099 PostSetNeedsCommitToMainThread();
1102 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1103 EXPECT_EQ(gfx::Size(20, 20), impl
->DrawViewportSize());
1104 EXPECT_EQ(SK_ColorGRAY
, impl
->active_tree()->background_color());
1109 void AfterTest() override
{}
1112 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit
);
1114 // This test verifies that LayerTreeHostImpl's current frame time gets
1115 // updated in consecutive frames when it doesn't draw due to tree
1116 // activation failure.
1117 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails
1118 : public LayerTreeHostTest
{
1120 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails()
1121 : frame_count_with_pending_tree_(0) {}
1123 void BeginTest() override
{
1124 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1125 layer_tree_host()->set_background_color(SK_ColorGRAY
);
1127 PostSetNeedsCommitToMainThread();
1130 void BeginCommitOnThread(LayerTreeHostImpl
* impl
) override
{
1131 EXPECT_EQ(frame_count_with_pending_tree_
, 0);
1132 impl
->BlockNotifyReadyToActivateForTesting(true);
1135 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* impl
,
1136 const BeginFrameArgs
& args
) override
{
1137 if (impl
->pending_tree())
1138 frame_count_with_pending_tree_
++;
1140 if (frame_count_with_pending_tree_
== 1) {
1141 EXPECT_EQ(first_frame_time_
.ToInternalValue(), 0);
1142 first_frame_time_
= impl
->CurrentBeginFrameArgs().frame_time
;
1143 } else if (frame_count_with_pending_tree_
== 2) {
1144 impl
->BlockNotifyReadyToActivateForTesting(false);
1148 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1149 EXPECT_GT(frame_count_with_pending_tree_
, 1);
1150 EXPECT_NE(first_frame_time_
.ToInternalValue(), 0);
1151 EXPECT_NE(first_frame_time_
.ToInternalValue(),
1152 impl
->CurrentBeginFrameArgs().frame_time
.ToInternalValue());
1156 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1157 EXPECT_GT(frame_count_with_pending_tree_
, 1);
1160 void AfterTest() override
{}
1163 int frame_count_with_pending_tree_
;
1164 base::TimeTicks first_frame_time_
;
1167 // This test blocks activation which is not supported for single thread mode.
1168 MULTI_THREAD_BLOCKNOTIFY_TEST_F(
1169 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails
);
1171 // This test verifies that LayerTreeHostImpl's current frame time gets
1172 // updated in consecutive frames when it draws in each frame.
1173 class LayerTreeHostTestFrameTimeUpdatesAfterDraw
: public LayerTreeHostTest
{
1175 LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {}
1177 void BeginTest() override
{
1178 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1179 layer_tree_host()->set_background_color(SK_ColorGRAY
);
1181 PostSetNeedsCommitToMainThread();
1184 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1187 first_frame_time_
= impl
->CurrentBeginFrameArgs().frame_time
;
1188 impl
->SetNeedsRedraw();
1190 // Since we might use a low-resolution clock on Windows, we need to
1191 // make sure that the clock has incremented past first_frame_time_.
1192 while (first_frame_time_
== base::TimeTicks::Now()) {
1198 EXPECT_NE(first_frame_time_
, impl
->CurrentBeginFrameArgs().frame_time
);
1202 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1203 // Ensure there isn't a commit between the two draws, to ensure that a
1204 // commit isn't required for updating the current frame time. We can
1205 // only check for this in the multi-threaded case, since in the single-
1206 // threaded case there will always be a commit between consecutive draws.
1207 if (HasImplThread())
1208 EXPECT_EQ(0, frame_
);
1211 void AfterTest() override
{}
1215 base::TimeTicks first_frame_time_
;
1218 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw
);
1220 // Verifies that StartPageScaleAnimation events propagate correctly
1221 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor.
1222 class LayerTreeHostTestStartPageScaleAnimation
: public LayerTreeHostTest
{
1224 LayerTreeHostTestStartPageScaleAnimation() {}
1226 void SetupTree() override
{
1227 LayerTreeHostTest::SetupTree();
1229 scoped_refptr
<FakePictureLayer
> layer
=
1230 FakePictureLayer::Create(layer_settings(), &client_
);
1231 layer
->set_always_update_resources(true);
1232 scroll_layer_
= layer
;
1234 Layer
* root_layer
= layer_tree_host()->root_layer();
1235 scroll_layer_
->SetScrollClipLayerId(root_layer
->id());
1236 scroll_layer_
->SetIsContainerForFixedPositionLayers(true);
1237 scroll_layer_
->SetBounds(gfx::Size(2 * root_layer
->bounds().width(),
1238 2 * root_layer
->bounds().height()));
1239 scroll_layer_
->SetScrollOffset(gfx::ScrollOffset());
1240 layer_tree_host()->root_layer()->AddChild(scroll_layer_
);
1241 // This test requires the page_scale and inner viewport layers to be
1243 layer_tree_host()->RegisterViewportLayers(NULL
, root_layer
,
1244 scroll_layer_
.get(), NULL
);
1245 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.5f
, 2.f
);
1248 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1250 void ApplyViewportDeltas(const gfx::Vector2dF
& scroll_delta
,
1251 const gfx::Vector2dF
&,
1252 const gfx::Vector2dF
& elastic_overscroll_delta
,
1255 gfx::ScrollOffset offset
= scroll_layer_
->scroll_offset();
1256 scroll_layer_
->SetScrollOffset(ScrollOffsetWithDelta(offset
,
1258 layer_tree_host()->SetPageScaleFactorAndLimits(scale
, 0.5f
, 2.f
);
1261 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1262 // We get one commit before the first draw, and the animation doesn't happen
1263 // until the second draw.
1264 switch (impl
->active_tree()->source_frame_number()) {
1266 EXPECT_EQ(1.f
, impl
->active_tree()->current_page_scale_factor());
1267 // We'll start an animation when we get back to the main thread.
1270 EXPECT_EQ(1.f
, impl
->active_tree()->current_page_scale_factor());
1273 EXPECT_EQ(1.25f
, impl
->active_tree()->current_page_scale_factor());
1281 void DidCommitAndDrawFrame() override
{
1282 switch (layer_tree_host()->source_frame_number()) {
1284 layer_tree_host()->StartPageScaleAnimation(
1285 gfx::Vector2d(), false, 1.25f
, base::TimeDelta());
1290 void AfterTest() override
{}
1292 FakeContentLayerClient client_
;
1293 scoped_refptr
<Layer
> scroll_layer_
;
1296 // Single thread proxy does not support impl-side page scale changes.
1297 MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation
);
1299 class LayerTreeHostTestSetVisible
: public LayerTreeHostTest
{
1301 LayerTreeHostTestSetVisible() : num_draws_(0) {}
1303 void BeginTest() override
{
1304 PostSetNeedsCommitToMainThread();
1305 PostSetVisibleToMainThread(false);
1306 // This is suppressed while we're invisible.
1307 PostSetNeedsRedrawToMainThread();
1308 // Triggers the redraw.
1309 PostSetVisibleToMainThread(true);
1312 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1313 EXPECT_TRUE(impl
->visible());
1318 void AfterTest() override
{ EXPECT_EQ(1, num_draws_
); }
1324 MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible
);
1326 class TestOpacityChangeLayerDelegate
: public ContentLayerClient
{
1328 TestOpacityChangeLayerDelegate() : test_layer_(0) {}
1330 void SetTestLayer(Layer
* test_layer
) { test_layer_
= test_layer
; }
1332 void PaintContents(SkCanvas
* canvas
,
1333 const gfx::Rect
& clip
,
1334 PaintingControlSetting picture_control
) override
{
1335 // Set layer opacity to 0.
1337 test_layer_
->SetOpacity(0.f
);
1339 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
1340 const gfx::Rect
& clip
,
1341 PaintingControlSetting picture_control
) override
{
1345 bool FillsBoundsCompletely() const override
{ return false; }
1351 // Layer opacity change during paint should not prevent compositor resources
1352 // from being updated during commit.
1353 class LayerTreeHostTestOpacityChange
: public LayerTreeHostTest
{
1355 LayerTreeHostTestOpacityChange() : test_opacity_change_delegate_() {}
1357 void SetupTree() override
{
1358 LayerTreeHostTest::SetupTree();
1360 update_check_picture_layer_
= FakePictureLayer::Create(
1361 layer_settings(), &test_opacity_change_delegate_
);
1362 test_opacity_change_delegate_
.SetTestLayer(
1363 update_check_picture_layer_
.get());
1364 layer_tree_host()->root_layer()->AddChild(update_check_picture_layer_
);
1367 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1369 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{ EndTest(); }
1371 void AfterTest() override
{
1372 // Update() should have been called once.
1373 EXPECT_EQ(1, update_check_picture_layer_
->update_count());
1377 TestOpacityChangeLayerDelegate test_opacity_change_delegate_
;
1378 scoped_refptr
<FakePictureLayer
> update_check_picture_layer_
;
1381 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange
);
1383 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers
1384 : public LayerTreeHostTest
{
1386 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() {}
1388 void BeginTest() override
{
1389 client_
.set_fill_with_nonsolid_color(true);
1390 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1391 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1393 layer_tree_host()->SetViewportSize(gfx::Size(60, 60));
1394 layer_tree_host()->SetDeviceScaleFactor(1.5);
1395 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size());
1397 root_layer_
->AddChild(child_layer_
);
1399 root_layer_
->SetIsDrawable(true);
1400 root_layer_
->SetBounds(gfx::Size(30, 30));
1402 child_layer_
->SetIsDrawable(true);
1403 child_layer_
->SetPosition(gfx::Point(2, 2));
1404 child_layer_
->SetBounds(gfx::Size(10, 10));
1406 layer_tree_host()->SetRootLayer(root_layer_
);
1408 PostSetNeedsCommitToMainThread();
1411 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1412 // Should only do one commit.
1413 EXPECT_EQ(0, impl
->active_tree()->source_frame_number());
1414 // Device scale factor should come over to impl.
1415 EXPECT_NEAR(impl
->device_scale_factor(), 1.5f
, 0.00001f
);
1417 // Both layers are on impl.
1418 ASSERT_EQ(1u, impl
->active_tree()->root_layer()->children().size());
1420 // Device viewport is scaled.
1421 EXPECT_EQ(gfx::Size(60, 60), impl
->DrawViewportSize());
1423 FakePictureLayerImpl
* root
=
1424 static_cast<FakePictureLayerImpl
*>(impl
->active_tree()->root_layer());
1425 FakePictureLayerImpl
* child
= static_cast<FakePictureLayerImpl
*>(
1426 impl
->active_tree()->root_layer()->children()[0]);
1428 // Positions remain in layout pixels.
1429 EXPECT_EQ(gfx::Point(0, 0), root
->position());
1430 EXPECT_EQ(gfx::Point(2, 2), child
->position());
1432 // Compute all the layer transforms for the frame.
1433 LayerTreeHostImpl::FrameData frame_data
;
1434 impl
->PrepareToDraw(&frame_data
);
1435 impl
->DidDrawAllLayers(frame_data
);
1437 const LayerImplList
& render_surface_layer_list
=
1438 *frame_data
.render_surface_layer_list
;
1440 // Both layers should be drawing into the root render surface.
1441 ASSERT_EQ(1u, render_surface_layer_list
.size());
1442 ASSERT_EQ(root
->render_surface(),
1443 render_surface_layer_list
[0]->render_surface());
1444 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
1446 // The root render surface is the size of the viewport.
1447 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), root
->render_surface()->content_rect());
1449 // The max tiling scale of the child should be scaled.
1450 EXPECT_FLOAT_EQ(1.5f
, child
->MaximumTilingContentsScale());
1452 gfx::Transform scale_transform
;
1453 scale_transform
.Scale(impl
->device_scale_factor(),
1454 impl
->device_scale_factor());
1456 // The root layer is scaled by 2x.
1457 gfx::Transform root_screen_space_transform
= scale_transform
;
1458 gfx::Transform root_draw_transform
= scale_transform
;
1460 EXPECT_EQ(root_draw_transform
, root
->draw_transform());
1461 EXPECT_EQ(root_screen_space_transform
, root
->screen_space_transform());
1463 // The child is at position 2,2, which is transformed to 3,3 after the scale
1464 gfx::Transform child_transform
;
1465 child_transform
.Translate(3.f
, 3.f
);
1466 child_transform
.Scale(child
->MaximumTilingContentsScale(),
1467 child
->MaximumTilingContentsScale());
1469 EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform
, child
->draw_transform());
1470 EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform
,
1471 child
->screen_space_transform());
1476 void AfterTest() override
{}
1479 FakeContentLayerClient client_
;
1480 scoped_refptr
<FakePictureLayer
> root_layer_
;
1481 scoped_refptr
<FakePictureLayer
> child_layer_
;
1484 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers
);
1486 class LayerTreeHostTestContinuousInvalidate
: public LayerTreeHostTest
{
1488 LayerTreeHostTestContinuousInvalidate()
1489 : num_commit_complete_(0), num_draw_layers_(0) {}
1491 void BeginTest() override
{
1492 layer_tree_host()->SetViewportSize(gfx::Size(10, 10));
1493 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
1495 layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1496 layer_
->SetBounds(gfx::Size(10, 10));
1497 layer_
->SetPosition(gfx::PointF(0.f
, 0.f
));
1498 layer_
->SetIsDrawable(true);
1499 layer_tree_host()->root_layer()->AddChild(layer_
);
1501 PostSetNeedsCommitToMainThread();
1504 void DidCommitAndDrawFrame() override
{
1505 if (num_draw_layers_
== 2)
1507 layer_
->SetNeedsDisplay();
1510 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
1511 if (num_draw_layers_
== 1)
1512 num_commit_complete_
++;
1515 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1517 if (num_draw_layers_
== 2)
1521 void AfterTest() override
{
1522 // Check that we didn't commit twice between first and second draw.
1523 EXPECT_EQ(1, num_commit_complete_
);
1527 FakeContentLayerClient client_
;
1528 scoped_refptr
<Layer
> layer_
;
1529 int num_commit_complete_
;
1530 int num_draw_layers_
;
1533 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate
);
1535 class LayerTreeHostTestDeferCommits
: public LayerTreeHostTest
{
1537 LayerTreeHostTestDeferCommits()
1538 : num_will_begin_impl_frame_(0),
1539 num_send_begin_main_frame_(0) {}
1541 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1543 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* host_impl
,
1544 const BeginFrameArgs
& args
) override
{
1545 num_will_begin_impl_frame_
++;
1546 switch (num_will_begin_impl_frame_
) {
1552 // Post a number of frames to increase the chance that, if there exist
1553 // bugs, an unexpected BeginMainFrame will be issued.
1554 PostSetNeedsCommitToMainThread();
1555 PostSetNeedsRedrawToMainThread();
1558 PostSetDeferCommitsToMainThread(false);
1561 // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the
1562 // main thread is slow to respond.
1567 void ScheduledActionSendBeginMainFrame() override
{
1568 num_send_begin_main_frame_
++;
1569 switch (num_send_begin_main_frame_
) {
1571 PostSetDeferCommitsToMainThread(true);
1582 void AfterTest() override
{
1583 EXPECT_GE(num_will_begin_impl_frame_
, 5);
1584 EXPECT_EQ(2, num_send_begin_main_frame_
);
1588 int num_will_begin_impl_frame_
;
1589 int num_send_begin_main_frame_
;
1592 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits
);
1594 class LayerTreeHostTestCompositeImmediatelyStateTransitions
1595 : public LayerTreeHostTest
{
1604 kCompletedMainFrame
,
1605 kCompletedImplFrame
,
1608 LayerTreeHostTestCompositeImmediatelyStateTransitions()
1609 : current_state_(kInvalid
), current_begin_frame_args_() {}
1611 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1612 settings
->single_thread_proxy_scheduler
= false;
1613 settings
->use_zero_copy
= true;
1614 settings
->use_one_copy
= false;
1617 void BeginTest() override
{
1618 current_state_
= kStartedTest
;
1619 PostCompositeImmediatelyToMainThread();
1622 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* host_impl
,
1623 const BeginFrameArgs
& args
) override
{
1624 EXPECT_EQ(current_state_
, kStartedTest
);
1625 current_state_
= kStartedImplFrame
;
1627 EXPECT_FALSE(current_begin_frame_args_
.IsValid());
1628 EXPECT_TRUE(args
.IsValid());
1629 current_begin_frame_args_
= args
;
1631 void WillBeginMainFrame() override
{
1632 EXPECT_EQ(current_state_
, kStartedImplFrame
);
1633 current_state_
= kStartedMainFrame
;
1635 void BeginMainFrame(const BeginFrameArgs
& args
) override
{
1636 EXPECT_EQ(current_state_
, kStartedMainFrame
);
1637 EXPECT_EQ(args
.frame_time
, current_begin_frame_args_
.frame_time
);
1639 void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) override
{
1640 EXPECT_EQ(current_state_
, kStartedMainFrame
);
1641 current_state_
= kStartedCommit
;
1643 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1644 EXPECT_EQ(current_state_
, kStartedCommit
);
1645 current_state_
= kCompletedCommit
;
1647 void DidBeginMainFrame() override
{
1648 EXPECT_EQ(current_state_
, kCompletedCommit
);
1649 current_state_
= kCompletedMainFrame
;
1651 void DidFinishImplFrameOnThread(LayerTreeHostImpl
* host_impl
) override
{
1652 EXPECT_EQ(current_state_
, kCompletedMainFrame
);
1653 current_state_
= kCompletedImplFrame
;
1656 void AfterTest() override
{ EXPECT_EQ(current_state_
, kCompletedImplFrame
); }
1660 BeginFrameArgs current_begin_frame_args_
;
1663 SINGLE_THREAD_TEST_F(LayerTreeHostTestCompositeImmediatelyStateTransitions
);
1665 class LayerTreeHostTestLCDChange
: public LayerTreeHostTest
{
1667 void SetupTree() override
{
1668 num_tiles_rastered_
= 0;
1670 scoped_refptr
<Layer
> root_layer
=
1671 PictureLayer::Create(layer_settings(), &client_
);
1672 client_
.set_fill_with_nonsolid_color(true);
1673 root_layer
->SetIsDrawable(true);
1674 root_layer
->SetBounds(gfx::Size(10, 10));
1675 root_layer
->SetContentsOpaque(true);
1677 layer_tree_host()->SetRootLayer(root_layer
);
1679 // The expectations are based on the assumption that the default
1680 // LCD settings are:
1681 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text
);
1683 LayerTreeHostTest::SetupTree();
1686 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1688 void DidCommitAndDrawFrame() override
{
1689 switch (layer_tree_host()->source_frame_number()) {
1691 PostSetNeedsCommitToMainThread();
1694 // Change layer opacity that should trigger lcd change.
1695 layer_tree_host()->root_layer()->SetOpacity(.5f
);
1698 // Change layer opacity that should not trigger lcd change.
1699 layer_tree_host()->root_layer()->SetOpacity(1.f
);
1707 void NotifyTileStateChangedOnThread(LayerTreeHostImpl
* host_impl
,
1708 const Tile
* tile
) override
{
1709 ++num_tiles_rastered_
;
1712 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
1713 PictureLayerImpl
* root_layer
=
1714 static_cast<PictureLayerImpl
*>(host_impl
->active_tree()->root_layer());
1715 bool can_use_lcd_text
=
1716 host_impl
->active_tree()->root_layer()->can_use_lcd_text();
1717 switch (host_impl
->active_tree()->source_frame_number()) {
1720 EXPECT_EQ(1, num_tiles_rastered_
);
1721 EXPECT_TRUE(can_use_lcd_text
);
1722 EXPECT_TRUE(root_layer
->RasterSourceUsesLCDText());
1725 // Nothing changed on the layer.
1726 EXPECT_EQ(1, num_tiles_rastered_
);
1727 EXPECT_TRUE(can_use_lcd_text
);
1728 EXPECT_TRUE(root_layer
->RasterSourceUsesLCDText());
1731 // LCD text was disabled; it should be re-rastered with LCD text off.
1732 EXPECT_EQ(2, num_tiles_rastered_
);
1733 EXPECT_FALSE(can_use_lcd_text
);
1734 EXPECT_FALSE(root_layer
->RasterSourceUsesLCDText());
1737 // LCD text was enabled, but it's sticky and stays off.
1738 EXPECT_EQ(2, num_tiles_rastered_
);
1739 EXPECT_TRUE(can_use_lcd_text
);
1740 EXPECT_FALSE(root_layer
->RasterSourceUsesLCDText());
1745 void AfterTest() override
{}
1748 FakeContentLayerClient client_
;
1749 int num_tiles_rastered_
;
1752 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDChange
);
1754 // Verify that the BeginFrame notification is used to initiate rendering.
1755 class LayerTreeHostTestBeginFrameNotification
: public LayerTreeHostTest
{
1757 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1758 settings
->use_external_begin_frame_source
= true;
1761 void BeginTest() override
{
1762 // This will trigger a SetNeedsBeginFrame which will trigger a
1764 PostSetNeedsCommitToMainThread();
1767 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
1768 LayerTreeHostImpl::FrameData
* frame
,
1769 DrawResult draw_result
) override
{
1771 return DRAW_SUCCESS
;
1774 void AfterTest() override
{}
1777 base::TimeTicks frame_time_
;
1780 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification
);
1782 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled
1783 : public LayerTreeHostTest
{
1785 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1786 settings
->use_external_begin_frame_source
= true;
1787 settings
->using_synchronous_renderer_compositor
= true;
1790 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1792 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1793 // The BeginFrame notification is turned off now but will get enabled
1794 // once we return. End test while it's enabled.
1795 ImplThreadTaskRunner()->PostTask(
1797 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest
,
1798 base::Unretained(this)));
1801 void AfterTest() override
{}
1804 MULTI_THREAD_TEST_F(
1805 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled
);
1807 class LayerTreeHostTestAbortedCommitDoesntStall
: public LayerTreeHostTest
{
1809 LayerTreeHostTestAbortedCommitDoesntStall()
1810 : commit_count_(0), commit_abort_count_(0), commit_complete_count_(0) {}
1812 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1813 settings
->use_external_begin_frame_source
= true;
1816 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1818 void DidCommit() override
{
1820 if (commit_count_
== 4) {
1821 // After two aborted commits, request a real commit now to make sure a
1822 // real commit following an aborted commit will still complete and
1823 // end the test even when the Impl thread is idle.
1824 layer_tree_host()->SetNeedsCommit();
1828 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl
* host_impl
,
1829 CommitEarlyOutReason reason
) override
{
1830 commit_abort_count_
++;
1831 // Initiate another abortable commit.
1832 host_impl
->SetNeedsCommit();
1835 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1836 commit_complete_count_
++;
1837 if (commit_complete_count_
== 1) {
1838 // Initiate an abortable commit after the first commit.
1839 host_impl
->SetNeedsCommit();
1845 void AfterTest() override
{
1846 EXPECT_EQ(commit_count_
, 5);
1847 EXPECT_EQ(commit_abort_count_
, 3);
1848 EXPECT_EQ(commit_complete_count_
, 2);
1852 int commit_abort_count_
;
1853 int commit_complete_count_
;
1856 class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
1857 : public LayerTreeHostTestAbortedCommitDoesntStall
{
1859 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1860 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings
);
1861 settings
->using_synchronous_renderer_compositor
= true;
1864 void ScheduledActionInvalidateOutputSurface() override
{
1865 ImplThreadTaskRunner()->PostTask(
1868 &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
1870 base::Unretained(this)));
1874 // Synchronous compositor does not draw unless told to do so by the output
1876 output_surface()->client()->OnDraw();
1880 MULTI_THREAD_TEST_F(
1881 LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
);
1883 class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync
1884 : public LayerTreeHostTestAbortedCommitDoesntStall
{
1885 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1886 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings
);
1887 settings
->renderer_settings
.disable_gpu_vsync
= true;
1891 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync
);
1893 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation
1894 : public LayerTreeHostTest
{
1896 void SetupTree() override
{
1897 LayerTreeHostTest::SetupTree();
1899 scoped_refptr
<Layer
> layer
=
1900 PictureLayer::Create(layer_settings(), &client_
);
1901 layer
->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
1902 layer
->SetBounds(gfx::Size(10, 10));
1903 layer_tree_host()->root_layer()->AddChild(layer
);
1906 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1908 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
1912 void AfterTest() override
{}
1914 FakeContentLayerClient client_
;
1917 SINGLE_AND_MULTI_THREAD_TEST_F(
1918 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation
);
1920 class LayerTreeHostTestChangeLayerPropertiesInPaintContents
1921 : public LayerTreeHostTest
{
1923 class SetBoundsClient
: public ContentLayerClient
{
1925 SetBoundsClient() : layer_(0) {}
1927 void set_layer(Layer
* layer
) { layer_
= layer
; }
1929 void PaintContents(SkCanvas
* canvas
,
1930 const gfx::Rect
& clip
,
1931 PaintingControlSetting picture_control
) override
{
1932 layer_
->SetBounds(gfx::Size(2, 2));
1935 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
1936 const gfx::Rect
& clip
,
1937 PaintingControlSetting picture_control
) override
{
1942 bool FillsBoundsCompletely() const override
{ return false; }
1948 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
1950 void SetupTree() override
{
1951 scoped_refptr
<PictureLayer
> root_layer
=
1952 PictureLayer::Create(layer_settings(), &client_
);
1953 root_layer
->SetIsDrawable(true);
1954 root_layer
->SetBounds(gfx::Size(1, 1));
1955 client_
.set_layer(root_layer
.get());
1957 layer_tree_host()->SetRootLayer(root_layer
);
1958 LayerTreeHostTest::SetupTree();
1961 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1962 void AfterTest() override
{}
1964 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
1966 if (num_commits_
== 1) {
1967 LayerImpl
* root_layer
= host_impl
->active_tree()->root_layer();
1968 EXPECT_EQ(gfx::Size(1, 1), root_layer
->bounds());
1970 LayerImpl
* root_layer
= host_impl
->active_tree()->root_layer();
1971 EXPECT_EQ(gfx::Size(2, 2), root_layer
->bounds());
1977 SetBoundsClient client_
;
1981 SINGLE_AND_MULTI_THREAD_TEST_F(
1982 LayerTreeHostTestChangeLayerPropertiesInPaintContents
);
1984 class MockIOSurfaceWebGraphicsContext3D
: public TestWebGraphicsContext3D
{
1986 MockIOSurfaceWebGraphicsContext3D() {
1987 test_capabilities_
.gpu
.iosurface
= true;
1988 test_capabilities_
.gpu
.texture_rectangle
= true;
1991 GLuint
createTexture() override
{ return 1; }
1992 MOCK_METHOD1(activeTexture
, void(GLenum texture
));
1993 MOCK_METHOD2(bindTexture
, void(GLenum target
,
1994 GLuint texture_id
));
1995 MOCK_METHOD3(texParameteri
, void(GLenum target
,
1998 MOCK_METHOD5(texImageIOSurface2DCHROMIUM
, void(GLenum target
,
2003 MOCK_METHOD4(drawElements
, void(GLenum mode
,
2007 MOCK_METHOD1(deleteTexture
, void(GLenum texture
));
2008 MOCK_METHOD3(produceTextureDirectCHROMIUM
,
2009 void(GLuint texture
, GLenum target
, const GLbyte
* mailbox
));
2012 class LayerTreeHostTestIOSurfaceDrawing
: public LayerTreeHostTest
{
2014 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
2015 scoped_ptr
<MockIOSurfaceWebGraphicsContext3D
> mock_context_owned(
2016 new MockIOSurfaceWebGraphicsContext3D
);
2017 mock_context_
= mock_context_owned
.get();
2019 if (delegating_renderer())
2020 return FakeOutputSurface::CreateDelegating3d(mock_context_owned
.Pass());
2022 return FakeOutputSurface::Create3d(mock_context_owned
.Pass());
2025 void SetupTree() override
{
2026 LayerTreeHostTest::SetupTree();
2028 layer_tree_host()->root_layer()->SetIsDrawable(false);
2031 io_surface_size_
= gfx::Size(6, 7);
2033 scoped_refptr
<IOSurfaceLayer
> io_surface_layer
=
2034 IOSurfaceLayer::Create(layer_settings());
2035 io_surface_layer
->SetBounds(gfx::Size(10, 10));
2036 io_surface_layer
->SetIsDrawable(true);
2037 io_surface_layer
->SetContentsOpaque(true);
2038 io_surface_layer
->SetIOSurfaceProperties(io_surface_id_
, io_surface_size_
);
2039 layer_tree_host()->root_layer()->AddChild(io_surface_layer
);
2042 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2044 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
2045 EXPECT_EQ(0u, host_impl
->resource_provider()->num_resources());
2046 // In WillDraw, the IOSurfaceLayer sets up the io surface texture.
2048 EXPECT_CALL(*mock_context_
, activeTexture(_
)).Times(0);
2049 EXPECT_CALL(*mock_context_
, bindTexture(GL_TEXTURE_RECTANGLE_ARB
, 1))
2051 EXPECT_CALL(*mock_context_
,
2053 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
))
2055 EXPECT_CALL(*mock_context_
,
2057 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
))
2059 EXPECT_CALL(*mock_context_
,
2060 texParameteri(GL_TEXTURE_RECTANGLE_ARB
,
2061 GL_TEXTURE_POOL_CHROMIUM
,
2062 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM
)).Times(1);
2063 EXPECT_CALL(*mock_context_
,
2064 texParameteri(GL_TEXTURE_RECTANGLE_ARB
,
2066 GL_CLAMP_TO_EDGE
)).Times(1);
2067 EXPECT_CALL(*mock_context_
,
2068 texParameteri(GL_TEXTURE_RECTANGLE_ARB
,
2070 GL_CLAMP_TO_EDGE
)).Times(1);
2072 EXPECT_CALL(*mock_context_
,
2073 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB
,
2074 io_surface_size_
.width(),
2075 io_surface_size_
.height(),
2079 EXPECT_CALL(*mock_context_
, bindTexture(_
, 0)).Times(AnyNumber());
2082 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
2083 LayerTreeHostImpl::FrameData
* frame
,
2084 DrawResult draw_result
) override
{
2085 Mock::VerifyAndClearExpectations(&mock_context_
);
2086 ResourceProvider
* resource_provider
= host_impl
->resource_provider();
2087 EXPECT_EQ(1u, resource_provider
->num_resources());
2088 CHECK_EQ(1u, frame
->render_passes
.size());
2089 CHECK_LE(1u, frame
->render_passes
[0]->quad_list
.size());
2090 const DrawQuad
* quad
= frame
->render_passes
[0]->quad_list
.front();
2091 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT
, quad
->material
);
2092 const IOSurfaceDrawQuad
* io_surface_draw_quad
=
2093 IOSurfaceDrawQuad::MaterialCast(quad
);
2094 EXPECT_EQ(io_surface_size_
, io_surface_draw_quad
->io_surface_size
);
2095 EXPECT_NE(0u, io_surface_draw_quad
->io_surface_resource_id());
2096 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_RECTANGLE_ARB
),
2097 resource_provider
->TargetForTesting(
2098 io_surface_draw_quad
->io_surface_resource_id()));
2100 if (delegating_renderer()) {
2101 // The io surface layer's resource should be sent to the parent.
2102 EXPECT_CALL(*mock_context_
, produceTextureDirectCHROMIUM(
2103 _
, GL_TEXTURE_RECTANGLE_ARB
, _
)).Times(1);
2105 // The io surface layer's texture is drawn.
2106 EXPECT_CALL(*mock_context_
, activeTexture(GL_TEXTURE0
)).Times(AtLeast(1));
2107 EXPECT_CALL(*mock_context_
, drawElements(GL_TRIANGLES
, 6, _
, _
))
2114 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
2115 Mock::VerifyAndClearExpectations(&mock_context_
);
2117 EXPECT_CALL(*mock_context_
, deleteTexture(1)).Times(AtLeast(1));
2121 void AfterTest() override
{}
2124 MockIOSurfaceWebGraphicsContext3D
* mock_context_
;
2125 gfx::Size io_surface_size_
;
2128 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing
);
2130 class LayerTreeHostTestNumFramesPending
: public LayerTreeHostTest
{
2132 void BeginTest() override
{
2134 PostSetNeedsCommitToMainThread();
2137 // Round 1: commit + draw
2138 // Round 2: commit only (no draw/swap)
2139 // Round 3: draw only (no commit)
2141 void DidCommit() override
{
2142 int commit
= layer_tree_host()->source_frame_number();
2146 EXPECT_EQ(1, frame_
);
2147 layer_tree_host()->SetNeedsRedraw();
2152 void DidCompleteSwapBuffers() override
{
2153 int commit
= layer_tree_host()->source_frame_number();
2158 EXPECT_EQ(1, commit
);
2159 layer_tree_host()->SetNeedsCommit();
2163 EXPECT_EQ(2, commit
);
2169 void AfterTest() override
{}
2175 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending
);
2177 class LayerTreeHostTestResourcelessSoftwareDraw
: public LayerTreeHostTest
{
2179 void SetupTree() override
{
2180 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
2181 root_layer_
->SetIsDrawable(true);
2182 root_layer_
->SetBounds(gfx::Size(50, 50));
2184 parent_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
2185 parent_layer_
->SetIsDrawable(true);
2186 parent_layer_
->SetBounds(gfx::Size(50, 50));
2187 parent_layer_
->SetForceRenderSurface(true);
2189 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
2190 child_layer_
->SetIsDrawable(true);
2191 child_layer_
->SetBounds(gfx::Size(50, 50));
2193 root_layer_
->AddChild(parent_layer_
);
2194 parent_layer_
->AddChild(child_layer_
);
2195 layer_tree_host()->SetRootLayer(root_layer_
);
2197 LayerTreeHostTest::SetupTree();
2200 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
2201 if (delegating_renderer()) {
2202 return FakeOutputSurface::CreateDelegatingSoftware(
2203 make_scoped_ptr(new SoftwareOutputDevice
));
2205 return FakeOutputSurface::CreateSoftware(
2206 make_scoped_ptr(new SoftwareOutputDevice
));
2210 void BeginTest() override
{
2211 PostSetNeedsCommitToMainThread();
2215 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
2216 LayerTreeHostImpl::FrameData
* frame_data
,
2217 DrawResult draw_result
) override
{
2218 if (host_impl
->GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE
) {
2219 EXPECT_EQ(1u, frame_data
->render_passes
.size());
2220 // Has at least 3 quads for each layer.
2221 RenderPass
* render_pass
= frame_data
->render_passes
[0];
2222 EXPECT_GE(render_pass
->quad_list
.size(), 3u);
2224 EXPECT_EQ(2u, frame_data
->render_passes
.size());
2226 // At least root layer quad in root render pass.
2227 EXPECT_GE(frame_data
->render_passes
[0]->quad_list
.size(), 1u);
2228 // At least parent and child layer quads in parent render pass.
2229 EXPECT_GE(frame_data
->render_passes
[1]->quad_list
.size(), 2u);
2234 void SwapBuffersCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
2236 switch (swap_count_
) {
2238 gfx::Transform identity
;
2239 gfx::Rect empty_rect
;
2240 bool resourceless_software_draw
= true;
2241 host_impl
->SetExternalDrawConstraints(identity
, empty_rect
, empty_rect
,
2242 empty_rect
, identity
,
2243 resourceless_software_draw
);
2244 host_impl
->SetFullRootLayerDamage();
2245 host_impl
->SetNeedsRedraw();
2256 void AfterTest() override
{}
2259 FakeContentLayerClient client_
;
2260 scoped_refptr
<Layer
> root_layer_
;
2261 scoped_refptr
<Layer
> parent_layer_
;
2262 scoped_refptr
<Layer
> child_layer_
;
2266 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw
);
2268 // Test for UI Resource management.
2269 class LayerTreeHostTestUIResource
: public LayerTreeHostTest
{
2271 LayerTreeHostTestUIResource() : num_ui_resources_(0) {}
2273 void InitializeSettings(LayerTreeSettings
* settings
) override
{
2274 settings
->renderer_settings
.texture_id_allocation_chunk_size
= 1;
2277 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2279 void DidCommit() override
{
2280 int frame
= layer_tree_host()->source_frame_number();
2285 PostSetNeedsCommitToMainThread();
2288 // Usually ScopedUIResource are deleted from the manager in their
2289 // destructor. Here we just want to test that a direct call to
2290 // DeleteUIResource works.
2291 layer_tree_host()->DeleteUIResource(ui_resources_
[0]->id());
2292 PostSetNeedsCommitToMainThread();
2295 // DeleteUIResource can be called with an invalid id.
2296 layer_tree_host()->DeleteUIResource(ui_resources_
[0]->id());
2297 PostSetNeedsCommitToMainThread();
2302 PostSetNeedsCommitToMainThread();
2311 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
2312 TestWebGraphicsContext3D
* context
= TestContext();
2314 int frame
= impl
->active_tree()->source_frame_number();
2317 ASSERT_EQ(0u, context
->NumTextures());
2320 // Created two textures.
2321 ASSERT_EQ(2u, context
->NumTextures());
2324 // One texture left after one deletion.
2325 ASSERT_EQ(1u, context
->NumTextures());
2328 // Resource manager state should not change when delete is called on an
2330 ASSERT_EQ(1u, context
->NumTextures());
2333 // Creation after deletion: two more creates should total up to
2335 ASSERT_EQ(3u, context
->NumTextures());
2340 void AfterTest() override
{}
2343 // Must clear all resources before exiting.
2344 void ClearResources() {
2345 for (int i
= 0; i
< num_ui_resources_
; i
++)
2346 ui_resources_
[i
] = nullptr;
2349 void CreateResource() {
2350 ui_resources_
[num_ui_resources_
++] =
2351 FakeScopedUIResource::Create(layer_tree_host());
2354 scoped_ptr
<FakeScopedUIResource
> ui_resources_
[5];
2355 int num_ui_resources_
;
2358 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource
);
2360 class PushPropertiesCountingLayerImpl
: public LayerImpl
{
2362 static scoped_ptr
<PushPropertiesCountingLayerImpl
> Create(
2363 LayerTreeImpl
* tree_impl
, int id
) {
2364 return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl
, id
));
2367 ~PushPropertiesCountingLayerImpl() override
{}
2369 void PushPropertiesTo(LayerImpl
* layer
) override
{
2370 LayerImpl::PushPropertiesTo(layer
);
2371 push_properties_count_
++;
2372 // Push state to the active tree because we can only access it from there.
2373 static_cast<PushPropertiesCountingLayerImpl
*>(
2374 layer
)->push_properties_count_
= push_properties_count_
;
2377 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
{
2378 return PushPropertiesCountingLayerImpl::Create(tree_impl
, id());
2381 size_t push_properties_count() const { return push_properties_count_
; }
2382 void reset_push_properties_count() { push_properties_count_
= 0; }
2385 size_t push_properties_count_
;
2387 PushPropertiesCountingLayerImpl(LayerTreeImpl
* tree_impl
, int id
)
2388 : LayerImpl(tree_impl
, id
),
2389 push_properties_count_(0) {
2390 SetBounds(gfx::Size(1, 1));
2394 class PushPropertiesCountingLayer
: public Layer
{
2396 static scoped_refptr
<PushPropertiesCountingLayer
> Create(
2397 const LayerSettings
& settings
) {
2398 return new PushPropertiesCountingLayer(settings
);
2401 void PushPropertiesTo(LayerImpl
* layer
) override
{
2402 Layer::PushPropertiesTo(layer
);
2403 push_properties_count_
++;
2404 if (persist_needs_push_properties_
)
2405 needs_push_properties_
= true;
2408 // Something to make this layer push properties, but no other layer.
2409 void MakePushProperties() { SetContentsOpaque(!contents_opaque()); }
2411 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
{
2412 return PushPropertiesCountingLayerImpl::Create(tree_impl
, id());
2415 void SetDrawsContent(bool draws_content
) { SetIsDrawable(draws_content
); }
2417 size_t push_properties_count() const { return push_properties_count_
; }
2418 void reset_push_properties_count() { push_properties_count_
= 0; }
2420 void set_persist_needs_push_properties(bool persist
) {
2421 persist_needs_push_properties_
= persist
;
2425 explicit PushPropertiesCountingLayer(const LayerSettings
& settings
)
2427 push_properties_count_(0),
2428 persist_needs_push_properties_(false) {
2429 SetBounds(gfx::Size(1, 1));
2431 ~PushPropertiesCountingLayer() override
{}
2433 size_t push_properties_count_
;
2434 bool persist_needs_push_properties_
;
2437 class LayerTreeHostTestLayersPushProperties
: public LayerTreeHostTest
{
2439 void BeginTest() override
{
2441 expected_push_properties_root_
= 0;
2442 expected_push_properties_child_
= 0;
2443 expected_push_properties_grandchild_
= 0;
2444 expected_push_properties_child2_
= 0;
2445 expected_push_properties_other_root_
= 0;
2446 expected_push_properties_leaf_layer_
= 0;
2447 PostSetNeedsCommitToMainThread();
2450 void SetupTree() override
{
2451 root_
= PushPropertiesCountingLayer::Create(layer_settings());
2452 root_
->CreateRenderSurface();
2453 child_
= PushPropertiesCountingLayer::Create(layer_settings());
2454 child2_
= PushPropertiesCountingLayer::Create(layer_settings());
2455 grandchild_
= PushPropertiesCountingLayer::Create(layer_settings());
2456 leaf_always_pushing_layer_
=
2457 PushPropertiesCountingLayer::Create(layer_settings());
2458 leaf_always_pushing_layer_
->set_persist_needs_push_properties(true);
2460 root_
->AddChild(child_
);
2461 root_
->AddChild(child2_
);
2462 child_
->AddChild(grandchild_
);
2463 child2_
->AddChild(leaf_always_pushing_layer_
);
2465 other_root_
= PushPropertiesCountingLayer::Create(layer_settings());
2466 other_root_
->CreateRenderSurface();
2468 // Don't set the root layer here.
2469 LayerTreeHostTest::SetupTree();
2472 void DidCommitAndDrawFrame() override
{
2473 EXPECT_EQ(expected_push_properties_root_
, root_
->push_properties_count())
2474 << "num_commits: " << num_commits_
;
2475 EXPECT_EQ(expected_push_properties_child_
, child_
->push_properties_count())
2476 << "num_commits: " << num_commits_
;
2477 EXPECT_EQ(expected_push_properties_grandchild_
,
2478 grandchild_
->push_properties_count())
2479 << "num_commits: " << num_commits_
;
2480 EXPECT_EQ(expected_push_properties_child2_
,
2481 child2_
->push_properties_count())
2482 << "num_commits: " << num_commits_
;
2483 EXPECT_EQ(expected_push_properties_other_root_
,
2484 other_root_
->push_properties_count())
2485 << "num_commits: " << num_commits_
;
2486 EXPECT_EQ(expected_push_properties_leaf_layer_
,
2487 leaf_always_pushing_layer_
->push_properties_count())
2488 << "num_commits: " << num_commits_
;
2492 // The scrollbar layer always needs to be pushed.
2493 if (root_
->layer_tree_host()) {
2494 EXPECT_TRUE(root_
->descendant_needs_push_properties());
2495 EXPECT_FALSE(root_
->needs_push_properties());
2497 if (child2_
->layer_tree_host()) {
2498 EXPECT_TRUE(child2_
->descendant_needs_push_properties());
2499 EXPECT_FALSE(child2_
->needs_push_properties());
2501 if (leaf_always_pushing_layer_
->layer_tree_host()) {
2503 leaf_always_pushing_layer_
->descendant_needs_push_properties());
2504 EXPECT_TRUE(leaf_always_pushing_layer_
->needs_push_properties());
2507 // child_ and grandchild_ don't persist their need to push properties.
2508 if (child_
->layer_tree_host()) {
2509 EXPECT_FALSE(child_
->descendant_needs_push_properties());
2510 EXPECT_FALSE(child_
->needs_push_properties());
2512 if (grandchild_
->layer_tree_host()) {
2513 EXPECT_FALSE(grandchild_
->descendant_needs_push_properties());
2514 EXPECT_FALSE(grandchild_
->needs_push_properties());
2517 if (other_root_
->layer_tree_host()) {
2518 EXPECT_FALSE(other_root_
->descendant_needs_push_properties());
2519 EXPECT_FALSE(other_root_
->needs_push_properties());
2522 switch (num_commits_
) {
2524 layer_tree_host()->SetRootLayer(root_
);
2525 // Layers added to the tree get committed.
2526 ++expected_push_properties_root_
;
2527 ++expected_push_properties_child_
;
2528 ++expected_push_properties_grandchild_
;
2529 ++expected_push_properties_child2_
;
2532 layer_tree_host()->SetNeedsCommit();
2533 // No layers need commit.
2536 layer_tree_host()->SetRootLayer(other_root_
);
2537 // Layers added to the tree get committed.
2538 ++expected_push_properties_other_root_
;
2541 layer_tree_host()->SetRootLayer(root_
);
2542 // Layers added to the tree get committed.
2543 ++expected_push_properties_root_
;
2544 ++expected_push_properties_child_
;
2545 ++expected_push_properties_grandchild_
;
2546 ++expected_push_properties_child2_
;
2549 layer_tree_host()->SetNeedsCommit();
2550 // No layers need commit.
2553 child_
->RemoveFromParent();
2554 // No layers need commit.
2557 root_
->AddChild(child_
);
2558 // Layers added to the tree get committed.
2559 ++expected_push_properties_child_
;
2560 ++expected_push_properties_grandchild_
;
2563 grandchild_
->RemoveFromParent();
2564 // No layers need commit.
2567 child_
->AddChild(grandchild_
);
2568 // Layers added to the tree get committed.
2569 ++expected_push_properties_grandchild_
;
2572 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
2573 // No layers need commit.
2576 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.8f
, 1.1f
);
2577 // No layers need commit.
2580 child_
->MakePushProperties();
2581 // The modified layer needs commit
2582 ++expected_push_properties_child_
;
2585 child2_
->MakePushProperties();
2586 // The modified layer needs commit
2587 ++expected_push_properties_child2_
;
2590 child_
->RemoveFromParent();
2591 root_
->AddChild(child_
);
2592 // Layers added to the tree get committed.
2593 ++expected_push_properties_child_
;
2594 ++expected_push_properties_grandchild_
;
2597 grandchild_
->MakePushProperties();
2598 // The modified layer needs commit
2599 ++expected_push_properties_grandchild_
;
2602 // SetNeedsDisplay does not always set needs commit (so call it
2603 // explicitly), but is a property change.
2604 child_
->SetNeedsDisplay();
2605 ++expected_push_properties_child_
;
2606 layer_tree_host()->SetNeedsCommit();
2613 // The leaf layer always pushes.
2614 if (leaf_always_pushing_layer_
->layer_tree_host())
2615 ++expected_push_properties_leaf_layer_
;
2618 void AfterTest() override
{}
2621 FakeContentLayerClient client_
;
2622 scoped_refptr
<PushPropertiesCountingLayer
> root_
;
2623 scoped_refptr
<PushPropertiesCountingLayer
> child_
;
2624 scoped_refptr
<PushPropertiesCountingLayer
> child2_
;
2625 scoped_refptr
<PushPropertiesCountingLayer
> grandchild_
;
2626 scoped_refptr
<PushPropertiesCountingLayer
> other_root_
;
2627 scoped_refptr
<PushPropertiesCountingLayer
> leaf_always_pushing_layer_
;
2628 size_t expected_push_properties_root_
;
2629 size_t expected_push_properties_child_
;
2630 size_t expected_push_properties_child2_
;
2631 size_t expected_push_properties_grandchild_
;
2632 size_t expected_push_properties_other_root_
;
2633 size_t expected_push_properties_leaf_layer_
;
2636 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties
);
2638 class LayerTreeHostTestImplLayersPushProperties
2639 : public LayerTreeHostTestLayersPushProperties
{
2641 void BeginTest() override
{
2642 expected_push_properties_root_impl_
= 0;
2643 expected_push_properties_child_impl_
= 0;
2644 expected_push_properties_grandchild_impl_
= 0;
2645 expected_push_properties_child2_impl_
= 0;
2646 expected_push_properties_grandchild2_impl_
= 0;
2647 LayerTreeHostTestLayersPushProperties::BeginTest();
2650 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
2651 // These commits are in response to the changes made in
2652 // LayerTreeHostTestLayersPushProperties::DidCommitAndDrawFrame()
2653 switch (num_commits_
) {
2655 // Tree hasn't been setup yet don't bother to check anything.
2658 // Root gets set up, Everyone is initialized.
2659 ++expected_push_properties_root_impl_
;
2660 ++expected_push_properties_child_impl_
;
2661 ++expected_push_properties_grandchild_impl_
;
2662 ++expected_push_properties_child2_impl_
;
2663 ++expected_push_properties_grandchild2_impl_
;
2666 // Tree doesn't change but the one leaf that always pushes is pushed.
2667 ++expected_push_properties_grandchild2_impl_
;
2670 // Root is swapped here.
2671 // Clear the expected push properties the tree will be rebuilt.
2672 expected_push_properties_root_impl_
= 0;
2673 expected_push_properties_child_impl_
= 0;
2674 expected_push_properties_grandchild_impl_
= 0;
2675 expected_push_properties_child2_impl_
= 0;
2676 expected_push_properties_grandchild2_impl_
= 0;
2678 // Make sure the new root is pushed.
2679 EXPECT_EQ(1u, static_cast<PushPropertiesCountingLayerImpl
*>(
2680 host_impl
->RootLayer())->push_properties_count());
2683 // Root is swapped back all of the layers in the tree get pushed.
2684 ++expected_push_properties_root_impl_
;
2685 ++expected_push_properties_child_impl_
;
2686 ++expected_push_properties_grandchild_impl_
;
2687 ++expected_push_properties_child2_impl_
;
2688 ++expected_push_properties_grandchild2_impl_
;
2691 // Tree doesn't change but the one leaf that always pushes is pushed.
2692 ++expected_push_properties_grandchild2_impl_
;
2695 // First child is removed. Structure of the tree changes here so swap
2696 // some of the values. child_impl becomes child2_impl.
2697 expected_push_properties_child_impl_
=
2698 expected_push_properties_child2_impl_
;
2699 expected_push_properties_child2_impl_
= 0;
2700 // grandchild_impl becomes grandchild2_impl.
2701 expected_push_properties_grandchild_impl_
=
2702 expected_push_properties_grandchild2_impl_
;
2703 expected_push_properties_grandchild2_impl_
= 0;
2705 // grandchild_impl is now the leaf that always pushes. It is pushed.
2706 ++expected_push_properties_grandchild_impl_
;
2709 // The leaf that always pushes is pushed.
2710 ++expected_push_properties_grandchild_impl_
;
2712 // Child is added back. New layers are initialized.
2713 ++expected_push_properties_grandchild2_impl_
;
2714 ++expected_push_properties_child2_impl_
;
2718 expected_push_properties_grandchild2_impl_
= 0;
2721 ++expected_push_properties_grandchild_impl_
;
2724 // Leaf is added back
2725 ++expected_push_properties_grandchild2_impl_
;
2727 // The leaf that always pushes is pushed.
2728 ++expected_push_properties_grandchild_impl_
;
2731 // The leaf that always pushes is pushed.
2732 ++expected_push_properties_grandchild_impl_
;
2735 // The leaf that always pushes is pushed.
2736 ++expected_push_properties_grandchild_impl_
;
2739 // The leaf that always pushes is pushed.
2740 ++expected_push_properties_grandchild_impl_
;
2742 // This child position was changed.
2743 ++expected_push_properties_child2_impl_
;
2746 // The position of this child was changed.
2747 ++expected_push_properties_child_impl_
;
2749 // The leaf that always pushes is pushed.
2750 ++expected_push_properties_grandchild_impl_
;
2753 // Second child is removed from tree. Don't discard counts because
2754 // they are added back before commit.
2756 // The leaf that always pushes is pushed.
2757 ++expected_push_properties_grandchild_impl_
;
2759 // Second child added back.
2760 ++expected_push_properties_child2_impl_
;
2761 ++expected_push_properties_grandchild2_impl_
;
2765 // The position of this child was changed.
2766 ++expected_push_properties_grandchild2_impl_
;
2768 // The leaf that always pushes is pushed.
2769 ++expected_push_properties_grandchild_impl_
;
2772 // Second child is invalidated with SetNeedsDisplay
2773 ++expected_push_properties_child2_impl_
;
2775 // The leaf that always pushed is pushed.
2776 ++expected_push_properties_grandchild_impl_
;
2780 PushPropertiesCountingLayerImpl
* root_impl_
= NULL
;
2781 PushPropertiesCountingLayerImpl
* child_impl_
= NULL
;
2782 PushPropertiesCountingLayerImpl
* child2_impl_
= NULL
;
2783 PushPropertiesCountingLayerImpl
* grandchild_impl_
= NULL
;
2784 PushPropertiesCountingLayerImpl
* leaf_always_pushing_layer_impl_
= NULL
;
2786 // Pull the layers that we need from the tree assuming the same structure
2787 // as LayerTreeHostTestLayersPushProperties
2788 root_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2789 host_impl
->RootLayer());
2791 if (root_impl_
&& root_impl_
->children().size() > 0) {
2792 child_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2793 root_impl_
->children()[0]);
2795 if (child_impl_
&& child_impl_
->children().size() > 0)
2796 grandchild_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2797 child_impl_
->children()[0]);
2800 if (root_impl_
&& root_impl_
->children().size() > 1) {
2801 child2_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2802 root_impl_
->children()[1]);
2804 if (child2_impl_
&& child2_impl_
->children().size() > 0)
2805 leaf_always_pushing_layer_impl_
=
2806 static_cast<PushPropertiesCountingLayerImpl
*>(
2807 child2_impl_
->children()[0]);
2811 EXPECT_EQ(expected_push_properties_root_impl_
,
2812 root_impl_
->push_properties_count());
2814 EXPECT_EQ(expected_push_properties_child_impl_
,
2815 child_impl_
->push_properties_count());
2816 if (grandchild_impl_
)
2817 EXPECT_EQ(expected_push_properties_grandchild_impl_
,
2818 grandchild_impl_
->push_properties_count());
2820 EXPECT_EQ(expected_push_properties_child2_impl_
,
2821 child2_impl_
->push_properties_count());
2822 if (leaf_always_pushing_layer_impl_
)
2823 EXPECT_EQ(expected_push_properties_grandchild2_impl_
,
2824 leaf_always_pushing_layer_impl_
->push_properties_count());
2827 size_t expected_push_properties_root_impl_
;
2828 size_t expected_push_properties_child_impl_
;
2829 size_t expected_push_properties_child2_impl_
;
2830 size_t expected_push_properties_grandchild_impl_
;
2831 size_t expected_push_properties_grandchild2_impl_
;
2834 // In single thread there's no pending tree to push properties from.
2835 MULTI_THREAD_TEST_F(LayerTreeHostTestImplLayersPushProperties
);
2837 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
2838 : public LayerTreeHostTest
{
2840 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2842 void SetupTree() override
{
2843 root_
= Layer::Create(layer_settings());
2844 root_
->CreateRenderSurface();
2845 root_
->SetBounds(gfx::Size(1, 1));
2847 bool paint_scrollbar
= true;
2848 bool has_thumb
= false;
2849 scrollbar_layer_
= FakePaintedScrollbarLayer::Create(
2850 layer_settings(), paint_scrollbar
, has_thumb
, root_
->id());
2852 root_
->AddChild(scrollbar_layer_
);
2854 layer_tree_host()->SetRootLayer(root_
);
2855 LayerTreeHostTest::SetupTree();
2858 void DidCommitAndDrawFrame() override
{
2859 switch (layer_tree_host()->source_frame_number()) {
2863 // During update, the ignore_set_needs_commit_ bit is set to true to
2864 // avoid causing a second commit to be scheduled. If a property change
2865 // is made during this, however, it needs to be pushed in the upcoming
2867 scoped_ptr
<base::AutoReset
<bool>> ignore
=
2868 scrollbar_layer_
->IgnoreSetNeedsCommit();
2870 scrollbar_layer_
->SetBounds(gfx::Size(30, 30));
2872 EXPECT_TRUE(scrollbar_layer_
->needs_push_properties());
2873 EXPECT_TRUE(root_
->descendant_needs_push_properties());
2874 layer_tree_host()->SetNeedsCommit();
2876 scrollbar_layer_
->reset_push_properties_count();
2877 EXPECT_EQ(0u, scrollbar_layer_
->push_properties_count());
2881 EXPECT_EQ(1u, scrollbar_layer_
->push_properties_count());
2887 void AfterTest() override
{}
2889 scoped_refptr
<Layer
> root_
;
2890 scoped_refptr
<FakePaintedScrollbarLayer
> scrollbar_layer_
;
2893 MULTI_THREAD_TEST_F(LayerTreeHostTestPropertyChangesDuringUpdateArePushed
);
2895 class LayerTreeHostTestSetDrawableCausesCommit
: public LayerTreeHostTest
{
2897 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2899 void SetupTree() override
{
2900 root_
= PushPropertiesCountingLayer::Create(layer_settings());
2901 root_
->CreateRenderSurface();
2902 child_
= PushPropertiesCountingLayer::Create(layer_settings());
2903 root_
->AddChild(child_
);
2905 layer_tree_host()->SetRootLayer(root_
);
2906 LayerTreeHostTest::SetupTree();
2909 void DidCommitAndDrawFrame() override
{
2910 switch (layer_tree_host()->source_frame_number()) {
2914 // During update, the ignore_set_needs_commit_ bit is set to true to
2915 // avoid causing a second commit to be scheduled. If a property change
2916 // is made during this, however, it needs to be pushed in the upcoming
2918 EXPECT_FALSE(root_
->needs_push_properties());
2919 EXPECT_FALSE(child_
->needs_push_properties());
2920 EXPECT_EQ(0, root_
->NumDescendantsThatDrawContent());
2921 root_
->reset_push_properties_count();
2922 child_
->reset_push_properties_count();
2923 child_
->SetDrawsContent(true);
2924 EXPECT_EQ(1, root_
->NumDescendantsThatDrawContent());
2925 EXPECT_EQ(0u, root_
->push_properties_count());
2926 EXPECT_EQ(0u, child_
->push_properties_count());
2927 EXPECT_TRUE(root_
->needs_push_properties());
2928 EXPECT_TRUE(child_
->needs_push_properties());
2932 EXPECT_EQ(1u, root_
->push_properties_count());
2933 EXPECT_EQ(1u, child_
->push_properties_count());
2934 EXPECT_FALSE(root_
->needs_push_properties());
2935 EXPECT_FALSE(child_
->needs_push_properties());
2941 void AfterTest() override
{}
2943 scoped_refptr
<PushPropertiesCountingLayer
> root_
;
2944 scoped_refptr
<PushPropertiesCountingLayer
> child_
;
2947 MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit
);
2949 class LayerTreeHostTestCasePushPropertiesThreeGrandChildren
2950 : public LayerTreeHostTest
{
2952 void BeginTest() override
{
2953 expected_push_properties_root_
= 0;
2954 expected_push_properties_child_
= 0;
2955 expected_push_properties_grandchild1_
= 0;
2956 expected_push_properties_grandchild2_
= 0;
2957 expected_push_properties_grandchild3_
= 0;
2958 PostSetNeedsCommitToMainThread();
2961 void SetupTree() override
{
2962 root_
= PushPropertiesCountingLayer::Create(layer_settings());
2963 root_
->CreateRenderSurface();
2964 child_
= PushPropertiesCountingLayer::Create(layer_settings());
2965 grandchild1_
= PushPropertiesCountingLayer::Create(layer_settings());
2966 grandchild2_
= PushPropertiesCountingLayer::Create(layer_settings());
2967 grandchild3_
= PushPropertiesCountingLayer::Create(layer_settings());
2969 root_
->AddChild(child_
);
2970 child_
->AddChild(grandchild1_
);
2971 child_
->AddChild(grandchild2_
);
2972 child_
->AddChild(grandchild3_
);
2974 // Don't set the root layer here.
2975 LayerTreeHostTest::SetupTree();
2978 void AfterTest() override
{}
2980 FakeContentLayerClient client_
;
2981 scoped_refptr
<PushPropertiesCountingLayer
> root_
;
2982 scoped_refptr
<PushPropertiesCountingLayer
> child_
;
2983 scoped_refptr
<PushPropertiesCountingLayer
> grandchild1_
;
2984 scoped_refptr
<PushPropertiesCountingLayer
> grandchild2_
;
2985 scoped_refptr
<PushPropertiesCountingLayer
> grandchild3_
;
2986 size_t expected_push_properties_root_
;
2987 size_t expected_push_properties_child_
;
2988 size_t expected_push_properties_grandchild1_
;
2989 size_t expected_push_properties_grandchild2_
;
2990 size_t expected_push_properties_grandchild3_
;
2993 class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush
2994 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
2996 void DidCommitAndDrawFrame() override
{
2997 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
2998 switch (last_source_frame_number
) {
3000 EXPECT_FALSE(root_
->needs_push_properties());
3001 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3002 EXPECT_FALSE(child_
->needs_push_properties());
3003 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3004 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3005 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3006 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3007 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3008 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3009 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3011 layer_tree_host()->SetRootLayer(root_
);
3013 EXPECT_TRUE(root_
->needs_push_properties());
3014 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3015 EXPECT_TRUE(child_
->needs_push_properties());
3016 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3017 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3018 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3019 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3020 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3021 EXPECT_TRUE(grandchild3_
->needs_push_properties());
3022 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3031 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush
);
3033 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion
3034 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3036 void DidCommitAndDrawFrame() override
{
3037 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3038 switch (last_source_frame_number
) {
3040 layer_tree_host()->SetRootLayer(root_
);
3043 EXPECT_FALSE(root_
->needs_push_properties());
3044 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3045 EXPECT_FALSE(child_
->needs_push_properties());
3046 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3047 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3048 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3049 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3050 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3051 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3052 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3054 grandchild1_
->RemoveFromParent();
3055 grandchild1_
->SetPosition(gfx::Point(1, 1));
3057 EXPECT_FALSE(root_
->needs_push_properties());
3058 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3059 EXPECT_FALSE(child_
->needs_push_properties());
3060 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3061 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3062 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3063 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3064 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3066 child_
->AddChild(grandchild1_
);
3068 EXPECT_FALSE(root_
->needs_push_properties());
3069 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3070 EXPECT_FALSE(child_
->needs_push_properties());
3071 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3072 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3073 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3074 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3075 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3076 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3077 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3079 grandchild2_
->SetPosition(gfx::Point(1, 1));
3081 EXPECT_FALSE(root_
->needs_push_properties());
3082 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3083 EXPECT_FALSE(child_
->needs_push_properties());
3084 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3085 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3086 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3087 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3088 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3089 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3090 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3092 // grandchild2_ will still need a push properties.
3093 grandchild1_
->RemoveFromParent();
3095 EXPECT_FALSE(root_
->needs_push_properties());
3096 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3097 EXPECT_FALSE(child_
->needs_push_properties());
3098 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3100 // grandchild3_ does not need a push properties, so recursing should
3101 // no longer be needed.
3102 grandchild2_
->RemoveFromParent();
3104 EXPECT_FALSE(root_
->needs_push_properties());
3105 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3106 EXPECT_FALSE(child_
->needs_push_properties());
3107 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3114 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion
);
3116 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence
3117 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3119 void DidCommitAndDrawFrame() override
{
3120 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3121 switch (last_source_frame_number
) {
3123 layer_tree_host()->SetRootLayer(root_
);
3124 grandchild1_
->set_persist_needs_push_properties(true);
3125 grandchild2_
->set_persist_needs_push_properties(true);
3128 EXPECT_FALSE(root_
->needs_push_properties());
3129 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3130 EXPECT_FALSE(child_
->needs_push_properties());
3131 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3132 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3133 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3134 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3135 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3136 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3137 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3139 // grandchild2_ will still need a push properties.
3140 grandchild1_
->RemoveFromParent();
3142 EXPECT_FALSE(root_
->needs_push_properties());
3143 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3144 EXPECT_FALSE(child_
->needs_push_properties());
3145 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3147 // grandchild3_ does not need a push properties, so recursing should
3148 // no longer be needed.
3149 grandchild2_
->RemoveFromParent();
3151 EXPECT_FALSE(root_
->needs_push_properties());
3152 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3153 EXPECT_FALSE(child_
->needs_push_properties());
3154 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3161 MULTI_THREAD_TEST_F(
3162 LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence
);
3164 class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree
3165 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3167 void DidCommitAndDrawFrame() override
{
3168 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3169 switch (last_source_frame_number
) {
3171 layer_tree_host()->SetRootLayer(root_
);
3174 EXPECT_FALSE(root_
->needs_push_properties());
3175 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3176 EXPECT_FALSE(child_
->needs_push_properties());
3177 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3178 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3179 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3180 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3181 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3182 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3183 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3185 // Change grandchildren while their parent is not in the tree.
3186 child_
->RemoveFromParent();
3187 grandchild1_
->SetPosition(gfx::Point(1, 1));
3188 grandchild2_
->SetPosition(gfx::Point(1, 1));
3189 root_
->AddChild(child_
);
3191 EXPECT_FALSE(root_
->needs_push_properties());
3192 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3193 EXPECT_TRUE(child_
->needs_push_properties());
3194 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3195 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3196 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3197 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3198 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3199 EXPECT_TRUE(grandchild3_
->needs_push_properties());
3200 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3202 grandchild1_
->RemoveFromParent();
3204 EXPECT_FALSE(root_
->needs_push_properties());
3205 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3206 EXPECT_TRUE(child_
->needs_push_properties());
3207 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3209 grandchild2_
->RemoveFromParent();
3211 EXPECT_FALSE(root_
->needs_push_properties());
3212 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3213 EXPECT_TRUE(child_
->needs_push_properties());
3214 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3216 grandchild3_
->RemoveFromParent();
3218 EXPECT_FALSE(root_
->needs_push_properties());
3219 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3220 EXPECT_TRUE(child_
->needs_push_properties());
3221 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3229 MULTI_THREAD_TEST_F(
3230 LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree
);
3232 class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild
3233 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3235 void DidCommitAndDrawFrame() override
{
3236 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3237 switch (last_source_frame_number
) {
3239 layer_tree_host()->SetRootLayer(root_
);
3242 EXPECT_FALSE(root_
->needs_push_properties());
3243 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3244 EXPECT_FALSE(child_
->needs_push_properties());
3245 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3246 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3247 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3248 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3249 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3250 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3251 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3253 child_
->SetPosition(gfx::Point(1, 1));
3254 grandchild1_
->SetPosition(gfx::Point(1, 1));
3255 grandchild2_
->SetPosition(gfx::Point(1, 1));
3257 EXPECT_FALSE(root_
->needs_push_properties());
3258 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3259 EXPECT_TRUE(child_
->needs_push_properties());
3260 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3261 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3262 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3263 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3264 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3265 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3266 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3268 grandchild1_
->RemoveFromParent();
3270 EXPECT_FALSE(root_
->needs_push_properties());
3271 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3272 EXPECT_TRUE(child_
->needs_push_properties());
3273 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3275 grandchild2_
->RemoveFromParent();
3277 EXPECT_FALSE(root_
->needs_push_properties());
3278 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3279 EXPECT_TRUE(child_
->needs_push_properties());
3280 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3282 child_
->RemoveFromParent();
3284 EXPECT_FALSE(root_
->needs_push_properties());
3285 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3293 MULTI_THREAD_TEST_F(
3294 LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild
);
3296 class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
3297 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3299 void DidCommitAndDrawFrame() override
{
3300 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3301 switch (last_source_frame_number
) {
3303 layer_tree_host()->SetRootLayer(root_
);
3306 EXPECT_FALSE(root_
->needs_push_properties());
3307 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3308 EXPECT_FALSE(child_
->needs_push_properties());
3309 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3310 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3311 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3312 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3313 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3314 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3315 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3317 grandchild1_
->SetPosition(gfx::Point(1, 1));
3318 grandchild2_
->SetPosition(gfx::Point(1, 1));
3319 child_
->SetPosition(gfx::Point(1, 1));
3321 EXPECT_FALSE(root_
->needs_push_properties());
3322 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3323 EXPECT_TRUE(child_
->needs_push_properties());
3324 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3325 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3326 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3327 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3328 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3329 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3330 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3332 grandchild1_
->RemoveFromParent();
3334 EXPECT_FALSE(root_
->needs_push_properties());
3335 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3336 EXPECT_TRUE(child_
->needs_push_properties());
3337 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3339 grandchild2_
->RemoveFromParent();
3341 EXPECT_FALSE(root_
->needs_push_properties());
3342 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3343 EXPECT_TRUE(child_
->needs_push_properties());
3344 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3346 child_
->RemoveFromParent();
3348 EXPECT_FALSE(root_
->needs_push_properties());
3349 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3357 MULTI_THREAD_TEST_F(
3358 LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
);
3360 // This test verifies that the tree activation callback is invoked correctly.
3361 class LayerTreeHostTestTreeActivationCallback
: public LayerTreeHostTest
{
3363 LayerTreeHostTestTreeActivationCallback()
3364 : num_commits_(0), callback_count_(0) {}
3366 void BeginTest() override
{
3367 PostSetNeedsCommitToMainThread();
3370 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
3371 LayerTreeHostImpl::FrameData
* frame_data
,
3372 DrawResult draw_result
) override
{
3374 switch (num_commits_
) {
3376 EXPECT_EQ(0, callback_count_
);
3377 callback_count_
= 0;
3379 PostSetNeedsCommitToMainThread();
3382 EXPECT_EQ(1, callback_count_
);
3383 callback_count_
= 0;
3385 PostSetNeedsCommitToMainThread();
3388 EXPECT_EQ(0, callback_count_
);
3389 callback_count_
= 0;
3393 ADD_FAILURE() << num_commits_
;
3397 return LayerTreeHostTest::PrepareToDrawOnThread(
3398 host_impl
, frame_data
, draw_result
);
3401 void AfterTest() override
{ EXPECT_EQ(3, num_commits_
); }
3403 void SetCallback(bool enable
) {
3404 output_surface()->SetTreeActivationCallback(
3407 &LayerTreeHostTestTreeActivationCallback::ActivationCallback
,
3408 base::Unretained(this))
3412 void ActivationCallback() { ++callback_count_
; }
3415 int callback_count_
;
3418 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTreeActivationCallback
);
3420 class LayerInvalidateCausesDraw
: public LayerTreeHostTest
{
3422 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {}
3424 void BeginTest() override
{
3425 ASSERT_TRUE(invalidate_layer_
)
3426 << "Derived tests must set this in SetupTree";
3428 // One initial commit.
3429 PostSetNeedsCommitToMainThread();
3432 void DidCommitAndDrawFrame() override
{
3433 // After commit, invalidate the layer. This should cause a commit.
3434 if (layer_tree_host()->source_frame_number() == 1)
3435 invalidate_layer_
->SetNeedsDisplay();
3438 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
3440 if (impl
->active_tree()->source_frame_number() == 1)
3444 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
3448 void AfterTest() override
{
3449 EXPECT_GE(2, num_commits_
);
3450 EXPECT_GE(2, num_draws_
);
3454 scoped_refptr
<Layer
> invalidate_layer_
;
3461 // VideoLayer must support being invalidated and then passing that along
3462 // to the compositor thread, even though no resources are updated in
3463 // response to that invalidation.
3464 class LayerTreeHostTestVideoLayerInvalidate
: public LayerInvalidateCausesDraw
{
3466 void SetupTree() override
{
3467 LayerTreeHostTest::SetupTree();
3468 scoped_refptr
<VideoLayer
> video_layer
= VideoLayer::Create(
3469 layer_settings(), &provider_
, media::VIDEO_ROTATION_0
);
3470 video_layer
->SetBounds(gfx::Size(10, 10));
3471 video_layer
->SetIsDrawable(true);
3472 layer_tree_host()->root_layer()->AddChild(video_layer
);
3474 invalidate_layer_
= video_layer
;
3478 FakeVideoFrameProvider provider_
;
3481 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate
);
3483 // IOSurfaceLayer must support being invalidated and then passing that along
3484 // to the compositor thread, even though no resources are updated in
3485 // response to that invalidation.
3486 class LayerTreeHostTestIOSurfaceLayerInvalidate
3487 : public LayerInvalidateCausesDraw
{
3489 void SetupTree() override
{
3490 LayerTreeHostTest::SetupTree();
3491 scoped_refptr
<IOSurfaceLayer
> layer
=
3492 IOSurfaceLayer::Create(layer_settings());
3493 layer
->SetBounds(gfx::Size(10, 10));
3494 uint32_t fake_io_surface_id
= 7;
3495 layer
->SetIOSurfaceProperties(fake_io_surface_id
, layer
->bounds());
3496 layer
->SetIsDrawable(true);
3497 layer_tree_host()->root_layer()->AddChild(layer
);
3499 invalidate_layer_
= layer
;
3503 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceLayerInvalidate
);
3505 class LayerTreeHostTestPushHiddenLayer
: public LayerTreeHostTest
{
3507 void SetupTree() override
{
3508 root_layer_
= Layer::Create(layer_settings());
3509 root_layer_
->CreateRenderSurface();
3510 root_layer_
->SetPosition(gfx::Point());
3511 root_layer_
->SetBounds(gfx::Size(10, 10));
3513 parent_layer_
= SolidColorLayer::Create(layer_settings());
3514 parent_layer_
->SetPosition(gfx::Point());
3515 parent_layer_
->SetBounds(gfx::Size(10, 10));
3516 parent_layer_
->SetIsDrawable(true);
3517 root_layer_
->AddChild(parent_layer_
);
3519 child_layer_
= SolidColorLayer::Create(layer_settings());
3520 child_layer_
->SetPosition(gfx::Point());
3521 child_layer_
->SetBounds(gfx::Size(10, 10));
3522 child_layer_
->SetIsDrawable(true);
3523 parent_layer_
->AddChild(child_layer_
);
3525 layer_tree_host()->SetRootLayer(root_layer_
);
3526 LayerTreeHostTest::SetupTree();
3529 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3531 void DidCommitAndDrawFrame() override
{
3532 switch (layer_tree_host()->source_frame_number()) {
3534 // The layer type used does not need to push properties every frame.
3535 EXPECT_FALSE(child_layer_
->needs_push_properties());
3537 // Change the bounds of the child layer, but make it skipped
3538 // by CalculateDrawProperties.
3539 parent_layer_
->SetOpacity(0.f
);
3540 child_layer_
->SetBounds(gfx::Size(5, 5));
3543 // The bounds of the child layer were pushed to the impl side.
3544 EXPECT_FALSE(child_layer_
->needs_push_properties());
3551 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
3552 LayerImpl
* root
= impl
->active_tree()->root_layer();
3553 LayerImpl
* parent
= root
->children()[0];
3554 LayerImpl
* child
= parent
->children()[0];
3556 switch (impl
->active_tree()->source_frame_number()) {
3558 EXPECT_EQ(gfx::Size(5, 5).ToString(), child
->bounds().ToString());
3563 void AfterTest() override
{}
3565 scoped_refptr
<Layer
> root_layer_
;
3566 scoped_refptr
<SolidColorLayer
> parent_layer_
;
3567 scoped_refptr
<SolidColorLayer
> child_layer_
;
3570 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushHiddenLayer
);
3572 class LayerTreeHostTestUpdateLayerInEmptyViewport
: public LayerTreeHostTest
{
3574 void SetupTree() override
{
3575 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
3576 root_layer_
->SetBounds(gfx::Size(10, 10));
3578 layer_tree_host()->SetRootLayer(root_layer_
);
3579 LayerTreeHostTest::SetupTree();
3582 void BeginTest() override
{
3583 // The viewport is empty, but we still need to update layers on the main
3585 layer_tree_host()->SetViewportSize(gfx::Size(0, 0));
3586 PostSetNeedsCommitToMainThread();
3589 void DidCommit() override
{
3590 // The layer should be updated even though the viewport is empty, so we
3591 // are capable of drawing it on the impl tree.
3592 EXPECT_GT(root_layer_
->update_count(), 0);
3596 void AfterTest() override
{}
3598 FakeContentLayerClient client_
;
3599 scoped_refptr
<FakePictureLayer
> root_layer_
;
3602 MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport
);
3604 class LayerTreeHostTestMaxTransferBufferUsageBytes
: public LayerTreeHostTest
{
3606 void InitializeSettings(LayerTreeSettings
* settings
) override
{
3607 // Testing async uploads.
3608 settings
->use_zero_copy
= false;
3609 settings
->use_one_copy
= false;
3612 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
3613 scoped_refptr
<TestContextProvider
> context_provider
=
3614 TestContextProvider::Create();
3615 context_provider
->SetMaxTransferBufferUsageBytes(512 * 512);
3616 if (delegating_renderer())
3617 return FakeOutputSurface::CreateDelegating3d(context_provider
);
3619 return FakeOutputSurface::Create3d(context_provider
);
3622 void SetupTree() override
{
3623 client_
.set_fill_with_nonsolid_color(true);
3624 scoped_refptr
<FakePictureLayer
> root_layer
=
3625 FakePictureLayer::Create(layer_settings(), &client_
);
3626 root_layer
->SetBounds(gfx::Size(1024, 1024));
3627 root_layer
->SetIsDrawable(true);
3629 layer_tree_host()->SetRootLayer(root_layer
);
3630 LayerTreeHostTest::SetupTree();
3633 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3635 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
3636 TestWebGraphicsContext3D
* context
= TestContext();
3638 // Expect that the transfer buffer memory used is equal to the
3639 // MaxTransferBufferUsageBytes value set in CreateOutputSurface.
3640 EXPECT_EQ(512 * 512u, context
->max_used_transfer_buffer_usage_bytes());
3644 void AfterTest() override
{}
3647 FakeContentLayerClient client_
;
3650 // Impl-side painting is a multi-threaded compositor feature.
3651 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes
);
3653 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
3654 : public LayerTreeHostTest
{
3656 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface()
3657 : first_output_surface_memory_limit_(4321234),
3658 second_output_surface_memory_limit_(1234321) {}
3660 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
3661 if (!first_context_provider_
.get()) {
3662 first_context_provider_
= TestContextProvider::Create();
3664 EXPECT_FALSE(second_context_provider_
.get());
3665 second_context_provider_
= TestContextProvider::Create();
3668 scoped_refptr
<TestContextProvider
> provider(second_context_provider_
.get()
3669 ? second_context_provider_
3670 : first_context_provider_
);
3671 scoped_ptr
<FakeOutputSurface
> output_surface
;
3672 if (delegating_renderer())
3673 output_surface
= FakeOutputSurface::CreateDelegating3d(provider
);
3675 output_surface
= FakeOutputSurface::Create3d(provider
);
3676 output_surface
->SetMemoryPolicyToSetAtBind(
3677 make_scoped_ptr(new ManagedMemoryPolicy(
3678 second_context_provider_
.get() ? second_output_surface_memory_limit_
3679 : first_output_surface_memory_limit_
,
3680 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE
,
3681 ManagedMemoryPolicy::kDefaultNumResourcesLimit
)));
3682 return output_surface
.Pass();
3685 void SetupTree() override
{
3686 root_
= FakePictureLayer::Create(layer_settings(), &client_
);
3687 root_
->SetBounds(gfx::Size(20, 20));
3688 layer_tree_host()->SetRootLayer(root_
);
3689 LayerTreeHostTest::SetupTree();
3692 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3694 void DidCommitAndDrawFrame() override
{
3695 // Lost context sometimes takes two frames to recreate. The third frame
3696 // is sometimes aborted, so wait until the fourth frame to verify that
3697 // the memory has been set, and the fifth frame to end the test.
3698 if (layer_tree_host()->source_frame_number() < 5) {
3699 layer_tree_host()->SetNeedsCommit();
3700 } else if (layer_tree_host()->source_frame_number() == 5) {
3705 void SwapBuffersOnThread(LayerTreeHostImpl
* impl
, bool result
) override
{
3706 switch (impl
->active_tree()->source_frame_number()) {
3708 EXPECT_EQ(first_output_surface_memory_limit_
,
3709 impl
->memory_allocation_limit_bytes());
3710 // Lose the output surface.
3711 first_context_provider_
->TestContext3d()->loseContextCHROMIUM(
3712 GL_GUILTY_CONTEXT_RESET_ARB
, GL_INNOCENT_CONTEXT_RESET_ARB
);
3715 EXPECT_EQ(second_output_surface_memory_limit_
,
3716 impl
->memory_allocation_limit_bytes());
3721 void AfterTest() override
{}
3723 scoped_refptr
<TestContextProvider
> first_context_provider_
;
3724 scoped_refptr
<TestContextProvider
> second_context_provider_
;
3725 size_t first_output_surface_memory_limit_
;
3726 size_t second_output_surface_memory_limit_
;
3727 FakeContentLayerClient client_
;
3728 scoped_refptr
<Layer
> root_
;
3731 SINGLE_AND_MULTI_THREAD_TEST_F(
3732 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
);
3734 struct TestSwapPromiseResult
{
3735 TestSwapPromiseResult()
3736 : did_activate_called(false),
3737 did_swap_called(false),
3738 did_not_swap_called(false),
3740 reason(SwapPromise::COMMIT_FAILS
) {}
3742 bool did_activate_called
;
3743 bool did_swap_called
;
3744 bool did_not_swap_called
;
3746 SwapPromise::DidNotSwapReason reason
;
3750 class TestSwapPromise
: public SwapPromise
{
3752 explicit TestSwapPromise(TestSwapPromiseResult
* result
) : result_(result
) {}
3754 ~TestSwapPromise() override
{
3755 base::AutoLock
lock(result_
->lock
);
3756 result_
->dtor_called
= true;
3759 void DidActivate() override
{
3760 base::AutoLock
lock(result_
->lock
);
3761 EXPECT_FALSE(result_
->did_activate_called
);
3762 EXPECT_FALSE(result_
->did_swap_called
);
3763 EXPECT_FALSE(result_
->did_not_swap_called
);
3764 result_
->did_activate_called
= true;
3767 void DidSwap(CompositorFrameMetadata
* metadata
) override
{
3768 base::AutoLock
lock(result_
->lock
);
3769 EXPECT_TRUE(result_
->did_activate_called
);
3770 EXPECT_FALSE(result_
->did_swap_called
);
3771 EXPECT_FALSE(result_
->did_not_swap_called
);
3772 result_
->did_swap_called
= true;
3775 void DidNotSwap(DidNotSwapReason reason
) override
{
3776 base::AutoLock
lock(result_
->lock
);
3777 EXPECT_FALSE(result_
->did_swap_called
);
3778 EXPECT_FALSE(result_
->did_not_swap_called
);
3779 EXPECT_FALSE(result_
->did_activate_called
&&
3780 reason
!= DidNotSwapReason::SWAP_FAILS
);
3781 result_
->did_not_swap_called
= true;
3782 result_
->reason
= reason
;
3785 int64
TraceId() const override
{ return 0; }
3789 TestSwapPromiseResult
* result_
;
3792 class LayerTreeHostTestBreakSwapPromise
: public LayerTreeHostTest
{
3794 LayerTreeHostTestBreakSwapPromise()
3795 : commit_count_(0), commit_complete_count_(0) {}
3797 void WillBeginMainFrame() override
{
3798 ASSERT_LE(commit_count_
, 2);
3799 scoped_ptr
<SwapPromise
> swap_promise(
3800 new TestSwapPromise(&swap_promise_result_
[commit_count_
]));
3801 layer_tree_host()->QueueSwapPromise(swap_promise
.Pass());
3804 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3806 void DidCommit() override
{
3808 if (commit_count_
== 2) {
3809 // This commit will finish.
3810 layer_tree_host()->SetNeedsCommit();
3814 void WillActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
3815 if (host_impl
->pending_tree()) {
3816 int frame
= host_impl
->pending_tree()->source_frame_number();
3817 base::AutoLock
lock(swap_promise_result_
[frame
].lock
);
3818 EXPECT_FALSE(swap_promise_result_
[frame
].did_activate_called
);
3819 EXPECT_FALSE(swap_promise_result_
[frame
].did_swap_called
);
3823 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
3824 int frame
= host_impl
->active_tree()->source_frame_number();
3825 base::AutoLock
lock(swap_promise_result_
[frame
].lock
);
3826 EXPECT_TRUE(swap_promise_result_
[frame
].did_activate_called
);
3827 EXPECT_FALSE(swap_promise_result_
[frame
].did_swap_called
);
3830 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
3831 commit_complete_count_
++;
3832 if (commit_complete_count_
== 1) {
3833 // This commit will be aborted because no actual update.
3834 PostSetNeedsUpdateLayersToMainThread();
3838 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
3839 int frame
= host_impl
->active_tree()->source_frame_number();
3845 void AfterTest() override
{
3846 // 3 commits are scheduled. 2 completes. 1 is aborted.
3847 EXPECT_EQ(commit_count_
, 3);
3848 EXPECT_EQ(commit_complete_count_
, 2);
3851 // The first commit completes and causes swap buffer which finishes
3853 base::AutoLock
lock(swap_promise_result_
[0].lock
);
3854 EXPECT_TRUE(swap_promise_result_
[0].did_swap_called
);
3855 EXPECT_FALSE(swap_promise_result_
[0].did_not_swap_called
);
3856 EXPECT_TRUE(swap_promise_result_
[0].dtor_called
);
3860 // The second commit is aborted since it contains no updates.
3861 base::AutoLock
lock(swap_promise_result_
[1].lock
);
3862 EXPECT_FALSE(swap_promise_result_
[1].did_activate_called
);
3863 EXPECT_FALSE(swap_promise_result_
[1].did_swap_called
);
3864 EXPECT_TRUE(swap_promise_result_
[1].did_not_swap_called
);
3865 EXPECT_EQ(SwapPromise::COMMIT_NO_UPDATE
, swap_promise_result_
[1].reason
);
3866 EXPECT_TRUE(swap_promise_result_
[1].dtor_called
);
3870 // The last commit completes but it does not cause swap buffer because
3871 // there is no damage in the frame data.
3872 base::AutoLock
lock(swap_promise_result_
[2].lock
);
3873 EXPECT_TRUE(swap_promise_result_
[2].did_activate_called
);
3874 EXPECT_FALSE(swap_promise_result_
[2].did_swap_called
);
3875 EXPECT_TRUE(swap_promise_result_
[2].did_not_swap_called
);
3876 EXPECT_EQ(SwapPromise::SWAP_FAILS
, swap_promise_result_
[2].reason
);
3877 EXPECT_TRUE(swap_promise_result_
[2].dtor_called
);
3882 int commit_complete_count_
;
3883 TestSwapPromiseResult swap_promise_result_
[3];
3886 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise
);
3888 class LayerTreeHostTestKeepSwapPromise
: public LayerTreeTest
{
3890 LayerTreeHostTestKeepSwapPromise() {}
3892 void BeginTest() override
{
3893 layer_
= SolidColorLayer::Create(layer_settings());
3894 layer_
->SetIsDrawable(true);
3895 layer_
->SetBounds(gfx::Size(10, 10));
3896 layer_tree_host()->SetRootLayer(layer_
);
3897 gfx::Size
bounds(100, 100);
3898 layer_tree_host()->SetViewportSize(bounds
);
3899 PostSetNeedsCommitToMainThread();
3902 void DidCommit() override
{
3903 MainThreadTaskRunner()->PostTask(
3904 FROM_HERE
, base::Bind(&LayerTreeHostTestKeepSwapPromise::ChangeFrame
,
3905 base::Unretained(this)));
3908 void ChangeFrame() {
3909 switch (layer_tree_host()->source_frame_number()) {
3911 layer_
->SetBounds(gfx::Size(10, 11));
3912 layer_tree_host()->QueueSwapPromise(
3913 make_scoped_ptr(new TestSwapPromise(&swap_promise_result_
)));
3923 void WillActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
3924 if (host_impl
->pending_tree()) {
3925 if (host_impl
->pending_tree()->source_frame_number() == 1) {
3926 base::AutoLock
lock(swap_promise_result_
.lock
);
3927 EXPECT_FALSE(swap_promise_result_
.did_activate_called
);
3928 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
3936 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
3937 if (host_impl
->active_tree()->source_frame_number() == 1) {
3938 base::AutoLock
lock(swap_promise_result_
.lock
);
3939 EXPECT_TRUE(swap_promise_result_
.did_activate_called
);
3940 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
3944 void ActivationCallback() {
3945 // DidActivate needs to happen before the tree activation callback.
3946 base::AutoLock
lock(swap_promise_result_
.lock
);
3947 EXPECT_TRUE(swap_promise_result_
.did_activate_called
);
3950 void SetCallback(bool enable
) {
3951 output_surface()->SetTreeActivationCallback(
3953 ? base::Bind(&LayerTreeHostTestKeepSwapPromise::ActivationCallback
,
3954 base::Unretained(this))
3958 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
3959 EXPECT_TRUE(result
);
3960 if (host_impl
->active_tree()->source_frame_number() >= 1) {
3961 // The commit changes layers so it should cause a swap.
3962 base::AutoLock
lock(swap_promise_result_
.lock
);
3963 EXPECT_TRUE(swap_promise_result_
.did_swap_called
);
3964 EXPECT_FALSE(swap_promise_result_
.did_not_swap_called
);
3965 EXPECT_TRUE(swap_promise_result_
.dtor_called
);
3970 void AfterTest() override
{}
3973 scoped_refptr
<Layer
> layer_
;
3974 TestSwapPromiseResult swap_promise_result_
;
3977 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise
);
3979 class LayerTreeHostTestBreakSwapPromiseForVisibility
3980 : public LayerTreeHostTest
{
3982 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3984 void SetVisibleFalseAndQueueSwapPromise() {
3985 layer_tree_host()->SetVisible(false);
3986 scoped_ptr
<SwapPromise
> swap_promise(
3987 new TestSwapPromise(&swap_promise_result_
));
3988 layer_tree_host()->QueueSwapPromise(swap_promise
.Pass());
3991 void ScheduledActionWillSendBeginMainFrame() override
{
3992 MainThreadTaskRunner()->PostTask(
3994 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
3995 ::SetVisibleFalseAndQueueSwapPromise
,
3996 base::Unretained(this)));
3999 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl
* host_impl
,
4000 CommitEarlyOutReason reason
) override
{
4004 void AfterTest() override
{
4006 base::AutoLock
lock(swap_promise_result_
.lock
);
4007 EXPECT_FALSE(swap_promise_result_
.did_activate_called
);
4008 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
4009 EXPECT_TRUE(swap_promise_result_
.did_not_swap_called
);
4010 EXPECT_EQ(SwapPromise::COMMIT_FAILS
, swap_promise_result_
.reason
);
4011 EXPECT_TRUE(swap_promise_result_
.dtor_called
);
4015 TestSwapPromiseResult swap_promise_result_
;
4018 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForVisibility
);
4020 class LayerTreeHostTestBreakSwapPromiseForContext
: public LayerTreeHostTest
{
4022 LayerTreeHostTestBreakSwapPromiseForContext()
4023 : output_surface_lost_triggered_(false) {
4026 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4028 void LoseOutputSurfaceAndQueueSwapPromise() {
4029 layer_tree_host()->DidLoseOutputSurface();
4030 scoped_ptr
<SwapPromise
> swap_promise(
4031 new TestSwapPromise(&swap_promise_result_
));
4032 layer_tree_host()->QueueSwapPromise(swap_promise
.Pass());
4035 void ScheduledActionWillSendBeginMainFrame() override
{
4036 if (output_surface_lost_triggered_
)
4038 output_surface_lost_triggered_
= true;
4040 MainThreadTaskRunner()->PostTask(
4042 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext
4043 ::LoseOutputSurfaceAndQueueSwapPromise
,
4044 base::Unretained(this)));
4047 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl
* host_impl
,
4048 CommitEarlyOutReason reason
) override
{
4049 // This is needed so that the impl-thread state matches main-thread state.
4050 host_impl
->DidLoseOutputSurface();
4054 void AfterTest() override
{
4056 base::AutoLock
lock(swap_promise_result_
.lock
);
4057 EXPECT_FALSE(swap_promise_result_
.did_activate_called
);
4058 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
4059 EXPECT_TRUE(swap_promise_result_
.did_not_swap_called
);
4060 EXPECT_EQ(SwapPromise::COMMIT_FAILS
, swap_promise_result_
.reason
);
4061 EXPECT_TRUE(swap_promise_result_
.dtor_called
);
4065 bool output_surface_lost_triggered_
;
4066 TestSwapPromiseResult swap_promise_result_
;
4069 SINGLE_AND_MULTI_THREAD_TEST_F(
4070 LayerTreeHostTestBreakSwapPromiseForContext
);
4072 class SimpleSwapPromiseMonitor
: public SwapPromiseMonitor
{
4074 SimpleSwapPromiseMonitor(LayerTreeHost
* layer_tree_host
,
4075 LayerTreeHostImpl
* layer_tree_host_impl
,
4076 int* set_needs_commit_count
,
4077 int* set_needs_redraw_count
)
4078 : SwapPromiseMonitor(layer_tree_host
, layer_tree_host_impl
),
4079 set_needs_commit_count_(set_needs_commit_count
) {}
4081 ~SimpleSwapPromiseMonitor() override
{}
4083 void OnSetNeedsCommitOnMain() override
{ (*set_needs_commit_count_
)++; }
4085 void OnSetNeedsRedrawOnImpl() override
{
4086 ADD_FAILURE() << "Should not get called on main thread.";
4089 void OnForwardScrollUpdateToMainThreadOnImpl() override
{
4090 ADD_FAILURE() << "Should not get called on main thread.";
4094 int* set_needs_commit_count_
;
4097 class LayerTreeHostTestSimpleSwapPromiseMonitor
: public LayerTreeHostTest
{
4099 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4101 void WillBeginMainFrame() override
{
4105 int set_needs_commit_count
= 0;
4106 int set_needs_redraw_count
= 0;
4109 scoped_ptr
<SimpleSwapPromiseMonitor
> swap_promise_monitor(
4110 new SimpleSwapPromiseMonitor(layer_tree_host(),
4112 &set_needs_commit_count
,
4113 &set_needs_redraw_count
));
4114 layer_tree_host()->SetNeedsCommit();
4115 EXPECT_EQ(1, set_needs_commit_count
);
4116 EXPECT_EQ(0, set_needs_redraw_count
);
4119 // Now the monitor is destroyed, SetNeedsCommit() is no longer being
4121 layer_tree_host()->SetNeedsCommit();
4122 EXPECT_EQ(1, set_needs_commit_count
);
4123 EXPECT_EQ(0, set_needs_redraw_count
);
4126 scoped_ptr
<SimpleSwapPromiseMonitor
> swap_promise_monitor(
4127 new SimpleSwapPromiseMonitor(layer_tree_host(),
4129 &set_needs_commit_count
,
4130 &set_needs_redraw_count
));
4131 layer_tree_host()->SetNeedsUpdateLayers();
4132 EXPECT_EQ(2, set_needs_commit_count
);
4133 EXPECT_EQ(0, set_needs_redraw_count
);
4137 scoped_ptr
<SimpleSwapPromiseMonitor
> swap_promise_monitor(
4138 new SimpleSwapPromiseMonitor(layer_tree_host(),
4140 &set_needs_commit_count
,
4141 &set_needs_redraw_count
));
4142 layer_tree_host()->SetNeedsAnimate();
4143 EXPECT_EQ(3, set_needs_commit_count
);
4144 EXPECT_EQ(0, set_needs_redraw_count
);
4150 void AfterTest() override
{}
4153 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor
);
4155 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources
4156 : public LayerTreeHostTest
{
4158 void SetupTree() override
{
4159 LayerTreeHostTest::SetupTree();
4160 ui_resource_
= FakeScopedUIResource::Create(layer_tree_host());
4163 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4165 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4166 host_impl
->EvictAllUIResources();
4167 // Existence of evicted UI resources will trigger NEW_CONTENT_TAKES_PRIORITY
4168 // mode. Active tree should require high-res to draw after entering this
4169 // mode to ensure that high-res tiles are also required for a pending tree
4171 EXPECT_TRUE(host_impl
->RequiresHighResToDraw());
4174 void DidCommit() override
{
4175 int frame
= layer_tree_host()->source_frame_number();
4178 PostSetNeedsCommitToMainThread();
4181 ui_resource_
= nullptr;
4187 void AfterTest() override
{}
4189 FakeContentLayerClient client_
;
4190 scoped_ptr
<FakeScopedUIResource
> ui_resource_
;
4193 // This test is flaky, see http://crbug.com/386199
4194 // MULTI_THREAD_TEST_F(LayerTreeHostTestHighResRequiredAfterEvictingUIResources)
4196 class LayerTreeHostTestGpuRasterizationDefault
: public LayerTreeHostTest
{
4198 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4199 EXPECT_FALSE(settings
->gpu_rasterization_enabled
);
4200 EXPECT_FALSE(settings
->gpu_rasterization_forced
);
4203 void SetupTree() override
{
4204 LayerTreeHostTest::SetupTree();
4206 scoped_refptr
<PictureLayer
> layer
=
4207 PictureLayer::Create(layer_settings(), &layer_client_
);
4208 layer
->SetBounds(gfx::Size(10, 10));
4209 layer
->SetIsDrawable(true);
4210 layer_tree_host()->root_layer()->AddChild(layer
);
4213 void BeginTest() override
{
4214 Layer
* root
= layer_tree_host()->root_layer();
4215 PictureLayer
* layer
= static_cast<PictureLayer
*>(root
->child_at(0));
4216 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4218 // Verify default values.
4219 EXPECT_TRUE(root
->IsSuitableForGpuRasterization());
4220 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
4221 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
4222 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4224 // Setting gpu rasterization trigger does not enable gpu rasterization.
4225 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4226 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4228 PostSetNeedsCommitToMainThread();
4231 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4232 EXPECT_FALSE(host_impl
->pending_tree()->use_gpu_rasterization());
4233 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4236 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4237 EXPECT_FALSE(host_impl
->active_tree()->use_gpu_rasterization());
4238 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4242 void AfterTest() override
{}
4244 FakeContentLayerClient layer_client_
;
4247 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDefault
);
4249 class LayerTreeHostTestGpuRasterizationEnabled
: public LayerTreeHostTest
{
4251 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4252 EXPECT_FALSE(settings
->gpu_rasterization_enabled
);
4253 settings
->gpu_rasterization_enabled
= true;
4256 void SetupTree() override
{
4257 LayerTreeHostTest::SetupTree();
4259 scoped_refptr
<PictureLayer
> layer
=
4260 PictureLayer::Create(layer_settings(), &layer_client_
);
4261 layer
->SetBounds(gfx::Size(10, 10));
4262 layer
->SetIsDrawable(true);
4263 layer_tree_host()->root_layer()->AddChild(layer
);
4266 void BeginTest() override
{
4267 Layer
* root
= layer_tree_host()->root_layer();
4268 PictureLayer
* layer
= static_cast<PictureLayer
*>(root
->child_at(0));
4269 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4271 // Verify default values.
4272 EXPECT_TRUE(root
->IsSuitableForGpuRasterization());
4273 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
4274 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
4275 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4277 // Gpu rasterization trigger is relevant.
4278 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4279 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4281 // Content-based veto is relevant as well.
4282 recording_source
->SetUnsuitableForGpuRasterizationForTesting();
4283 EXPECT_FALSE(recording_source
->IsSuitableForGpuRasterization());
4284 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
4285 // Veto will take effect when layers are updated.
4286 // The results will be verified after commit is completed below.
4287 // Since we are manually marking picture pile as unsuitable,
4288 // make sure that the layer gets a chance to update.
4289 layer
->SetNeedsDisplay();
4290 PostSetNeedsCommitToMainThread();
4293 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4294 EXPECT_FALSE(host_impl
->pending_tree()->use_gpu_rasterization());
4295 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4298 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4299 EXPECT_FALSE(host_impl
->active_tree()->use_gpu_rasterization());
4300 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4304 void AfterTest() override
{}
4306 FakeContentLayerClient layer_client_
;
4309 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled
);
4311 class LayerTreeHostTestGpuRasterizationForced
: public LayerTreeHostTest
{
4313 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4314 EXPECT_FALSE(settings
->gpu_rasterization_forced
);
4315 settings
->gpu_rasterization_forced
= true;
4318 void SetupTree() override
{
4319 LayerTreeHostTest::SetupTree();
4321 scoped_refptr
<FakePictureLayer
> layer
=
4322 FakePictureLayer::Create(layer_settings(), &layer_client_
);
4323 layer
->SetBounds(gfx::Size(10, 10));
4324 layer
->SetIsDrawable(true);
4325 layer_tree_host()->root_layer()->AddChild(layer
);
4328 void BeginTest() override
{
4329 Layer
* root
= layer_tree_host()->root_layer();
4330 PictureLayer
* layer
= static_cast<PictureLayer
*>(root
->child_at(0));
4331 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4333 // Verify default values.
4334 EXPECT_TRUE(root
->IsSuitableForGpuRasterization());
4335 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
4336 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
4337 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4339 // With gpu rasterization forced, gpu rasterization trigger is irrelevant.
4340 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4341 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4343 // Content-based veto is irrelevant as well.
4344 recording_source
->SetUnsuitableForGpuRasterizationForTesting();
4345 EXPECT_FALSE(recording_source
->IsSuitableForGpuRasterization());
4346 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
4347 // Veto will take effect when layers are updated.
4348 // The results will be verified after commit is completed below.
4349 // Since we are manually marking picture pile as unsuitable,
4350 // make sure that the layer gets a chance to update.
4351 layer
->SetNeedsDisplay();
4352 PostSetNeedsCommitToMainThread();
4355 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4356 EXPECT_TRUE(host_impl
->sync_tree()->use_gpu_rasterization());
4357 EXPECT_TRUE(host_impl
->use_gpu_rasterization());
4360 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4361 EXPECT_TRUE(host_impl
->active_tree()->use_gpu_rasterization());
4362 EXPECT_TRUE(host_impl
->use_gpu_rasterization());
4366 void AfterTest() override
{}
4368 FakeContentLayerClient layer_client_
;
4371 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationForced
);
4373 class LayerTreeHostTestContinuousPainting
: public LayerTreeHostTest
{
4375 LayerTreeHostTestContinuousPainting()
4376 : num_commits_(0), num_draws_(0), bounds_(20, 20), child_layer_(NULL
) {}
4379 enum { kExpectedNumCommits
= 10 };
4381 void SetupTree() override
{
4382 scoped_refptr
<Layer
> root_layer
= Layer::Create(layer_settings());
4383 root_layer
->SetBounds(bounds_
);
4384 root_layer
->CreateRenderSurface();
4386 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
4387 child_layer_
->SetBounds(bounds_
);
4388 child_layer_
->SetIsDrawable(true);
4389 root_layer
->AddChild(child_layer_
);
4391 layer_tree_host()->SetRootLayer(root_layer
);
4392 layer_tree_host()->SetViewportSize(bounds_
);
4393 LayerTreeHostTest::SetupTree();
4396 void BeginTest() override
{
4397 MainThreadTaskRunner()->PostTask(
4400 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting
,
4401 base::Unretained(this)));
4402 // Wait 50x longer than expected.
4403 double milliseconds_per_frame
=
4404 1000.0 / layer_tree_host()->settings().renderer_settings
.refresh_rate
;
4405 MainThreadTaskRunner()->PostDelayedTask(
4408 &LayerTreeHostTestContinuousPainting::DisableContinuousPainting
,
4409 base::Unretained(this)),
4410 base::TimeDelta::FromMilliseconds(50 * kExpectedNumCommits
*
4411 milliseconds_per_frame
));
4414 void BeginMainFrame(const BeginFrameArgs
& args
) override
{
4415 child_layer_
->SetNeedsDisplay();
4418 void AfterTest() override
{
4419 EXPECT_LE(kExpectedNumCommits
, num_commits_
);
4420 EXPECT_LE(kExpectedNumCommits
, num_draws_
);
4421 EXPECT_LE(kExpectedNumCommits
, child_layer_
->update_count());
4424 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
4425 if (++num_draws_
== kExpectedNumCommits
)
4429 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
4434 void EnableContinuousPainting() {
4435 LayerTreeDebugState debug_state
= layer_tree_host()->debug_state();
4436 debug_state
.continuous_painting
= true;
4437 layer_tree_host()->SetDebugState(debug_state
);
4440 void DisableContinuousPainting() {
4441 LayerTreeDebugState debug_state
= layer_tree_host()->debug_state();
4442 debug_state
.continuous_painting
= false;
4443 layer_tree_host()->SetDebugState(debug_state
);
4449 const gfx::Size bounds_
;
4450 FakeContentLayerClient client_
;
4451 scoped_refptr
<FakePictureLayer
> child_layer_
;
4454 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting
);
4456 class LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame
4457 : public LayerTreeHostTest
{
4459 enum { kExpectedNumImplFrames
= 10 };
4461 LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame()
4462 : will_begin_impl_frame_count_(0), did_finish_impl_frame_count_(0) {}
4464 void BeginTest() override
{
4465 // Kick off the test with a commit.
4466 PostSetNeedsCommitToMainThread();
4469 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* host_impl
,
4470 const BeginFrameArgs
& args
) override
{
4471 EXPECT_EQ(will_begin_impl_frame_count_
, did_finish_impl_frame_count_
);
4472 EXPECT_FALSE(TestEnded());
4473 will_begin_impl_frame_count_
++;
4476 void DidFinishImplFrameOnThread(LayerTreeHostImpl
* host_impl
) override
{
4477 did_finish_impl_frame_count_
++;
4478 EXPECT_EQ(will_begin_impl_frame_count_
, did_finish_impl_frame_count_
);
4480 // Request a number of commits to cause multiple impl frames. We expect to
4481 // get one more impl frames than the number of commits requested because
4482 // after a commit it takes one frame to become idle.
4483 if (did_finish_impl_frame_count_
< kExpectedNumImplFrames
- 1)
4484 PostSetNeedsCommitToMainThread();
4487 void SendBeginMainFrameNotExpectedSoon() override
{ EndTest(); }
4489 void AfterTest() override
{
4490 EXPECT_GT(will_begin_impl_frame_count_
, 0);
4491 EXPECT_GT(did_finish_impl_frame_count_
, 0);
4492 EXPECT_EQ(will_begin_impl_frame_count_
, did_finish_impl_frame_count_
);
4494 // TODO(mithro): Figure out why the multithread version of this test
4495 // sometimes has one more frame then expected. Possibly related to
4496 // http://crbug.com/443185
4497 if (!HasImplThread()) {
4498 EXPECT_EQ(will_begin_impl_frame_count_
, kExpectedNumImplFrames
);
4499 EXPECT_EQ(did_finish_impl_frame_count_
, kExpectedNumImplFrames
);
4504 int will_begin_impl_frame_count_
;
4505 int did_finish_impl_frame_count_
;
4508 SINGLE_AND_MULTI_THREAD_TEST_F(
4509 LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame
);
4511 class LayerTreeHostTestSendBeginFramesToChildren
: public LayerTreeHostTest
{
4513 LayerTreeHostTestSendBeginFramesToChildren()
4514 : begin_frame_sent_to_children_(false) {
4517 void BeginTest() override
{
4518 // Kick off the test with a commit.
4519 PostSetNeedsCommitToMainThread();
4522 void SendBeginFramesToChildren(const BeginFrameArgs
& args
) override
{
4523 begin_frame_sent_to_children_
= true;
4527 void DidBeginMainFrame() override
{
4528 // Children requested BeginFrames.
4529 layer_tree_host()->SetChildrenNeedBeginFrames(true);
4532 void AfterTest() override
{
4533 // Ensure that BeginFrame message is sent to children during parent
4534 // scheduler handles its BeginFrame.
4535 EXPECT_TRUE(begin_frame_sent_to_children_
);
4539 bool begin_frame_sent_to_children_
;
4542 SINGLE_THREAD_TEST_F(LayerTreeHostTestSendBeginFramesToChildren
);
4544 class LayerTreeHostTestSendBeginFramesToChildrenWithExternalBFS
4545 : public LayerTreeHostTest
{
4547 LayerTreeHostTestSendBeginFramesToChildrenWithExternalBFS()
4548 : begin_frame_sent_to_children_(false) {
4551 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4552 settings
->use_external_begin_frame_source
= true;
4555 void BeginTest() override
{
4556 // Kick off the test with a commit.
4557 PostSetNeedsCommitToMainThread();
4560 void SendBeginFramesToChildren(const BeginFrameArgs
& args
) override
{
4561 begin_frame_sent_to_children_
= true;
4565 void DidBeginMainFrame() override
{
4566 // Children requested BeginFrames.
4567 layer_tree_host()->SetChildrenNeedBeginFrames(true);
4570 void AfterTest() override
{
4571 // Ensure that BeginFrame message is sent to children during parent
4572 // scheduler handles its BeginFrame.
4573 EXPECT_TRUE(begin_frame_sent_to_children_
);
4577 bool begin_frame_sent_to_children_
;
4580 SINGLE_THREAD_TEST_F(LayerTreeHostTestSendBeginFramesToChildrenWithExternalBFS
);
4582 class LayerTreeHostTestActivateOnInvisible
: public LayerTreeHostTest
{
4584 LayerTreeHostTestActivateOnInvisible()
4585 : activation_count_(0), visible_(true) {}
4587 void BeginTest() override
{
4588 // Kick off the test with a commit.
4589 PostSetNeedsCommitToMainThread();
4592 void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) override
{
4593 // Make sure we don't activate using the notify signal from tile manager.
4594 host_impl
->BlockNotifyReadyToActivateForTesting(true);
4597 void DidCommit() override
{ layer_tree_host()->SetVisible(false); }
4599 void DidSetVisibleOnImplTree(LayerTreeHostImpl
* host_impl
,
4600 bool visible
) override
{
4603 // Once invisible, we can go visible again.
4605 PostSetVisibleToMainThread(true);
4607 EXPECT_TRUE(host_impl
->RequiresHighResToDraw());
4612 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4613 ++activation_count_
;
4614 EXPECT_FALSE(visible_
);
4617 void AfterTest() override
{
4618 // Ensure we activated even though the signal was blocked.
4619 EXPECT_EQ(1, activation_count_
);
4620 EXPECT_TRUE(visible_
);
4624 int activation_count_
;
4627 FakeContentLayerClient client_
;
4628 scoped_refptr
<FakePictureLayer
> picture_layer_
;
4631 // TODO(vmpstr): Enable with single thread impl-side painting.
4632 // This test blocks activation which is not supported for single thread mode.
4633 MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestActivateOnInvisible
);
4635 // Do a synchronous composite and assert that the swap promise succeeds.
4636 class LayerTreeHostTestSynchronousCompositeSwapPromise
4637 : public LayerTreeHostTest
{
4639 LayerTreeHostTestSynchronousCompositeSwapPromise() : commit_count_(0) {}
4641 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4642 settings
->single_thread_proxy_scheduler
= false;
4643 settings
->use_zero_copy
= true;
4644 settings
->use_one_copy
= false;
4647 void BeginTest() override
{
4648 // Successful composite.
4649 scoped_ptr
<SwapPromise
> swap_promise0(
4650 new TestSwapPromise(&swap_promise_result_
[0]));
4651 layer_tree_host()->QueueSwapPromise(swap_promise0
.Pass());
4652 layer_tree_host()->Composite(base::TimeTicks::Now());
4654 // Fail to swap (no damage).
4655 scoped_ptr
<SwapPromise
> swap_promise1(
4656 new TestSwapPromise(&swap_promise_result_
[1]));
4657 layer_tree_host()->QueueSwapPromise(swap_promise1
.Pass());
4658 layer_tree_host()->SetNeedsCommit();
4659 layer_tree_host()->Composite(base::TimeTicks::Now());
4661 // Fail to draw (not visible).
4662 scoped_ptr
<SwapPromise
> swap_promise2(
4663 new TestSwapPromise(&swap_promise_result_
[2]));
4664 layer_tree_host()->QueueSwapPromise(swap_promise2
.Pass());
4665 layer_tree_host()->SetNeedsDisplayOnAllLayers();
4666 layer_tree_host()->SetVisible(false);
4667 layer_tree_host()->Composite(base::TimeTicks::Now());
4672 void DidCommit() override
{
4674 ASSERT_LE(commit_count_
, 3);
4677 void AfterTest() override
{
4678 EXPECT_EQ(3, commit_count_
);
4680 // Initial swap promise should have succeded.
4682 base::AutoLock
lock(swap_promise_result_
[0].lock
);
4683 EXPECT_TRUE(swap_promise_result_
[0].did_swap_called
);
4684 EXPECT_FALSE(swap_promise_result_
[0].did_not_swap_called
);
4685 EXPECT_TRUE(swap_promise_result_
[0].dtor_called
);
4688 // Second swap promise fails to swap.
4690 base::AutoLock
lock(swap_promise_result_
[1].lock
);
4691 EXPECT_TRUE(swap_promise_result_
[1].did_activate_called
);
4692 EXPECT_FALSE(swap_promise_result_
[1].did_swap_called
);
4693 EXPECT_TRUE(swap_promise_result_
[1].did_not_swap_called
);
4694 EXPECT_EQ(SwapPromise::SWAP_FAILS
, swap_promise_result_
[1].reason
);
4695 EXPECT_TRUE(swap_promise_result_
[1].dtor_called
);
4698 // Third swap promises also fails to swap (and draw).
4700 base::AutoLock
lock(swap_promise_result_
[2].lock
);
4701 EXPECT_TRUE(swap_promise_result_
[2].did_activate_called
);
4702 EXPECT_FALSE(swap_promise_result_
[2].did_swap_called
);
4703 EXPECT_TRUE(swap_promise_result_
[2].did_not_swap_called
);
4704 EXPECT_EQ(SwapPromise::SWAP_FAILS
, swap_promise_result_
[2].reason
);
4705 EXPECT_TRUE(swap_promise_result_
[2].dtor_called
);
4710 TestSwapPromiseResult swap_promise_result_
[3];
4713 SINGLE_THREAD_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise
);
4715 // Make sure page scale and top control deltas are applied to the client even
4716 // when the LayerTreeHost doesn't have a root layer.
4717 class LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer
4718 : public LayerTreeHostTest
{
4720 LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer()
4721 : deltas_sent_to_client_(false) {}
4723 void BeginTest() override
{
4724 layer_tree_host()->SetRootLayer(nullptr);
4725 info_
.page_scale_delta
= 3.14f
;
4726 info_
.top_controls_delta
= 2.73f
;
4728 PostSetNeedsCommitToMainThread();
4731 void BeginMainFrame(const BeginFrameArgs
& args
) override
{
4732 EXPECT_EQ(nullptr, layer_tree_host()->root_layer());
4734 layer_tree_host()->ApplyScrollAndScale(&info_
);
4738 void ApplyViewportDeltas(const gfx::Vector2dF
& inner
,
4739 const gfx::Vector2dF
& outer
,
4740 const gfx::Vector2dF
& elastic_overscroll_delta
,
4742 float top_controls_delta
) override
{
4743 EXPECT_EQ(info_
.page_scale_delta
, scale_delta
);
4744 EXPECT_EQ(info_
.top_controls_delta
, top_controls_delta
);
4745 deltas_sent_to_client_
= true;
4748 void AfterTest() override
{
4749 EXPECT_TRUE(deltas_sent_to_client_
);
4752 ScrollAndScaleSet info_
;
4753 bool deltas_sent_to_client_
;
4756 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer
);
4758 class LayerTreeHostTestCrispUpAfterPinchEnds
: public LayerTreeHostTest
{
4760 LayerTreeHostTestCrispUpAfterPinchEnds()
4761 : playback_allowed_event_(true, true) {}
4763 void SetupTree() override
{
4766 client_
.set_fill_with_nonsolid_color(true);
4768 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4769 root
->SetBounds(gfx::Size(500, 500));
4771 scoped_refptr
<Layer
> pinch
= Layer::Create(layer_settings());
4772 pinch
->SetBounds(gfx::Size(500, 500));
4773 pinch
->SetScrollClipLayerId(root
->id());
4774 pinch
->SetIsContainerForFixedPositionLayers(true);
4775 root
->AddChild(pinch
);
4777 scoped_ptr
<FakePicturePile
> pile(
4778 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
4779 LayerTreeSettings().default_tile_grid_size
));
4780 pile
->SetPlaybackAllowedEvent(&playback_allowed_event_
);
4781 scoped_refptr
<FakePictureLayer
> layer
=
4782 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
4784 layer
->SetBounds(gfx::Size(500, 500));
4785 layer
->SetContentsOpaque(true);
4786 // Avoid LCD text on the layer so we don't cause extra commits when we
4788 layer
->disable_lcd_text();
4789 pinch
->AddChild(layer
);
4791 layer_tree_host()->RegisterViewportLayers(NULL
, root
, pinch
, pinch
);
4792 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 1.f
, 4.f
);
4793 layer_tree_host()->SetRootLayer(root
);
4794 LayerTreeHostTest::SetupTree();
4797 // Returns the delta scale of all quads in the frame's root pass from their
4798 // ideal, or 0 if they are not all the same.
4799 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData
* frame_data
) {
4800 if (frame_data
->has_no_damage
)
4802 float frame_scale
= 0.f
;
4803 RenderPass
* root_pass
= frame_data
->render_passes
.back();
4804 for (const auto& draw_quad
: root_pass
->quad_list
) {
4805 // Checkerboards mean an incomplete frame.
4806 if (draw_quad
->material
!= DrawQuad::TILED_CONTENT
)
4808 const TileDrawQuad
* quad
= TileDrawQuad::MaterialCast(draw_quad
);
4810 quad
->tex_coord_rect
.width() / static_cast<float>(quad
->rect
.width());
4811 float transform_scale
= SkMScalarToFloat(
4812 quad
->shared_quad_state
->quad_to_target_transform
.matrix().get(0, 0));
4813 float scale
= quad_scale
/ transform_scale
;
4814 if (frame_scale
!= 0.f
&& frame_scale
!= scale
)
4816 frame_scale
= scale
;
4821 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4823 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
4824 LayerTreeHostImpl::FrameData
* frame_data
,
4825 DrawResult draw_result
) override
{
4826 float quad_scale_delta
= FrameQuadScaleDeltaFromIdeal(frame_data
);
4829 // Drew at page scale 1 before any pinching.
4830 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4831 EXPECT_EQ(1.f
, quad_scale_delta
);
4832 PostNextAfterDraw(host_impl
);
4835 if (quad_scale_delta
!= 1.f
)
4837 // Drew at page scale 1.5 after pinching in.
4838 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
4839 EXPECT_EQ(1.f
, quad_scale_delta
);
4840 PostNextAfterDraw(host_impl
);
4843 // By pinching out, we will create a new tiling and raster it. This may
4844 // cause some additional draws, though we should still be drawing with
4845 // the old 1.5 tiling.
4846 if (frame_data
->has_no_damage
)
4848 // Drew at page scale 1 with the 1.5 tiling while pinching out.
4849 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4850 EXPECT_EQ(1.5f
, quad_scale_delta
);
4851 // We don't PostNextAfterDraw here, instead we wait for the new tiling
4852 // to finish rastering so we don't get any noise in further steps.
4855 // Drew at page scale 1 with the 1.5 tiling after pinching out completed
4856 // while waiting for texture uploads to complete.
4857 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4858 // This frame will not have any damage, since it's actually the same as
4859 // the last frame, and should contain no incomplete tiles. We just want
4860 // to make sure we drew here at least once after the pinch ended to be
4861 // sure that drawing after pinch doesn't leave us at the wrong scale
4862 EXPECT_TRUE(frame_data
->has_no_damage
);
4863 PostNextAfterDraw(host_impl
);
4866 if (quad_scale_delta
!= 1.f
)
4868 // Drew at scale 1 after texture uploads are done.
4869 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4870 EXPECT_EQ(1.f
, quad_scale_delta
);
4877 void PostNextAfterDraw(LayerTreeHostImpl
* host_impl
) {
4881 ImplThreadTaskRunner()->PostDelayedTask(
4882 FROM_HERE
, base::Bind(&LayerTreeHostTestCrispUpAfterPinchEnds::Next
,
4883 base::Unretained(this), host_impl
),
4884 // Use a delay to allow raster/upload to happen in between frames. This
4885 // should cause flakiness if we fail to block raster/upload when
4887 base::TimeDelta::FromMilliseconds(16 * 4));
4890 void Next(LayerTreeHostImpl
* host_impl
) {
4896 host_impl
->PinchGestureBegin();
4897 host_impl
->PinchGestureUpdate(1.5f
, gfx::Point(100, 100));
4898 host_impl
->PinchGestureEnd();
4901 // Pinch zoom back to 1.f but don't end it.
4902 host_impl
->PinchGestureBegin();
4903 host_impl
->PinchGestureUpdate(1.f
/ 1.5f
, gfx::Point(100, 100));
4906 // End the pinch, but delay tile production.
4907 playback_allowed_event_
.Reset();
4908 host_impl
->PinchGestureEnd();
4911 // Let tiles complete.
4912 playback_allowed_event_
.Signal();
4917 void NotifyTileStateChangedOnThread(LayerTreeHostImpl
* host_impl
,
4918 const Tile
* tile
) override
{
4920 // On frame 3, we will have a lower res tile complete for the pinch-out
4921 // gesture even though it's not displayed. We wait for it here to prevent
4923 EXPECT_EQ(0.75f
, tile
->contents_scale());
4924 PostNextAfterDraw(host_impl
);
4926 // On frame_ == 4, we are preventing texture uploads from completing,
4927 // so this verifies they are not completing before frame_ == 5.
4928 // Flaky failures here indicate we're failing to prevent uploads from
4930 EXPECT_NE(4, frame_
) << tile
->contents_scale();
4933 void AfterTest() override
{}
4935 FakeContentLayerClient client_
;
4938 base::WaitableEvent playback_allowed_event_
;
4941 // This test does pinching on the impl side which is not supported in single
4943 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds
);
4945 class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy
4946 : public LayerTreeHostTestCrispUpAfterPinchEnds
{
4948 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4949 settings
->use_one_copy
= true;
4952 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
4953 scoped_ptr
<TestWebGraphicsContext3D
> context3d
=
4954 TestWebGraphicsContext3D::Create();
4955 context3d
->set_support_image(true);
4956 context3d
->set_support_sync_query(true);
4957 #if defined(OS_MACOSX)
4958 context3d
->set_support_texture_rectangle(true);
4961 if (delegating_renderer())
4962 return FakeOutputSurface::CreateDelegating3d(context3d
.Pass());
4964 return FakeOutputSurface::Create3d(context3d
.Pass());
4968 // This test does pinching on the impl side which is not supported in single
4970 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy
);
4972 class RasterizeWithGpuRasterizationCreatesResources
: public LayerTreeHostTest
{
4974 RasterizeWithGpuRasterizationCreatesResources() {}
4976 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4977 settings
->gpu_rasterization_forced
= true;
4980 void SetupTree() override
{
4981 client_
.set_fill_with_nonsolid_color(true);
4983 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4984 root
->SetBounds(gfx::Size(500, 500));
4986 scoped_ptr
<FakePicturePile
> pile(
4987 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
4988 LayerTreeSettings().default_tile_grid_size
));
4989 scoped_refptr
<FakePictureLayer
> layer
=
4990 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
4992 layer
->SetBounds(gfx::Size(500, 500));
4993 layer
->SetContentsOpaque(true);
4994 root
->AddChild(layer
);
4996 layer_tree_host()->SetRootLayer(root
);
4997 LayerTreeHostTest::SetupTree();
5000 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5002 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5003 LayerTreeHostImpl::FrameData
* frame_data
,
5004 DrawResult draw_result
) override
{
5005 EXPECT_NE(0u, host_impl
->resource_provider()->num_resources());
5009 void AfterTest() override
{}
5011 FakeContentLayerClient client_
;
5014 SINGLE_AND_MULTI_THREAD_TEST_F(RasterizeWithGpuRasterizationCreatesResources
);
5016 class GpuRasterizationRasterizesBorderTiles
: public LayerTreeHostTest
{
5018 GpuRasterizationRasterizesBorderTiles() : viewport_size_(1024, 2048) {}
5020 void InitializeSettings(LayerTreeSettings
* settings
) override
{
5021 settings
->gpu_rasterization_enabled
= true;
5022 settings
->gpu_rasterization_forced
= true;
5025 void SetupTree() override
{
5026 client_
.set_fill_with_nonsolid_color(true);
5028 scoped_ptr
<FakePicturePile
> pile(
5029 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
5030 LayerTreeSettings().default_tile_grid_size
));
5031 scoped_refptr
<FakePictureLayer
> root
=
5032 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
5034 root
->SetBounds(gfx::Size(10000, 10000));
5035 root
->SetContentsOpaque(true);
5037 layer_tree_host()->SetRootLayer(root
);
5038 LayerTreeHostTest::SetupTree();
5039 layer_tree_host()->SetViewportSize(viewport_size_
);
5042 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5044 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5045 LayerTreeHostImpl::FrameData
* frame_data
,
5046 DrawResult draw_result
) override
{
5047 EXPECT_EQ(10u, host_impl
->resource_provider()->num_resources());
5052 void AfterTest() override
{}
5055 FakeContentLayerClient client_
;
5056 gfx::Size viewport_size_
;
5059 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationRasterizesBorderTiles
);
5061 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
5062 : public LayerTreeHostTest
{
5064 LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles()
5065 : playback_allowed_event_(true, true) {}
5067 void SetupTree() override
{
5069 continuous_draws_
= 0;
5070 client_
.set_fill_with_nonsolid_color(true);
5072 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5073 root
->SetBounds(gfx::Size(500, 500));
5075 scoped_refptr
<Layer
> pinch
= Layer::Create(layer_settings());
5076 pinch
->SetBounds(gfx::Size(500, 500));
5077 pinch
->SetScrollClipLayerId(root
->id());
5078 pinch
->SetIsContainerForFixedPositionLayers(true);
5079 root
->AddChild(pinch
);
5081 scoped_ptr
<FakePicturePile
> pile(
5082 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
5083 LayerTreeSettings().default_tile_grid_size
));
5084 pile
->SetPlaybackAllowedEvent(&playback_allowed_event_
);
5085 scoped_refptr
<FakePictureLayer
> layer
=
5086 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
5088 layer
->SetBounds(gfx::Size(500, 500));
5089 layer
->SetContentsOpaque(true);
5090 // Avoid LCD text on the layer so we don't cause extra commits when we
5092 layer
->disable_lcd_text();
5093 pinch
->AddChild(layer
);
5095 layer_tree_host()->RegisterViewportLayers(NULL
, root
, pinch
, pinch
);
5096 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 1.f
, 4.f
);
5097 layer_tree_host()->SetRootLayer(root
);
5098 LayerTreeHostTest::SetupTree();
5101 // Returns the delta scale of all quads in the frame's root pass from their
5102 // ideal, or 0 if they are not all the same.
5103 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData
* frame_data
) {
5104 if (frame_data
->has_no_damage
)
5106 float frame_scale
= 0.f
;
5107 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5108 for (const auto& draw_quad
: root_pass
->quad_list
) {
5109 const TileDrawQuad
* quad
= TileDrawQuad::MaterialCast(draw_quad
);
5111 quad
->tex_coord_rect
.width() / static_cast<float>(quad
->rect
.width());
5112 float transform_scale
= SkMScalarToFloat(
5113 quad
->shared_quad_state
->quad_to_target_transform
.matrix().get(0, 0));
5114 float scale
= quad_scale
/ transform_scale
;
5115 if (frame_scale
!= 0.f
&& frame_scale
!= scale
)
5117 frame_scale
= scale
;
5122 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5124 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5125 LayerTreeHostImpl::FrameData
* frame_data
,
5126 DrawResult draw_result
) override
{
5127 float quad_scale_delta
= FrameQuadScaleDeltaFromIdeal(frame_data
);
5130 // Drew at scale 1 before any pinching.
5131 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
5132 EXPECT_EQ(1.f
, quad_scale_delta
);
5135 if (quad_scale_delta
!= 1.f
/ 1.5f
)
5137 // Drew at scale 1 still though the ideal is 1.5.
5138 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
5139 EXPECT_EQ(1.f
/ 1.5f
, quad_scale_delta
);
5142 // Continuous draws are attempted.
5143 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
5144 if (!frame_data
->has_no_damage
)
5145 EXPECT_EQ(1.f
/ 1.5f
, quad_scale_delta
);
5148 if (quad_scale_delta
!= 1.f
)
5150 // Drew at scale 1.5 when all the tiles completed.
5151 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
5152 EXPECT_EQ(1.f
, quad_scale_delta
);
5155 // TODO(danakj): We get more draws before the NotifyReadyToDraw
5156 // because it is asynchronous from the previous draw and happens late.
5159 // NotifyReadyToDraw happened. If we were already inside a frame, we may
5160 // try to draw once more.
5163 NOTREACHED() << "No draws should happen once we have a complete frame.";
5169 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
5172 // Delay tile production.
5173 playback_allowed_event_
.Reset();
5174 // Pinch zoom in to cause new tiles to be required.
5175 host_impl
->PinchGestureBegin();
5176 host_impl
->PinchGestureUpdate(1.5f
, gfx::Point(100, 100));
5177 host_impl
->PinchGestureEnd();
5184 // We should continue to try draw while there are incomplete visible
5186 if (++continuous_draws_
> 5) {
5187 // Allow the tiles to complete.
5188 playback_allowed_event_
.Signal();
5196 // Waiting for NotifyReadyToDraw.
5199 // NotifyReadyToDraw happened.
5205 void NotifyReadyToDrawOnThread(LayerTreeHostImpl
* host_impl
) override
{
5208 // NotifyReadyToDraw has happened, we may draw once more, but should not
5209 // get any more draws after that. End the test after a timeout to watch
5210 // for any extraneous draws.
5211 // TODO(brianderson): We could remove this delay and instead wait until
5212 // the BeginFrameSource decides it doesn't need to send frames anymore,
5213 // or test that it already doesn't here.
5214 EndTestAfterDelayMs(16 * 4);
5218 void NotifyTileStateChangedOnThread(LayerTreeHostImpl
* host_impl
,
5219 const Tile
* tile
) override
{
5220 // On step_ == 2, we are preventing texture uploads from completing,
5221 // so this verifies they are not completing before step_ == 3.
5222 // Flaky failures here indicate we're failing to prevent uploads from
5224 EXPECT_NE(2, step_
);
5227 void AfterTest() override
{ EXPECT_GT(continuous_draws_
, 5); }
5229 FakeContentLayerClient client_
;
5231 int continuous_draws_
;
5232 base::WaitableEvent playback_allowed_event_
;
5235 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
);
5237 class LayerTreeHostTestOneActivatePerPrepareTiles
: public LayerTreeHostTest
{
5239 LayerTreeHostTestOneActivatePerPrepareTiles()
5240 : notify_ready_to_activate_count_(0u),
5241 scheduled_prepare_tiles_count_(0) {}
5243 void SetupTree() override
{
5244 client_
.set_fill_with_nonsolid_color(true);
5245 scoped_refptr
<FakePictureLayer
> root_layer
=
5246 FakePictureLayer::Create(layer_settings(), &client_
);
5247 root_layer
->SetBounds(gfx::Size(1500, 1500));
5248 root_layer
->SetIsDrawable(true);
5250 layer_tree_host()->SetRootLayer(root_layer
);
5251 LayerTreeHostTest::SetupTree();
5254 void BeginTest() override
{
5255 layer_tree_host()->SetViewportSize(gfx::Size(16, 16));
5256 PostSetNeedsCommitToMainThread();
5259 void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
5260 bool success
) override
{
5261 ASSERT_TRUE(success
);
5262 host_impl
->tile_manager()->SetScheduledRasterTaskLimitForTesting(1);
5265 void NotifyReadyToActivateOnThread(LayerTreeHostImpl
* impl
) override
{
5266 ++notify_ready_to_activate_count_
;
5267 EndTestAfterDelayMs(100);
5270 void ScheduledActionPrepareTiles() override
{
5271 ++scheduled_prepare_tiles_count_
;
5274 void AfterTest() override
{
5275 // Expect at most a notification for each scheduled prepare tiles, plus one
5276 // for the initial commit (which doesn't go through scheduled actions).
5277 // The reason this is not an equality is because depending on timing, we
5278 // might get a prepare tiles but not yet get a notification that we're
5279 // ready to activate. The intent of a test is to ensure that we don't
5280 // get more than one notification per prepare tiles, so this is OK.
5281 EXPECT_LE(notify_ready_to_activate_count_
,
5282 1u + scheduled_prepare_tiles_count_
);
5286 FakeContentLayerClient client_
;
5287 size_t notify_ready_to_activate_count_
;
5288 size_t scheduled_prepare_tiles_count_
;
5291 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestOneActivatePerPrepareTiles
);
5293 class LayerTreeHostTestFrameTimingRequestsSaveTimestamps
5294 : public LayerTreeHostTest
{
5296 LayerTreeHostTestFrameTimingRequestsSaveTimestamps()
5297 : check_results_on_commit_(false) {}
5299 void SetupTree() override
{
5300 scoped_refptr
<FakePictureLayer
> root_layer
=
5301 FakePictureLayer::Create(layer_settings(), &client_
);
5302 root_layer
->SetBounds(gfx::Size(200, 200));
5303 root_layer
->SetIsDrawable(true);
5305 scoped_refptr
<FakePictureLayer
> child_layer
=
5306 FakePictureLayer::Create(layer_settings(), &client_
);
5307 child_layer
->SetBounds(gfx::Size(1500, 1500));
5308 child_layer
->SetIsDrawable(true);
5310 std::vector
<FrameTimingRequest
> requests
;
5311 requests
.push_back(FrameTimingRequest(1, gfx::Rect(0, 0, 100, 100)));
5312 requests
.push_back(FrameTimingRequest(2, gfx::Rect(300, 0, 100, 100)));
5313 child_layer
->SetFrameTimingRequests(requests
);
5315 root_layer
->AddChild(child_layer
);
5316 layer_tree_host()->SetRootLayer(root_layer
);
5317 LayerTreeHostTest::SetupTree();
5320 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5322 void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) override
{
5323 if (!check_results_on_commit_
)
5326 // Since in reality, the events will be read by LayerTreeHost during commit,
5327 // we check the requests here to ensure that they are correct at the next
5328 // commit time (as opposed to checking in DrawLayers for instance).
5329 // TODO(vmpstr): Change this to read things from the main thread when this
5330 // information is propagated to the main thread (not yet implemented).
5331 FrameTimingTracker
* tracker
= host_impl
->frame_timing_tracker();
5333 // Check composite events.
5335 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> timing_set
=
5336 tracker
->GroupCompositeCountsByRectId();
5337 EXPECT_EQ(1u, timing_set
->size());
5338 auto rect_1_it
= timing_set
->find(1);
5339 EXPECT_TRUE(rect_1_it
!= timing_set
->end());
5340 const auto& timing_events
= rect_1_it
->second
;
5341 EXPECT_EQ(1u, timing_events
.size());
5342 EXPECT_EQ(host_impl
->active_tree()->source_frame_number(),
5343 timing_events
[0].frame_id
);
5344 EXPECT_GT(timing_events
[0].timestamp
, base::TimeTicks());
5347 // Check main frame events.
5349 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> timing_set
=
5350 tracker
->GroupMainFrameCountsByRectId();
5351 EXPECT_EQ(2u, timing_set
->size());
5352 auto rect_1_it
= timing_set
->find(1);
5353 EXPECT_TRUE(rect_1_it
!= timing_set
->end());
5354 const auto& timing_events
= rect_1_it
->second
;
5355 EXPECT_EQ(1u, timing_events
.size());
5356 EXPECT_EQ(host_impl
->active_tree()->source_frame_number(),
5357 timing_events
[0].frame_id
);
5358 EXPECT_GT(timing_events
[0].timestamp
, base::TimeTicks());
5359 EXPECT_GT(timing_events
[0].end_time
, timing_events
[0].timestamp
);
5365 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
5366 check_results_on_commit_
= true;
5367 PostSetNeedsCommitToMainThread();
5370 void AfterTest() override
{}
5373 FakeContentLayerClient client_
;
5374 bool check_results_on_commit_
;
5377 // Frame timing is not implemented in single thread proxy.
5378 MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimingRequestsSaveTimestamps
);
5380 class LayerTreeHostTestActivationCausesPrepareTiles
: public LayerTreeHostTest
{
5382 LayerTreeHostTestActivationCausesPrepareTiles()
5383 : scheduled_prepare_tiles_count_(0) {}
5385 void SetupTree() override
{
5386 client_
.set_fill_with_nonsolid_color(true);
5387 scoped_refptr
<FakePictureLayer
> root_layer
=
5388 FakePictureLayer::Create(layer_settings(), &client_
);
5389 root_layer
->SetBounds(gfx::Size(150, 150));
5390 root_layer
->SetIsDrawable(true);
5392 layer_tree_host()->SetRootLayer(root_layer
);
5393 LayerTreeHostTest::SetupTree();
5396 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5398 void NotifyReadyToActivateOnThread(LayerTreeHostImpl
* impl
) override
{
5399 // Ensure we've already activated.
5400 EXPECT_FALSE(impl
->pending_tree());
5402 // After activating, we either need to prepare tiles, or we've already
5403 // called a scheduled prepare tiles. This is done because activation might
5404 // cause us to have to memory available (old active tree is gone), so we
5405 // need to ensure we will get a PrepareTiles call.
5406 if (!impl
->prepare_tiles_needed())
5407 EXPECT_GE(scheduled_prepare_tiles_count_
, 1);
5411 void ScheduledActionPrepareTiles() override
{
5412 ++scheduled_prepare_tiles_count_
;
5415 void AfterTest() override
{}
5418 FakeContentLayerClient client_
;
5419 int scheduled_prepare_tiles_count_
;
5422 // This test is testing activation from a pending tree and doesn't make sense
5423 // with single thread commit-to-active.
5424 MULTI_THREAD_TEST_F(LayerTreeHostTestActivationCausesPrepareTiles
);
5426 // This tests an assertion that DidCommit and WillCommit happen in the same
5427 // stack frame with no tasks that run between them. Various embedders of
5428 // cc depend on this logic. ui::Compositor holds a compositor lock between
5429 // these events and the inspector timeline wants begin/end CompositeLayers
5430 // to be properly nested with other begin/end events.
5431 class LayerTreeHostTestNoTasksBetweenWillAndDidCommit
5432 : public LayerTreeHostTest
{
5434 LayerTreeHostTestNoTasksBetweenWillAndDidCommit() : did_commit_(false) {}
5436 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5438 void WillCommit() override
{
5439 MainThreadTaskRunner()->PostTask(
5440 FROM_HERE
, base::Bind(&LayerTreeHostTestNoTasksBetweenWillAndDidCommit::
5441 EndTestShouldRunAfterDidCommit
,
5442 base::Unretained(this)));
5445 void EndTestShouldRunAfterDidCommit() {
5446 EXPECT_TRUE(did_commit_
);
5450 void DidCommit() override
{
5451 EXPECT_FALSE(did_commit_
);
5455 void AfterTest() override
{ EXPECT_TRUE(did_commit_
); }
5461 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit
);
5463 class LayerTreeHostTestUpdateCopyRequests
: public LayerTreeHostTest
{
5465 void SetupTree() override
{
5466 root
= Layer::Create(layer_settings());
5467 child
= Layer::Create(layer_settings());
5468 root
->AddChild(child
);
5469 layer_tree_host()->SetRootLayer(root
);
5470 LayerTreeHostTest::SetupTree();
5473 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
5475 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5477 void DidCommit() override
{
5478 switch (layer_tree_host()->source_frame_number()) {
5480 child
->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
5481 base::Bind(CopyOutputCallback
)));
5483 root
->draw_properties().layer_or_descendant_has_copy_request
);
5487 root
->draw_properties().layer_or_descendant_has_copy_request
);
5493 void AfterTest() override
{}
5496 scoped_refptr
<Layer
> root
;
5497 scoped_refptr
<Layer
> child
;
5500 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateCopyRequests
);
5502 class LayerTreeTestMaskLayerForSurfaceWithClippedLayer
: public LayerTreeTest
{
5504 void SetupTree() override
{
5505 // The masked layer has bounds 50x50, but it has a child that causes
5506 // the surface bounds to be larger. It also has a parent that clips the
5507 // masked layer and its surface.
5509 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5511 scoped_refptr
<Layer
> clipping_layer
= Layer::Create(layer_settings());
5512 root
->AddChild(clipping_layer
);
5514 scoped_refptr
<FakePictureLayer
> content_layer
=
5515 FakePictureLayer::Create(layer_settings(), &client_
);
5516 clipping_layer
->AddChild(content_layer
);
5518 scoped_refptr
<FakePictureLayer
> content_child_layer
=
5519 FakePictureLayer::Create(layer_settings(), &client_
);
5520 content_layer
->AddChild(content_child_layer
);
5522 scoped_refptr
<FakePictureLayer
> mask_layer
=
5523 FakePictureLayer::Create(layer_settings(), &client_
);
5524 content_layer
->SetMaskLayer(mask_layer
.get());
5526 gfx::Size
root_size(100, 100);
5527 root
->SetBounds(root_size
);
5529 gfx::Rect
clipping_rect(20, 10, 10, 20);
5530 clipping_layer
->SetBounds(clipping_rect
.size());
5531 clipping_layer
->SetPosition(clipping_rect
.origin());
5532 clipping_layer
->SetMasksToBounds(true);
5534 gfx::Size
layer_size(50, 50);
5535 content_layer
->SetBounds(layer_size
);
5536 content_layer
->SetPosition(gfx::Point() - clipping_rect
.OffsetFromOrigin());
5538 gfx::Size
child_size(50, 50);
5539 content_child_layer
->SetBounds(child_size
);
5540 content_child_layer
->SetPosition(gfx::Point(20, 0));
5542 gfx::Size
mask_size(100, 100);
5543 mask_layer
->SetBounds(mask_size
);
5544 mask_layer
->SetIsMask(true);
5546 layer_tree_host()->SetRootLayer(root
);
5547 LayerTreeTest::SetupTree();
5550 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5552 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5553 LayerTreeHostImpl::FrameData
* frame_data
,
5554 DrawResult draw_result
) override
{
5555 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5556 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5557 EXPECT_EQ(2u, root_pass
->quad_list
.size());
5559 // There's a solid color quad under everything.
5560 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5562 // The surface is clipped to 10x20.
5563 EXPECT_EQ(DrawQuad::RENDER_PASS
, root_pass
->quad_list
.front()->material
);
5564 const RenderPassDrawQuad
* render_pass_quad
=
5565 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.front());
5566 EXPECT_EQ(gfx::Rect(20, 10, 10, 20).ToString(),
5567 render_pass_quad
->rect
.ToString());
5568 // The masked layer is 50x50, but the surface size is 10x20. So the texture
5569 // coords in the mask are scaled by 10/50 and 20/50.
5570 // The surface is clipped to (20,10) so the mask texture coords are offset
5571 // by 20/50 and 10/50
5572 EXPECT_EQ(gfx::ScaleRect(gfx::RectF(20.f
, 10.f
, 10.f
, 20.f
), 1.f
/ 50.f
)
5574 render_pass_quad
->MaskUVRect().ToString());
5575 EXPECT_EQ(gfx::Vector2dF(10.f
/ 50.f
, 20.f
/ 50.f
).ToString(),
5576 render_pass_quad
->mask_uv_scale
.ToString());
5581 void AfterTest() override
{}
5583 FakeContentLayerClient client_
;
5586 SINGLE_AND_MULTI_THREAD_TEST_F(
5587 LayerTreeTestMaskLayerForSurfaceWithClippedLayer
);
5589 class LayerTreeTestMaskLayerWithScaling
: public LayerTreeTest
{
5591 void InitializeSettings(LayerTreeSettings
* settings
) override
{
5592 settings
->layer_transforms_should_scale_layer_contents
= true;
5595 void SetupTree() override
{
5598 // +-- Scaling Layer (adds a 2x scale)
5600 // +-- Content Layer
5603 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5605 scoped_refptr
<Layer
> scaling_layer
= Layer::Create(layer_settings());
5606 root
->AddChild(scaling_layer
);
5608 scoped_refptr
<FakePictureLayer
> content_layer
=
5609 FakePictureLayer::Create(layer_settings(), &client_
);
5610 scaling_layer
->AddChild(content_layer
);
5612 scoped_refptr
<FakePictureLayer
> mask_layer
=
5613 FakePictureLayer::Create(layer_settings(), &client_
);
5614 content_layer
->SetMaskLayer(mask_layer
.get());
5616 gfx::Size
root_size(100, 100);
5617 root
->SetBounds(root_size
);
5619 gfx::Size
scaling_layer_size(50, 50);
5620 scaling_layer
->SetBounds(scaling_layer_size
);
5621 gfx::Transform scale
;
5622 scale
.Scale(2.f
, 2.f
);
5623 scaling_layer
->SetTransform(scale
);
5625 content_layer
->SetBounds(scaling_layer_size
);
5627 mask_layer
->SetBounds(scaling_layer_size
);
5628 mask_layer
->SetIsMask(true);
5630 layer_tree_host()->SetRootLayer(root
);
5631 LayerTreeTest::SetupTree();
5634 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5636 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5637 LayerTreeHostImpl::FrameData
* frame_data
,
5638 DrawResult draw_result
) override
{
5639 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5640 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5641 EXPECT_EQ(2u, root_pass
->quad_list
.size());
5643 // There's a solid color quad under everything.
5644 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5646 EXPECT_EQ(DrawQuad::RENDER_PASS
, root_pass
->quad_list
.front()->material
);
5647 const RenderPassDrawQuad
* render_pass_quad
=
5648 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.front());
5649 switch (host_impl
->active_tree()->source_frame_number()) {
5651 // Check that the tree scaling is correctly taken into account for the
5652 // mask, that should fully map onto the quad.
5653 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5654 render_pass_quad
->rect
.ToString());
5655 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5656 render_pass_quad
->MaskUVRect().ToString());
5657 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5658 render_pass_quad
->mask_uv_scale
.ToString());
5661 // Applying a DSF should change the render surface size, but won't
5662 // affect which part of the mask is used.
5663 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
5664 render_pass_quad
->rect
.ToString());
5665 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5666 render_pass_quad
->MaskUVRect().ToString());
5667 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5668 render_pass_quad
->mask_uv_scale
.ToString());
5675 void DidCommit() override
{
5676 switch (layer_tree_host()->source_frame_number()) {
5678 gfx::Size
double_root_size(200, 200);
5679 layer_tree_host()->SetViewportSize(double_root_size
);
5680 layer_tree_host()->SetDeviceScaleFactor(2.f
);
5685 void AfterTest() override
{}
5687 FakeContentLayerClient client_
;
5690 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskLayerWithScaling
);
5692 class LayerTreeTestMaskLayerWithDifferentBounds
: public LayerTreeTest
{
5694 void SetupTree() override
{
5695 // The mask layer has bounds 100x100 but is attached to a layer with bounds
5698 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5700 scoped_refptr
<FakePictureLayer
> content_layer
=
5701 FakePictureLayer::Create(layer_settings(), &client_
);
5702 root
->AddChild(content_layer
);
5704 scoped_refptr
<FakePictureLayer
> mask_layer
=
5705 FakePictureLayer::Create(layer_settings(), &client_
);
5706 content_layer
->SetMaskLayer(mask_layer
.get());
5708 gfx::Size
root_size(100, 100);
5709 root
->SetBounds(root_size
);
5711 gfx::Size
layer_size(50, 50);
5712 content_layer
->SetBounds(layer_size
);
5714 gfx::Size
mask_size(100, 100);
5715 mask_layer
->SetBounds(mask_size
);
5716 mask_layer
->SetIsMask(true);
5718 layer_tree_host()->SetRootLayer(root
);
5719 LayerTreeTest::SetupTree();
5722 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5724 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5725 LayerTreeHostImpl::FrameData
* frame_data
,
5726 DrawResult draw_result
) override
{
5727 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5728 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5729 EXPECT_EQ(2u, root_pass
->quad_list
.size());
5731 // There's a solid color quad under everything.
5732 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5734 EXPECT_EQ(DrawQuad::RENDER_PASS
, root_pass
->quad_list
.front()->material
);
5735 const RenderPassDrawQuad
* render_pass_quad
=
5736 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.front());
5737 switch (host_impl
->active_tree()->source_frame_number()) {
5739 // Check that the mask fills the surface.
5740 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
5741 render_pass_quad
->rect
.ToString());
5742 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5743 render_pass_quad
->MaskUVRect().ToString());
5744 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5745 render_pass_quad
->mask_uv_scale
.ToString());
5748 // Applying a DSF should change the render surface size, but won't
5749 // affect which part of the mask is used.
5750 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5751 render_pass_quad
->rect
.ToString());
5752 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5753 render_pass_quad
->MaskUVRect().ToString());
5754 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5755 render_pass_quad
->mask_uv_scale
.ToString());
5762 void DidCommit() override
{
5763 switch (layer_tree_host()->source_frame_number()) {
5765 gfx::Size
double_root_size(200, 200);
5766 layer_tree_host()->SetViewportSize(double_root_size
);
5767 layer_tree_host()->SetDeviceScaleFactor(2.f
);
5772 void AfterTest() override
{}
5774 FakeContentLayerClient client_
;
5777 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskLayerWithDifferentBounds
);
5779 class LayerTreeTestReflectionMaskLayerWithDifferentBounds
5780 : public LayerTreeTest
{
5782 void SetupTree() override
{
5783 // The replica's mask layer has bounds 100x100 but the replica is of a
5784 // layer with bounds 50x50.
5786 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5788 scoped_refptr
<FakePictureLayer
> content_layer
=
5789 FakePictureLayer::Create(layer_settings(), &client_
);
5790 root
->AddChild(content_layer
);
5792 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
5793 content_layer
->SetReplicaLayer(replica_layer
.get());
5795 scoped_refptr
<FakePictureLayer
> mask_layer
=
5796 FakePictureLayer::Create(layer_settings(), &client_
);
5797 replica_layer
->SetMaskLayer(mask_layer
.get());
5799 gfx::Size
root_size(100, 100);
5800 root
->SetBounds(root_size
);
5802 gfx::Size
layer_size(50, 50);
5803 content_layer
->SetBounds(layer_size
);
5805 gfx::Size
mask_size(100, 100);
5806 mask_layer
->SetBounds(mask_size
);
5807 mask_layer
->SetIsMask(true);
5809 layer_tree_host()->SetRootLayer(root
);
5810 LayerTreeTest::SetupTree();
5813 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5815 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5816 LayerTreeHostImpl::FrameData
* frame_data
,
5817 DrawResult draw_result
) override
{
5818 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5819 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5820 EXPECT_EQ(3u, root_pass
->quad_list
.size());
5822 // There's a solid color quad under everything.
5823 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5825 EXPECT_EQ(DrawQuad::RENDER_PASS
,
5826 root_pass
->quad_list
.ElementAt(1)->material
);
5827 const RenderPassDrawQuad
* render_pass_quad
=
5828 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.ElementAt(1));
5829 switch (host_impl
->active_tree()->source_frame_number()) {
5831 // Check that the mask fills the surface.
5832 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
5833 render_pass_quad
->rect
.ToString());
5834 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5835 render_pass_quad
->MaskUVRect().ToString());
5836 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5837 render_pass_quad
->mask_uv_scale
.ToString());
5840 // Applying a DSF should change the render surface size, but won't
5841 // affect which part of the mask is used.
5842 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5843 render_pass_quad
->rect
.ToString());
5844 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5845 render_pass_quad
->MaskUVRect().ToString());
5846 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5847 render_pass_quad
->mask_uv_scale
.ToString());
5854 void DidCommit() override
{
5855 switch (layer_tree_host()->source_frame_number()) {
5857 gfx::Size
double_root_size(200, 200);
5858 layer_tree_host()->SetViewportSize(double_root_size
);
5859 layer_tree_host()->SetDeviceScaleFactor(2.f
);
5864 void AfterTest() override
{}
5866 FakeContentLayerClient client_
;
5869 SINGLE_AND_MULTI_THREAD_TEST_F(
5870 LayerTreeTestReflectionMaskLayerWithDifferentBounds
);
5872 class LayerTreeTestReflectionMaskLayerForSurfaceWithUnclippedChild
5873 : public LayerTreeTest
{
5875 void SetupTree() override
{
5876 // The replica is of a layer with bounds 50x50, but it has a child that
5877 // causes the surface bounds to be larger.
5879 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5881 scoped_refptr
<FakePictureLayer
> content_layer
=
5882 FakePictureLayer::Create(layer_settings(), &client_
);
5883 root
->AddChild(content_layer
);
5885 content_child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
5886 content_layer
->AddChild(content_child_layer_
);
5888 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
5889 content_layer
->SetReplicaLayer(replica_layer
.get());
5891 scoped_refptr
<FakePictureLayer
> mask_layer
=
5892 FakePictureLayer::Create(layer_settings(), &client_
);
5893 replica_layer
->SetMaskLayer(mask_layer
.get());
5895 gfx::Size
root_size(100, 100);
5896 root
->SetBounds(root_size
);
5898 gfx::Size
layer_size(50, 50);
5899 content_layer
->SetBounds(layer_size
);
5900 content_child_layer_
->SetBounds(layer_size
);
5901 content_child_layer_
->SetPosition(gfx::PointF(50.f
, 0.f
));
5903 gfx::Size
mask_size(100, 100);
5904 mask_layer
->SetBounds(mask_size
);
5905 mask_layer
->SetIsMask(true);
5907 layer_tree_host()->SetRootLayer(root
);
5908 LayerTreeTest::SetupTree();
5911 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5913 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5914 LayerTreeHostImpl::FrameData
* frame_data
,
5915 DrawResult draw_result
) override
{
5916 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5917 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5918 EXPECT_EQ(3u, root_pass
->quad_list
.size());
5920 // There's a solid color quad under everything.
5921 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5923 EXPECT_EQ(DrawQuad::RENDER_PASS
,
5924 root_pass
->quad_list
.ElementAt(1)->material
);
5925 const RenderPassDrawQuad
* replica_quad
=
5926 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.ElementAt(1));
5927 switch (host_impl
->active_tree()->source_frame_number()) {
5929 // The surface is 100x50.
5930 // The mask covers the owning layer only.
5931 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
5932 replica_quad
->rect
.ToString());
5933 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 2.f
, 1.f
).ToString(),
5934 replica_quad
->MaskUVRect().ToString());
5935 EXPECT_EQ(gfx::Vector2dF(2.f
, 1.f
).ToString(),
5936 replica_quad
->mask_uv_scale
.ToString());
5939 // The surface is 100x50 with its origin at (-50, 0).
5940 // The mask covers the owning layer only.
5941 EXPECT_EQ(gfx::Rect(-50, 0, 100, 50).ToString(),
5942 replica_quad
->rect
.ToString());
5943 EXPECT_EQ(gfx::RectF(-1.f
, 0.f
, 2.f
, 1.f
).ToString(),
5944 replica_quad
->MaskUVRect().ToString());
5945 EXPECT_EQ(gfx::Vector2dF(2.f
, 1.f
).ToString(),
5946 replica_quad
->mask_uv_scale
.ToString());
5953 void DidCommit() override
{
5954 switch (layer_tree_host()->source_frame_number()) {
5956 // Move the child to (-50, 0) instead. Now the mask should be moved to
5957 // still cover the layer being replicated.
5958 content_child_layer_
->SetPosition(gfx::PointF(-50.f
, 0.f
));
5963 void AfterTest() override
{}
5965 scoped_refptr
<FakePictureLayer
> content_child_layer_
;
5966 FakeContentLayerClient client_
;
5969 SINGLE_AND_MULTI_THREAD_TEST_F(
5970 LayerTreeTestReflectionMaskLayerForSurfaceWithUnclippedChild
);
5972 class LayerTreeTestPageScaleFlags
: public LayerTreeTest
{
5974 void SetupTree() override
{
5978 // -page scale child1
5979 // -page scale grandchild
5980 // -page scale child2
5983 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5984 scoped_refptr
<Layer
> pre_page_scale
= Layer::Create(layer_settings());
5985 scoped_refptr
<Layer
> page_scale
= Layer::Create(layer_settings());
5986 scoped_refptr
<Layer
> page_scale_child1
= Layer::Create(layer_settings());
5987 scoped_refptr
<Layer
> page_scale_grandchild
=
5988 Layer::Create(layer_settings());
5989 scoped_refptr
<Layer
> page_scale_child2
= Layer::Create(layer_settings());
5990 scoped_refptr
<Layer
> post_page_scale
= Layer::Create(layer_settings());
5992 root
->AddChild(pre_page_scale
);
5993 root
->AddChild(page_scale
);
5994 root
->AddChild(post_page_scale
);
5996 page_scale
->AddChild(page_scale_child1
);
5997 page_scale
->AddChild(page_scale_child2
);
5998 page_scale_child1
->AddChild(page_scale_grandchild
);
6000 layer_tree_host()->SetRootLayer(root
);
6001 LayerTreeTest::SetupTree();
6003 scoped_refptr
<Layer
> overscroll_elasticity_layer
= nullptr;
6004 scoped_refptr
<Layer
> inner_viewport_scroll_layer
= nullptr;
6005 scoped_refptr
<Layer
> outer_viewport_scroll_layer
= nullptr;
6006 layer_tree_host()->RegisterViewportLayers(
6007 overscroll_elasticity_layer
, page_scale
, inner_viewport_scroll_layer
,
6008 outer_viewport_scroll_layer
);
6010 affected_by_page_scale_
.push_back(page_scale
->id());
6011 affected_by_page_scale_
.push_back(page_scale_child1
->id());
6012 affected_by_page_scale_
.push_back(page_scale_child2
->id());
6013 affected_by_page_scale_
.push_back(page_scale_grandchild
->id());
6015 not_affected_by_page_scale_
.push_back(root
->id());
6016 not_affected_by_page_scale_
.push_back(pre_page_scale
->id());
6017 not_affected_by_page_scale_
.push_back(post_page_scale
->id());
6020 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
6022 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
6023 LayerTreeHostCommon::CallFunctionForSubtree(
6024 host_impl
->sync_tree()->root_layer(), [this](LayerImpl
* layer
) {
6025 const std::vector
<int>& list
=
6026 layer
->IsAffectedByPageScale()
6027 ? this->affected_by_page_scale_
6028 : this->not_affected_by_page_scale_
;
6029 EXPECT_TRUE(std::find(list
.begin(), list
.end(), layer
->id()) !=
6036 void AfterTest() override
{}
6038 std::vector
<int> affected_by_page_scale_
;
6039 std::vector
<int> not_affected_by_page_scale_
;
6042 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags
);