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/playback/display_item_list_settings.h"
30 #include "cc/quads/draw_quad.h"
31 #include "cc/quads/io_surface_draw_quad.h"
32 #include "cc/quads/render_pass_draw_quad.h"
33 #include "cc/quads/tile_draw_quad.h"
34 #include "cc/test/fake_content_layer_client.h"
35 #include "cc/test/fake_display_list_recording_source.h"
36 #include "cc/test/fake_layer_tree_host_client.h"
37 #include "cc/test/fake_output_surface.h"
38 #include "cc/test/fake_painted_scrollbar_layer.h"
39 #include "cc/test/fake_picture_layer.h"
40 #include "cc/test/fake_picture_layer_impl.h"
41 #include "cc/test/fake_picture_pile.h"
42 #include "cc/test/fake_proxy.h"
43 #include "cc/test/fake_scoped_ui_resource.h"
44 #include "cc/test/fake_video_frame_provider.h"
45 #include "cc/test/geometry_test_utils.h"
46 #include "cc/test/layer_tree_test.h"
47 #include "cc/test/test_shared_bitmap_manager.h"
48 #include "cc/test/test_web_graphics_context_3d.h"
49 #include "cc/trees/layer_tree_host_impl.h"
50 #include "cc/trees/layer_tree_impl.h"
51 #include "cc/trees/single_thread_proxy.h"
52 #include "cc/trees/thread_proxy.h"
53 #include "gpu/GLES2/gl2extchromium.h"
54 #include "skia/ext/refptr.h"
55 #include "testing/gmock/include/gmock/gmock.h"
56 #include "third_party/khronos/GLES2/gl2.h"
57 #include "third_party/khronos/GLES2/gl2ext.h"
58 #include "third_party/skia/include/core/SkPicture.h"
59 #include "ui/gfx/geometry/point_conversions.h"
60 #include "ui/gfx/geometry/size_conversions.h"
61 #include "ui/gfx/geometry/vector2d_conversions.h"
64 using testing::AnyNumber
;
65 using testing::AtLeast
;
71 class LayerTreeHostTest
: public LayerTreeTest
{};
73 class LayerTreeHostTestHasImplThreadTest
: public LayerTreeHostTest
{
75 LayerTreeHostTestHasImplThreadTest() : threaded_(false) {}
77 void RunTest(bool threaded
, bool delegating_renderer
) override
{
79 LayerTreeHostTest::RunTest(threaded
, delegating_renderer
);
82 void BeginTest() override
{
83 EXPECT_EQ(threaded_
, HasImplThread());
87 void AfterTest() override
{ EXPECT_EQ(threaded_
, HasImplThread()); }
93 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHasImplThreadTest
);
95 class LayerTreeHostTestSetNeedsCommitInsideLayout
: public LayerTreeHostTest
{
97 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
99 void Layout() override
{
100 // This shouldn't cause a second commit to happen.
101 layer_tree_host()->SetNeedsCommit();
104 void DidCommit() override
{
105 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
109 void AfterTest() override
{}
112 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommitInsideLayout
);
114 class LayerTreeHostTestFrameOrdering
: public LayerTreeHostTest
{
116 enum MainOrder
: int {
119 MAIN_COMMIT_COMPLETE
,
120 MAIN_DID_BEGIN_FRAME
,
124 enum ImplOrder
: int {
127 IMPL_COMMIT_COMPLETE
,
134 template <typename T
>
135 bool CheckStep(T next
, T
* var
) {
136 int expected
= next
- 1;
137 EXPECT_EQ(expected
, *var
);
138 bool correct
= expected
== *var
;
143 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
145 void Layout() override
{ EXPECT_TRUE(CheckStep(MAIN_LAYOUT
, &main_
)); }
147 void DidCommit() override
{
148 EXPECT_TRUE(CheckStep(MAIN_COMMIT_COMPLETE
, &main_
));
151 void DidBeginMainFrame() override
{
152 EXPECT_TRUE(CheckStep(MAIN_DID_BEGIN_FRAME
, &main_
));
155 void BeginCommitOnThread(LayerTreeHostImpl
* impl
) override
{
156 EXPECT_TRUE(CheckStep(IMPL_COMMIT
, &impl_
));
159 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
160 EXPECT_TRUE(CheckStep(IMPL_COMMIT_COMPLETE
, &impl_
));
163 void WillActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
164 EXPECT_TRUE(CheckStep(IMPL_ACTIVATE
, &impl_
));
167 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
168 EXPECT_TRUE(CheckStep(IMPL_DRAW
, &impl_
));
171 void SwapBuffersCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
172 EXPECT_TRUE(CheckStep(IMPL_SWAP
, &impl_
));
177 void AfterTest() override
{
178 EXPECT_TRUE(CheckStep(MAIN_END
, &main_
));
179 EXPECT_TRUE(CheckStep(IMPL_END
, &impl_
));
182 MainOrder main_
= MAIN_START
;
183 ImplOrder impl_
= IMPL_START
;
186 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameOrdering
);
188 class LayerTreeHostTestSetNeedsUpdateInsideLayout
: public LayerTreeHostTest
{
190 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
192 void Layout() override
{
193 // This shouldn't cause a second commit to happen.
194 layer_tree_host()->SetNeedsUpdateLayers();
197 void DidCommit() override
{
198 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
202 void AfterTest() override
{}
205 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsUpdateInsideLayout
);
207 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
208 // when no raster tasks get scheduled.
209 class LayerTreeHostTestReadyToActivateEmpty
: public LayerTreeHostTest
{
211 LayerTreeHostTestReadyToActivateEmpty()
212 : did_notify_ready_to_activate_(false),
213 all_tiles_required_for_activation_are_ready_to_draw_(false),
214 required_for_activation_count_(0) {}
216 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
218 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
219 const std::vector
<PictureLayerImpl
*>& layers
=
220 impl
->sync_tree()->picture_layers();
221 required_for_activation_count_
= 0;
222 for (const auto& layer
: layers
) {
223 FakePictureLayerImpl
* fake_layer
=
224 static_cast<FakePictureLayerImpl
*>(layer
);
225 required_for_activation_count_
+=
226 fake_layer
->CountTilesRequiredForActivation();
230 void NotifyReadyToActivateOnThread(LayerTreeHostImpl
* impl
) override
{
231 did_notify_ready_to_activate_
= true;
232 all_tiles_required_for_activation_are_ready_to_draw_
=
233 impl
->tile_manager()->IsReadyToActivate();
237 void AfterTest() override
{
238 EXPECT_TRUE(did_notify_ready_to_activate_
);
239 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_
);
240 EXPECT_EQ(size_t(0), required_for_activation_count_
);
244 bool did_notify_ready_to_activate_
;
245 bool all_tiles_required_for_activation_are_ready_to_draw_
;
246 size_t required_for_activation_count_
;
249 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateEmpty
);
251 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
252 // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled.
253 class LayerTreeHostTestReadyToActivateNonEmpty
254 : public LayerTreeHostTestReadyToActivateEmpty
{
256 void SetupTree() override
{
257 client_
.set_fill_with_nonsolid_color(true);
258 scoped_refptr
<FakePictureLayer
> root_layer
=
259 FakePictureLayer::Create(layer_settings(), &client_
);
260 root_layer
->SetBounds(gfx::Size(1024, 1024));
261 root_layer
->SetIsDrawable(true);
263 layer_tree_host()->SetRootLayer(root_layer
);
264 LayerTreeHostTest::SetupTree();
267 void AfterTest() override
{
268 EXPECT_TRUE(did_notify_ready_to_activate_
);
269 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_
);
270 EXPECT_LE(size_t(1), required_for_activation_count_
);
274 FakeContentLayerClient client_
;
277 // Multi-thread only because in single thread the commit goes directly to the
278 // active tree, so notify ready to activate is skipped.
279 MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty
);
281 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
282 // no raster tasks get scheduled.
283 class LayerTreeHostTestReadyToDrawEmpty
: public LayerTreeHostTest
{
285 LayerTreeHostTestReadyToDrawEmpty()
286 : did_notify_ready_to_draw_(false),
287 all_tiles_required_for_draw_are_ready_to_draw_(false),
288 required_for_draw_count_(0) {}
290 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
292 void NotifyReadyToDrawOnThread(LayerTreeHostImpl
* impl
) override
{
293 did_notify_ready_to_draw_
= true;
294 const std::vector
<PictureLayerImpl
*>& layers
=
295 impl
->active_tree()->picture_layers();
296 all_tiles_required_for_draw_are_ready_to_draw_
=
297 impl
->tile_manager()->IsReadyToDraw();
298 for (const auto& layer
: layers
) {
299 FakePictureLayerImpl
* fake_layer
=
300 static_cast<FakePictureLayerImpl
*>(layer
);
301 required_for_draw_count_
+= fake_layer
->CountTilesRequiredForDraw();
307 void AfterTest() override
{
308 EXPECT_TRUE(did_notify_ready_to_draw_
);
309 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_
);
310 EXPECT_EQ(size_t(0), required_for_draw_count_
);
314 bool did_notify_ready_to_draw_
;
315 bool all_tiles_required_for_draw_are_ready_to_draw_
;
316 size_t required_for_draw_count_
;
319 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToDrawEmpty
);
321 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
322 // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled.
323 class LayerTreeHostTestReadyToDrawNonEmpty
324 : public LayerTreeHostTestReadyToDrawEmpty
{
326 void SetupTree() override
{
327 client_
.set_fill_with_nonsolid_color(true);
328 scoped_refptr
<FakePictureLayer
> root_layer
=
329 FakePictureLayer::Create(layer_settings(), &client_
);
330 root_layer
->SetBounds(gfx::Size(1024, 1024));
331 root_layer
->SetIsDrawable(true);
333 layer_tree_host()->SetRootLayer(root_layer
);
334 LayerTreeHostTest::SetupTree();
337 void AfterTest() override
{
338 EXPECT_TRUE(did_notify_ready_to_draw_
);
339 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_
);
340 EXPECT_LE(size_t(1), required_for_draw_count_
);
344 FakeContentLayerClient client_
;
347 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
348 // single threaded mode.
349 SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty
);
351 // This tests if we get the READY_TO_DRAW signal and draw if we become invisible
352 // and then become visible again.
353 class LayerTreeHostTestReadyToDrawVisibility
: public LayerTreeHostTest
{
355 LayerTreeHostTestReadyToDrawVisibility()
356 : LayerTreeHostTest(),
357 toggled_visibility_(false),
358 did_notify_ready_to_draw_(false),
361 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
363 void SetupTree() override
{
364 client_
.set_fill_with_nonsolid_color(true);
365 scoped_refptr
<FakePictureLayer
> root_layer
=
366 FakePictureLayer::Create(layer_settings(), &client_
);
367 root_layer
->SetBounds(gfx::Size(1024, 1024));
368 root_layer
->SetIsDrawable(true);
370 layer_tree_host()->SetRootLayer(root_layer
);
371 LayerTreeHostTest::SetupTree();
374 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
375 if (!toggled_visibility_
) {
377 DebugScopedSetMainThread
main(proxy());
378 layer_tree_host()->SetVisible(false);
380 toggled_visibility_
= true;
381 EXPECT_FALSE(host_impl
->visible());
385 void NotifyReadyToDrawOnThread(LayerTreeHostImpl
* host_impl
) override
{
386 // Sometimes the worker thread posts NotifyReadyToDraw in the extremely
387 // short duration of time between PrepareTiles and SetVisible(false) so we
388 // might get two NotifyReadyToDraw signals for this test.
389 did_notify_ready_to_draw_
= true;
392 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
393 EXPECT_FALSE(did_draw_
);
398 void DidFinishImplFrameOnThread(LayerTreeHostImpl
* host_impl
) override
{
399 if (!host_impl
->visible()) {
401 DebugScopedSetMainThread
main(proxy());
402 layer_tree_host()->SetVisible(true);
404 EXPECT_TRUE(host_impl
->visible());
408 void AfterTest() override
{
409 EXPECT_TRUE(did_notify_ready_to_draw_
);
410 EXPECT_TRUE(did_draw_
);
414 FakeContentLayerClient client_
;
415 bool toggled_visibility_
;
416 bool did_notify_ready_to_draw_
;
420 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
421 // single threaded mode.
422 SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawVisibility
);
424 class LayerTreeHostFreeWorkerContextResourcesTest
: public LayerTreeHostTest
{
426 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
427 auto output_surface
= make_scoped_ptr(new testing::StrictMock
<
428 MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface
>(
429 delegating_renderer()));
431 // At init, we expect one call to set visibility to true.
432 testing::Expectation visibility_true
=
433 EXPECT_CALL(*output_surface
,
434 SetWorkerContextShouldAggressivelyFreeResources(false))
437 // After running, we should get exactly one call to
438 // FreeWorkerContextGpuResources.
439 EXPECT_CALL(*output_surface
,
440 SetWorkerContextShouldAggressivelyFreeResources(true))
441 .After(visibility_true
)
442 .WillOnce(testing::Invoke([this](bool is_visible
) { EndTest(); }));
443 return output_surface
.Pass();
446 void InitializeSettings(LayerTreeSettings
* settings
) override
{
447 settings
->gpu_rasterization_enabled
= true;
448 settings
->gpu_rasterization_forced
= true;
451 void BeginTest() override
{
452 // Logic is handled in InitializedRendererOnThread to ensure that our
453 // LTHI is fully set up.
456 void AfterTest() override
{
457 // Expectations handled via mock.
461 class MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface
462 : public FakeOutputSurface
{
464 ~MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface() {}
465 explicit MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface(
466 bool delegated_rendering
)
467 : FakeOutputSurface(TestContextProvider::Create(),
468 TestContextProvider::Create(),
469 delegated_rendering
) {}
470 MOCK_METHOD1(SetWorkerContextShouldAggressivelyFreeResources
,
471 void(bool is_visible
));
475 // Test if the LTH successfully frees resources on the worker context when
476 // visibility is set to false.
477 class LayerTreeHostFreeWorkerContextResourcesOnInvisible
478 : public LayerTreeHostFreeWorkerContextResourcesTest
{
480 void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
481 bool success
) override
{
482 PostSetVisibleToMainThread(false);
486 SINGLE_AND_MULTI_THREAD_TEST_F(
487 LayerTreeHostFreeWorkerContextResourcesOnInvisible
);
489 // Test if the LTH successfully frees resources on the worker context when
490 // hard memory limit is set to zero.
491 class LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit
492 : public LayerTreeHostFreeWorkerContextResourcesTest
{
494 void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
495 bool success
) override
{
496 ManagedMemoryPolicy
zero_policy(
497 0, gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING
, 0);
498 host_impl
->SetMemoryPolicy(zero_policy
);
502 SINGLE_AND_MULTI_THREAD_TEST_F(
503 LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit
);
505 // Test if the LTH successfully frees resources on the worker context when
506 // hard memory limit is set to zero while using a synchronous compositor (like
508 class LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimitSynchronous
509 : public LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit
{
511 void InitializeSettings(LayerTreeSettings
* settings
) override
{
512 LayerTreeHostFreeWorkerContextResourcesTest::InitializeSettings(settings
);
513 settings
->use_external_begin_frame_source
= true;
514 settings
->using_synchronous_renderer_compositor
= true;
518 SINGLE_AND_MULTI_THREAD_TEST_F(
519 LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimitSynchronous
);
521 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
522 // draw with frame 0.
523 class LayerTreeHostTestSetNeedsCommit1
: public LayerTreeHostTest
{
525 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
527 void BeginTest() override
{
528 PostSetNeedsCommitToMainThread();
529 PostSetNeedsCommitToMainThread();
532 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
534 if (!impl
->active_tree()->source_frame_number())
538 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
542 void AfterTest() override
{
543 EXPECT_LE(1, num_commits_
);
544 EXPECT_LE(1, num_draws_
);
552 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1
);
554 // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that
555 // first committed frame draws should lead to another commit.
556 class LayerTreeHostTestSetNeedsCommit2
: public LayerTreeHostTest
{
558 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {}
560 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
562 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{ ++num_draws_
; }
564 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
566 switch (num_commits_
) {
568 PostSetNeedsCommitToMainThread();
578 void AfterTest() override
{
579 EXPECT_EQ(2, num_commits_
);
580 EXPECT_LE(1, num_draws_
);
588 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2
);
590 // Verify that we pass property values in PushPropertiesTo.
591 class LayerTreeHostTestPushPropertiesTo
: public LayerTreeHostTest
{
593 void SetupTree() override
{
594 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
595 root
->SetBounds(gfx::Size(10, 10));
596 layer_tree_host()->SetRootLayer(root
);
597 LayerTreeHostTest::SetupTree();
603 HIDE_LAYER_AND_SUBTREE
,
608 void BeginTest() override
{
610 PostSetNeedsCommitToMainThread();
613 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
614 VerifyAfterValues(impl
->active_tree()->root_layer());
617 void DidCommitAndDrawFrame() override
{
618 SetBeforeValues(layer_tree_host()->root_layer());
619 VerifyBeforeValues(layer_tree_host()->root_layer());
622 if (index_
== DONE
) {
627 SetAfterValues(layer_tree_host()->root_layer());
630 void AfterTest() override
{}
632 void VerifyBeforeValues(Layer
* layer
) {
633 EXPECT_EQ(gfx::Size(10, 10).ToString(), layer
->bounds().ToString());
634 EXPECT_FALSE(layer
->hide_layer_and_subtree());
635 EXPECT_FALSE(layer
->DrawsContent());
638 void SetBeforeValues(Layer
* layer
) {
639 layer
->SetBounds(gfx::Size(10, 10));
640 layer
->SetHideLayerAndSubtree(false);
641 layer
->SetIsDrawable(false);
644 void VerifyAfterValues(LayerImpl
* layer
) {
645 switch (static_cast<Properties
>(index_
)) {
650 EXPECT_EQ(gfx::Size(20, 20).ToString(), layer
->bounds().ToString());
652 case HIDE_LAYER_AND_SUBTREE
:
653 EXPECT_TRUE(layer
->hide_layer_and_subtree());
656 EXPECT_TRUE(layer
->DrawsContent());
661 void SetAfterValues(Layer
* layer
) {
662 switch (static_cast<Properties
>(index_
)) {
667 layer
->SetBounds(gfx::Size(20, 20));
669 case HIDE_LAYER_AND_SUBTREE
:
670 layer
->SetHideLayerAndSubtree(true);
673 layer
->SetIsDrawable(true);
681 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo
);
683 // 1 setNeedsRedraw after the first commit has completed should lead to 1
685 class LayerTreeHostTestSetNeedsRedraw
: public LayerTreeHostTest
{
687 LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {}
689 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
691 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
692 EXPECT_EQ(0, impl
->active_tree()->source_frame_number());
694 // Redraw again to verify that the second redraw doesn't commit.
695 PostSetNeedsRedrawToMainThread();
702 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
703 EXPECT_EQ(0, num_draws_
);
707 void AfterTest() override
{
708 EXPECT_GE(2, num_draws_
);
709 EXPECT_EQ(1, num_commits_
);
717 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw
);
719 // After setNeedsRedrawRect(invalid_rect) the final damage_rect
720 // must contain invalid_rect.
721 class LayerTreeHostTestSetNeedsRedrawRect
: public LayerTreeHostTest
{
723 LayerTreeHostTestSetNeedsRedrawRect()
724 : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {}
726 void BeginTest() override
{
727 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
728 root_layer_
->SetIsDrawable(true);
729 root_layer_
->SetBounds(bounds_
);
730 layer_tree_host()->SetRootLayer(root_layer_
);
731 layer_tree_host()->SetViewportSize(bounds_
);
732 PostSetNeedsCommitToMainThread();
735 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
736 LayerTreeHostImpl::FrameData
* frame_data
,
737 DrawResult draw_result
) override
{
738 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
740 gfx::Rect root_damage_rect
;
741 if (!frame_data
->render_passes
.empty())
742 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
745 // If this is the first frame, expect full frame damage.
746 EXPECT_EQ(root_damage_rect
, gfx::Rect(bounds_
));
748 // Check that invalid_rect_ is indeed repainted.
749 EXPECT_TRUE(root_damage_rect
.Contains(invalid_rect_
));
755 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
757 PostSetNeedsRedrawRectToMainThread(invalid_rect_
);
764 void AfterTest() override
{ EXPECT_EQ(2, num_draws_
); }
768 const gfx::Size bounds_
;
769 const gfx::Rect invalid_rect_
;
770 FakeContentLayerClient client_
;
771 scoped_refptr
<FakePictureLayer
> root_layer_
;
774 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect
);
776 // Ensure the texture size of the pending and active trees are identical when a
777 // layer is not in the viewport and a resize happens on the viewport
778 class LayerTreeHostTestGpuRasterDeviceSizeChanged
: public LayerTreeHostTest
{
780 LayerTreeHostTestGpuRasterDeviceSizeChanged()
781 : num_draws_(0), bounds_(500, 64), invalid_rect_(10, 10, 20, 20) {}
783 void BeginTest() override
{
784 client_
.set_fill_with_nonsolid_color(true);
785 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
786 root_layer_
->SetIsDrawable(true);
787 gfx::Transform transform
;
788 // Translate the layer out of the viewport to force it to not update its
789 // tile size via PushProperties.
790 transform
.Translate(10000.0, 10000.0);
791 root_layer_
->SetTransform(transform
);
792 root_layer_
->SetBounds(bounds_
);
793 layer_tree_host()->SetRootLayer(root_layer_
);
794 layer_tree_host()->SetViewportSize(bounds_
);
796 PostSetNeedsCommitToMainThread();
799 void InitializeSettings(LayerTreeSettings
* settings
) override
{
800 settings
->gpu_rasterization_enabled
= true;
801 settings
->gpu_rasterization_forced
= true;
804 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
805 // Perform 2 commits.
807 PostSetNeedsRedrawRectToMainThread(invalid_rect_
);
814 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
815 if (num_draws_
== 2) {
816 auto pending_tree
= host_impl
->pending_tree();
817 auto pending_layer_impl
=
818 static_cast<FakePictureLayerImpl
*>(pending_tree
->root_layer());
819 EXPECT_NE(pending_layer_impl
, nullptr);
821 auto active_tree
= host_impl
->pending_tree();
822 auto active_layer_impl
=
823 static_cast<FakePictureLayerImpl
*>(active_tree
->root_layer());
824 EXPECT_NE(pending_layer_impl
, nullptr);
826 auto active_tiling_set
= active_layer_impl
->picture_layer_tiling_set();
827 auto active_tiling
= active_tiling_set
->tiling_at(0);
828 auto pending_tiling_set
= pending_layer_impl
->picture_layer_tiling_set();
829 auto pending_tiling
= pending_tiling_set
->tiling_at(0);
831 pending_tiling
->TilingDataForTesting().max_texture_size().width(),
832 active_tiling
->TilingDataForTesting().max_texture_size().width());
836 void DidCommitAndDrawFrame() override
{
837 // On the second commit, resize the viewport.
838 if (num_draws_
== 1) {
839 layer_tree_host()->SetViewportSize(gfx::Size(400, 64));
843 void AfterTest() override
{}
847 const gfx::Size bounds_
;
848 const gfx::Rect invalid_rect_
;
849 FakeContentLayerClient client_
;
850 scoped_refptr
<FakePictureLayer
> root_layer_
;
853 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterDeviceSizeChanged
);
855 class LayerTreeHostTestNoExtraCommitFromInvalidate
: public LayerTreeHostTest
{
857 void InitializeSettings(LayerTreeSettings
* settings
) override
{
858 settings
->layer_transforms_should_scale_layer_contents
= true;
861 void SetupTree() override
{
862 root_layer_
= Layer::Create(layer_settings());
863 root_layer_
->SetBounds(gfx::Size(10, 20));
865 scaled_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
866 scaled_layer_
->SetBounds(gfx::Size(1, 1));
867 root_layer_
->AddChild(scaled_layer_
);
869 layer_tree_host()->SetRootLayer(root_layer_
);
870 LayerTreeHostTest::SetupTree();
873 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
875 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
876 if (host_impl
->active_tree()->source_frame_number() == 1)
880 void DidCommit() override
{
881 switch (layer_tree_host()->source_frame_number()) {
883 // SetBounds grows the layer and exposes new content.
884 scaled_layer_
->SetBounds(gfx::Size(4, 4));
888 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
892 void AfterTest() override
{
893 EXPECT_EQ(gfx::Size(4, 4).ToString(), scaled_layer_
->bounds().ToString());
897 FakeContentLayerClient client_
;
898 scoped_refptr
<Layer
> root_layer_
;
899 scoped_refptr
<Layer
> scaled_layer_
;
902 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate
);
904 class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate
905 : public LayerTreeHostTest
{
907 void InitializeSettings(LayerTreeSettings
* settings
) override
{
908 settings
->layer_transforms_should_scale_layer_contents
= true;
911 void SetupTree() override
{
912 root_layer_
= Layer::Create(layer_settings());
913 root_layer_
->SetBounds(gfx::Size(10, 20));
915 bool paint_scrollbar
= true;
916 bool has_thumb
= false;
917 scrollbar_
= FakePaintedScrollbarLayer::Create(
918 layer_settings(), paint_scrollbar
, has_thumb
, root_layer_
->id());
919 scrollbar_
->SetPosition(gfx::Point(0, 10));
920 scrollbar_
->SetBounds(gfx::Size(10, 10));
922 root_layer_
->AddChild(scrollbar_
);
924 layer_tree_host()->SetRootLayer(root_layer_
);
925 LayerTreeHostTest::SetupTree();
928 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
930 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
931 if (host_impl
->active_tree()->source_frame_number() == 1)
935 void DidCommit() override
{
936 switch (layer_tree_host()->source_frame_number()) {
938 // Changing the device scale factor causes a commit. It also changes
939 // the content bounds of |scrollbar_|, which should not generate
940 // a second commit as a result.
941 layer_tree_host()->SetDeviceScaleFactor(4.f
);
945 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
950 void AfterTest() override
{
954 FakeContentLayerClient client_
;
955 scoped_refptr
<Layer
> root_layer_
;
956 scoped_refptr
<FakePaintedScrollbarLayer
> scrollbar_
;
959 SINGLE_AND_MULTI_THREAD_TEST_F(
960 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate
);
962 class LayerTreeHostTestSetNextCommitForcesRedraw
: public LayerTreeHostTest
{
964 LayerTreeHostTestSetNextCommitForcesRedraw()
965 : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {}
967 void BeginTest() override
{
968 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
969 root_layer_
->SetIsDrawable(true);
970 root_layer_
->SetBounds(bounds_
);
971 layer_tree_host()->SetRootLayer(root_layer_
);
972 layer_tree_host()->SetViewportSize(bounds_
);
973 PostSetNeedsCommitToMainThread();
976 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
978 host_impl
->SetNeedsRedrawRect(invalid_rect_
);
981 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
982 LayerTreeHostImpl::FrameData
* frame_data
,
983 DrawResult draw_result
) override
{
984 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
986 gfx::Rect root_damage_rect
;
987 if (!frame_data
->render_passes
.empty())
988 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
990 switch (num_draws_
) {
992 EXPECT_EQ(gfx::Rect(bounds_
), root_damage_rect
);
996 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect
);
999 EXPECT_EQ(invalid_rect_
, root_damage_rect
);
1002 EXPECT_EQ(gfx::Rect(bounds_
), root_damage_rect
);
1011 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
1012 switch (num_draws_
) {
1015 // Cycle through a couple of empty commits to ensure we're observing the
1017 PostSetNeedsCommitToMainThread();
1020 // Should force full frame damage on the next commit
1021 PostSetNextCommitForcesRedrawToMainThread();
1022 PostSetNeedsCommitToMainThread();
1023 host_impl
->BlockNotifyReadyToActivateForTesting(true);
1026 host_impl
->BlockNotifyReadyToActivateForTesting(false);
1035 void AfterTest() override
{ EXPECT_EQ(5, num_draws_
); }
1039 const gfx::Size bounds_
;
1040 const gfx::Rect invalid_rect_
;
1041 FakeContentLayerClient client_
;
1042 scoped_refptr
<FakePictureLayer
> root_layer_
;
1045 // This test blocks activation which is not supported for single thread mode.
1046 MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw
);
1048 // Tests that if a layer is not drawn because of some reason in the parent then
1049 // its damage is preserved until the next time it is drawn.
1050 class LayerTreeHostTestUndrawnLayersDamageLater
: public LayerTreeHostTest
{
1052 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1053 // If we don't set the minimum contents scale, it's harder to verify whether
1054 // the damage we get is correct. For other scale amounts, please see
1055 // LayerTreeHostTestDamageWithScale.
1056 settings
->minimum_contents_scale
= 1.f
;
1059 void SetupTree() override
{
1060 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1061 root_layer_
->SetIsDrawable(true);
1062 root_layer_
->SetBounds(gfx::Size(50, 50));
1063 layer_tree_host()->SetRootLayer(root_layer_
);
1065 // The initially transparent layer has a larger child layer, which is
1066 // not initially drawn because of the this (parent) layer.
1067 parent_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1068 parent_layer_
->SetBounds(gfx::Size(15, 15));
1069 parent_layer_
->SetOpacity(0.0f
);
1070 root_layer_
->AddChild(parent_layer_
);
1072 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1073 child_layer_
->SetBounds(gfx::Size(25, 25));
1074 parent_layer_
->AddChild(child_layer_
);
1076 LayerTreeHostTest::SetupTree();
1079 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1081 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
1082 LayerTreeHostImpl::FrameData
* frame_data
,
1083 DrawResult draw_result
) override
{
1084 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
1086 gfx::Rect root_damage_rect
;
1087 if (!frame_data
->render_passes
.empty())
1088 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
1090 // The first time, the whole view needs be drawn.
1091 // Afterwards, just the opacity of surface_layer1 is changed a few times,
1092 // and each damage should be the bounding box of it and its child. If this
1093 // was working improperly, the damage might not include its childs bounding
1095 switch (host_impl
->active_tree()->source_frame_number()) {
1097 EXPECT_EQ(gfx::Rect(root_layer_
->bounds()), root_damage_rect
);
1102 EXPECT_EQ(gfx::Rect(child_layer_
->bounds()), root_damage_rect
);
1111 void DidCommitAndDrawFrame() override
{
1112 switch (layer_tree_host()->source_frame_number()) {
1114 // Test not owning the surface.
1115 parent_layer_
->SetOpacity(1.0f
);
1118 parent_layer_
->SetOpacity(0.0f
);
1121 // Test owning the surface.
1122 parent_layer_
->SetOpacity(0.5f
);
1123 parent_layer_
->SetForceRenderSurface(true);
1133 void AfterTest() override
{}
1136 FakeContentLayerClient client_
;
1137 scoped_refptr
<FakePictureLayer
> root_layer_
;
1138 scoped_refptr
<FakePictureLayer
> parent_layer_
;
1139 scoped_refptr
<FakePictureLayer
> child_layer_
;
1142 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater
);
1144 // Tests that if a layer is not drawn because of some reason in the parent then
1145 // its damage is preserved until the next time it is drawn.
1146 class LayerTreeHostTestDamageWithScale
: public LayerTreeHostTest
{
1148 LayerTreeHostTestDamageWithScale() {}
1150 void SetupTree() override
{
1151 client_
.set_fill_with_nonsolid_color(true);
1153 scoped_ptr
<FakePicturePile
> pile(
1154 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
1155 LayerTreeSettings().default_tile_grid_size
));
1156 root_layer_
= FakePictureLayer::CreateWithRecordingSource(
1157 layer_settings(), &client_
, pile
.Pass());
1158 root_layer_
->SetBounds(gfx::Size(50, 50));
1160 pile
.reset(new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
1161 LayerTreeSettings().default_tile_grid_size
));
1162 child_layer_
= FakePictureLayer::CreateWithRecordingSource(
1163 layer_settings(), &client_
, pile
.Pass());
1164 child_layer_
->SetBounds(gfx::Size(25, 25));
1165 child_layer_
->SetIsDrawable(true);
1166 child_layer_
->SetContentsOpaque(true);
1167 root_layer_
->AddChild(child_layer_
);
1169 layer_tree_host()->SetRootLayer(root_layer_
);
1170 LayerTreeHostTest::SetupTree();
1173 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
1174 // Force the layer to have a tiling at 1.3f scale. Note that if we simply
1175 // add tiling, it will be gone by the time we draw because of aggressive
1176 // cleanup. AddTilingUntilNextDraw ensures that it remains there during
1177 // damage calculation.
1178 FakePictureLayerImpl
* child_layer_impl
= static_cast<FakePictureLayerImpl
*>(
1179 host_impl
->active_tree()->LayerById(child_layer_
->id()));
1180 child_layer_impl
->AddTilingUntilNextDraw(1.3f
);
1183 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1185 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
1186 LayerTreeHostImpl::FrameData
* frame_data
,
1187 DrawResult draw_result
) override
{
1188 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
1190 gfx::Rect root_damage_rect
;
1191 if (!frame_data
->render_passes
.empty())
1192 root_damage_rect
= frame_data
->render_passes
.back()->damage_rect
;
1194 // The first time, the whole view needs be drawn.
1195 // Afterwards, just the opacity of surface_layer1 is changed a few times,
1196 // and each damage should be the bounding box of it and its child. If this
1197 // was working improperly, the damage might not include its childs bounding
1199 switch (host_impl
->active_tree()->source_frame_number()) {
1201 EXPECT_EQ(gfx::Rect(root_layer_
->bounds()), root_damage_rect
);
1204 FakePictureLayerImpl
* child_layer_impl
=
1205 static_cast<FakePictureLayerImpl
*>(
1206 host_impl
->active_tree()->LayerById(child_layer_
->id()));
1207 // We remove tilings pretty aggressively if they are not ideal. Add this
1208 // back in so that we can compare
1209 // child_layer_impl->GetEnclosingRectInTargetSpace to the damage.
1210 child_layer_impl
->AddTilingUntilNextDraw(1.3f
);
1212 EXPECT_EQ(gfx::Rect(26, 26), root_damage_rect
);
1213 EXPECT_EQ(child_layer_impl
->GetEnclosingRectInTargetSpace(),
1215 EXPECT_TRUE(child_layer_impl
->GetEnclosingRectInTargetSpace().Contains(
1216 gfx::Rect(child_layer_
->bounds())));
1226 void DidCommitAndDrawFrame() override
{
1227 switch (layer_tree_host()->source_frame_number()) {
1229 // Test not owning the surface.
1230 child_layer_
->SetOpacity(0.5f
);
1241 void AfterTest() override
{}
1244 FakeContentLayerClient client_
;
1245 scoped_refptr
<Layer
> root_layer_
;
1246 scoped_refptr
<Layer
> child_layer_
;
1249 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDamageWithScale
);
1251 // This test verifies that properties on the layer tree host are commited
1252 // to the impl side.
1253 class LayerTreeHostTestCommit
: public LayerTreeHostTest
{
1255 LayerTreeHostTestCommit() {}
1257 void BeginTest() override
{
1258 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1259 layer_tree_host()->set_background_color(SK_ColorGRAY
);
1261 PostSetNeedsCommitToMainThread();
1264 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1265 EXPECT_EQ(gfx::Size(20, 20), impl
->DrawViewportSize());
1266 EXPECT_EQ(SK_ColorGRAY
, impl
->active_tree()->background_color());
1271 void AfterTest() override
{}
1274 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit
);
1276 // This test verifies that LayerTreeHostImpl's current frame time gets
1277 // updated in consecutive frames when it doesn't draw due to tree
1278 // activation failure.
1279 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails
1280 : public LayerTreeHostTest
{
1282 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails()
1283 : frame_count_with_pending_tree_(0) {}
1285 void BeginTest() override
{
1286 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1287 layer_tree_host()->set_background_color(SK_ColorGRAY
);
1289 PostSetNeedsCommitToMainThread();
1292 void BeginCommitOnThread(LayerTreeHostImpl
* impl
) override
{
1293 EXPECT_EQ(frame_count_with_pending_tree_
, 0);
1294 impl
->BlockNotifyReadyToActivateForTesting(true);
1297 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* impl
,
1298 const BeginFrameArgs
& args
) override
{
1299 if (impl
->pending_tree())
1300 frame_count_with_pending_tree_
++;
1302 if (frame_count_with_pending_tree_
== 1) {
1303 EXPECT_EQ(first_frame_time_
.ToInternalValue(), 0);
1304 first_frame_time_
= impl
->CurrentBeginFrameArgs().frame_time
;
1305 } else if (frame_count_with_pending_tree_
== 2) {
1306 impl
->BlockNotifyReadyToActivateForTesting(false);
1310 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1311 EXPECT_GT(frame_count_with_pending_tree_
, 1);
1312 EXPECT_NE(first_frame_time_
.ToInternalValue(), 0);
1313 EXPECT_NE(first_frame_time_
.ToInternalValue(),
1314 impl
->CurrentBeginFrameArgs().frame_time
.ToInternalValue());
1318 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1319 EXPECT_GT(frame_count_with_pending_tree_
, 1);
1322 void AfterTest() override
{}
1325 int frame_count_with_pending_tree_
;
1326 base::TimeTicks first_frame_time_
;
1329 // This test blocks activation which is not supported for single thread mode.
1330 MULTI_THREAD_BLOCKNOTIFY_TEST_F(
1331 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails
);
1333 // This test verifies that LayerTreeHostImpl's current frame time gets
1334 // updated in consecutive frames when it draws in each frame.
1335 class LayerTreeHostTestFrameTimeUpdatesAfterDraw
: public LayerTreeHostTest
{
1337 LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {}
1339 void BeginTest() override
{
1340 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1341 layer_tree_host()->set_background_color(SK_ColorGRAY
);
1343 PostSetNeedsCommitToMainThread();
1346 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1349 first_frame_time_
= impl
->CurrentBeginFrameArgs().frame_time
;
1350 impl
->SetNeedsRedraw();
1352 // Since we might use a low-resolution clock on Windows, we need to
1353 // make sure that the clock has incremented past first_frame_time_.
1354 while (first_frame_time_
== base::TimeTicks::Now()) {
1360 EXPECT_NE(first_frame_time_
, impl
->CurrentBeginFrameArgs().frame_time
);
1364 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1365 // Ensure there isn't a commit between the two draws, to ensure that a
1366 // commit isn't required for updating the current frame time. We can
1367 // only check for this in the multi-threaded case, since in the single-
1368 // threaded case there will always be a commit between consecutive draws.
1369 if (HasImplThread())
1370 EXPECT_EQ(0, frame_
);
1373 void AfterTest() override
{}
1377 base::TimeTicks first_frame_time_
;
1380 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw
);
1382 // Verifies that StartPageScaleAnimation events propagate correctly
1383 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor.
1384 class LayerTreeHostTestStartPageScaleAnimation
: public LayerTreeHostTest
{
1386 LayerTreeHostTestStartPageScaleAnimation() {}
1388 void SetupTree() override
{
1389 LayerTreeHostTest::SetupTree();
1391 Layer
* root_layer
= layer_tree_host()->root_layer();
1393 scoped_refptr
<FakePictureLayer
> layer
=
1394 FakePictureLayer::Create(layer_settings(), &client_
);
1395 layer
->set_always_update_resources(true);
1396 scroll_layer_
= layer
;
1398 scroll_layer_
->SetBounds(gfx::Size(2 * root_layer
->bounds().width(),
1399 2 * root_layer
->bounds().height()));
1400 scroll_layer_
->SetScrollOffset(gfx::ScrollOffset());
1402 CreateVirtualViewportLayers(root_layer
,
1404 root_layer
->bounds(),
1405 root_layer
->bounds(),
1409 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.5f
, 2.f
);
1412 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1414 void ApplyViewportDeltas(const gfx::Vector2dF
& scroll_delta
,
1415 const gfx::Vector2dF
&,
1416 const gfx::Vector2dF
& elastic_overscroll_delta
,
1419 gfx::ScrollOffset offset
= scroll_layer_
->scroll_offset();
1420 scroll_layer_
->SetScrollOffset(ScrollOffsetWithDelta(offset
,
1422 layer_tree_host()->SetPageScaleFactorAndLimits(scale
, 0.5f
, 2.f
);
1425 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1426 // We get one commit before the first draw, and the animation doesn't happen
1427 // until the second draw.
1428 switch (impl
->active_tree()->source_frame_number()) {
1430 EXPECT_EQ(1.f
, impl
->active_tree()->current_page_scale_factor());
1431 // We'll start an animation when we get back to the main thread.
1434 EXPECT_EQ(1.f
, impl
->active_tree()->current_page_scale_factor());
1437 EXPECT_EQ(1.25f
, impl
->active_tree()->current_page_scale_factor());
1445 void DidCommitAndDrawFrame() override
{
1446 switch (layer_tree_host()->source_frame_number()) {
1448 layer_tree_host()->StartPageScaleAnimation(
1449 gfx::Vector2d(), false, 1.25f
, base::TimeDelta());
1454 void AfterTest() override
{}
1456 FakeContentLayerClient client_
;
1457 scoped_refptr
<Layer
> scroll_layer_
;
1460 // Single thread proxy does not support impl-side page scale changes.
1461 MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation
);
1463 class LayerTreeHostTestSetVisible
: public LayerTreeHostTest
{
1465 LayerTreeHostTestSetVisible() : num_draws_(0) {}
1467 void BeginTest() override
{
1468 PostSetNeedsCommitToMainThread();
1469 PostSetVisibleToMainThread(false);
1470 // This is suppressed while we're invisible.
1471 PostSetNeedsRedrawToMainThread();
1472 // Triggers the redraw.
1473 PostSetVisibleToMainThread(true);
1476 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1477 EXPECT_TRUE(impl
->visible());
1482 void AfterTest() override
{ EXPECT_EQ(1, num_draws_
); }
1488 MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible
);
1490 class TestOpacityChangeLayerDelegate
: public ContentLayerClient
{
1492 TestOpacityChangeLayerDelegate() : test_layer_(0) {}
1494 void SetTestLayer(Layer
* test_layer
) { test_layer_
= test_layer
; }
1496 void PaintContents(SkCanvas
* canvas
,
1497 const gfx::Rect
& clip
,
1498 PaintingControlSetting picture_control
) override
{
1501 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
1502 const gfx::Rect
& clip
,
1503 PaintingControlSetting picture_control
) override
{
1504 // Set layer opacity to 0.
1506 test_layer_
->SetOpacity(0.f
);
1508 // Return a dummy display list.
1509 scoped_refptr
<DisplayItemList
> display_list
=
1510 DisplayItemList::Create(clip
, DisplayItemListSettings());
1511 return display_list
;
1513 bool FillsBoundsCompletely() const override
{ return false; }
1514 size_t GetApproximateUnsharedMemoryUsage() const override
{ return 0; }
1520 // Layer opacity change during paint should not prevent compositor resources
1521 // from being updated during commit.
1522 class LayerTreeHostTestOpacityChange
: public LayerTreeHostTest
{
1524 LayerTreeHostTestOpacityChange() : test_opacity_change_delegate_() {}
1526 void SetupTree() override
{
1527 LayerTreeHostTest::SetupTree();
1529 update_check_picture_layer_
= FakePictureLayer::Create(
1530 layer_settings(), &test_opacity_change_delegate_
);
1531 test_opacity_change_delegate_
.SetTestLayer(
1532 update_check_picture_layer_
.get());
1533 layer_tree_host()->root_layer()->AddChild(update_check_picture_layer_
);
1536 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1538 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{ EndTest(); }
1540 void AfterTest() override
{
1541 // Update() should have been called once.
1542 EXPECT_EQ(1, update_check_picture_layer_
->update_count());
1546 TestOpacityChangeLayerDelegate test_opacity_change_delegate_
;
1547 scoped_refptr
<FakePictureLayer
> update_check_picture_layer_
;
1550 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange
);
1552 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers
1553 : public LayerTreeHostTest
{
1555 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() {}
1557 void BeginTest() override
{
1558 client_
.set_fill_with_nonsolid_color(true);
1559 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1560 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1562 layer_tree_host()->SetViewportSize(gfx::Size(60, 60));
1563 layer_tree_host()->SetDeviceScaleFactor(1.5);
1564 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size());
1566 root_layer_
->AddChild(child_layer_
);
1568 root_layer_
->SetIsDrawable(true);
1569 root_layer_
->SetBounds(gfx::Size(30, 30));
1571 child_layer_
->SetIsDrawable(true);
1572 child_layer_
->SetPosition(gfx::Point(2, 2));
1573 child_layer_
->SetBounds(gfx::Size(10, 10));
1575 layer_tree_host()->SetRootLayer(root_layer_
);
1577 PostSetNeedsCommitToMainThread();
1580 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
1581 // Should only do one commit.
1582 EXPECT_EQ(0, impl
->active_tree()->source_frame_number());
1583 // Device scale factor should come over to impl.
1584 EXPECT_NEAR(impl
->device_scale_factor(), 1.5f
, 0.00001f
);
1586 // Both layers are on impl.
1587 ASSERT_EQ(1u, impl
->active_tree()->root_layer()->children().size());
1589 // Device viewport is scaled.
1590 EXPECT_EQ(gfx::Size(60, 60), impl
->DrawViewportSize());
1592 FakePictureLayerImpl
* root
=
1593 static_cast<FakePictureLayerImpl
*>(impl
->active_tree()->root_layer());
1594 FakePictureLayerImpl
* child
= static_cast<FakePictureLayerImpl
*>(
1595 impl
->active_tree()->root_layer()->children()[0]);
1597 // Positions remain in layout pixels.
1598 EXPECT_EQ(gfx::Point(0, 0), root
->position());
1599 EXPECT_EQ(gfx::Point(2, 2), child
->position());
1601 // Compute all the layer transforms for the frame.
1602 LayerTreeHostImpl::FrameData frame_data
;
1603 impl
->PrepareToDraw(&frame_data
);
1604 impl
->DidDrawAllLayers(frame_data
);
1606 const LayerImplList
& render_surface_layer_list
=
1607 *frame_data
.render_surface_layer_list
;
1609 // Both layers should be drawing into the root render surface.
1610 ASSERT_EQ(1u, render_surface_layer_list
.size());
1611 ASSERT_EQ(root
->render_surface(),
1612 render_surface_layer_list
[0]->render_surface());
1613 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
1615 // The root render surface is the size of the viewport.
1616 EXPECT_EQ(gfx::Rect(0, 0, 60, 60), root
->render_surface()->content_rect());
1618 // The max tiling scale of the child should be scaled.
1619 EXPECT_FLOAT_EQ(1.5f
, child
->MaximumTilingContentsScale());
1621 gfx::Transform scale_transform
;
1622 scale_transform
.Scale(impl
->device_scale_factor(),
1623 impl
->device_scale_factor());
1625 // The root layer is scaled by 2x.
1626 gfx::Transform root_screen_space_transform
= scale_transform
;
1627 gfx::Transform root_draw_transform
= scale_transform
;
1629 EXPECT_EQ(root_draw_transform
, root
->draw_transform());
1630 EXPECT_EQ(root_screen_space_transform
, root
->screen_space_transform());
1632 // The child is at position 2,2, which is transformed to 3,3 after the scale
1633 gfx::Transform child_transform
;
1634 child_transform
.Translate(3.f
, 3.f
);
1635 child_transform
.Scale(child
->MaximumTilingContentsScale(),
1636 child
->MaximumTilingContentsScale());
1638 EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform
, child
->draw_transform());
1639 EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform
,
1640 child
->screen_space_transform());
1645 void AfterTest() override
{}
1648 FakeContentLayerClient client_
;
1649 scoped_refptr
<FakePictureLayer
> root_layer_
;
1650 scoped_refptr
<FakePictureLayer
> child_layer_
;
1653 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers
);
1655 class LayerTreeHostTestContinuousInvalidate
: public LayerTreeHostTest
{
1657 LayerTreeHostTestContinuousInvalidate()
1658 : num_commit_complete_(0), num_draw_layers_(0) {}
1660 void BeginTest() override
{
1661 layer_tree_host()->SetViewportSize(gfx::Size(10, 10));
1662 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
1664 layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
1665 layer_
->SetBounds(gfx::Size(10, 10));
1666 layer_
->SetPosition(gfx::PointF(0.f
, 0.f
));
1667 layer_
->SetIsDrawable(true);
1668 layer_tree_host()->root_layer()->AddChild(layer_
);
1670 PostSetNeedsCommitToMainThread();
1673 void DidCommitAndDrawFrame() override
{
1674 if (num_draw_layers_
== 2)
1676 layer_
->SetNeedsDisplay();
1679 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
1680 if (num_draw_layers_
== 1)
1681 num_commit_complete_
++;
1684 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
1686 if (num_draw_layers_
== 2)
1690 void AfterTest() override
{
1691 // Check that we didn't commit twice between first and second draw.
1692 EXPECT_EQ(1, num_commit_complete_
);
1696 FakeContentLayerClient client_
;
1697 scoped_refptr
<Layer
> layer_
;
1698 int num_commit_complete_
;
1699 int num_draw_layers_
;
1702 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate
);
1704 class LayerTreeHostTestDeferCommits
: public LayerTreeHostTest
{
1706 LayerTreeHostTestDeferCommits()
1707 : num_will_begin_impl_frame_(0),
1708 num_send_begin_main_frame_(0) {}
1710 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1712 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* host_impl
,
1713 const BeginFrameArgs
& args
) override
{
1714 num_will_begin_impl_frame_
++;
1715 switch (num_will_begin_impl_frame_
) {
1721 // Post a number of frames to increase the chance that, if there exist
1722 // bugs, an unexpected BeginMainFrame will be issued.
1723 PostSetNeedsCommitToMainThread();
1724 PostSetNeedsRedrawToMainThread();
1727 PostSetDeferCommitsToMainThread(false);
1730 // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the
1731 // main thread is slow to respond.
1736 void ScheduledActionSendBeginMainFrame() override
{
1737 num_send_begin_main_frame_
++;
1738 switch (num_send_begin_main_frame_
) {
1740 PostSetDeferCommitsToMainThread(true);
1751 void AfterTest() override
{
1752 EXPECT_GE(num_will_begin_impl_frame_
, 5);
1753 EXPECT_EQ(2, num_send_begin_main_frame_
);
1757 int num_will_begin_impl_frame_
;
1758 int num_send_begin_main_frame_
;
1761 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits
);
1763 class LayerTreeHostTestCompositeImmediatelyStateTransitions
1764 : public LayerTreeHostTest
{
1773 kCompletedMainFrame
,
1774 kCompletedImplFrame
,
1777 LayerTreeHostTestCompositeImmediatelyStateTransitions()
1778 : current_state_(kInvalid
), current_begin_frame_args_() {}
1780 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1781 settings
->single_thread_proxy_scheduler
= false;
1782 settings
->use_zero_copy
= true;
1785 void BeginTest() override
{
1786 current_state_
= kStartedTest
;
1787 PostCompositeImmediatelyToMainThread();
1790 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* host_impl
,
1791 const BeginFrameArgs
& args
) override
{
1792 EXPECT_EQ(current_state_
, kStartedTest
);
1793 current_state_
= kStartedImplFrame
;
1795 EXPECT_FALSE(current_begin_frame_args_
.IsValid());
1796 EXPECT_TRUE(args
.IsValid());
1797 current_begin_frame_args_
= args
;
1799 void WillBeginMainFrame() override
{
1800 EXPECT_EQ(current_state_
, kStartedImplFrame
);
1801 current_state_
= kStartedMainFrame
;
1803 void BeginMainFrame(const BeginFrameArgs
& args
) override
{
1804 EXPECT_EQ(current_state_
, kStartedMainFrame
);
1805 EXPECT_EQ(args
.frame_time
, current_begin_frame_args_
.frame_time
);
1807 void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) override
{
1808 EXPECT_EQ(current_state_
, kStartedMainFrame
);
1809 current_state_
= kStartedCommit
;
1811 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1812 EXPECT_EQ(current_state_
, kStartedCommit
);
1813 current_state_
= kCompletedCommit
;
1815 void DidBeginMainFrame() override
{
1816 EXPECT_EQ(current_state_
, kCompletedCommit
);
1817 current_state_
= kCompletedMainFrame
;
1819 void DidFinishImplFrameOnThread(LayerTreeHostImpl
* host_impl
) override
{
1820 EXPECT_EQ(current_state_
, kCompletedMainFrame
);
1821 current_state_
= kCompletedImplFrame
;
1824 void AfterTest() override
{ EXPECT_EQ(current_state_
, kCompletedImplFrame
); }
1828 BeginFrameArgs current_begin_frame_args_
;
1831 SINGLE_THREAD_TEST_F(LayerTreeHostTestCompositeImmediatelyStateTransitions
);
1833 class LayerTreeHostTestLCDChange
: public LayerTreeHostTest
{
1835 void SetupTree() override
{
1836 num_tiles_rastered_
= 0;
1838 scoped_refptr
<Layer
> root_layer
=
1839 PictureLayer::Create(layer_settings(), &client_
);
1840 client_
.set_fill_with_nonsolid_color(true);
1841 root_layer
->SetIsDrawable(true);
1842 root_layer
->SetBounds(gfx::Size(10, 10));
1843 root_layer
->SetContentsOpaque(true);
1845 layer_tree_host()->SetRootLayer(root_layer
);
1847 // The expectations are based on the assumption that the default
1848 // LCD settings are:
1849 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text
);
1851 LayerTreeHostTest::SetupTree();
1854 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1856 void DidCommitAndDrawFrame() override
{
1857 switch (layer_tree_host()->source_frame_number()) {
1859 PostSetNeedsCommitToMainThread();
1862 // Change layer opacity that should trigger lcd change.
1863 layer_tree_host()->root_layer()->SetOpacity(.5f
);
1866 // Change layer opacity that should not trigger lcd change.
1867 layer_tree_host()->root_layer()->SetOpacity(1.f
);
1875 void NotifyTileStateChangedOnThread(LayerTreeHostImpl
* host_impl
,
1876 const Tile
* tile
) override
{
1877 ++num_tiles_rastered_
;
1880 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
1881 PictureLayerImpl
* root_layer
=
1882 static_cast<PictureLayerImpl
*>(host_impl
->active_tree()->root_layer());
1883 bool can_use_lcd_text
=
1884 host_impl
->active_tree()->root_layer()->can_use_lcd_text();
1885 switch (host_impl
->active_tree()->source_frame_number()) {
1888 EXPECT_EQ(1, num_tiles_rastered_
);
1889 EXPECT_TRUE(can_use_lcd_text
);
1890 EXPECT_TRUE(root_layer
->RasterSourceUsesLCDText());
1893 // Nothing changed on the layer.
1894 EXPECT_EQ(1, num_tiles_rastered_
);
1895 EXPECT_TRUE(can_use_lcd_text
);
1896 EXPECT_TRUE(root_layer
->RasterSourceUsesLCDText());
1899 // LCD text was disabled; it should be re-rastered with LCD text off.
1900 EXPECT_EQ(2, num_tiles_rastered_
);
1901 EXPECT_FALSE(can_use_lcd_text
);
1902 EXPECT_FALSE(root_layer
->RasterSourceUsesLCDText());
1905 // LCD text was enabled, but it's sticky and stays off.
1906 EXPECT_EQ(2, num_tiles_rastered_
);
1907 EXPECT_TRUE(can_use_lcd_text
);
1908 EXPECT_FALSE(root_layer
->RasterSourceUsesLCDText());
1913 void AfterTest() override
{}
1916 FakeContentLayerClient client_
;
1917 int num_tiles_rastered_
;
1920 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDChange
);
1922 // Verify that the BeginFrame notification is used to initiate rendering.
1923 class LayerTreeHostTestBeginFrameNotification
: public LayerTreeHostTest
{
1925 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1926 settings
->use_external_begin_frame_source
= true;
1929 void BeginTest() override
{
1930 // This will trigger a SetNeedsBeginFrame which will trigger a
1932 PostSetNeedsCommitToMainThread();
1935 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
1936 LayerTreeHostImpl::FrameData
* frame
,
1937 DrawResult draw_result
) override
{
1939 return DRAW_SUCCESS
;
1942 void AfterTest() override
{}
1945 base::TimeTicks frame_time_
;
1948 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification
);
1950 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled
1951 : public LayerTreeHostTest
{
1953 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1954 settings
->use_external_begin_frame_source
= true;
1955 settings
->using_synchronous_renderer_compositor
= true;
1958 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1960 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
1961 // The BeginFrame notification is turned off now but will get enabled
1962 // once we return. End test while it's enabled.
1963 ImplThreadTaskRunner()->PostTask(
1965 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest
,
1966 base::Unretained(this)));
1969 void AfterTest() override
{}
1972 MULTI_THREAD_TEST_F(
1973 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled
);
1975 class LayerTreeHostTestAbortedCommitDoesntStall
: public LayerTreeHostTest
{
1977 LayerTreeHostTestAbortedCommitDoesntStall()
1978 : commit_count_(0), commit_abort_count_(0), commit_complete_count_(0) {}
1980 void InitializeSettings(LayerTreeSettings
* settings
) override
{
1981 settings
->use_external_begin_frame_source
= true;
1984 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
1986 void DidCommit() override
{
1988 if (commit_count_
== 4) {
1989 // After two aborted commits, request a real commit now to make sure a
1990 // real commit following an aborted commit will still complete and
1991 // end the test even when the Impl thread is idle.
1992 layer_tree_host()->SetNeedsCommit();
1996 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl
* host_impl
,
1997 CommitEarlyOutReason reason
) override
{
1998 commit_abort_count_
++;
1999 // Initiate another abortable commit.
2000 host_impl
->SetNeedsCommit();
2003 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
2004 commit_complete_count_
++;
2005 if (commit_complete_count_
== 1) {
2006 // Initiate an abortable commit after the first commit.
2007 host_impl
->SetNeedsCommit();
2013 void AfterTest() override
{
2014 EXPECT_EQ(commit_count_
, 5);
2015 EXPECT_EQ(commit_abort_count_
, 3);
2016 EXPECT_EQ(commit_complete_count_
, 2);
2020 int commit_abort_count_
;
2021 int commit_complete_count_
;
2024 class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
2025 : public LayerTreeHostTestAbortedCommitDoesntStall
{
2027 void InitializeSettings(LayerTreeSettings
* settings
) override
{
2028 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings
);
2029 settings
->using_synchronous_renderer_compositor
= true;
2032 void ScheduledActionInvalidateOutputSurface() override
{
2033 // Do not call ImplThreadTaskRunner after the test ended because of the
2034 // possibility of use-after-free due to a race.
2037 ImplThreadTaskRunner()->PostTask(
2040 &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
2042 base::Unretained(this)));
2046 // Synchronous compositor does not draw unless told to do so by the output
2048 output_surface()->client()->OnDraw();
2052 MULTI_THREAD_TEST_F(
2053 LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
);
2055 class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync
2056 : public LayerTreeHostTestAbortedCommitDoesntStall
{
2057 void InitializeSettings(LayerTreeSettings
* settings
) override
{
2058 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings
);
2059 settings
->wait_for_beginframe_interval
= false;
2060 settings
->renderer_settings
.disable_display_vsync
= true;
2064 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync
);
2066 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation
2067 : public LayerTreeHostTest
{
2069 void SetupTree() override
{
2070 LayerTreeHostTest::SetupTree();
2072 scoped_refptr
<Layer
> layer
=
2073 PictureLayer::Create(layer_settings(), &client_
);
2074 layer
->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2075 layer
->SetBounds(gfx::Size(10, 10));
2076 layer_tree_host()->root_layer()->AddChild(layer
);
2079 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2081 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
2085 void AfterTest() override
{}
2087 FakeContentLayerClient client_
;
2090 SINGLE_AND_MULTI_THREAD_TEST_F(
2091 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation
);
2093 class LayerTreeHostTestChangeLayerPropertiesInPaintContents
2094 : public LayerTreeHostTest
{
2096 class SetBoundsClient
: public ContentLayerClient
{
2098 SetBoundsClient() : layer_(0) {}
2100 void set_layer(Layer
* layer
) { layer_
= layer
; }
2102 void PaintContents(SkCanvas
* canvas
,
2103 const gfx::Rect
& clip
,
2104 PaintingControlSetting picture_control
) override
{
2108 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
2109 const gfx::Rect
& clip
,
2110 PaintingControlSetting picture_control
) override
{
2111 layer_
->SetBounds(gfx::Size(2, 2));
2113 // Return a dummy display list.
2114 scoped_refptr
<DisplayItemList
> display_list
=
2115 DisplayItemList::Create(clip
, DisplayItemListSettings());
2116 return display_list
;
2119 bool FillsBoundsCompletely() const override
{ return false; }
2120 size_t GetApproximateUnsharedMemoryUsage() const override
{ return 0; }
2126 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
2128 void SetupTree() override
{
2129 scoped_refptr
<PictureLayer
> root_layer
=
2130 PictureLayer::Create(layer_settings(), &client_
);
2131 root_layer
->SetIsDrawable(true);
2132 root_layer
->SetBounds(gfx::Size(1, 1));
2133 client_
.set_layer(root_layer
.get());
2135 layer_tree_host()->SetRootLayer(root_layer
);
2136 LayerTreeHostTest::SetupTree();
2139 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2140 void AfterTest() override
{}
2142 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
2144 if (num_commits_
== 1) {
2145 LayerImpl
* root_layer
= host_impl
->active_tree()->root_layer();
2146 EXPECT_EQ(gfx::Size(1, 1), root_layer
->bounds());
2148 LayerImpl
* root_layer
= host_impl
->active_tree()->root_layer();
2149 EXPECT_EQ(gfx::Size(2, 2), root_layer
->bounds());
2155 SetBoundsClient client_
;
2159 SINGLE_AND_MULTI_THREAD_TEST_F(
2160 LayerTreeHostTestChangeLayerPropertiesInPaintContents
);
2162 class MockIOSurfaceWebGraphicsContext3D
: public TestWebGraphicsContext3D
{
2164 MockIOSurfaceWebGraphicsContext3D() {
2165 test_capabilities_
.gpu
.iosurface
= true;
2166 test_capabilities_
.gpu
.texture_rectangle
= true;
2169 GLuint
createTexture() override
{ return 1; }
2170 MOCK_METHOD1(activeTexture
, void(GLenum texture
));
2171 MOCK_METHOD2(bindTexture
, void(GLenum target
,
2172 GLuint texture_id
));
2173 MOCK_METHOD3(texParameteri
, void(GLenum target
,
2176 MOCK_METHOD5(texImageIOSurface2DCHROMIUM
, void(GLenum target
,
2181 MOCK_METHOD4(drawElements
, void(GLenum mode
,
2185 MOCK_METHOD1(deleteTexture
, void(GLenum texture
));
2186 MOCK_METHOD3(produceTextureDirectCHROMIUM
,
2187 void(GLuint texture
, GLenum target
, const GLbyte
* mailbox
));
2190 class LayerTreeHostTestIOSurfaceDrawing
: public LayerTreeHostTest
{
2192 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
2193 scoped_ptr
<MockIOSurfaceWebGraphicsContext3D
> mock_context_owned(
2194 new MockIOSurfaceWebGraphicsContext3D
);
2195 mock_context_
= mock_context_owned
.get();
2197 if (delegating_renderer())
2198 return FakeOutputSurface::CreateDelegating3d(mock_context_owned
.Pass());
2200 return FakeOutputSurface::Create3d(mock_context_owned
.Pass());
2203 void SetupTree() override
{
2204 LayerTreeHostTest::SetupTree();
2206 layer_tree_host()->root_layer()->SetIsDrawable(false);
2209 io_surface_size_
= gfx::Size(6, 7);
2211 scoped_refptr
<IOSurfaceLayer
> io_surface_layer
=
2212 IOSurfaceLayer::Create(layer_settings());
2213 io_surface_layer
->SetBounds(gfx::Size(10, 10));
2214 io_surface_layer
->SetIsDrawable(true);
2215 io_surface_layer
->SetContentsOpaque(true);
2216 io_surface_layer
->SetIOSurfaceProperties(io_surface_id_
, io_surface_size_
);
2217 layer_tree_host()->root_layer()->AddChild(io_surface_layer
);
2220 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2222 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
2223 EXPECT_EQ(0u, host_impl
->resource_provider()->num_resources());
2224 // In WillDraw, the IOSurfaceLayer sets up the io surface texture.
2226 EXPECT_CALL(*mock_context_
, activeTexture(_
)).Times(0);
2227 EXPECT_CALL(*mock_context_
, bindTexture(GL_TEXTURE_RECTANGLE_ARB
, 1))
2229 EXPECT_CALL(*mock_context_
,
2231 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
))
2233 EXPECT_CALL(*mock_context_
,
2235 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
))
2237 EXPECT_CALL(*mock_context_
,
2238 texParameteri(GL_TEXTURE_RECTANGLE_ARB
,
2239 GL_TEXTURE_POOL_CHROMIUM
,
2240 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM
)).Times(1);
2241 EXPECT_CALL(*mock_context_
,
2242 texParameteri(GL_TEXTURE_RECTANGLE_ARB
,
2244 GL_CLAMP_TO_EDGE
)).Times(1);
2245 EXPECT_CALL(*mock_context_
,
2246 texParameteri(GL_TEXTURE_RECTANGLE_ARB
,
2248 GL_CLAMP_TO_EDGE
)).Times(1);
2250 EXPECT_CALL(*mock_context_
,
2251 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB
,
2252 io_surface_size_
.width(),
2253 io_surface_size_
.height(),
2257 EXPECT_CALL(*mock_context_
, bindTexture(_
, 0)).Times(AnyNumber());
2260 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
2261 LayerTreeHostImpl::FrameData
* frame
,
2262 DrawResult draw_result
) override
{
2263 Mock::VerifyAndClearExpectations(&mock_context_
);
2264 ResourceProvider
* resource_provider
= host_impl
->resource_provider();
2265 EXPECT_EQ(1u, resource_provider
->num_resources());
2266 CHECK_EQ(1u, frame
->render_passes
.size());
2267 CHECK_LE(1u, frame
->render_passes
[0]->quad_list
.size());
2268 const DrawQuad
* quad
= frame
->render_passes
[0]->quad_list
.front();
2269 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT
, quad
->material
);
2270 const IOSurfaceDrawQuad
* io_surface_draw_quad
=
2271 IOSurfaceDrawQuad::MaterialCast(quad
);
2272 EXPECT_EQ(io_surface_size_
, io_surface_draw_quad
->io_surface_size
);
2273 EXPECT_NE(0u, io_surface_draw_quad
->io_surface_resource_id());
2274 EXPECT_EQ(static_cast<GLenum
>(GL_TEXTURE_RECTANGLE_ARB
),
2275 resource_provider
->TargetForTesting(
2276 io_surface_draw_quad
->io_surface_resource_id()));
2278 if (delegating_renderer()) {
2279 // The io surface layer's resource should be sent to the parent.
2280 EXPECT_CALL(*mock_context_
, produceTextureDirectCHROMIUM(
2281 _
, GL_TEXTURE_RECTANGLE_ARB
, _
)).Times(1);
2283 // The io surface layer's texture is drawn.
2284 EXPECT_CALL(*mock_context_
, activeTexture(GL_TEXTURE0
)).Times(AtLeast(1));
2285 EXPECT_CALL(*mock_context_
, drawElements(GL_TRIANGLES
, 6, _
, _
))
2292 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
2293 Mock::VerifyAndClearExpectations(&mock_context_
);
2295 EXPECT_CALL(*mock_context_
, deleteTexture(1)).Times(AtLeast(1));
2299 void AfterTest() override
{}
2302 MockIOSurfaceWebGraphicsContext3D
* mock_context_
;
2303 gfx::Size io_surface_size_
;
2306 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing
);
2308 class LayerTreeHostTestNumFramesPending
: public LayerTreeHostTest
{
2310 void BeginTest() override
{
2312 PostSetNeedsCommitToMainThread();
2315 // Round 1: commit + draw
2316 // Round 2: commit only (no draw/swap)
2317 // Round 3: draw only (no commit)
2319 void DidCommit() override
{
2320 int commit
= layer_tree_host()->source_frame_number();
2324 EXPECT_EQ(1, frame_
);
2325 layer_tree_host()->SetNeedsRedraw();
2330 void DidCompleteSwapBuffers() override
{
2331 int commit
= layer_tree_host()->source_frame_number();
2336 EXPECT_EQ(1, commit
);
2337 layer_tree_host()->SetNeedsCommit();
2341 EXPECT_EQ(2, commit
);
2347 void AfterTest() override
{}
2353 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending
);
2355 class LayerTreeHostTestResourcelessSoftwareDraw
: public LayerTreeHostTest
{
2357 void SetupTree() override
{
2358 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
2359 root_layer_
->SetIsDrawable(true);
2360 root_layer_
->SetBounds(gfx::Size(50, 50));
2362 parent_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
2363 parent_layer_
->SetIsDrawable(true);
2364 parent_layer_
->SetBounds(gfx::Size(50, 50));
2365 parent_layer_
->SetForceRenderSurface(true);
2367 child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
2368 child_layer_
->SetIsDrawable(true);
2369 child_layer_
->SetBounds(gfx::Size(50, 50));
2371 root_layer_
->AddChild(parent_layer_
);
2372 parent_layer_
->AddChild(child_layer_
);
2373 layer_tree_host()->SetRootLayer(root_layer_
);
2375 LayerTreeHostTest::SetupTree();
2378 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
2379 if (delegating_renderer()) {
2380 return FakeOutputSurface::CreateDelegatingSoftware(
2381 make_scoped_ptr(new SoftwareOutputDevice
));
2383 return FakeOutputSurface::CreateSoftware(
2384 make_scoped_ptr(new SoftwareOutputDevice
));
2388 void BeginTest() override
{
2389 PostSetNeedsCommitToMainThread();
2393 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
2394 LayerTreeHostImpl::FrameData
* frame_data
,
2395 DrawResult draw_result
) override
{
2396 if (host_impl
->GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE
) {
2397 EXPECT_EQ(1u, frame_data
->render_passes
.size());
2398 // Has at least 3 quads for each layer.
2399 RenderPass
* render_pass
= frame_data
->render_passes
[0];
2400 EXPECT_GE(render_pass
->quad_list
.size(), 3u);
2402 EXPECT_EQ(2u, frame_data
->render_passes
.size());
2404 // At least root layer quad in root render pass.
2405 EXPECT_GE(frame_data
->render_passes
[0]->quad_list
.size(), 1u);
2406 // At least parent and child layer quads in parent render pass.
2407 EXPECT_GE(frame_data
->render_passes
[1]->quad_list
.size(), 2u);
2412 void SwapBuffersCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
2414 switch (swap_count_
) {
2416 gfx::Transform identity
;
2417 gfx::Rect empty_rect
;
2418 bool resourceless_software_draw
= true;
2419 host_impl
->SetExternalDrawConstraints(identity
, empty_rect
, empty_rect
,
2420 empty_rect
, identity
,
2421 resourceless_software_draw
);
2422 host_impl
->SetFullRootLayerDamage();
2423 host_impl
->SetNeedsRedraw();
2434 void AfterTest() override
{}
2437 FakeContentLayerClient client_
;
2438 scoped_refptr
<Layer
> root_layer_
;
2439 scoped_refptr
<Layer
> parent_layer_
;
2440 scoped_refptr
<Layer
> child_layer_
;
2444 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw
);
2446 // Test for UI Resource management.
2447 class LayerTreeHostTestUIResource
: public LayerTreeHostTest
{
2449 LayerTreeHostTestUIResource() : num_ui_resources_(0) {}
2451 void InitializeSettings(LayerTreeSettings
* settings
) override
{
2452 settings
->renderer_settings
.texture_id_allocation_chunk_size
= 1;
2455 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
2457 void DidCommit() override
{
2458 int frame
= layer_tree_host()->source_frame_number();
2463 PostSetNeedsCommitToMainThread();
2466 // Usually ScopedUIResource are deleted from the manager in their
2467 // destructor. Here we just want to test that a direct call to
2468 // DeleteUIResource works.
2469 layer_tree_host()->DeleteUIResource(ui_resources_
[0]->id());
2470 PostSetNeedsCommitToMainThread();
2473 // DeleteUIResource can be called with an invalid id.
2474 layer_tree_host()->DeleteUIResource(ui_resources_
[0]->id());
2475 PostSetNeedsCommitToMainThread();
2480 PostSetNeedsCommitToMainThread();
2489 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
2490 TestWebGraphicsContext3D
* context
= TestContext();
2492 int frame
= impl
->active_tree()->source_frame_number();
2495 ASSERT_EQ(0u, context
->NumTextures());
2498 // Created two textures.
2499 ASSERT_EQ(2u, context
->NumTextures());
2502 // One texture left after one deletion.
2503 ASSERT_EQ(1u, context
->NumTextures());
2506 // Resource manager state should not change when delete is called on an
2508 ASSERT_EQ(1u, context
->NumTextures());
2511 // Creation after deletion: two more creates should total up to
2513 ASSERT_EQ(3u, context
->NumTextures());
2518 void AfterTest() override
{}
2521 // Must clear all resources before exiting.
2522 void ClearResources() {
2523 for (int i
= 0; i
< num_ui_resources_
; i
++)
2524 ui_resources_
[i
] = nullptr;
2527 void CreateResource() {
2528 ui_resources_
[num_ui_resources_
++] =
2529 FakeScopedUIResource::Create(layer_tree_host());
2532 scoped_ptr
<FakeScopedUIResource
> ui_resources_
[5];
2533 int num_ui_resources_
;
2536 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource
);
2538 class PushPropertiesCountingLayerImpl
: public LayerImpl
{
2540 static scoped_ptr
<PushPropertiesCountingLayerImpl
> Create(
2541 LayerTreeImpl
* tree_impl
, int id
) {
2542 return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl
, id
));
2545 ~PushPropertiesCountingLayerImpl() override
{}
2547 void PushPropertiesTo(LayerImpl
* layer
) override
{
2548 LayerImpl::PushPropertiesTo(layer
);
2549 push_properties_count_
++;
2550 // Push state to the active tree because we can only access it from there.
2551 static_cast<PushPropertiesCountingLayerImpl
*>(
2552 layer
)->push_properties_count_
= push_properties_count_
;
2555 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
{
2556 return PushPropertiesCountingLayerImpl::Create(tree_impl
, id());
2559 size_t push_properties_count() const { return push_properties_count_
; }
2560 void reset_push_properties_count() { push_properties_count_
= 0; }
2563 size_t push_properties_count_
;
2565 PushPropertiesCountingLayerImpl(LayerTreeImpl
* tree_impl
, int id
)
2566 : LayerImpl(tree_impl
, id
),
2567 push_properties_count_(0) {
2568 SetBounds(gfx::Size(1, 1));
2572 class PushPropertiesCountingLayer
: public Layer
{
2574 static scoped_refptr
<PushPropertiesCountingLayer
> Create(
2575 const LayerSettings
& settings
) {
2576 return new PushPropertiesCountingLayer(settings
);
2579 void PushPropertiesTo(LayerImpl
* layer
) override
{
2580 Layer::PushPropertiesTo(layer
);
2581 push_properties_count_
++;
2582 if (persist_needs_push_properties_
)
2583 needs_push_properties_
= true;
2586 // Something to make this layer push properties, but no other layer.
2587 void MakePushProperties() { SetContentsOpaque(!contents_opaque()); }
2589 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
{
2590 return PushPropertiesCountingLayerImpl::Create(tree_impl
, id());
2593 void SetDrawsContent(bool draws_content
) { SetIsDrawable(draws_content
); }
2595 size_t push_properties_count() const { return push_properties_count_
; }
2596 void reset_push_properties_count() { push_properties_count_
= 0; }
2598 void set_persist_needs_push_properties(bool persist
) {
2599 persist_needs_push_properties_
= persist
;
2603 explicit PushPropertiesCountingLayer(const LayerSettings
& settings
)
2605 push_properties_count_(0),
2606 persist_needs_push_properties_(false) {
2607 SetBounds(gfx::Size(1, 1));
2609 ~PushPropertiesCountingLayer() override
{}
2611 size_t push_properties_count_
;
2612 bool persist_needs_push_properties_
;
2615 class LayerTreeHostTestLayersPushProperties
: public LayerTreeHostTest
{
2617 void BeginTest() override
{
2619 expected_push_properties_root_
= 0;
2620 expected_push_properties_child_
= 0;
2621 expected_push_properties_grandchild_
= 0;
2622 expected_push_properties_child2_
= 0;
2623 expected_push_properties_other_root_
= 0;
2624 expected_push_properties_leaf_layer_
= 0;
2625 PostSetNeedsCommitToMainThread();
2628 void SetupTree() override
{
2629 root_
= PushPropertiesCountingLayer::Create(layer_settings());
2630 child_
= PushPropertiesCountingLayer::Create(layer_settings());
2631 child2_
= PushPropertiesCountingLayer::Create(layer_settings());
2632 grandchild_
= PushPropertiesCountingLayer::Create(layer_settings());
2633 leaf_always_pushing_layer_
=
2634 PushPropertiesCountingLayer::Create(layer_settings());
2635 leaf_always_pushing_layer_
->set_persist_needs_push_properties(true);
2637 root_
->AddChild(child_
);
2638 root_
->AddChild(child2_
);
2639 child_
->AddChild(grandchild_
);
2640 child2_
->AddChild(leaf_always_pushing_layer_
);
2642 other_root_
= PushPropertiesCountingLayer::Create(layer_settings());
2644 // Don't set the root layer here.
2645 LayerTreeHostTest::SetupTree();
2648 void DidCommitAndDrawFrame() override
{
2649 EXPECT_EQ(expected_push_properties_root_
, root_
->push_properties_count())
2650 << "num_commits: " << num_commits_
;
2651 EXPECT_EQ(expected_push_properties_child_
, child_
->push_properties_count())
2652 << "num_commits: " << num_commits_
;
2653 EXPECT_EQ(expected_push_properties_grandchild_
,
2654 grandchild_
->push_properties_count())
2655 << "num_commits: " << num_commits_
;
2656 EXPECT_EQ(expected_push_properties_child2_
,
2657 child2_
->push_properties_count())
2658 << "num_commits: " << num_commits_
;
2659 EXPECT_EQ(expected_push_properties_other_root_
,
2660 other_root_
->push_properties_count())
2661 << "num_commits: " << num_commits_
;
2662 EXPECT_EQ(expected_push_properties_leaf_layer_
,
2663 leaf_always_pushing_layer_
->push_properties_count())
2664 << "num_commits: " << num_commits_
;
2668 // The scrollbar layer always needs to be pushed.
2669 if (root_
->layer_tree_host()) {
2670 EXPECT_TRUE(root_
->descendant_needs_push_properties());
2671 EXPECT_FALSE(root_
->needs_push_properties());
2673 if (child2_
->layer_tree_host()) {
2674 EXPECT_TRUE(child2_
->descendant_needs_push_properties());
2675 EXPECT_FALSE(child2_
->needs_push_properties());
2677 if (leaf_always_pushing_layer_
->layer_tree_host()) {
2679 leaf_always_pushing_layer_
->descendant_needs_push_properties());
2680 EXPECT_TRUE(leaf_always_pushing_layer_
->needs_push_properties());
2683 // child_ and grandchild_ don't persist their need to push properties.
2684 if (child_
->layer_tree_host()) {
2685 EXPECT_FALSE(child_
->descendant_needs_push_properties());
2686 EXPECT_FALSE(child_
->needs_push_properties());
2688 if (grandchild_
->layer_tree_host()) {
2689 EXPECT_FALSE(grandchild_
->descendant_needs_push_properties());
2690 EXPECT_FALSE(grandchild_
->needs_push_properties());
2693 if (other_root_
->layer_tree_host()) {
2694 EXPECT_FALSE(other_root_
->descendant_needs_push_properties());
2695 EXPECT_FALSE(other_root_
->needs_push_properties());
2698 switch (num_commits_
) {
2700 layer_tree_host()->SetRootLayer(root_
);
2701 // Layers added to the tree get committed.
2702 ++expected_push_properties_root_
;
2703 ++expected_push_properties_child_
;
2704 ++expected_push_properties_grandchild_
;
2705 ++expected_push_properties_child2_
;
2708 layer_tree_host()->SetNeedsCommit();
2709 // No layers need commit.
2712 layer_tree_host()->SetRootLayer(other_root_
);
2713 // Layers added to the tree get committed.
2714 ++expected_push_properties_other_root_
;
2717 layer_tree_host()->SetRootLayer(root_
);
2718 // Layers added to the tree get committed.
2719 ++expected_push_properties_root_
;
2720 ++expected_push_properties_child_
;
2721 ++expected_push_properties_grandchild_
;
2722 ++expected_push_properties_child2_
;
2725 layer_tree_host()->SetNeedsCommit();
2726 // No layers need commit.
2729 child_
->RemoveFromParent();
2730 // No layers need commit.
2733 root_
->AddChild(child_
);
2734 // Layers added to the tree get committed.
2735 ++expected_push_properties_child_
;
2736 ++expected_push_properties_grandchild_
;
2739 grandchild_
->RemoveFromParent();
2740 // No layers need commit.
2743 child_
->AddChild(grandchild_
);
2744 // Layers added to the tree get committed.
2745 ++expected_push_properties_grandchild_
;
2748 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
2749 // No layers need commit.
2752 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.8f
, 1.1f
);
2753 // No layers need commit.
2756 child_
->MakePushProperties();
2757 // The modified layer needs commit
2758 ++expected_push_properties_child_
;
2761 child2_
->MakePushProperties();
2762 // The modified layer needs commit
2763 ++expected_push_properties_child2_
;
2766 child_
->RemoveFromParent();
2767 root_
->AddChild(child_
);
2768 // Layers added to the tree get committed.
2769 ++expected_push_properties_child_
;
2770 ++expected_push_properties_grandchild_
;
2773 grandchild_
->MakePushProperties();
2774 // The modified layer needs commit
2775 ++expected_push_properties_grandchild_
;
2778 // SetNeedsDisplay does not always set needs commit (so call it
2779 // explicitly), but is a property change.
2780 child_
->SetNeedsDisplay();
2781 ++expected_push_properties_child_
;
2782 layer_tree_host()->SetNeedsCommit();
2789 // The leaf layer always pushes.
2790 if (leaf_always_pushing_layer_
->layer_tree_host())
2791 ++expected_push_properties_leaf_layer_
;
2794 void AfterTest() override
{}
2797 FakeContentLayerClient client_
;
2798 scoped_refptr
<PushPropertiesCountingLayer
> root_
;
2799 scoped_refptr
<PushPropertiesCountingLayer
> child_
;
2800 scoped_refptr
<PushPropertiesCountingLayer
> child2_
;
2801 scoped_refptr
<PushPropertiesCountingLayer
> grandchild_
;
2802 scoped_refptr
<PushPropertiesCountingLayer
> other_root_
;
2803 scoped_refptr
<PushPropertiesCountingLayer
> leaf_always_pushing_layer_
;
2804 size_t expected_push_properties_root_
;
2805 size_t expected_push_properties_child_
;
2806 size_t expected_push_properties_child2_
;
2807 size_t expected_push_properties_grandchild_
;
2808 size_t expected_push_properties_other_root_
;
2809 size_t expected_push_properties_leaf_layer_
;
2812 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties
);
2814 class LayerTreeHostTestImplLayersPushProperties
2815 : public LayerTreeHostTestLayersPushProperties
{
2817 void BeginTest() override
{
2818 expected_push_properties_root_impl_
= 0;
2819 expected_push_properties_child_impl_
= 0;
2820 expected_push_properties_grandchild_impl_
= 0;
2821 expected_push_properties_child2_impl_
= 0;
2822 expected_push_properties_grandchild2_impl_
= 0;
2823 LayerTreeHostTestLayersPushProperties::BeginTest();
2826 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
2827 // These commits are in response to the changes made in
2828 // LayerTreeHostTestLayersPushProperties::DidCommitAndDrawFrame()
2829 switch (num_commits_
) {
2831 // Tree hasn't been setup yet don't bother to check anything.
2834 // Root gets set up, Everyone is initialized.
2835 ++expected_push_properties_root_impl_
;
2836 ++expected_push_properties_child_impl_
;
2837 ++expected_push_properties_grandchild_impl_
;
2838 ++expected_push_properties_child2_impl_
;
2839 ++expected_push_properties_grandchild2_impl_
;
2842 // Tree doesn't change but the one leaf that always pushes is pushed.
2843 ++expected_push_properties_grandchild2_impl_
;
2846 // Root is swapped here.
2847 // Clear the expected push properties the tree will be rebuilt.
2848 expected_push_properties_root_impl_
= 0;
2849 expected_push_properties_child_impl_
= 0;
2850 expected_push_properties_grandchild_impl_
= 0;
2851 expected_push_properties_child2_impl_
= 0;
2852 expected_push_properties_grandchild2_impl_
= 0;
2854 // Make sure the new root is pushed.
2855 EXPECT_EQ(1u, static_cast<PushPropertiesCountingLayerImpl
*>(
2856 host_impl
->RootLayer())->push_properties_count());
2859 // Root is swapped back all of the layers in the tree get pushed.
2860 ++expected_push_properties_root_impl_
;
2861 ++expected_push_properties_child_impl_
;
2862 ++expected_push_properties_grandchild_impl_
;
2863 ++expected_push_properties_child2_impl_
;
2864 ++expected_push_properties_grandchild2_impl_
;
2867 // Tree doesn't change but the one leaf that always pushes is pushed.
2868 ++expected_push_properties_grandchild2_impl_
;
2871 // First child is removed. Structure of the tree changes here so swap
2872 // some of the values. child_impl becomes child2_impl.
2873 expected_push_properties_child_impl_
=
2874 expected_push_properties_child2_impl_
;
2875 expected_push_properties_child2_impl_
= 0;
2876 // grandchild_impl becomes grandchild2_impl.
2877 expected_push_properties_grandchild_impl_
=
2878 expected_push_properties_grandchild2_impl_
;
2879 expected_push_properties_grandchild2_impl_
= 0;
2881 // grandchild_impl is now the leaf that always pushes. It is pushed.
2882 ++expected_push_properties_grandchild_impl_
;
2885 // The leaf that always pushes is pushed.
2886 ++expected_push_properties_grandchild_impl_
;
2888 // Child is added back. New layers are initialized.
2889 ++expected_push_properties_grandchild2_impl_
;
2890 ++expected_push_properties_child2_impl_
;
2894 expected_push_properties_grandchild2_impl_
= 0;
2897 ++expected_push_properties_grandchild_impl_
;
2900 // Leaf is added back
2901 ++expected_push_properties_grandchild2_impl_
;
2903 // The leaf that always pushes is pushed.
2904 ++expected_push_properties_grandchild_impl_
;
2907 // The leaf that always pushes is pushed.
2908 ++expected_push_properties_grandchild_impl_
;
2911 // The leaf that always pushes is pushed.
2912 ++expected_push_properties_grandchild_impl_
;
2915 // The leaf that always pushes is pushed.
2916 ++expected_push_properties_grandchild_impl_
;
2918 // This child position was changed.
2919 ++expected_push_properties_child2_impl_
;
2922 // The position of this child was changed.
2923 ++expected_push_properties_child_impl_
;
2925 // The leaf that always pushes is pushed.
2926 ++expected_push_properties_grandchild_impl_
;
2929 // Second child is removed from tree. Don't discard counts because
2930 // they are added back before commit.
2932 // The leaf that always pushes is pushed.
2933 ++expected_push_properties_grandchild_impl_
;
2935 // Second child added back.
2936 ++expected_push_properties_child2_impl_
;
2937 ++expected_push_properties_grandchild2_impl_
;
2941 // The position of this child was changed.
2942 ++expected_push_properties_grandchild2_impl_
;
2944 // The leaf that always pushes is pushed.
2945 ++expected_push_properties_grandchild_impl_
;
2948 // Second child is invalidated with SetNeedsDisplay
2949 ++expected_push_properties_child2_impl_
;
2951 // The leaf that always pushed is pushed.
2952 ++expected_push_properties_grandchild_impl_
;
2956 PushPropertiesCountingLayerImpl
* root_impl_
= NULL
;
2957 PushPropertiesCountingLayerImpl
* child_impl_
= NULL
;
2958 PushPropertiesCountingLayerImpl
* child2_impl_
= NULL
;
2959 PushPropertiesCountingLayerImpl
* grandchild_impl_
= NULL
;
2960 PushPropertiesCountingLayerImpl
* leaf_always_pushing_layer_impl_
= NULL
;
2962 // Pull the layers that we need from the tree assuming the same structure
2963 // as LayerTreeHostTestLayersPushProperties
2964 root_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2965 host_impl
->RootLayer());
2967 if (root_impl_
&& root_impl_
->children().size() > 0) {
2968 child_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2969 root_impl_
->children()[0]);
2971 if (child_impl_
&& child_impl_
->children().size() > 0)
2972 grandchild_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2973 child_impl_
->children()[0]);
2976 if (root_impl_
&& root_impl_
->children().size() > 1) {
2977 child2_impl_
= static_cast<PushPropertiesCountingLayerImpl
*>(
2978 root_impl_
->children()[1]);
2980 if (child2_impl_
&& child2_impl_
->children().size() > 0)
2981 leaf_always_pushing_layer_impl_
=
2982 static_cast<PushPropertiesCountingLayerImpl
*>(
2983 child2_impl_
->children()[0]);
2987 EXPECT_EQ(expected_push_properties_root_impl_
,
2988 root_impl_
->push_properties_count());
2990 EXPECT_EQ(expected_push_properties_child_impl_
,
2991 child_impl_
->push_properties_count());
2992 if (grandchild_impl_
)
2993 EXPECT_EQ(expected_push_properties_grandchild_impl_
,
2994 grandchild_impl_
->push_properties_count());
2996 EXPECT_EQ(expected_push_properties_child2_impl_
,
2997 child2_impl_
->push_properties_count());
2998 if (leaf_always_pushing_layer_impl_
)
2999 EXPECT_EQ(expected_push_properties_grandchild2_impl_
,
3000 leaf_always_pushing_layer_impl_
->push_properties_count());
3003 size_t expected_push_properties_root_impl_
;
3004 size_t expected_push_properties_child_impl_
;
3005 size_t expected_push_properties_child2_impl_
;
3006 size_t expected_push_properties_grandchild_impl_
;
3007 size_t expected_push_properties_grandchild2_impl_
;
3010 // In single thread there's no pending tree to push properties from.
3011 MULTI_THREAD_TEST_F(LayerTreeHostTestImplLayersPushProperties
);
3013 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
3014 : public LayerTreeHostTest
{
3016 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3018 void SetupTree() override
{
3019 root_
= Layer::Create(layer_settings());
3020 root_
->SetBounds(gfx::Size(1, 1));
3022 bool paint_scrollbar
= true;
3023 bool has_thumb
= false;
3024 scrollbar_layer_
= FakePaintedScrollbarLayer::Create(
3025 layer_settings(), paint_scrollbar
, has_thumb
, root_
->id());
3027 root_
->AddChild(scrollbar_layer_
);
3029 layer_tree_host()->SetRootLayer(root_
);
3030 LayerTreeHostTest::SetupTree();
3033 void DidCommitAndDrawFrame() override
{
3034 switch (layer_tree_host()->source_frame_number()) {
3038 // During update, the ignore_set_needs_commit_ bit is set to true to
3039 // avoid causing a second commit to be scheduled. If a property change
3040 // is made during this, however, it needs to be pushed in the upcoming
3042 scoped_ptr
<base::AutoReset
<bool>> ignore
=
3043 scrollbar_layer_
->IgnoreSetNeedsCommit();
3045 scrollbar_layer_
->SetBounds(gfx::Size(30, 30));
3047 EXPECT_TRUE(scrollbar_layer_
->needs_push_properties());
3048 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3049 layer_tree_host()->SetNeedsCommit();
3051 scrollbar_layer_
->reset_push_properties_count();
3052 EXPECT_EQ(0u, scrollbar_layer_
->push_properties_count());
3056 EXPECT_EQ(1u, scrollbar_layer_
->push_properties_count());
3062 void AfterTest() override
{}
3064 scoped_refptr
<Layer
> root_
;
3065 scoped_refptr
<FakePaintedScrollbarLayer
> scrollbar_layer_
;
3068 MULTI_THREAD_TEST_F(LayerTreeHostTestPropertyChangesDuringUpdateArePushed
);
3070 class LayerTreeHostTestSetDrawableCausesCommit
: public LayerTreeHostTest
{
3072 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3074 void SetupTree() override
{
3075 root_
= PushPropertiesCountingLayer::Create(layer_settings());
3076 child_
= PushPropertiesCountingLayer::Create(layer_settings());
3077 root_
->AddChild(child_
);
3079 layer_tree_host()->SetRootLayer(root_
);
3080 LayerTreeHostTest::SetupTree();
3083 void DidCommitAndDrawFrame() override
{
3084 switch (layer_tree_host()->source_frame_number()) {
3088 // During update, the ignore_set_needs_commit_ bit is set to true to
3089 // avoid causing a second commit to be scheduled. If a property change
3090 // is made during this, however, it needs to be pushed in the upcoming
3092 EXPECT_FALSE(root_
->needs_push_properties());
3093 EXPECT_FALSE(child_
->needs_push_properties());
3094 EXPECT_EQ(0, root_
->NumDescendantsThatDrawContent());
3095 root_
->reset_push_properties_count();
3096 child_
->reset_push_properties_count();
3097 child_
->SetDrawsContent(true);
3098 EXPECT_EQ(1, root_
->NumDescendantsThatDrawContent());
3099 EXPECT_EQ(0u, root_
->push_properties_count());
3100 EXPECT_EQ(0u, child_
->push_properties_count());
3101 EXPECT_TRUE(root_
->needs_push_properties());
3102 EXPECT_TRUE(child_
->needs_push_properties());
3106 EXPECT_EQ(1u, root_
->push_properties_count());
3107 EXPECT_EQ(1u, child_
->push_properties_count());
3108 EXPECT_FALSE(root_
->needs_push_properties());
3109 EXPECT_FALSE(child_
->needs_push_properties());
3115 void AfterTest() override
{}
3117 scoped_refptr
<PushPropertiesCountingLayer
> root_
;
3118 scoped_refptr
<PushPropertiesCountingLayer
> child_
;
3121 MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit
);
3123 class LayerTreeHostTestCasePushPropertiesThreeGrandChildren
3124 : public LayerTreeHostTest
{
3126 void BeginTest() override
{
3127 expected_push_properties_root_
= 0;
3128 expected_push_properties_child_
= 0;
3129 expected_push_properties_grandchild1_
= 0;
3130 expected_push_properties_grandchild2_
= 0;
3131 expected_push_properties_grandchild3_
= 0;
3132 PostSetNeedsCommitToMainThread();
3135 void SetupTree() override
{
3136 root_
= PushPropertiesCountingLayer::Create(layer_settings());
3137 child_
= PushPropertiesCountingLayer::Create(layer_settings());
3138 grandchild1_
= PushPropertiesCountingLayer::Create(layer_settings());
3139 grandchild2_
= PushPropertiesCountingLayer::Create(layer_settings());
3140 grandchild3_
= PushPropertiesCountingLayer::Create(layer_settings());
3142 root_
->AddChild(child_
);
3143 child_
->AddChild(grandchild1_
);
3144 child_
->AddChild(grandchild2_
);
3145 child_
->AddChild(grandchild3_
);
3147 // Don't set the root layer here.
3148 LayerTreeHostTest::SetupTree();
3151 void AfterTest() override
{}
3153 FakeContentLayerClient client_
;
3154 scoped_refptr
<PushPropertiesCountingLayer
> root_
;
3155 scoped_refptr
<PushPropertiesCountingLayer
> child_
;
3156 scoped_refptr
<PushPropertiesCountingLayer
> grandchild1_
;
3157 scoped_refptr
<PushPropertiesCountingLayer
> grandchild2_
;
3158 scoped_refptr
<PushPropertiesCountingLayer
> grandchild3_
;
3159 size_t expected_push_properties_root_
;
3160 size_t expected_push_properties_child_
;
3161 size_t expected_push_properties_grandchild1_
;
3162 size_t expected_push_properties_grandchild2_
;
3163 size_t expected_push_properties_grandchild3_
;
3166 class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush
3167 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3169 void DidCommitAndDrawFrame() override
{
3170 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3171 switch (last_source_frame_number
) {
3173 EXPECT_FALSE(root_
->needs_push_properties());
3174 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3175 EXPECT_FALSE(child_
->needs_push_properties());
3176 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3177 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3178 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3179 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3180 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3181 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3182 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3184 layer_tree_host()->SetRootLayer(root_
);
3186 EXPECT_TRUE(root_
->needs_push_properties());
3187 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3188 EXPECT_TRUE(child_
->needs_push_properties());
3189 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3190 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3191 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3192 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3193 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3194 EXPECT_TRUE(grandchild3_
->needs_push_properties());
3195 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3204 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush
);
3206 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion
3207 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3209 void DidCommitAndDrawFrame() override
{
3210 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3211 switch (last_source_frame_number
) {
3213 layer_tree_host()->SetRootLayer(root_
);
3216 EXPECT_FALSE(root_
->needs_push_properties());
3217 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3218 EXPECT_FALSE(child_
->needs_push_properties());
3219 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3220 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3221 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3222 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3223 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3224 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3225 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3227 grandchild1_
->RemoveFromParent();
3228 grandchild1_
->SetPosition(gfx::Point(1, 1));
3230 EXPECT_FALSE(root_
->needs_push_properties());
3231 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3232 EXPECT_FALSE(child_
->needs_push_properties());
3233 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3234 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3235 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3236 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3237 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3239 child_
->AddChild(grandchild1_
);
3241 EXPECT_FALSE(root_
->needs_push_properties());
3242 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3243 EXPECT_FALSE(child_
->needs_push_properties());
3244 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3245 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3246 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3247 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3248 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3249 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3250 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3252 grandchild2_
->SetPosition(gfx::Point(1, 1));
3254 EXPECT_FALSE(root_
->needs_push_properties());
3255 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3256 EXPECT_FALSE(child_
->needs_push_properties());
3257 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3258 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3259 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3260 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3261 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3262 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3263 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3265 // grandchild2_ will still need a push properties.
3266 grandchild1_
->RemoveFromParent();
3268 EXPECT_FALSE(root_
->needs_push_properties());
3269 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3270 EXPECT_FALSE(child_
->needs_push_properties());
3271 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3273 // grandchild3_ does not need a push properties, so recursing should
3274 // no longer be needed.
3275 grandchild2_
->RemoveFromParent();
3277 EXPECT_FALSE(root_
->needs_push_properties());
3278 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3279 EXPECT_FALSE(child_
->needs_push_properties());
3280 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3287 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion
);
3289 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence
3290 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3292 void DidCommitAndDrawFrame() override
{
3293 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3294 switch (last_source_frame_number
) {
3296 layer_tree_host()->SetRootLayer(root_
);
3297 grandchild1_
->set_persist_needs_push_properties(true);
3298 grandchild2_
->set_persist_needs_push_properties(true);
3301 EXPECT_FALSE(root_
->needs_push_properties());
3302 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3303 EXPECT_FALSE(child_
->needs_push_properties());
3304 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3305 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3306 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3307 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3308 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3309 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3310 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3312 // grandchild2_ will still need a push properties.
3313 grandchild1_
->RemoveFromParent();
3315 EXPECT_FALSE(root_
->needs_push_properties());
3316 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3317 EXPECT_FALSE(child_
->needs_push_properties());
3318 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3320 // grandchild3_ does not need a push properties, so recursing should
3321 // no longer be needed.
3322 grandchild2_
->RemoveFromParent();
3324 EXPECT_FALSE(root_
->needs_push_properties());
3325 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3326 EXPECT_FALSE(child_
->needs_push_properties());
3327 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3334 MULTI_THREAD_TEST_F(
3335 LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence
);
3337 class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree
3338 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3340 void DidCommitAndDrawFrame() override
{
3341 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3342 switch (last_source_frame_number
) {
3344 layer_tree_host()->SetRootLayer(root_
);
3347 EXPECT_FALSE(root_
->needs_push_properties());
3348 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3349 EXPECT_FALSE(child_
->needs_push_properties());
3350 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3351 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3352 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3353 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3354 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3355 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3356 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3358 // Change grandchildren while their parent is not in the tree.
3359 child_
->RemoveFromParent();
3360 grandchild1_
->SetPosition(gfx::Point(1, 1));
3361 grandchild2_
->SetPosition(gfx::Point(1, 1));
3362 root_
->AddChild(child_
);
3364 EXPECT_FALSE(root_
->needs_push_properties());
3365 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3366 EXPECT_TRUE(child_
->needs_push_properties());
3367 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3368 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3369 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3370 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3371 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3372 EXPECT_TRUE(grandchild3_
->needs_push_properties());
3373 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3375 grandchild1_
->RemoveFromParent();
3377 EXPECT_FALSE(root_
->needs_push_properties());
3378 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3379 EXPECT_TRUE(child_
->needs_push_properties());
3380 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3382 grandchild2_
->RemoveFromParent();
3384 EXPECT_FALSE(root_
->needs_push_properties());
3385 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3386 EXPECT_TRUE(child_
->needs_push_properties());
3387 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3389 grandchild3_
->RemoveFromParent();
3391 EXPECT_FALSE(root_
->needs_push_properties());
3392 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3393 EXPECT_TRUE(child_
->needs_push_properties());
3394 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3402 MULTI_THREAD_TEST_F(
3403 LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree
);
3405 class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild
3406 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3408 void DidCommitAndDrawFrame() override
{
3409 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3410 switch (last_source_frame_number
) {
3412 layer_tree_host()->SetRootLayer(root_
);
3415 EXPECT_FALSE(root_
->needs_push_properties());
3416 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3417 EXPECT_FALSE(child_
->needs_push_properties());
3418 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3419 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3420 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3421 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3422 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3423 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3424 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3426 child_
->SetPosition(gfx::Point(1, 1));
3427 grandchild1_
->SetPosition(gfx::Point(1, 1));
3428 grandchild2_
->SetPosition(gfx::Point(1, 1));
3430 EXPECT_FALSE(root_
->needs_push_properties());
3431 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3432 EXPECT_TRUE(child_
->needs_push_properties());
3433 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3434 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3435 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3436 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3437 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3438 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3439 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3441 grandchild1_
->RemoveFromParent();
3443 EXPECT_FALSE(root_
->needs_push_properties());
3444 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3445 EXPECT_TRUE(child_
->needs_push_properties());
3446 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3448 grandchild2_
->RemoveFromParent();
3450 EXPECT_FALSE(root_
->needs_push_properties());
3451 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3452 EXPECT_TRUE(child_
->needs_push_properties());
3453 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3455 child_
->RemoveFromParent();
3457 EXPECT_FALSE(root_
->needs_push_properties());
3458 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3466 MULTI_THREAD_TEST_F(
3467 LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild
);
3469 class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
3470 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren
{
3472 void DidCommitAndDrawFrame() override
{
3473 int last_source_frame_number
= layer_tree_host()->source_frame_number() - 1;
3474 switch (last_source_frame_number
) {
3476 layer_tree_host()->SetRootLayer(root_
);
3479 EXPECT_FALSE(root_
->needs_push_properties());
3480 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3481 EXPECT_FALSE(child_
->needs_push_properties());
3482 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3483 EXPECT_FALSE(grandchild1_
->needs_push_properties());
3484 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3485 EXPECT_FALSE(grandchild2_
->needs_push_properties());
3486 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3487 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3488 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3490 grandchild1_
->SetPosition(gfx::Point(1, 1));
3491 grandchild2_
->SetPosition(gfx::Point(1, 1));
3492 child_
->SetPosition(gfx::Point(1, 1));
3494 EXPECT_FALSE(root_
->needs_push_properties());
3495 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3496 EXPECT_TRUE(child_
->needs_push_properties());
3497 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3498 EXPECT_TRUE(grandchild1_
->needs_push_properties());
3499 EXPECT_FALSE(grandchild1_
->descendant_needs_push_properties());
3500 EXPECT_TRUE(grandchild2_
->needs_push_properties());
3501 EXPECT_FALSE(grandchild2_
->descendant_needs_push_properties());
3502 EXPECT_FALSE(grandchild3_
->needs_push_properties());
3503 EXPECT_FALSE(grandchild3_
->descendant_needs_push_properties());
3505 grandchild1_
->RemoveFromParent();
3507 EXPECT_FALSE(root_
->needs_push_properties());
3508 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3509 EXPECT_TRUE(child_
->needs_push_properties());
3510 EXPECT_TRUE(child_
->descendant_needs_push_properties());
3512 grandchild2_
->RemoveFromParent();
3514 EXPECT_FALSE(root_
->needs_push_properties());
3515 EXPECT_TRUE(root_
->descendant_needs_push_properties());
3516 EXPECT_TRUE(child_
->needs_push_properties());
3517 EXPECT_FALSE(child_
->descendant_needs_push_properties());
3519 child_
->RemoveFromParent();
3521 EXPECT_FALSE(root_
->needs_push_properties());
3522 EXPECT_FALSE(root_
->descendant_needs_push_properties());
3530 MULTI_THREAD_TEST_F(
3531 LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
);
3533 // This test verifies that the tree activation callback is invoked correctly.
3534 class LayerTreeHostTestTreeActivationCallback
: public LayerTreeHostTest
{
3536 LayerTreeHostTestTreeActivationCallback()
3537 : num_commits_(0), callback_count_(0) {}
3539 void BeginTest() override
{
3540 PostSetNeedsCommitToMainThread();
3543 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
3544 LayerTreeHostImpl::FrameData
* frame_data
,
3545 DrawResult draw_result
) override
{
3547 switch (num_commits_
) {
3549 EXPECT_EQ(0, callback_count_
);
3550 callback_count_
= 0;
3552 PostSetNeedsCommitToMainThread();
3555 EXPECT_EQ(1, callback_count_
);
3556 callback_count_
= 0;
3558 PostSetNeedsCommitToMainThread();
3561 EXPECT_EQ(0, callback_count_
);
3562 callback_count_
= 0;
3566 ADD_FAILURE() << num_commits_
;
3570 return LayerTreeHostTest::PrepareToDrawOnThread(
3571 host_impl
, frame_data
, draw_result
);
3574 void AfterTest() override
{ EXPECT_EQ(3, num_commits_
); }
3576 void SetCallback(bool enable
) {
3577 output_surface()->SetTreeActivationCallback(
3580 &LayerTreeHostTestTreeActivationCallback::ActivationCallback
,
3581 base::Unretained(this))
3585 void ActivationCallback() { ++callback_count_
; }
3588 int callback_count_
;
3591 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTreeActivationCallback
);
3593 class LayerInvalidateCausesDraw
: public LayerTreeHostTest
{
3595 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {}
3597 void BeginTest() override
{
3598 ASSERT_TRUE(invalidate_layer_
)
3599 << "Derived tests must set this in SetupTree";
3601 // One initial commit.
3602 PostSetNeedsCommitToMainThread();
3605 void DidCommitAndDrawFrame() override
{
3606 // After commit, invalidate the layer. This should cause a commit.
3607 if (layer_tree_host()->source_frame_number() == 1)
3608 invalidate_layer_
->SetNeedsDisplay();
3611 void DrawLayersOnThread(LayerTreeHostImpl
* impl
) override
{
3613 if (impl
->active_tree()->source_frame_number() == 1)
3617 void CommitCompleteOnThread(LayerTreeHostImpl
* impl
) override
{
3621 void AfterTest() override
{
3622 EXPECT_GE(2, num_commits_
);
3623 EXPECT_GE(2, num_draws_
);
3627 scoped_refptr
<Layer
> invalidate_layer_
;
3634 // VideoLayer must support being invalidated and then passing that along
3635 // to the compositor thread, even though no resources are updated in
3636 // response to that invalidation.
3637 class LayerTreeHostTestVideoLayerInvalidate
: public LayerInvalidateCausesDraw
{
3639 void SetupTree() override
{
3640 LayerTreeHostTest::SetupTree();
3641 scoped_refptr
<VideoLayer
> video_layer
= VideoLayer::Create(
3642 layer_settings(), &provider_
, media::VIDEO_ROTATION_0
);
3643 video_layer
->SetBounds(gfx::Size(10, 10));
3644 video_layer
->SetIsDrawable(true);
3645 layer_tree_host()->root_layer()->AddChild(video_layer
);
3647 invalidate_layer_
= video_layer
;
3651 FakeVideoFrameProvider provider_
;
3654 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate
);
3656 // IOSurfaceLayer must support being invalidated and then passing that along
3657 // to the compositor thread, even though no resources are updated in
3658 // response to that invalidation.
3659 class LayerTreeHostTestIOSurfaceLayerInvalidate
3660 : public LayerInvalidateCausesDraw
{
3662 void SetupTree() override
{
3663 LayerTreeHostTest::SetupTree();
3664 scoped_refptr
<IOSurfaceLayer
> layer
=
3665 IOSurfaceLayer::Create(layer_settings());
3666 layer
->SetBounds(gfx::Size(10, 10));
3667 uint32_t fake_io_surface_id
= 7;
3668 layer
->SetIOSurfaceProperties(fake_io_surface_id
, layer
->bounds());
3669 layer
->SetIsDrawable(true);
3670 layer_tree_host()->root_layer()->AddChild(layer
);
3672 invalidate_layer_
= layer
;
3676 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceLayerInvalidate
);
3678 class LayerTreeHostTestPushHiddenLayer
: public LayerTreeHostTest
{
3680 void SetupTree() override
{
3681 root_layer_
= Layer::Create(layer_settings());
3682 root_layer_
->SetPosition(gfx::Point());
3683 root_layer_
->SetBounds(gfx::Size(10, 10));
3685 parent_layer_
= SolidColorLayer::Create(layer_settings());
3686 parent_layer_
->SetPosition(gfx::Point());
3687 parent_layer_
->SetBounds(gfx::Size(10, 10));
3688 parent_layer_
->SetIsDrawable(true);
3689 root_layer_
->AddChild(parent_layer_
);
3691 child_layer_
= SolidColorLayer::Create(layer_settings());
3692 child_layer_
->SetPosition(gfx::Point());
3693 child_layer_
->SetBounds(gfx::Size(10, 10));
3694 child_layer_
->SetIsDrawable(true);
3695 parent_layer_
->AddChild(child_layer_
);
3697 layer_tree_host()->SetRootLayer(root_layer_
);
3698 LayerTreeHostTest::SetupTree();
3701 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3703 void DidCommitAndDrawFrame() override
{
3704 switch (layer_tree_host()->source_frame_number()) {
3706 // The layer type used does not need to push properties every frame.
3707 EXPECT_FALSE(child_layer_
->needs_push_properties());
3709 // Change the bounds of the child layer, but make it skipped
3710 // by CalculateDrawProperties.
3711 parent_layer_
->SetOpacity(0.f
);
3712 child_layer_
->SetBounds(gfx::Size(5, 5));
3715 // The bounds of the child layer were pushed to the impl side.
3716 EXPECT_FALSE(child_layer_
->needs_push_properties());
3723 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
3724 LayerImpl
* root
= impl
->active_tree()->root_layer();
3725 LayerImpl
* parent
= root
->children()[0];
3726 LayerImpl
* child
= parent
->children()[0];
3728 switch (impl
->active_tree()->source_frame_number()) {
3730 EXPECT_EQ(gfx::Size(5, 5).ToString(), child
->bounds().ToString());
3735 void AfterTest() override
{}
3737 scoped_refptr
<Layer
> root_layer_
;
3738 scoped_refptr
<SolidColorLayer
> parent_layer_
;
3739 scoped_refptr
<SolidColorLayer
> child_layer_
;
3742 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushHiddenLayer
);
3744 class LayerTreeHostTestUpdateLayerInEmptyViewport
: public LayerTreeHostTest
{
3746 void SetupTree() override
{
3747 root_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
3748 root_layer_
->SetBounds(gfx::Size(10, 10));
3750 layer_tree_host()->SetRootLayer(root_layer_
);
3751 LayerTreeHostTest::SetupTree();
3754 void BeginTest() override
{
3755 // The viewport is empty, but we still need to update layers on the main
3757 layer_tree_host()->SetViewportSize(gfx::Size(0, 0));
3758 PostSetNeedsCommitToMainThread();
3761 void DidCommit() override
{
3762 // The layer should be updated even though the viewport is empty, so we
3763 // are capable of drawing it on the impl tree.
3764 EXPECT_GT(root_layer_
->update_count(), 0);
3768 void AfterTest() override
{}
3770 FakeContentLayerClient client_
;
3771 scoped_refptr
<FakePictureLayer
> root_layer_
;
3774 MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport
);
3776 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
3777 : public LayerTreeHostTest
{
3779 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface()
3780 : first_output_surface_memory_limit_(4321234),
3781 second_output_surface_memory_limit_(1234321) {}
3783 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
3784 if (!first_context_provider_
.get()) {
3785 first_context_provider_
= TestContextProvider::Create();
3787 EXPECT_FALSE(second_context_provider_
.get());
3788 second_context_provider_
= TestContextProvider::Create();
3791 scoped_refptr
<TestContextProvider
> provider(second_context_provider_
.get()
3792 ? second_context_provider_
3793 : first_context_provider_
);
3794 scoped_ptr
<FakeOutputSurface
> output_surface
;
3795 if (delegating_renderer())
3796 output_surface
= FakeOutputSurface::CreateDelegating3d(provider
);
3798 output_surface
= FakeOutputSurface::Create3d(provider
);
3799 output_surface
->SetMemoryPolicyToSetAtBind(
3800 make_scoped_ptr(new ManagedMemoryPolicy(
3801 second_context_provider_
.get() ? second_output_surface_memory_limit_
3802 : first_output_surface_memory_limit_
,
3803 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE
,
3804 ManagedMemoryPolicy::kDefaultNumResourcesLimit
)));
3805 return output_surface
.Pass();
3808 void SetupTree() override
{
3809 root_
= FakePictureLayer::Create(layer_settings(), &client_
);
3810 root_
->SetBounds(gfx::Size(20, 20));
3811 layer_tree_host()->SetRootLayer(root_
);
3812 LayerTreeHostTest::SetupTree();
3815 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3817 void DidCommitAndDrawFrame() override
{
3818 // Lost context sometimes takes two frames to recreate. The third frame
3819 // is sometimes aborted, so wait until the fourth frame to verify that
3820 // the memory has been set, and the fifth frame to end the test.
3821 if (layer_tree_host()->source_frame_number() < 5) {
3822 layer_tree_host()->SetNeedsCommit();
3823 } else if (layer_tree_host()->source_frame_number() == 5) {
3828 void SwapBuffersOnThread(LayerTreeHostImpl
* impl
, bool result
) override
{
3829 switch (impl
->active_tree()->source_frame_number()) {
3831 EXPECT_EQ(first_output_surface_memory_limit_
,
3832 impl
->memory_allocation_limit_bytes());
3833 // Lose the output surface.
3834 first_context_provider_
->TestContext3d()->loseContextCHROMIUM(
3835 GL_GUILTY_CONTEXT_RESET_ARB
, GL_INNOCENT_CONTEXT_RESET_ARB
);
3838 EXPECT_EQ(second_output_surface_memory_limit_
,
3839 impl
->memory_allocation_limit_bytes());
3844 void AfterTest() override
{}
3846 scoped_refptr
<TestContextProvider
> first_context_provider_
;
3847 scoped_refptr
<TestContextProvider
> second_context_provider_
;
3848 size_t first_output_surface_memory_limit_
;
3849 size_t second_output_surface_memory_limit_
;
3850 FakeContentLayerClient client_
;
3851 scoped_refptr
<Layer
> root_
;
3854 SINGLE_AND_MULTI_THREAD_TEST_F(
3855 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
);
3857 struct TestSwapPromiseResult
{
3858 TestSwapPromiseResult()
3859 : did_activate_called(false),
3860 did_swap_called(false),
3861 did_not_swap_called(false),
3863 reason(SwapPromise::COMMIT_FAILS
) {}
3865 bool did_activate_called
;
3866 bool did_swap_called
;
3867 bool did_not_swap_called
;
3869 SwapPromise::DidNotSwapReason reason
;
3873 class TestSwapPromise
: public SwapPromise
{
3875 explicit TestSwapPromise(TestSwapPromiseResult
* result
) : result_(result
) {}
3877 ~TestSwapPromise() override
{
3878 base::AutoLock
lock(result_
->lock
);
3879 result_
->dtor_called
= true;
3882 void DidActivate() override
{
3883 base::AutoLock
lock(result_
->lock
);
3884 EXPECT_FALSE(result_
->did_activate_called
);
3885 EXPECT_FALSE(result_
->did_swap_called
);
3886 EXPECT_FALSE(result_
->did_not_swap_called
);
3887 result_
->did_activate_called
= true;
3890 void DidSwap(CompositorFrameMetadata
* metadata
) override
{
3891 base::AutoLock
lock(result_
->lock
);
3892 EXPECT_FALSE(result_
->did_swap_called
);
3893 EXPECT_FALSE(result_
->did_not_swap_called
);
3894 result_
->did_swap_called
= true;
3897 void DidNotSwap(DidNotSwapReason reason
) override
{
3898 base::AutoLock
lock(result_
->lock
);
3899 EXPECT_FALSE(result_
->did_swap_called
);
3900 EXPECT_FALSE(result_
->did_not_swap_called
);
3901 EXPECT_FALSE(result_
->did_activate_called
&&
3902 reason
!= DidNotSwapReason::SWAP_FAILS
);
3903 result_
->did_not_swap_called
= true;
3904 result_
->reason
= reason
;
3907 int64
TraceId() const override
{ return 0; }
3911 TestSwapPromiseResult
* result_
;
3914 class PinnedLayerTreeSwapPromise
: public LayerTreeHostTest
{
3916 void BeginTest() override
{
3917 PostSetNextCommitForcesRedrawToMainThread();
3918 PostSetNeedsCommitToMainThread();
3921 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
3922 int frame
= host_impl
->active_tree()->source_frame_number();
3924 host_impl
->active_tree()->QueuePinnedSwapPromise(make_scoped_ptr(
3925 new TestSwapPromise(&pinned_active_swap_promise_result_
)));
3926 host_impl
->pending_tree()->QueueSwapPromise(
3927 make_scoped_ptr(new TestSwapPromise(&pending_swap_promise_result_
)));
3928 host_impl
->active_tree()->QueueSwapPromise(
3929 make_scoped_ptr(new TestSwapPromise(&active_swap_promise_result_
)));
3933 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
3937 void AfterTest() override
{
3938 // The pending swap promise should activate and swap.
3939 EXPECT_TRUE(pending_swap_promise_result_
.did_activate_called
);
3940 EXPECT_TRUE(pending_swap_promise_result_
.did_swap_called
);
3942 // The active swap promise should fail to swap (it is cancelled by
3943 // the activation of a new frame).
3944 EXPECT_FALSE(active_swap_promise_result_
.did_activate_called
);
3945 EXPECT_FALSE(active_swap_promise_result_
.did_swap_called
);
3946 EXPECT_TRUE(active_swap_promise_result_
.did_not_swap_called
);
3947 EXPECT_EQ(active_swap_promise_result_
.reason
, SwapPromise::SWAP_FAILS
);
3949 // The pinned active swap promise should not activate, but should swap.
3950 EXPECT_FALSE(pinned_active_swap_promise_result_
.did_activate_called
);
3951 EXPECT_TRUE(pinned_active_swap_promise_result_
.did_swap_called
);
3954 TestSwapPromiseResult pending_swap_promise_result_
;
3955 TestSwapPromiseResult active_swap_promise_result_
;
3956 TestSwapPromiseResult pinned_active_swap_promise_result_
;
3959 MULTI_THREAD_TEST_F(PinnedLayerTreeSwapPromise
);
3961 class LayerTreeHostTestBreakSwapPromise
: public LayerTreeHostTest
{
3963 LayerTreeHostTestBreakSwapPromise()
3964 : commit_count_(0), commit_complete_count_(0) {}
3966 void WillBeginMainFrame() override
{
3967 ASSERT_LE(commit_count_
, 2);
3968 scoped_ptr
<SwapPromise
> swap_promise(
3969 new TestSwapPromise(&swap_promise_result_
[commit_count_
]));
3970 layer_tree_host()->QueueSwapPromise(swap_promise
.Pass());
3973 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
3975 void DidCommit() override
{
3977 if (commit_count_
== 2) {
3978 // This commit will finish.
3979 layer_tree_host()->SetNeedsCommit();
3983 void WillActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
3984 if (host_impl
->pending_tree()) {
3985 int frame
= host_impl
->pending_tree()->source_frame_number();
3986 base::AutoLock
lock(swap_promise_result_
[frame
].lock
);
3987 EXPECT_FALSE(swap_promise_result_
[frame
].did_activate_called
);
3988 EXPECT_FALSE(swap_promise_result_
[frame
].did_swap_called
);
3992 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
3993 int frame
= host_impl
->active_tree()->source_frame_number();
3994 base::AutoLock
lock(swap_promise_result_
[frame
].lock
);
3995 EXPECT_TRUE(swap_promise_result_
[frame
].did_activate_called
);
3996 EXPECT_FALSE(swap_promise_result_
[frame
].did_swap_called
);
3999 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4000 commit_complete_count_
++;
4001 if (commit_complete_count_
== 1) {
4002 // This commit will be aborted because no actual update.
4003 PostSetNeedsUpdateLayersToMainThread();
4007 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
4008 int frame
= host_impl
->active_tree()->source_frame_number();
4014 void AfterTest() override
{
4015 // 3 commits are scheduled. 2 completes. 1 is aborted.
4016 EXPECT_EQ(commit_count_
, 3);
4017 EXPECT_EQ(commit_complete_count_
, 2);
4020 // The first commit completes and causes swap buffer which finishes
4022 base::AutoLock
lock(swap_promise_result_
[0].lock
);
4023 EXPECT_TRUE(swap_promise_result_
[0].did_swap_called
);
4024 EXPECT_FALSE(swap_promise_result_
[0].did_not_swap_called
);
4025 EXPECT_TRUE(swap_promise_result_
[0].dtor_called
);
4029 // The second commit is aborted since it contains no updates.
4030 base::AutoLock
lock(swap_promise_result_
[1].lock
);
4031 EXPECT_FALSE(swap_promise_result_
[1].did_activate_called
);
4032 EXPECT_FALSE(swap_promise_result_
[1].did_swap_called
);
4033 EXPECT_TRUE(swap_promise_result_
[1].did_not_swap_called
);
4034 EXPECT_EQ(SwapPromise::COMMIT_NO_UPDATE
, swap_promise_result_
[1].reason
);
4035 EXPECT_TRUE(swap_promise_result_
[1].dtor_called
);
4039 // The last commit completes but it does not cause swap buffer because
4040 // there is no damage in the frame data.
4041 base::AutoLock
lock(swap_promise_result_
[2].lock
);
4042 EXPECT_TRUE(swap_promise_result_
[2].did_activate_called
);
4043 EXPECT_FALSE(swap_promise_result_
[2].did_swap_called
);
4044 EXPECT_TRUE(swap_promise_result_
[2].did_not_swap_called
);
4045 EXPECT_EQ(SwapPromise::SWAP_FAILS
, swap_promise_result_
[2].reason
);
4046 EXPECT_TRUE(swap_promise_result_
[2].dtor_called
);
4051 int commit_complete_count_
;
4052 TestSwapPromiseResult swap_promise_result_
[3];
4055 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise
);
4057 class LayerTreeHostTestKeepSwapPromise
: public LayerTreeTest
{
4059 LayerTreeHostTestKeepSwapPromise() {}
4061 void BeginTest() override
{
4062 layer_
= SolidColorLayer::Create(layer_settings());
4063 layer_
->SetIsDrawable(true);
4064 layer_
->SetBounds(gfx::Size(10, 10));
4065 layer_tree_host()->SetRootLayer(layer_
);
4066 gfx::Size
bounds(100, 100);
4067 layer_tree_host()->SetViewportSize(bounds
);
4068 PostSetNeedsCommitToMainThread();
4071 void DidCommit() override
{
4072 MainThreadTaskRunner()->PostTask(
4073 FROM_HERE
, base::Bind(&LayerTreeHostTestKeepSwapPromise::ChangeFrame
,
4074 base::Unretained(this)));
4077 void ChangeFrame() {
4078 switch (layer_tree_host()->source_frame_number()) {
4080 layer_
->SetBounds(gfx::Size(10, 11));
4081 layer_tree_host()->QueueSwapPromise(
4082 make_scoped_ptr(new TestSwapPromise(&swap_promise_result_
)));
4092 void WillActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4093 if (host_impl
->pending_tree()) {
4094 if (host_impl
->pending_tree()->source_frame_number() == 1) {
4095 base::AutoLock
lock(swap_promise_result_
.lock
);
4096 EXPECT_FALSE(swap_promise_result_
.did_activate_called
);
4097 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
4105 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4106 if (host_impl
->active_tree()->source_frame_number() == 1) {
4107 base::AutoLock
lock(swap_promise_result_
.lock
);
4108 EXPECT_TRUE(swap_promise_result_
.did_activate_called
);
4109 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
4113 void ActivationCallback() {
4114 // DidActivate needs to happen before the tree activation callback.
4115 base::AutoLock
lock(swap_promise_result_
.lock
);
4116 EXPECT_TRUE(swap_promise_result_
.did_activate_called
);
4119 void SetCallback(bool enable
) {
4120 output_surface()->SetTreeActivationCallback(
4122 ? base::Bind(&LayerTreeHostTestKeepSwapPromise::ActivationCallback
,
4123 base::Unretained(this))
4127 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
4128 EXPECT_TRUE(result
);
4129 if (host_impl
->active_tree()->source_frame_number() >= 1) {
4130 // The commit changes layers so it should cause a swap.
4131 base::AutoLock
lock(swap_promise_result_
.lock
);
4132 EXPECT_TRUE(swap_promise_result_
.did_swap_called
);
4133 EXPECT_FALSE(swap_promise_result_
.did_not_swap_called
);
4134 EXPECT_TRUE(swap_promise_result_
.dtor_called
);
4139 void AfterTest() override
{}
4142 scoped_refptr
<Layer
> layer_
;
4143 TestSwapPromiseResult swap_promise_result_
;
4146 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise
);
4148 class LayerTreeHostTestBreakSwapPromiseForVisibility
4149 : public LayerTreeHostTest
{
4151 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4153 void SetVisibleFalseAndQueueSwapPromise() {
4154 layer_tree_host()->SetVisible(false);
4155 scoped_ptr
<SwapPromise
> swap_promise(
4156 new TestSwapPromise(&swap_promise_result_
));
4157 layer_tree_host()->QueueSwapPromise(swap_promise
.Pass());
4160 void ScheduledActionWillSendBeginMainFrame() override
{
4161 MainThreadTaskRunner()->PostTask(
4163 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
4164 ::SetVisibleFalseAndQueueSwapPromise
,
4165 base::Unretained(this)));
4168 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl
* host_impl
,
4169 CommitEarlyOutReason reason
) override
{
4173 void AfterTest() override
{
4175 base::AutoLock
lock(swap_promise_result_
.lock
);
4176 EXPECT_FALSE(swap_promise_result_
.did_activate_called
);
4177 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
4178 EXPECT_TRUE(swap_promise_result_
.did_not_swap_called
);
4179 EXPECT_EQ(SwapPromise::COMMIT_FAILS
, swap_promise_result_
.reason
);
4180 EXPECT_TRUE(swap_promise_result_
.dtor_called
);
4184 TestSwapPromiseResult swap_promise_result_
;
4187 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForVisibility
);
4189 class LayerTreeHostTestBreakSwapPromiseForContext
: public LayerTreeHostTest
{
4191 LayerTreeHostTestBreakSwapPromiseForContext()
4192 : output_surface_lost_triggered_(false) {
4195 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4197 void LoseOutputSurfaceAndQueueSwapPromise() {
4198 layer_tree_host()->DidLoseOutputSurface();
4199 scoped_ptr
<SwapPromise
> swap_promise(
4200 new TestSwapPromise(&swap_promise_result_
));
4201 layer_tree_host()->QueueSwapPromise(swap_promise
.Pass());
4204 void ScheduledActionWillSendBeginMainFrame() override
{
4205 if (output_surface_lost_triggered_
)
4207 output_surface_lost_triggered_
= true;
4209 MainThreadTaskRunner()->PostTask(
4211 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext
4212 ::LoseOutputSurfaceAndQueueSwapPromise
,
4213 base::Unretained(this)));
4216 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl
* host_impl
,
4217 CommitEarlyOutReason reason
) override
{
4218 // This is needed so that the impl-thread state matches main-thread state.
4219 host_impl
->DidLoseOutputSurface();
4223 void AfterTest() override
{
4225 base::AutoLock
lock(swap_promise_result_
.lock
);
4226 EXPECT_FALSE(swap_promise_result_
.did_activate_called
);
4227 EXPECT_FALSE(swap_promise_result_
.did_swap_called
);
4228 EXPECT_TRUE(swap_promise_result_
.did_not_swap_called
);
4229 EXPECT_EQ(SwapPromise::COMMIT_FAILS
, swap_promise_result_
.reason
);
4230 EXPECT_TRUE(swap_promise_result_
.dtor_called
);
4234 bool output_surface_lost_triggered_
;
4235 TestSwapPromiseResult swap_promise_result_
;
4238 SINGLE_AND_MULTI_THREAD_TEST_F(
4239 LayerTreeHostTestBreakSwapPromiseForContext
);
4241 class SimpleSwapPromiseMonitor
: public SwapPromiseMonitor
{
4243 SimpleSwapPromiseMonitor(LayerTreeHost
* layer_tree_host
,
4244 LayerTreeHostImpl
* layer_tree_host_impl
,
4245 int* set_needs_commit_count
,
4246 int* set_needs_redraw_count
)
4247 : SwapPromiseMonitor(layer_tree_host
, layer_tree_host_impl
),
4248 set_needs_commit_count_(set_needs_commit_count
) {}
4250 ~SimpleSwapPromiseMonitor() override
{}
4252 void OnSetNeedsCommitOnMain() override
{ (*set_needs_commit_count_
)++; }
4254 void OnSetNeedsRedrawOnImpl() override
{
4255 ADD_FAILURE() << "Should not get called on main thread.";
4258 void OnForwardScrollUpdateToMainThreadOnImpl() override
{
4259 ADD_FAILURE() << "Should not get called on main thread.";
4263 int* set_needs_commit_count_
;
4266 class LayerTreeHostTestSimpleSwapPromiseMonitor
: public LayerTreeHostTest
{
4268 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4270 void WillBeginMainFrame() override
{
4274 int set_needs_commit_count
= 0;
4275 int set_needs_redraw_count
= 0;
4278 scoped_ptr
<SimpleSwapPromiseMonitor
> swap_promise_monitor(
4279 new SimpleSwapPromiseMonitor(layer_tree_host(),
4281 &set_needs_commit_count
,
4282 &set_needs_redraw_count
));
4283 layer_tree_host()->SetNeedsCommit();
4284 EXPECT_EQ(1, set_needs_commit_count
);
4285 EXPECT_EQ(0, set_needs_redraw_count
);
4288 // Now the monitor is destroyed, SetNeedsCommit() is no longer being
4290 layer_tree_host()->SetNeedsCommit();
4291 EXPECT_EQ(1, set_needs_commit_count
);
4292 EXPECT_EQ(0, set_needs_redraw_count
);
4295 scoped_ptr
<SimpleSwapPromiseMonitor
> swap_promise_monitor(
4296 new SimpleSwapPromiseMonitor(layer_tree_host(),
4298 &set_needs_commit_count
,
4299 &set_needs_redraw_count
));
4300 layer_tree_host()->SetNeedsUpdateLayers();
4301 EXPECT_EQ(2, set_needs_commit_count
);
4302 EXPECT_EQ(0, set_needs_redraw_count
);
4306 scoped_ptr
<SimpleSwapPromiseMonitor
> swap_promise_monitor(
4307 new SimpleSwapPromiseMonitor(layer_tree_host(),
4309 &set_needs_commit_count
,
4310 &set_needs_redraw_count
));
4311 layer_tree_host()->SetNeedsAnimate();
4312 EXPECT_EQ(3, set_needs_commit_count
);
4313 EXPECT_EQ(0, set_needs_redraw_count
);
4319 void AfterTest() override
{}
4322 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor
);
4324 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources
4325 : public LayerTreeHostTest
{
4327 void SetupTree() override
{
4328 LayerTreeHostTest::SetupTree();
4329 ui_resource_
= FakeScopedUIResource::Create(layer_tree_host());
4332 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4334 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4335 host_impl
->EvictAllUIResources();
4336 // Existence of evicted UI resources will trigger NEW_CONTENT_TAKES_PRIORITY
4337 // mode. Active tree should require high-res to draw after entering this
4338 // mode to ensure that high-res tiles are also required for a pending tree
4340 EXPECT_TRUE(host_impl
->RequiresHighResToDraw());
4343 void DidCommit() override
{
4344 int frame
= layer_tree_host()->source_frame_number();
4347 PostSetNeedsCommitToMainThread();
4350 ui_resource_
= nullptr;
4356 void AfterTest() override
{}
4358 FakeContentLayerClient client_
;
4359 scoped_ptr
<FakeScopedUIResource
> ui_resource_
;
4362 // This test is flaky, see http://crbug.com/386199
4363 // MULTI_THREAD_TEST_F(LayerTreeHostTestHighResRequiredAfterEvictingUIResources)
4365 class LayerTreeHostTestGpuRasterizationDefault
: public LayerTreeHostTest
{
4367 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4368 EXPECT_FALSE(settings
->gpu_rasterization_enabled
);
4369 EXPECT_FALSE(settings
->gpu_rasterization_forced
);
4372 void SetupTree() override
{
4373 LayerTreeHostTest::SetupTree();
4375 scoped_refptr
<PictureLayer
> layer
=
4376 PictureLayer::Create(layer_settings(), &layer_client_
);
4377 layer
->SetBounds(gfx::Size(10, 10));
4378 layer
->SetIsDrawable(true);
4379 layer_tree_host()->root_layer()->AddChild(layer
);
4382 void BeginTest() override
{
4383 Layer
* root
= layer_tree_host()->root_layer();
4384 PictureLayer
* layer
= static_cast<PictureLayer
*>(root
->child_at(0));
4385 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4387 // Verify default values.
4388 EXPECT_TRUE(root
->IsSuitableForGpuRasterization());
4389 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
4390 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
4391 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4393 // Setting gpu rasterization trigger does not enable gpu rasterization.
4394 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4395 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4397 PostSetNeedsCommitToMainThread();
4400 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4401 EXPECT_FALSE(host_impl
->pending_tree()->use_gpu_rasterization());
4402 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4405 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4406 EXPECT_FALSE(host_impl
->active_tree()->use_gpu_rasterization());
4407 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4411 void AfterTest() override
{}
4413 FakeContentLayerClient layer_client_
;
4416 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDefault
);
4418 class LayerTreeHostTestGpuRasterizationEnabled
: public LayerTreeHostTest
{
4420 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4421 EXPECT_FALSE(settings
->gpu_rasterization_enabled
);
4422 settings
->gpu_rasterization_enabled
= true;
4425 void SetupTree() override
{
4426 LayerTreeHostTest::SetupTree();
4428 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source(
4429 new FakeDisplayListRecordingSource(gfx::Size(10, 10)));
4431 scoped_refptr
<FakePictureLayer
> layer
=
4432 FakePictureLayer::CreateWithRecordingSource(
4433 layer_settings(), &layer_client_
, recording_source
.Pass());
4434 layer
->SetBounds(gfx::Size(10, 10));
4435 layer
->SetIsDrawable(true);
4436 layer_tree_host()->root_layer()->AddChild(layer
);
4439 void BeginTest() override
{
4440 Layer
* root
= layer_tree_host()->root_layer();
4441 FakePictureLayer
* layer
= static_cast<FakePictureLayer
*>(root
->child_at(0));
4442 FakeDisplayListRecordingSource
* recording_source
=
4443 static_cast<FakeDisplayListRecordingSource
*>(
4444 layer
->GetRecordingSourceForTesting());
4446 // Verify default values.
4447 EXPECT_TRUE(root
->IsSuitableForGpuRasterization());
4448 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
4449 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
4450 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4452 // Gpu rasterization trigger is relevant.
4453 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4454 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4456 // Content-based veto is relevant as well.
4457 recording_source
->SetUnsuitableForGpuRasterizationForTesting();
4458 EXPECT_FALSE(recording_source
->IsSuitableForGpuRasterization());
4459 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
4460 // Veto will take effect when layers are updated.
4461 // The results will be verified after commit is completed below.
4462 // Since we are manually marking picture pile as unsuitable,
4463 // make sure that the layer gets a chance to update.
4464 layer
->SetNeedsDisplay();
4465 PostSetNeedsCommitToMainThread();
4468 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4469 EXPECT_FALSE(host_impl
->pending_tree()->use_gpu_rasterization());
4470 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4473 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4474 EXPECT_FALSE(host_impl
->active_tree()->use_gpu_rasterization());
4475 EXPECT_FALSE(host_impl
->use_gpu_rasterization());
4479 void AfterTest() override
{}
4481 FakeContentLayerClient layer_client_
;
4484 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled
);
4486 class LayerTreeHostTestGpuRasterizationForced
: public LayerTreeHostTest
{
4488 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4489 EXPECT_FALSE(settings
->gpu_rasterization_forced
);
4490 settings
->gpu_rasterization_forced
= true;
4493 void SetupTree() override
{
4494 LayerTreeHostTest::SetupTree();
4496 scoped_refptr
<FakePictureLayer
> layer
=
4497 FakePictureLayer::Create(layer_settings(), &layer_client_
);
4498 layer
->SetBounds(gfx::Size(10, 10));
4499 layer
->SetIsDrawable(true);
4500 layer_tree_host()->root_layer()->AddChild(layer
);
4503 void BeginTest() override
{
4504 Layer
* root
= layer_tree_host()->root_layer();
4505 PictureLayer
* layer
= static_cast<PictureLayer
*>(root
->child_at(0));
4506 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
4508 // Verify default values.
4509 EXPECT_TRUE(root
->IsSuitableForGpuRasterization());
4510 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
4511 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
4512 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4514 // With gpu rasterization forced, gpu rasterization trigger is irrelevant.
4515 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4516 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4518 // Content-based veto is irrelevant as well.
4519 recording_source
->SetUnsuitableForGpuRasterizationForTesting();
4520 EXPECT_FALSE(recording_source
->IsSuitableForGpuRasterization());
4521 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
4522 // Veto will take effect when layers are updated.
4523 // The results will be verified after commit is completed below.
4524 // Since we are manually marking picture pile as unsuitable,
4525 // make sure that the layer gets a chance to update.
4526 layer
->SetNeedsDisplay();
4527 PostSetNeedsCommitToMainThread();
4530 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
4531 EXPECT_TRUE(host_impl
->sync_tree()->use_gpu_rasterization());
4532 EXPECT_TRUE(host_impl
->use_gpu_rasterization());
4535 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4536 EXPECT_TRUE(host_impl
->active_tree()->use_gpu_rasterization());
4537 EXPECT_TRUE(host_impl
->use_gpu_rasterization());
4541 void AfterTest() override
{}
4543 FakeContentLayerClient layer_client_
;
4546 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationForced
);
4548 class LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame
4549 : public LayerTreeHostTest
{
4551 enum { kExpectedNumImplFrames
= 10 };
4553 LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame()
4554 : will_begin_impl_frame_count_(0), did_finish_impl_frame_count_(0) {}
4556 void BeginTest() override
{
4557 // Kick off the test with a commit.
4558 PostSetNeedsCommitToMainThread();
4561 void WillBeginImplFrameOnThread(LayerTreeHostImpl
* host_impl
,
4562 const BeginFrameArgs
& args
) override
{
4563 EXPECT_EQ(will_begin_impl_frame_count_
, did_finish_impl_frame_count_
);
4564 EXPECT_FALSE(TestEnded());
4565 will_begin_impl_frame_count_
++;
4568 void DidFinishImplFrameOnThread(LayerTreeHostImpl
* host_impl
) override
{
4569 did_finish_impl_frame_count_
++;
4570 EXPECT_EQ(will_begin_impl_frame_count_
, did_finish_impl_frame_count_
);
4572 // Request a number of commits to cause multiple impl frames. We expect to
4573 // get one more impl frames than the number of commits requested because
4574 // after a commit it takes one frame to become idle.
4575 if (did_finish_impl_frame_count_
< kExpectedNumImplFrames
- 1)
4576 PostSetNeedsCommitToMainThread();
4579 void SendBeginMainFrameNotExpectedSoon() override
{ EndTest(); }
4581 void AfterTest() override
{
4582 EXPECT_GT(will_begin_impl_frame_count_
, 0);
4583 EXPECT_GT(did_finish_impl_frame_count_
, 0);
4584 EXPECT_EQ(will_begin_impl_frame_count_
, did_finish_impl_frame_count_
);
4586 // TODO(mithro): Figure out why the multithread version of this test
4587 // sometimes has one more frame then expected. Possibly related to
4588 // http://crbug.com/443185
4589 if (!HasImplThread()) {
4590 EXPECT_EQ(will_begin_impl_frame_count_
, kExpectedNumImplFrames
);
4591 EXPECT_EQ(did_finish_impl_frame_count_
, kExpectedNumImplFrames
);
4596 int will_begin_impl_frame_count_
;
4597 int did_finish_impl_frame_count_
;
4600 SINGLE_AND_MULTI_THREAD_TEST_F(
4601 LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame
);
4603 class LayerTreeHostTestSendBeginFramesToChildren
: public LayerTreeHostTest
{
4605 LayerTreeHostTestSendBeginFramesToChildren()
4606 : begin_frame_sent_to_children_(false) {
4609 void BeginTest() override
{
4610 // Kick off the test with a commit.
4611 PostSetNeedsCommitToMainThread();
4614 void SendBeginFramesToChildren(const BeginFrameArgs
& args
) override
{
4615 begin_frame_sent_to_children_
= true;
4619 void DidBeginMainFrame() override
{
4620 // Children requested BeginFrames.
4621 layer_tree_host()->SetChildrenNeedBeginFrames(true);
4624 void AfterTest() override
{
4625 // Ensure that BeginFrame message is sent to children during parent
4626 // scheduler handles its BeginFrame.
4627 EXPECT_TRUE(begin_frame_sent_to_children_
);
4631 bool begin_frame_sent_to_children_
;
4634 SINGLE_THREAD_TEST_F(LayerTreeHostTestSendBeginFramesToChildren
);
4636 class LayerTreeHostTestSendBeginFramesToChildrenWithExternalBFS
4637 : public LayerTreeHostTest
{
4639 LayerTreeHostTestSendBeginFramesToChildrenWithExternalBFS()
4640 : begin_frame_sent_to_children_(false) {
4643 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4644 settings
->use_external_begin_frame_source
= true;
4647 void BeginTest() override
{
4648 // Kick off the test with a commit.
4649 PostSetNeedsCommitToMainThread();
4652 void SendBeginFramesToChildren(const BeginFrameArgs
& args
) override
{
4653 begin_frame_sent_to_children_
= true;
4657 void DidBeginMainFrame() override
{
4658 // Children requested BeginFrames.
4659 layer_tree_host()->SetChildrenNeedBeginFrames(true);
4662 void AfterTest() override
{
4663 // Ensure that BeginFrame message is sent to children during parent
4664 // scheduler handles its BeginFrame.
4665 EXPECT_TRUE(begin_frame_sent_to_children_
);
4669 bool begin_frame_sent_to_children_
;
4672 SINGLE_THREAD_TEST_F(LayerTreeHostTestSendBeginFramesToChildrenWithExternalBFS
);
4674 class LayerTreeHostTestActivateOnInvisible
: public LayerTreeHostTest
{
4676 LayerTreeHostTestActivateOnInvisible()
4677 : activation_count_(0), visible_(true) {}
4679 void BeginTest() override
{
4680 // Kick off the test with a commit.
4681 PostSetNeedsCommitToMainThread();
4684 void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) override
{
4685 // Make sure we don't activate using the notify signal from tile manager.
4686 host_impl
->BlockNotifyReadyToActivateForTesting(true);
4689 void DidCommit() override
{ layer_tree_host()->SetVisible(false); }
4691 void DidSetVisibleOnImplTree(LayerTreeHostImpl
* host_impl
,
4692 bool visible
) override
{
4695 // Once invisible, we can go visible again.
4697 PostSetVisibleToMainThread(true);
4699 EXPECT_TRUE(host_impl
->RequiresHighResToDraw());
4704 void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) override
{
4705 ++activation_count_
;
4706 EXPECT_FALSE(visible_
);
4709 void AfterTest() override
{
4710 // Ensure we activated even though the signal was blocked.
4711 EXPECT_EQ(1, activation_count_
);
4712 EXPECT_TRUE(visible_
);
4716 int activation_count_
;
4719 FakeContentLayerClient client_
;
4720 scoped_refptr
<FakePictureLayer
> picture_layer_
;
4723 // TODO(vmpstr): Enable with single thread impl-side painting.
4724 // This test blocks activation which is not supported for single thread mode.
4725 MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestActivateOnInvisible
);
4727 // Do a synchronous composite and assert that the swap promise succeeds.
4728 class LayerTreeHostTestSynchronousCompositeSwapPromise
4729 : public LayerTreeHostTest
{
4731 LayerTreeHostTestSynchronousCompositeSwapPromise() : commit_count_(0) {}
4733 void InitializeSettings(LayerTreeSettings
* settings
) override
{
4734 settings
->single_thread_proxy_scheduler
= false;
4735 settings
->use_zero_copy
= true;
4738 void BeginTest() override
{
4739 // Successful composite.
4740 scoped_ptr
<SwapPromise
> swap_promise0(
4741 new TestSwapPromise(&swap_promise_result_
[0]));
4742 layer_tree_host()->QueueSwapPromise(swap_promise0
.Pass());
4743 layer_tree_host()->Composite(base::TimeTicks::Now());
4745 // Fail to swap (no damage).
4746 scoped_ptr
<SwapPromise
> swap_promise1(
4747 new TestSwapPromise(&swap_promise_result_
[1]));
4748 layer_tree_host()->QueueSwapPromise(swap_promise1
.Pass());
4749 layer_tree_host()->SetNeedsCommit();
4750 layer_tree_host()->Composite(base::TimeTicks::Now());
4752 // Fail to draw (not visible).
4753 scoped_ptr
<SwapPromise
> swap_promise2(
4754 new TestSwapPromise(&swap_promise_result_
[2]));
4755 layer_tree_host()->QueueSwapPromise(swap_promise2
.Pass());
4756 layer_tree_host()->SetNeedsDisplayOnAllLayers();
4757 layer_tree_host()->SetVisible(false);
4758 layer_tree_host()->Composite(base::TimeTicks::Now());
4763 void DidCommit() override
{
4765 ASSERT_LE(commit_count_
, 3);
4768 void AfterTest() override
{
4769 EXPECT_EQ(3, commit_count_
);
4771 // Initial swap promise should have succeded.
4773 base::AutoLock
lock(swap_promise_result_
[0].lock
);
4774 EXPECT_TRUE(swap_promise_result_
[0].did_swap_called
);
4775 EXPECT_FALSE(swap_promise_result_
[0].did_not_swap_called
);
4776 EXPECT_TRUE(swap_promise_result_
[0].dtor_called
);
4779 // Second swap promise fails to swap.
4781 base::AutoLock
lock(swap_promise_result_
[1].lock
);
4782 EXPECT_TRUE(swap_promise_result_
[1].did_activate_called
);
4783 EXPECT_FALSE(swap_promise_result_
[1].did_swap_called
);
4784 EXPECT_TRUE(swap_promise_result_
[1].did_not_swap_called
);
4785 EXPECT_EQ(SwapPromise::SWAP_FAILS
, swap_promise_result_
[1].reason
);
4786 EXPECT_TRUE(swap_promise_result_
[1].dtor_called
);
4789 // Third swap promises also fails to swap (and draw).
4791 base::AutoLock
lock(swap_promise_result_
[2].lock
);
4792 EXPECT_TRUE(swap_promise_result_
[2].did_activate_called
);
4793 EXPECT_FALSE(swap_promise_result_
[2].did_swap_called
);
4794 EXPECT_TRUE(swap_promise_result_
[2].did_not_swap_called
);
4795 EXPECT_EQ(SwapPromise::SWAP_FAILS
, swap_promise_result_
[2].reason
);
4796 EXPECT_TRUE(swap_promise_result_
[2].dtor_called
);
4801 TestSwapPromiseResult swap_promise_result_
[3];
4804 SINGLE_THREAD_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise
);
4806 // Make sure page scale and top control deltas are applied to the client even
4807 // when the LayerTreeHost doesn't have a root layer.
4808 class LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer
4809 : public LayerTreeHostTest
{
4811 LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer()
4812 : deltas_sent_to_client_(false) {}
4814 void BeginTest() override
{
4815 layer_tree_host()->SetRootLayer(nullptr);
4816 info_
.page_scale_delta
= 3.14f
;
4817 info_
.top_controls_delta
= 2.73f
;
4819 PostSetNeedsCommitToMainThread();
4822 void BeginMainFrame(const BeginFrameArgs
& args
) override
{
4823 EXPECT_EQ(nullptr, layer_tree_host()->root_layer());
4825 layer_tree_host()->ApplyScrollAndScale(&info_
);
4829 void ApplyViewportDeltas(const gfx::Vector2dF
& inner
,
4830 const gfx::Vector2dF
& outer
,
4831 const gfx::Vector2dF
& elastic_overscroll_delta
,
4833 float top_controls_delta
) override
{
4834 EXPECT_EQ(info_
.page_scale_delta
, scale_delta
);
4835 EXPECT_EQ(info_
.top_controls_delta
, top_controls_delta
);
4836 deltas_sent_to_client_
= true;
4839 void AfterTest() override
{
4840 EXPECT_TRUE(deltas_sent_to_client_
);
4843 ScrollAndScaleSet info_
;
4844 bool deltas_sent_to_client_
;
4847 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer
);
4849 class LayerTreeHostTestCrispUpAfterPinchEnds
: public LayerTreeHostTest
{
4851 LayerTreeHostTestCrispUpAfterPinchEnds()
4852 : playback_allowed_event_(true, true) {}
4854 void SetupTree() override
{
4857 client_
.set_fill_with_nonsolid_color(true);
4859 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4860 root
->SetBounds(gfx::Size(500, 500));
4862 scoped_refptr
<Layer
> pinch
= Layer::Create(layer_settings());
4863 pinch
->SetBounds(gfx::Size(500, 500));
4864 pinch
->SetScrollClipLayerId(root
->id());
4865 pinch
->SetIsContainerForFixedPositionLayers(true);
4866 root
->AddChild(pinch
);
4868 scoped_ptr
<FakePicturePile
> pile(
4869 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
4870 LayerTreeSettings().default_tile_grid_size
));
4871 pile
->SetPlaybackAllowedEvent(&playback_allowed_event_
);
4872 scoped_refptr
<FakePictureLayer
> layer
=
4873 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
4875 layer
->SetBounds(gfx::Size(500, 500));
4876 layer
->SetContentsOpaque(true);
4877 // Avoid LCD text on the layer so we don't cause extra commits when we
4879 pinch
->AddChild(layer
);
4881 layer_tree_host()->RegisterViewportLayers(NULL
, root
, pinch
, pinch
);
4882 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 1.f
, 4.f
);
4883 layer_tree_host()->SetRootLayer(root
);
4884 LayerTreeHostTest::SetupTree();
4887 // Returns the delta scale of all quads in the frame's root pass from their
4888 // ideal, or 0 if they are not all the same.
4889 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData
* frame_data
) {
4890 if (frame_data
->has_no_damage
)
4892 float frame_scale
= 0.f
;
4893 RenderPass
* root_pass
= frame_data
->render_passes
.back();
4894 for (const auto& draw_quad
: root_pass
->quad_list
) {
4895 // Checkerboards mean an incomplete frame.
4896 if (draw_quad
->material
!= DrawQuad::TILED_CONTENT
)
4898 const TileDrawQuad
* quad
= TileDrawQuad::MaterialCast(draw_quad
);
4900 quad
->tex_coord_rect
.width() / static_cast<float>(quad
->rect
.width());
4901 float transform_scale
= SkMScalarToFloat(
4902 quad
->shared_quad_state
->quad_to_target_transform
.matrix().get(0, 0));
4903 float scale
= quad_scale
/ transform_scale
;
4904 if (frame_scale
!= 0.f
&& frame_scale
!= scale
)
4906 frame_scale
= scale
;
4911 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
4913 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
4914 LayerTreeHostImpl::FrameData
* frame_data
,
4915 DrawResult draw_result
) override
{
4916 float quad_scale_delta
= FrameQuadScaleDeltaFromIdeal(frame_data
);
4919 // Drew at page scale 1 before any pinching.
4920 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4921 EXPECT_EQ(1.f
, quad_scale_delta
);
4922 PostNextAfterDraw(host_impl
);
4925 if (quad_scale_delta
!= 1.f
)
4927 // Drew at page scale 1.5 after pinching in.
4928 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
4929 EXPECT_EQ(1.f
, quad_scale_delta
);
4930 PostNextAfterDraw(host_impl
);
4933 // By pinching out, we will create a new tiling and raster it. This may
4934 // cause some additional draws, though we should still be drawing with
4935 // the old 1.5 tiling.
4936 if (frame_data
->has_no_damage
)
4938 // Drew at page scale 1 with the 1.5 tiling while pinching out.
4939 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4940 EXPECT_EQ(1.5f
, quad_scale_delta
);
4941 // We don't PostNextAfterDraw here, instead we wait for the new tiling
4942 // to finish rastering so we don't get any noise in further steps.
4945 // Drew at page scale 1 with the 1.5 tiling after pinching out completed
4946 // while waiting for texture uploads to complete.
4947 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4948 // This frame will not have any damage, since it's actually the same as
4949 // the last frame, and should contain no incomplete tiles. We just want
4950 // to make sure we drew here at least once after the pinch ended to be
4951 // sure that drawing after pinch doesn't leave us at the wrong scale
4952 EXPECT_TRUE(frame_data
->has_no_damage
);
4953 PostNextAfterDraw(host_impl
);
4956 if (quad_scale_delta
!= 1.f
)
4958 // Drew at scale 1 after texture uploads are done.
4959 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
4960 EXPECT_EQ(1.f
, quad_scale_delta
);
4967 void PostNextAfterDraw(LayerTreeHostImpl
* host_impl
) {
4971 ImplThreadTaskRunner()->PostDelayedTask(
4972 FROM_HERE
, base::Bind(&LayerTreeHostTestCrispUpAfterPinchEnds::Next
,
4973 base::Unretained(this), host_impl
),
4974 // Use a delay to allow raster/upload to happen in between frames. This
4975 // should cause flakiness if we fail to block raster/upload when
4977 base::TimeDelta::FromMilliseconds(16 * 4));
4980 void Next(LayerTreeHostImpl
* host_impl
) {
4986 host_impl
->PinchGestureBegin();
4987 host_impl
->PinchGestureUpdate(1.5f
, gfx::Point(100, 100));
4988 host_impl
->PinchGestureEnd();
4991 // Pinch zoom back to 1.f but don't end it.
4992 host_impl
->PinchGestureBegin();
4993 host_impl
->PinchGestureUpdate(1.f
/ 1.5f
, gfx::Point(100, 100));
4996 // End the pinch, but delay tile production.
4997 playback_allowed_event_
.Reset();
4998 host_impl
->PinchGestureEnd();
5001 // Let tiles complete.
5002 playback_allowed_event_
.Signal();
5007 void NotifyTileStateChangedOnThread(LayerTreeHostImpl
* host_impl
,
5008 const Tile
* tile
) override
{
5010 // On frame 3, we will have a lower res tile complete for the pinch-out
5011 // gesture even though it's not displayed. We wait for it here to prevent
5013 EXPECT_EQ(0.75f
, tile
->contents_scale());
5014 PostNextAfterDraw(host_impl
);
5016 // On frame_ == 4, we are preventing texture uploads from completing,
5017 // so this verifies they are not completing before frame_ == 5.
5018 // Flaky failures here indicate we're failing to prevent uploads from
5020 EXPECT_NE(4, frame_
) << tile
->contents_scale();
5023 void AfterTest() override
{}
5025 FakeContentLayerClient client_
;
5028 base::WaitableEvent playback_allowed_event_
;
5031 // This test does pinching on the impl side which is not supported in single
5033 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds
);
5035 class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy
5036 : public LayerTreeHostTestCrispUpAfterPinchEnds
{
5038 scoped_ptr
<FakeOutputSurface
> CreateFakeOutputSurface() override
{
5039 scoped_ptr
<TestWebGraphicsContext3D
> context3d
=
5040 TestWebGraphicsContext3D::Create();
5041 context3d
->set_support_image(true);
5042 context3d
->set_support_sync_query(true);
5043 #if defined(OS_MACOSX)
5044 context3d
->set_support_texture_rectangle(true);
5047 if (delegating_renderer())
5048 return FakeOutputSurface::CreateDelegating3d(context3d
.Pass());
5050 return FakeOutputSurface::Create3d(context3d
.Pass());
5054 // This test does pinching on the impl side which is not supported in single
5056 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy
);
5058 class RasterizeWithGpuRasterizationCreatesResources
: public LayerTreeHostTest
{
5060 RasterizeWithGpuRasterizationCreatesResources() {}
5062 void InitializeSettings(LayerTreeSettings
* settings
) override
{
5063 settings
->gpu_rasterization_forced
= true;
5066 void SetupTree() override
{
5067 client_
.set_fill_with_nonsolid_color(true);
5069 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5070 root
->SetBounds(gfx::Size(500, 500));
5072 scoped_ptr
<FakePicturePile
> pile(
5073 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
5074 LayerTreeSettings().default_tile_grid_size
));
5075 scoped_refptr
<FakePictureLayer
> layer
=
5076 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
5078 layer
->SetBounds(gfx::Size(500, 500));
5079 layer
->SetContentsOpaque(true);
5080 root
->AddChild(layer
);
5082 layer_tree_host()->SetRootLayer(root
);
5083 LayerTreeHostTest::SetupTree();
5086 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5088 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5089 LayerTreeHostImpl::FrameData
* frame_data
,
5090 DrawResult draw_result
) override
{
5091 EXPECT_NE(0u, host_impl
->resource_provider()->num_resources());
5095 void AfterTest() override
{}
5097 FakeContentLayerClient client_
;
5100 SINGLE_AND_MULTI_THREAD_TEST_F(RasterizeWithGpuRasterizationCreatesResources
);
5102 class GpuRasterizationRasterizesBorderTiles
: public LayerTreeHostTest
{
5104 GpuRasterizationRasterizesBorderTiles() : viewport_size_(1024, 2048) {}
5106 void InitializeSettings(LayerTreeSettings
* settings
) override
{
5107 settings
->gpu_rasterization_enabled
= true;
5108 settings
->gpu_rasterization_forced
= true;
5111 void SetupTree() override
{
5112 client_
.set_fill_with_nonsolid_color(true);
5114 scoped_ptr
<FakePicturePile
> pile(
5115 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
5116 LayerTreeSettings().default_tile_grid_size
));
5117 scoped_refptr
<FakePictureLayer
> root
=
5118 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
5120 root
->SetBounds(gfx::Size(10000, 10000));
5121 root
->SetContentsOpaque(true);
5123 layer_tree_host()->SetRootLayer(root
);
5124 LayerTreeHostTest::SetupTree();
5125 layer_tree_host()->SetViewportSize(viewport_size_
);
5128 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5130 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5131 LayerTreeHostImpl::FrameData
* frame_data
,
5132 DrawResult draw_result
) override
{
5133 EXPECT_EQ(10u, host_impl
->resource_provider()->num_resources());
5138 void AfterTest() override
{}
5141 FakeContentLayerClient client_
;
5142 gfx::Size viewport_size_
;
5145 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationRasterizesBorderTiles
);
5147 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
5148 : public LayerTreeHostTest
{
5150 LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles()
5151 : playback_allowed_event_(true, true) {}
5153 void SetupTree() override
{
5155 continuous_draws_
= 0;
5156 client_
.set_fill_with_nonsolid_color(true);
5158 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5159 root
->SetBounds(gfx::Size(500, 500));
5161 scoped_refptr
<Layer
> pinch
= Layer::Create(layer_settings());
5162 pinch
->SetBounds(gfx::Size(500, 500));
5163 pinch
->SetScrollClipLayerId(root
->id());
5164 pinch
->SetIsContainerForFixedPositionLayers(true);
5165 root
->AddChild(pinch
);
5167 scoped_ptr
<FakePicturePile
> pile(
5168 new FakePicturePile(LayerTreeSettings().minimum_contents_scale
,
5169 LayerTreeSettings().default_tile_grid_size
));
5170 pile
->SetPlaybackAllowedEvent(&playback_allowed_event_
);
5171 scoped_refptr
<FakePictureLayer
> layer
=
5172 FakePictureLayer::CreateWithRecordingSource(layer_settings(), &client_
,
5174 layer
->SetBounds(gfx::Size(500, 500));
5175 layer
->SetContentsOpaque(true);
5176 // Avoid LCD text on the layer so we don't cause extra commits when we
5178 pinch
->AddChild(layer
);
5180 layer_tree_host()->RegisterViewportLayers(NULL
, root
, pinch
, pinch
);
5181 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 1.f
, 4.f
);
5182 layer_tree_host()->SetRootLayer(root
);
5183 LayerTreeHostTest::SetupTree();
5186 // Returns the delta scale of all quads in the frame's root pass from their
5187 // ideal, or 0 if they are not all the same.
5188 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData
* frame_data
) {
5189 if (frame_data
->has_no_damage
)
5191 float frame_scale
= 0.f
;
5192 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5193 for (const auto& draw_quad
: root_pass
->quad_list
) {
5194 const TileDrawQuad
* quad
= TileDrawQuad::MaterialCast(draw_quad
);
5196 quad
->tex_coord_rect
.width() / static_cast<float>(quad
->rect
.width());
5197 float transform_scale
= SkMScalarToFloat(
5198 quad
->shared_quad_state
->quad_to_target_transform
.matrix().get(0, 0));
5199 float scale
= quad_scale
/ transform_scale
;
5200 if (frame_scale
!= 0.f
&& frame_scale
!= scale
)
5202 frame_scale
= scale
;
5207 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5209 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5210 LayerTreeHostImpl::FrameData
* frame_data
,
5211 DrawResult draw_result
) override
{
5212 float quad_scale_delta
= FrameQuadScaleDeltaFromIdeal(frame_data
);
5215 // Drew at scale 1 before any pinching.
5216 EXPECT_EQ(1.f
, host_impl
->active_tree()->current_page_scale_factor());
5217 EXPECT_EQ(1.f
, quad_scale_delta
);
5220 if (quad_scale_delta
!= 1.f
/ 1.5f
)
5222 // Drew at scale 1 still though the ideal is 1.5.
5223 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
5224 EXPECT_EQ(1.f
/ 1.5f
, quad_scale_delta
);
5227 // Continuous draws are attempted.
5228 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
5229 if (!frame_data
->has_no_damage
)
5230 EXPECT_EQ(1.f
/ 1.5f
, quad_scale_delta
);
5233 if (quad_scale_delta
!= 1.f
)
5235 // Drew at scale 1.5 when all the tiles completed.
5236 EXPECT_EQ(1.5f
, host_impl
->active_tree()->current_page_scale_factor());
5237 EXPECT_EQ(1.f
, quad_scale_delta
);
5240 // TODO(danakj): We get more draws before the NotifyReadyToDraw
5241 // because it is asynchronous from the previous draw and happens late.
5244 // NotifyReadyToDraw happened. If we were already inside a frame, we may
5245 // try to draw once more.
5248 NOTREACHED() << "No draws should happen once we have a complete frame.";
5254 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
5257 // Delay tile production.
5258 playback_allowed_event_
.Reset();
5259 // Pinch zoom in to cause new tiles to be required.
5260 host_impl
->PinchGestureBegin();
5261 host_impl
->PinchGestureUpdate(1.5f
, gfx::Point(100, 100));
5262 host_impl
->PinchGestureEnd();
5269 // We should continue to try draw while there are incomplete visible
5271 if (++continuous_draws_
> 5) {
5272 // Allow the tiles to complete.
5273 playback_allowed_event_
.Signal();
5281 // Waiting for NotifyReadyToDraw.
5284 // NotifyReadyToDraw happened.
5290 void NotifyReadyToDrawOnThread(LayerTreeHostImpl
* host_impl
) override
{
5293 // NotifyReadyToDraw has happened, we may draw once more, but should not
5294 // get any more draws after that. End the test after a timeout to watch
5295 // for any extraneous draws.
5296 // TODO(brianderson): We could remove this delay and instead wait until
5297 // the BeginFrameSource decides it doesn't need to send frames anymore,
5298 // or test that it already doesn't here.
5299 EndTestAfterDelayMs(16 * 4);
5303 void NotifyTileStateChangedOnThread(LayerTreeHostImpl
* host_impl
,
5304 const Tile
* tile
) override
{
5305 // On step_ == 2, we are preventing texture uploads from completing,
5306 // so this verifies they are not completing before step_ == 3.
5307 // Flaky failures here indicate we're failing to prevent uploads from
5309 EXPECT_NE(2, step_
);
5312 void AfterTest() override
{ EXPECT_GT(continuous_draws_
, 5); }
5314 FakeContentLayerClient client_
;
5316 int continuous_draws_
;
5317 base::WaitableEvent playback_allowed_event_
;
5320 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
);
5322 class LayerTreeHostTestOneActivatePerPrepareTiles
: public LayerTreeHostTest
{
5324 LayerTreeHostTestOneActivatePerPrepareTiles()
5325 : notify_ready_to_activate_count_(0u),
5326 scheduled_prepare_tiles_count_(0) {}
5328 void SetupTree() override
{
5329 client_
.set_fill_with_nonsolid_color(true);
5330 scoped_refptr
<FakePictureLayer
> root_layer
=
5331 FakePictureLayer::Create(layer_settings(), &client_
);
5332 root_layer
->SetBounds(gfx::Size(1500, 1500));
5333 root_layer
->SetIsDrawable(true);
5335 layer_tree_host()->SetRootLayer(root_layer
);
5336 LayerTreeHostTest::SetupTree();
5339 void BeginTest() override
{
5340 layer_tree_host()->SetViewportSize(gfx::Size(16, 16));
5341 PostSetNeedsCommitToMainThread();
5344 void InitializedRendererOnThread(LayerTreeHostImpl
* host_impl
,
5345 bool success
) override
{
5346 ASSERT_TRUE(success
);
5347 host_impl
->tile_manager()->SetScheduledRasterTaskLimitForTesting(1);
5350 void NotifyReadyToActivateOnThread(LayerTreeHostImpl
* impl
) override
{
5351 ++notify_ready_to_activate_count_
;
5352 EndTestAfterDelayMs(100);
5355 void ScheduledActionPrepareTiles() override
{
5356 ++scheduled_prepare_tiles_count_
;
5359 void AfterTest() override
{
5360 // Expect at most a notification for each scheduled prepare tiles, plus one
5361 // for the initial commit (which doesn't go through scheduled actions).
5362 // The reason this is not an equality is because depending on timing, we
5363 // might get a prepare tiles but not yet get a notification that we're
5364 // ready to activate. The intent of a test is to ensure that we don't
5365 // get more than one notification per prepare tiles, so this is OK.
5366 EXPECT_LE(notify_ready_to_activate_count_
,
5367 1u + scheduled_prepare_tiles_count_
);
5371 FakeContentLayerClient client_
;
5372 size_t notify_ready_to_activate_count_
;
5373 size_t scheduled_prepare_tiles_count_
;
5376 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestOneActivatePerPrepareTiles
);
5378 class LayerTreeHostTestFrameTimingRequestsSaveTimestamps
5379 : public LayerTreeHostTest
{
5381 LayerTreeHostTestFrameTimingRequestsSaveTimestamps()
5382 : check_results_on_commit_(false) {}
5384 void SetupTree() override
{
5385 scoped_refptr
<FakePictureLayer
> root_layer
=
5386 FakePictureLayer::Create(layer_settings(), &client_
);
5387 root_layer
->SetBounds(gfx::Size(200, 200));
5388 root_layer
->SetIsDrawable(true);
5390 scoped_refptr
<FakePictureLayer
> child_layer
=
5391 FakePictureLayer::Create(layer_settings(), &client_
);
5392 child_layer
->SetBounds(gfx::Size(1500, 1500));
5393 child_layer
->SetIsDrawable(true);
5395 std::vector
<FrameTimingRequest
> requests
;
5396 requests
.push_back(FrameTimingRequest(1, gfx::Rect(0, 0, 100, 100)));
5397 requests
.push_back(FrameTimingRequest(2, gfx::Rect(300, 0, 100, 100)));
5398 child_layer
->SetFrameTimingRequests(requests
);
5400 root_layer
->AddChild(child_layer
);
5401 layer_tree_host()->SetRootLayer(root_layer
);
5402 LayerTreeHostTest::SetupTree();
5405 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5407 void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) override
{
5408 if (!check_results_on_commit_
)
5411 // Since in reality, the events will be read by LayerTreeHost during commit,
5412 // we check the requests here to ensure that they are correct at the next
5413 // commit time (as opposed to checking in DrawLayers for instance).
5414 // TODO(vmpstr): Change this to read things from the main thread when this
5415 // information is propagated to the main thread (not yet implemented).
5416 FrameTimingTracker
* tracker
= host_impl
->frame_timing_tracker();
5418 // Check composite events.
5420 scoped_ptr
<FrameTimingTracker::CompositeTimingSet
> timing_set
=
5421 tracker
->GroupCompositeCountsByRectId();
5422 EXPECT_EQ(1u, timing_set
->size());
5423 auto rect_1_it
= timing_set
->find(1);
5424 EXPECT_TRUE(rect_1_it
!= timing_set
->end());
5425 const auto& timing_events
= rect_1_it
->second
;
5426 EXPECT_EQ(1u, timing_events
.size());
5427 EXPECT_EQ(host_impl
->active_tree()->source_frame_number(),
5428 timing_events
[0].frame_id
);
5429 EXPECT_GT(timing_events
[0].timestamp
, base::TimeTicks());
5432 // Check main frame events.
5434 scoped_ptr
<FrameTimingTracker::MainFrameTimingSet
> timing_set
=
5435 tracker
->GroupMainFrameCountsByRectId();
5436 EXPECT_EQ(2u, timing_set
->size());
5437 auto rect_1_it
= timing_set
->find(1);
5438 EXPECT_TRUE(rect_1_it
!= timing_set
->end());
5439 const auto& timing_events
= rect_1_it
->second
;
5440 EXPECT_EQ(1u, timing_events
.size());
5441 EXPECT_EQ(host_impl
->active_tree()->source_frame_number(),
5442 timing_events
[0].frame_id
);
5443 EXPECT_GT(timing_events
[0].timestamp
, base::TimeTicks());
5444 EXPECT_GT(timing_events
[0].end_time
, timing_events
[0].timestamp
);
5450 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
5451 check_results_on_commit_
= true;
5452 PostSetNeedsCommitToMainThread();
5455 void AfterTest() override
{}
5458 FakeContentLayerClient client_
;
5459 bool check_results_on_commit_
;
5462 // Frame timing is not implemented in single thread proxy.
5463 MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimingRequestsSaveTimestamps
);
5465 class LayerTreeHostTestActivationCausesPrepareTiles
: public LayerTreeHostTest
{
5467 LayerTreeHostTestActivationCausesPrepareTiles()
5468 : scheduled_prepare_tiles_count_(0) {}
5470 void SetupTree() override
{
5471 client_
.set_fill_with_nonsolid_color(true);
5472 scoped_refptr
<FakePictureLayer
> root_layer
=
5473 FakePictureLayer::Create(layer_settings(), &client_
);
5474 root_layer
->SetBounds(gfx::Size(150, 150));
5475 root_layer
->SetIsDrawable(true);
5477 layer_tree_host()->SetRootLayer(root_layer
);
5478 LayerTreeHostTest::SetupTree();
5481 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5483 void NotifyReadyToActivateOnThread(LayerTreeHostImpl
* impl
) override
{
5484 // Ensure we've already activated.
5485 EXPECT_FALSE(impl
->pending_tree());
5487 // After activating, we either need to prepare tiles, or we've already
5488 // called a scheduled prepare tiles. This is done because activation might
5489 // cause us to have to memory available (old active tree is gone), so we
5490 // need to ensure we will get a PrepareTiles call.
5491 if (!impl
->prepare_tiles_needed())
5492 EXPECT_GE(scheduled_prepare_tiles_count_
, 1);
5496 void ScheduledActionPrepareTiles() override
{
5497 ++scheduled_prepare_tiles_count_
;
5500 void AfterTest() override
{}
5503 FakeContentLayerClient client_
;
5504 int scheduled_prepare_tiles_count_
;
5507 // This test is testing activation from a pending tree and doesn't make sense
5508 // with single thread commit-to-active.
5509 MULTI_THREAD_TEST_F(LayerTreeHostTestActivationCausesPrepareTiles
);
5511 // This tests an assertion that DidCommit and WillCommit happen in the same
5512 // stack frame with no tasks that run between them. Various embedders of
5513 // cc depend on this logic. ui::Compositor holds a compositor lock between
5514 // these events and the inspector timeline wants begin/end CompositeLayers
5515 // to be properly nested with other begin/end events.
5516 class LayerTreeHostTestNoTasksBetweenWillAndDidCommit
5517 : public LayerTreeHostTest
{
5519 LayerTreeHostTestNoTasksBetweenWillAndDidCommit() : did_commit_(false) {}
5521 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5523 void WillCommit() override
{
5524 MainThreadTaskRunner()->PostTask(
5525 FROM_HERE
, base::Bind(&LayerTreeHostTestNoTasksBetweenWillAndDidCommit::
5526 EndTestShouldRunAfterDidCommit
,
5527 base::Unretained(this)));
5530 void EndTestShouldRunAfterDidCommit() {
5531 EXPECT_TRUE(did_commit_
);
5535 void DidCommit() override
{
5536 EXPECT_FALSE(did_commit_
);
5540 void AfterTest() override
{ EXPECT_TRUE(did_commit_
); }
5546 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit
);
5548 class LayerTreeHostTestUpdateCopyRequests
: public LayerTreeHostTest
{
5550 void SetupTree() override
{
5551 root
= Layer::Create(layer_settings());
5552 child
= Layer::Create(layer_settings());
5553 root
->AddChild(child
);
5554 layer_tree_host()->SetRootLayer(root
);
5555 LayerTreeHostTest::SetupTree();
5558 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
5560 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5562 void DidCommit() override
{
5563 switch (layer_tree_host()->source_frame_number()) {
5565 child
->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
5566 base::Bind(CopyOutputCallback
)));
5567 EXPECT_GT(root
->num_layer_or_descendants_with_copy_request(), 0);
5570 EXPECT_EQ(root
->num_layer_or_descendants_with_copy_request(), 0);
5576 void AfterTest() override
{}
5579 scoped_refptr
<Layer
> root
;
5580 scoped_refptr
<Layer
> child
;
5583 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateCopyRequests
);
5585 class LayerTreeTestMaskLayerForSurfaceWithClippedLayer
: public LayerTreeTest
{
5587 void SetupTree() override
{
5588 // The masked layer has bounds 50x50, but it has a child that causes
5589 // the surface bounds to be larger. It also has a parent that clips the
5590 // masked layer and its surface.
5592 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5594 scoped_refptr
<Layer
> clipping_layer
= Layer::Create(layer_settings());
5595 root
->AddChild(clipping_layer
);
5597 scoped_refptr
<FakePictureLayer
> content_layer
=
5598 FakePictureLayer::Create(layer_settings(), &client_
);
5599 clipping_layer
->AddChild(content_layer
);
5601 scoped_refptr
<FakePictureLayer
> content_child_layer
=
5602 FakePictureLayer::Create(layer_settings(), &client_
);
5603 content_layer
->AddChild(content_child_layer
);
5605 scoped_refptr
<FakePictureLayer
> mask_layer
=
5606 FakePictureLayer::Create(layer_settings(), &client_
);
5607 content_layer
->SetMaskLayer(mask_layer
.get());
5609 gfx::Size
root_size(100, 100);
5610 root
->SetBounds(root_size
);
5612 gfx::Rect
clipping_rect(20, 10, 10, 20);
5613 clipping_layer
->SetBounds(clipping_rect
.size());
5614 clipping_layer
->SetPosition(clipping_rect
.origin());
5615 clipping_layer
->SetMasksToBounds(true);
5617 gfx::Size
layer_size(50, 50);
5618 content_layer
->SetBounds(layer_size
);
5619 content_layer
->SetPosition(gfx::Point() - clipping_rect
.OffsetFromOrigin());
5621 gfx::Size
child_size(50, 50);
5622 content_child_layer
->SetBounds(child_size
);
5623 content_child_layer
->SetPosition(gfx::Point(20, 0));
5625 gfx::Size
mask_size(100, 100);
5626 mask_layer
->SetBounds(mask_size
);
5627 mask_layer
->SetIsMask(true);
5629 layer_tree_host()->SetRootLayer(root
);
5630 LayerTreeTest::SetupTree();
5633 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5635 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5636 LayerTreeHostImpl::FrameData
* frame_data
,
5637 DrawResult draw_result
) override
{
5638 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5639 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5640 EXPECT_EQ(2u, root_pass
->quad_list
.size());
5642 // There's a solid color quad under everything.
5643 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5645 // The surface is clipped to 10x20.
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 EXPECT_EQ(gfx::Rect(20, 10, 10, 20).ToString(),
5650 render_pass_quad
->rect
.ToString());
5651 // The masked layer is 50x50, but the surface size is 10x20. So the texture
5652 // coords in the mask are scaled by 10/50 and 20/50.
5653 // The surface is clipped to (20,10) so the mask texture coords are offset
5654 // by 20/50 and 10/50
5655 EXPECT_EQ(gfx::ScaleRect(gfx::RectF(20.f
, 10.f
, 10.f
, 20.f
), 1.f
/ 50.f
)
5657 render_pass_quad
->MaskUVRect().ToString());
5658 EXPECT_EQ(gfx::Vector2dF(10.f
/ 50.f
, 20.f
/ 50.f
).ToString(),
5659 render_pass_quad
->mask_uv_scale
.ToString());
5664 void AfterTest() override
{}
5666 FakeContentLayerClient client_
;
5669 SINGLE_AND_MULTI_THREAD_TEST_F(
5670 LayerTreeTestMaskLayerForSurfaceWithClippedLayer
);
5672 class LayerTreeTestMaskLayerWithScaling
: public LayerTreeTest
{
5674 void InitializeSettings(LayerTreeSettings
* settings
) override
{
5675 settings
->layer_transforms_should_scale_layer_contents
= true;
5678 void SetupTree() override
{
5681 // +-- Scaling Layer (adds a 2x scale)
5683 // +-- Content Layer
5686 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5688 scoped_refptr
<Layer
> scaling_layer
= Layer::Create(layer_settings());
5689 root
->AddChild(scaling_layer
);
5691 scoped_refptr
<FakePictureLayer
> content_layer
=
5692 FakePictureLayer::Create(layer_settings(), &client_
);
5693 scaling_layer
->AddChild(content_layer
);
5695 scoped_refptr
<FakePictureLayer
> mask_layer
=
5696 FakePictureLayer::Create(layer_settings(), &client_
);
5697 content_layer
->SetMaskLayer(mask_layer
.get());
5699 gfx::Size
root_size(100, 100);
5700 root
->SetBounds(root_size
);
5702 gfx::Size
scaling_layer_size(50, 50);
5703 scaling_layer
->SetBounds(scaling_layer_size
);
5704 gfx::Transform scale
;
5705 scale
.Scale(2.f
, 2.f
);
5706 scaling_layer
->SetTransform(scale
);
5708 content_layer
->SetBounds(scaling_layer_size
);
5710 mask_layer
->SetBounds(scaling_layer_size
);
5711 mask_layer
->SetIsMask(true);
5713 layer_tree_host()->SetRootLayer(root
);
5714 LayerTreeTest::SetupTree();
5717 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5719 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5720 LayerTreeHostImpl::FrameData
* frame_data
,
5721 DrawResult draw_result
) override
{
5722 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5723 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5724 EXPECT_EQ(2u, root_pass
->quad_list
.size());
5726 // There's a solid color quad under everything.
5727 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5729 EXPECT_EQ(DrawQuad::RENDER_PASS
, root_pass
->quad_list
.front()->material
);
5730 const RenderPassDrawQuad
* render_pass_quad
=
5731 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.front());
5732 switch (host_impl
->active_tree()->source_frame_number()) {
5734 // Check that the tree scaling is correctly taken into account for the
5735 // mask, that should fully map onto the quad.
5736 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5737 render_pass_quad
->rect
.ToString());
5738 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5739 render_pass_quad
->MaskUVRect().ToString());
5740 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5741 render_pass_quad
->mask_uv_scale
.ToString());
5744 // Applying a DSF should change the render surface size, but won't
5745 // affect which part of the mask is used.
5746 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
5747 render_pass_quad
->rect
.ToString());
5748 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5749 render_pass_quad
->MaskUVRect().ToString());
5750 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5751 render_pass_quad
->mask_uv_scale
.ToString());
5758 void DidCommit() override
{
5759 switch (layer_tree_host()->source_frame_number()) {
5761 gfx::Size
double_root_size(200, 200);
5762 layer_tree_host()->SetViewportSize(double_root_size
);
5763 layer_tree_host()->SetDeviceScaleFactor(2.f
);
5768 void AfterTest() override
{}
5770 FakeContentLayerClient client_
;
5773 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskLayerWithScaling
);
5775 class LayerTreeTestMaskLayerWithDifferentBounds
: public LayerTreeTest
{
5777 void SetupTree() override
{
5778 // The mask layer has bounds 100x100 but is attached to a layer with bounds
5781 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5783 scoped_refptr
<FakePictureLayer
> content_layer
=
5784 FakePictureLayer::Create(layer_settings(), &client_
);
5785 root
->AddChild(content_layer
);
5787 scoped_refptr
<FakePictureLayer
> mask_layer
=
5788 FakePictureLayer::Create(layer_settings(), &client_
);
5789 content_layer
->SetMaskLayer(mask_layer
.get());
5791 gfx::Size
root_size(100, 100);
5792 root
->SetBounds(root_size
);
5794 gfx::Size
layer_size(50, 50);
5795 content_layer
->SetBounds(layer_size
);
5797 gfx::Size
mask_size(100, 100);
5798 mask_layer
->SetBounds(mask_size
);
5799 mask_layer
->SetIsMask(true);
5801 layer_tree_host()->SetRootLayer(root
);
5802 LayerTreeTest::SetupTree();
5805 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5807 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5808 LayerTreeHostImpl::FrameData
* frame_data
,
5809 DrawResult draw_result
) override
{
5810 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5811 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5812 EXPECT_EQ(2u, root_pass
->quad_list
.size());
5814 // There's a solid color quad under everything.
5815 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5817 EXPECT_EQ(DrawQuad::RENDER_PASS
, root_pass
->quad_list
.front()->material
);
5818 const RenderPassDrawQuad
* render_pass_quad
=
5819 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.front());
5820 switch (host_impl
->active_tree()->source_frame_number()) {
5822 // Check that the mask fills the surface.
5823 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
5824 render_pass_quad
->rect
.ToString());
5825 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5826 render_pass_quad
->MaskUVRect().ToString());
5827 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5828 render_pass_quad
->mask_uv_scale
.ToString());
5831 // Applying a DSF should change the render surface size, but won't
5832 // affect which part of the mask is used.
5833 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5834 render_pass_quad
->rect
.ToString());
5835 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5836 render_pass_quad
->MaskUVRect().ToString());
5837 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5838 render_pass_quad
->mask_uv_scale
.ToString());
5845 void DidCommit() override
{
5846 switch (layer_tree_host()->source_frame_number()) {
5848 gfx::Size
double_root_size(200, 200);
5849 layer_tree_host()->SetViewportSize(double_root_size
);
5850 layer_tree_host()->SetDeviceScaleFactor(2.f
);
5855 void AfterTest() override
{}
5857 FakeContentLayerClient client_
;
5860 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskLayerWithDifferentBounds
);
5862 class LayerTreeTestReflectionMaskLayerWithDifferentBounds
5863 : public LayerTreeTest
{
5865 void SetupTree() override
{
5866 // The replica's mask layer has bounds 100x100 but the replica is of a
5867 // layer with bounds 50x50.
5869 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5871 scoped_refptr
<FakePictureLayer
> content_layer
=
5872 FakePictureLayer::Create(layer_settings(), &client_
);
5873 root
->AddChild(content_layer
);
5875 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
5876 content_layer
->SetReplicaLayer(replica_layer
.get());
5878 scoped_refptr
<FakePictureLayer
> mask_layer
=
5879 FakePictureLayer::Create(layer_settings(), &client_
);
5880 replica_layer
->SetMaskLayer(mask_layer
.get());
5882 gfx::Size
root_size(100, 100);
5883 root
->SetBounds(root_size
);
5885 gfx::Size
layer_size(50, 50);
5886 content_layer
->SetBounds(layer_size
);
5888 gfx::Size
mask_size(100, 100);
5889 mask_layer
->SetBounds(mask_size
);
5890 mask_layer
->SetIsMask(true);
5892 layer_tree_host()->SetRootLayer(root
);
5893 LayerTreeTest::SetupTree();
5896 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5898 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5899 LayerTreeHostImpl::FrameData
* frame_data
,
5900 DrawResult draw_result
) override
{
5901 EXPECT_EQ(2u, frame_data
->render_passes
.size());
5902 RenderPass
* root_pass
= frame_data
->render_passes
.back();
5903 EXPECT_EQ(3u, root_pass
->quad_list
.size());
5905 // There's a solid color quad under everything.
5906 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
5908 EXPECT_EQ(DrawQuad::RENDER_PASS
,
5909 root_pass
->quad_list
.ElementAt(1)->material
);
5910 const RenderPassDrawQuad
* render_pass_quad
=
5911 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.ElementAt(1));
5912 switch (host_impl
->active_tree()->source_frame_number()) {
5914 // Check that the mask fills the surface.
5915 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
5916 render_pass_quad
->rect
.ToString());
5917 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5918 render_pass_quad
->MaskUVRect().ToString());
5919 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5920 render_pass_quad
->mask_uv_scale
.ToString());
5923 // Applying a DSF should change the render surface size, but won't
5924 // affect which part of the mask is used.
5925 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
5926 render_pass_quad
->rect
.ToString());
5927 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
).ToString(),
5928 render_pass_quad
->MaskUVRect().ToString());
5929 EXPECT_EQ(gfx::Vector2dF(1.f
, 1.f
).ToString(),
5930 render_pass_quad
->mask_uv_scale
.ToString());
5937 void DidCommit() override
{
5938 switch (layer_tree_host()->source_frame_number()) {
5940 gfx::Size
double_root_size(200, 200);
5941 layer_tree_host()->SetViewportSize(double_root_size
);
5942 layer_tree_host()->SetDeviceScaleFactor(2.f
);
5947 void AfterTest() override
{}
5949 FakeContentLayerClient client_
;
5952 SINGLE_AND_MULTI_THREAD_TEST_F(
5953 LayerTreeTestReflectionMaskLayerWithDifferentBounds
);
5955 class LayerTreeTestReflectionMaskLayerForSurfaceWithUnclippedChild
5956 : public LayerTreeTest
{
5958 void SetupTree() override
{
5959 // The replica is of a layer with bounds 50x50, but it has a child that
5960 // causes the surface bounds to be larger.
5962 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5964 scoped_refptr
<FakePictureLayer
> content_layer
=
5965 FakePictureLayer::Create(layer_settings(), &client_
);
5966 root
->AddChild(content_layer
);
5968 content_child_layer_
= FakePictureLayer::Create(layer_settings(), &client_
);
5969 content_layer
->AddChild(content_child_layer_
);
5971 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
5972 content_layer
->SetReplicaLayer(replica_layer
.get());
5974 scoped_refptr
<FakePictureLayer
> mask_layer
=
5975 FakePictureLayer::Create(layer_settings(), &client_
);
5976 replica_layer
->SetMaskLayer(mask_layer
.get());
5978 gfx::Size
root_size(100, 100);
5979 root
->SetBounds(root_size
);
5981 gfx::Size
layer_size(50, 50);
5982 content_layer
->SetBounds(layer_size
);
5983 content_child_layer_
->SetBounds(layer_size
);
5984 content_child_layer_
->SetPosition(gfx::PointF(50.f
, 0.f
));
5986 gfx::Size
mask_size(100, 100);
5987 mask_layer
->SetBounds(mask_size
);
5988 mask_layer
->SetIsMask(true);
5990 layer_tree_host()->SetRootLayer(root
);
5991 LayerTreeTest::SetupTree();
5994 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
5996 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
5997 LayerTreeHostImpl::FrameData
* frame_data
,
5998 DrawResult draw_result
) override
{
5999 EXPECT_EQ(2u, frame_data
->render_passes
.size());
6000 RenderPass
* root_pass
= frame_data
->render_passes
.back();
6001 EXPECT_EQ(3u, root_pass
->quad_list
.size());
6003 // There's a solid color quad under everything.
6004 EXPECT_EQ(DrawQuad::SOLID_COLOR
, root_pass
->quad_list
.back()->material
);
6006 EXPECT_EQ(DrawQuad::RENDER_PASS
,
6007 root_pass
->quad_list
.ElementAt(1)->material
);
6008 const RenderPassDrawQuad
* replica_quad
=
6009 RenderPassDrawQuad::MaterialCast(root_pass
->quad_list
.ElementAt(1));
6010 switch (host_impl
->active_tree()->source_frame_number()) {
6012 // The surface is 100x50.
6013 // The mask covers the owning layer only.
6014 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
6015 replica_quad
->rect
.ToString());
6016 EXPECT_EQ(gfx::RectF(0.f
, 0.f
, 2.f
, 1.f
).ToString(),
6017 replica_quad
->MaskUVRect().ToString());
6018 EXPECT_EQ(gfx::Vector2dF(2.f
, 1.f
).ToString(),
6019 replica_quad
->mask_uv_scale
.ToString());
6022 // The surface is 100x50 with its origin at (-50, 0).
6023 // The mask covers the owning layer only.
6024 EXPECT_EQ(gfx::Rect(-50, 0, 100, 50).ToString(),
6025 replica_quad
->rect
.ToString());
6026 EXPECT_EQ(gfx::RectF(-1.f
, 0.f
, 2.f
, 1.f
).ToString(),
6027 replica_quad
->MaskUVRect().ToString());
6028 EXPECT_EQ(gfx::Vector2dF(2.f
, 1.f
).ToString(),
6029 replica_quad
->mask_uv_scale
.ToString());
6036 void DidCommit() override
{
6037 switch (layer_tree_host()->source_frame_number()) {
6039 // Move the child to (-50, 0) instead. Now the mask should be moved to
6040 // still cover the layer being replicated.
6041 content_child_layer_
->SetPosition(gfx::PointF(-50.f
, 0.f
));
6046 void AfterTest() override
{}
6048 scoped_refptr
<FakePictureLayer
> content_child_layer_
;
6049 FakeContentLayerClient client_
;
6052 SINGLE_AND_MULTI_THREAD_TEST_F(
6053 LayerTreeTestReflectionMaskLayerForSurfaceWithUnclippedChild
);
6055 class LayerTreeTestPageScaleFlags
: public LayerTreeTest
{
6057 void SetupTree() override
{
6061 // -page scale child1
6062 // -page scale grandchild
6063 // -page scale child2
6066 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6067 scoped_refptr
<Layer
> pre_page_scale
= Layer::Create(layer_settings());
6068 scoped_refptr
<Layer
> page_scale
= Layer::Create(layer_settings());
6069 scoped_refptr
<Layer
> page_scale_child1
= Layer::Create(layer_settings());
6070 scoped_refptr
<Layer
> page_scale_grandchild
=
6071 Layer::Create(layer_settings());
6072 scoped_refptr
<Layer
> page_scale_child2
= Layer::Create(layer_settings());
6073 scoped_refptr
<Layer
> post_page_scale
= Layer::Create(layer_settings());
6075 root
->AddChild(pre_page_scale
);
6076 root
->AddChild(page_scale
);
6077 root
->AddChild(post_page_scale
);
6079 page_scale
->AddChild(page_scale_child1
);
6080 page_scale
->AddChild(page_scale_child2
);
6081 page_scale_child1
->AddChild(page_scale_grandchild
);
6083 layer_tree_host()->SetRootLayer(root
);
6084 LayerTreeTest::SetupTree();
6086 scoped_refptr
<Layer
> overscroll_elasticity_layer
= nullptr;
6087 scoped_refptr
<Layer
> inner_viewport_scroll_layer
= nullptr;
6088 scoped_refptr
<Layer
> outer_viewport_scroll_layer
= nullptr;
6089 layer_tree_host()->RegisterViewportLayers(
6090 overscroll_elasticity_layer
, page_scale
, inner_viewport_scroll_layer
,
6091 outer_viewport_scroll_layer
);
6093 affected_by_page_scale_
.push_back(page_scale
->id());
6094 affected_by_page_scale_
.push_back(page_scale_child1
->id());
6095 affected_by_page_scale_
.push_back(page_scale_child2
->id());
6096 affected_by_page_scale_
.push_back(page_scale_grandchild
->id());
6098 not_affected_by_page_scale_
.push_back(root
->id());
6099 not_affected_by_page_scale_
.push_back(pre_page_scale
->id());
6100 not_affected_by_page_scale_
.push_back(post_page_scale
->id());
6103 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
6105 void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) override
{
6106 LayerTreeHostCommon::CallFunctionForSubtree(
6107 host_impl
->sync_tree()->root_layer(), [this](LayerImpl
* layer
) {
6108 const std::vector
<int>& list
=
6109 layer
->IsAffectedByPageScale()
6110 ? this->affected_by_page_scale_
6111 : this->not_affected_by_page_scale_
;
6112 EXPECT_TRUE(std::find(list
.begin(), list
.end(), layer
->id()) !=
6119 void AfterTest() override
{}
6121 std::vector
<int> affected_by_page_scale_
;
6122 std::vector
<int> not_affected_by_page_scale_
;
6125 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags
);
6127 class LayerTreeHostScrollingAndScalingUpdatesLayers
: public LayerTreeHostTest
{
6129 LayerTreeHostScrollingAndScalingUpdatesLayers()
6130 : requested_update_layers_(false), commit_count_(0) {}
6132 void SetupTree() override
{
6133 LayerTreeHostTest::SetupTree();
6134 Layer
* root_layer
= layer_tree_host()->root_layer();
6135 scoped_refptr
<Layer
> scroll_layer
= Layer::Create(layer_settings());
6136 CreateVirtualViewportLayers(root_layer
, scroll_layer
, root_layer
->bounds(),
6137 root_layer
->bounds(), layer_tree_host(),
6141 void BeginTest() override
{
6142 LayerTreeHostCommon::ScrollUpdateInfo scroll
;
6143 scroll
.layer_id
= layer_tree_host()->root_layer()->id();
6144 scroll
.scroll_delta
= gfx::Vector2d(0, 33);
6145 scroll_info_
.scrolls
.push_back(scroll
);
6147 scale_info_
.page_scale_delta
= 2.71f
;
6149 PostSetNeedsCommitToMainThread();
6152 void BeginMainFrame(const BeginFrameArgs
& args
) override
{
6153 switch (commit_count_
) {
6155 requested_update_layers_
= false;
6156 layer_tree_host()->ApplyScrollAndScale(&no_op_info_
);
6157 EXPECT_FALSE(requested_update_layers_
);
6160 requested_update_layers_
= false;
6161 layer_tree_host()->ApplyScrollAndScale(&scale_info_
);
6162 EXPECT_TRUE(requested_update_layers_
);
6165 requested_update_layers_
= false;
6166 layer_tree_host()->ApplyScrollAndScale(&scroll_info_
);
6167 EXPECT_TRUE(requested_update_layers_
);
6175 void DidSetNeedsUpdateLayers() override
{ requested_update_layers_
= true; }
6177 void DidCommit() override
{
6178 if (++commit_count_
< 3)
6179 PostSetNeedsCommitToMainThread();
6182 void AfterTest() override
{}
6184 ScrollAndScaleSet scroll_info_
;
6185 ScrollAndScaleSet scale_info_
;
6186 ScrollAndScaleSet no_op_info_
;
6187 bool requested_update_layers_
;
6191 MULTI_THREAD_TEST_F(LayerTreeHostScrollingAndScalingUpdatesLayers
);