1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/trees/layer_tree_host.h"
7 #include "cc/test/fake_content_layer_client.h"
8 #include "cc/test/fake_picture_layer.h"
9 #include "cc/test/fake_picture_layer_impl.h"
10 #include "cc/test/layer_tree_test.h"
11 #include "cc/trees/layer_tree_impl.h"
16 // These tests deal with picture layers.
17 class LayerTreeHostPictureTest
: public LayerTreeTest
{
19 void InitializeSettings(LayerTreeSettings
* settings
) override
{
20 // PictureLayer can only be used with impl side painting enabled.
21 settings
->impl_side_painting
= true;
25 class LayerTreeHostPictureTestTwinLayer
26 : public LayerTreeHostPictureTest
{
27 void SetupTree() override
{
28 LayerTreeHostPictureTest::SetupTree();
30 scoped_refptr
<FakePictureLayer
> picture
=
31 FakePictureLayer::Create(&client_
);
32 layer_tree_host()->root_layer()->AddChild(picture
);
35 void BeginTest() override
{
37 PostSetNeedsCommitToMainThread();
40 void DidCommit() override
{
41 switch (layer_tree_host()->source_frame_number()) {
43 // Drop the picture layer from the tree.
44 layer_tree_host()->root_layer()->children()[0]->RemoveFromParent();
47 // Add a new picture layer.
48 scoped_refptr
<FakePictureLayer
> picture
=
49 FakePictureLayer::Create(&client_
);
50 layer_tree_host()->root_layer()->AddChild(picture
);
55 void WillActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
56 LayerImpl
* pending_root_impl
= impl
->pending_tree()->root_layer();
57 LayerImpl
* active_root_impl
= impl
->active_tree()->root_layer();
59 if (pending_root_impl
->children().empty()) {
60 EXPECT_EQ(2, activates_
);
64 FakePictureLayerImpl
* pending_picture_impl
=
65 static_cast<FakePictureLayerImpl
*>(pending_root_impl
->children()[0]);
67 if (!active_root_impl
) {
68 EXPECT_EQ(0, activates_
);
69 EXPECT_EQ(nullptr, pending_picture_impl
->GetPendingOrActiveTwinLayer());
73 if (active_root_impl
->children().empty()) {
74 EXPECT_EQ(3, activates_
);
75 EXPECT_EQ(nullptr, pending_picture_impl
->GetPendingOrActiveTwinLayer());
79 FakePictureLayerImpl
* active_picture_impl
=
80 static_cast<FakePictureLayerImpl
*>(active_root_impl
->children()[0]);
82 // After the first activation, when we commit again, we'll have a pending
83 // and active layer. Then we recreate a picture layer in the 4th activate
84 // and the next commit will have a pending and active twin again.
85 EXPECT_TRUE(activates_
== 1 || activates_
== 4);
87 EXPECT_EQ(pending_picture_impl
,
88 active_picture_impl
->GetPendingOrActiveTwinLayer());
89 EXPECT_EQ(active_picture_impl
,
90 pending_picture_impl
->GetPendingOrActiveTwinLayer());
91 EXPECT_EQ(nullptr, active_picture_impl
->GetRecycledTwinLayer());
94 void DidActivateTreeOnThread(LayerTreeHostImpl
* impl
) override
{
95 LayerImpl
* active_root_impl
= impl
->active_tree()->root_layer();
96 LayerImpl
* recycle_root_impl
= impl
->recycle_tree()->root_layer();
98 if (active_root_impl
->children().empty()) {
99 EXPECT_EQ(2, activates_
);
101 FakePictureLayerImpl
* active_picture_impl
=
102 static_cast<FakePictureLayerImpl
*>(active_root_impl
->children()[0]);
103 FakePictureLayerImpl
* recycle_picture_impl
=
104 static_cast<FakePictureLayerImpl
*>(recycle_root_impl
->children()[0]);
106 EXPECT_EQ(nullptr, active_picture_impl
->GetPendingOrActiveTwinLayer());
107 EXPECT_EQ(recycle_picture_impl
,
108 active_picture_impl
->GetRecycledTwinLayer());
113 PostSetNeedsCommitToMainThread();
118 void AfterTest() override
{}
120 FakeContentLayerClient client_
;
124 MULTI_THREAD_TEST_F(LayerTreeHostPictureTestTwinLayer
);