OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "cc/test/fake_content_layer_client.h" | 7 #include "cc/test/fake_content_layer_client.h" |
8 #include "cc/test/fake_picture_layer.h" | 8 #include "cc/test/fake_picture_layer.h" |
9 #include "cc/test/fake_picture_layer_impl.h" | 9 #include "cc/test/fake_picture_layer_impl.h" |
10 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 SetupTreeWithSinglePictureLayer(gfx::Size(1, 1)); | 37 SetupTreeWithSinglePictureLayer(gfx::Size(1, 1)); |
38 } | 38 } |
39 | 39 |
40 void BeginTest() override { | 40 void BeginTest() override { |
41 activates_ = 0; | 41 activates_ = 0; |
42 PostSetNeedsCommitToMainThread(); | 42 PostSetNeedsCommitToMainThread(); |
43 } | 43 } |
44 | 44 |
45 void DidCommit() override { | 45 void DidCommit() override { |
46 switch (layer_tree_host()->source_frame_number()) { | 46 switch (layer_tree_host()->source_frame_number()) { |
| 47 case 1: |
| 48 // Activate while there are pending and active twins in place. |
| 49 layer_tree_host()->SetNeedsCommit(); |
| 50 break; |
47 case 2: | 51 case 2: |
48 // Drop the picture layer from the tree. | 52 // Drop the picture layer from the tree so the activate will have an |
| 53 // active layer without a pending twin. |
49 layer_tree_host()->root_layer()->children()[0]->RemoveFromParent(); | 54 layer_tree_host()->root_layer()->children()[0]->RemoveFromParent(); |
50 break; | 55 break; |
51 case 3: | 56 case 3: { |
52 // Add a new picture layer. | 57 // Add a new picture layer so the activate will have a pending layer |
| 58 // without an active twin. |
53 scoped_refptr<FakePictureLayer> picture = | 59 scoped_refptr<FakePictureLayer> picture = |
54 FakePictureLayer::Create(&client_); | 60 FakePictureLayer::Create(&client_); |
55 layer_tree_host()->root_layer()->AddChild(picture); | 61 layer_tree_host()->root_layer()->AddChild(picture); |
56 break; | 62 break; |
| 63 } |
| 64 case 4: |
| 65 // Active while there are pending and active twins again. |
| 66 layer_tree_host()->SetNeedsCommit(); |
| 67 break; |
| 68 case 5: |
| 69 EndTest(); |
| 70 break; |
57 } | 71 } |
58 } | 72 } |
59 | 73 |
60 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 74 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
61 LayerImpl* pending_root_impl = impl->pending_tree()->root_layer(); | 75 LayerImpl* pending_root_impl = impl->pending_tree()->root_layer(); |
62 LayerImpl* active_root_impl = impl->active_tree()->root_layer(); | 76 LayerImpl* active_root_impl = impl->active_tree()->root_layer(); |
63 | 77 |
64 if (pending_root_impl->children().empty()) { | 78 if (pending_root_impl->children().empty()) { |
65 EXPECT_EQ(2, activates_); | 79 EXPECT_EQ(2, activates_); |
66 return; | 80 return; |
(...skipping 13 matching lines...) Expand all Loading... |
80 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer()); | 94 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer()); |
81 return; | 95 return; |
82 } | 96 } |
83 | 97 |
84 FakePictureLayerImpl* active_picture_impl = | 98 FakePictureLayerImpl* active_picture_impl = |
85 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]); | 99 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]); |
86 | 100 |
87 // After the first activation, when we commit again, we'll have a pending | 101 // After the first activation, when we commit again, we'll have a pending |
88 // and active layer. Then we recreate a picture layer in the 4th activate | 102 // and active layer. Then we recreate a picture layer in the 4th activate |
89 // and the next commit will have a pending and active twin again. | 103 // and the next commit will have a pending and active twin again. |
90 EXPECT_TRUE(activates_ == 1 || activates_ == 4); | 104 EXPECT_TRUE(activates_ == 1 || activates_ == 4) << activates_; |
91 | 105 |
92 EXPECT_EQ(pending_picture_impl, | 106 EXPECT_EQ(pending_picture_impl, |
93 active_picture_impl->GetPendingOrActiveTwinLayer()); | 107 active_picture_impl->GetPendingOrActiveTwinLayer()); |
94 EXPECT_EQ(active_picture_impl, | 108 EXPECT_EQ(active_picture_impl, |
95 pending_picture_impl->GetPendingOrActiveTwinLayer()); | 109 pending_picture_impl->GetPendingOrActiveTwinLayer()); |
96 EXPECT_EQ(nullptr, active_picture_impl->GetRecycledTwinLayer()); | 110 EXPECT_EQ(nullptr, active_picture_impl->GetRecycledTwinLayer()); |
97 } | 111 } |
98 | 112 |
99 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 113 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
100 LayerImpl* active_root_impl = impl->active_tree()->root_layer(); | 114 LayerImpl* active_root_impl = impl->active_tree()->root_layer(); |
101 LayerImpl* recycle_root_impl = impl->recycle_tree()->root_layer(); | 115 LayerImpl* recycle_root_impl = impl->recycle_tree()->root_layer(); |
102 | 116 |
103 if (active_root_impl->children().empty()) { | 117 if (active_root_impl->children().empty()) { |
104 EXPECT_EQ(2, activates_); | 118 EXPECT_EQ(2, activates_); |
105 } else { | 119 } else { |
106 FakePictureLayerImpl* active_picture_impl = | 120 FakePictureLayerImpl* active_picture_impl = |
107 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]); | 121 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]); |
108 FakePictureLayerImpl* recycle_picture_impl = | 122 FakePictureLayerImpl* recycle_picture_impl = |
109 static_cast<FakePictureLayerImpl*>(recycle_root_impl->children()[0]); | 123 static_cast<FakePictureLayerImpl*>(recycle_root_impl->children()[0]); |
110 | 124 |
111 EXPECT_EQ(nullptr, active_picture_impl->GetPendingOrActiveTwinLayer()); | 125 EXPECT_EQ(nullptr, active_picture_impl->GetPendingOrActiveTwinLayer()); |
112 EXPECT_EQ(recycle_picture_impl, | 126 EXPECT_EQ(recycle_picture_impl, |
113 active_picture_impl->GetRecycledTwinLayer()); | 127 active_picture_impl->GetRecycledTwinLayer()); |
114 } | 128 } |
115 | 129 |
116 ++activates_; | 130 ++activates_; |
117 if (activates_ <= 4) | |
118 PostSetNeedsCommitToMainThread(); | |
119 else | |
120 EndTest(); | |
121 } | 131 } |
122 | 132 |
123 void AfterTest() override {} | 133 void AfterTest() override { EXPECT_EQ(5, activates_); } |
124 | 134 |
125 int activates_; | 135 int activates_; |
126 }; | 136 }; |
127 | 137 |
128 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer); | 138 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer); |
129 | 139 |
130 class LayerTreeHostPictureTestResizeViewportWithGpuRaster | 140 class LayerTreeHostPictureTestResizeViewportWithGpuRaster |
131 : public LayerTreeHostPictureTest { | 141 : public LayerTreeHostPictureTest { |
132 void InitializeSettings(LayerTreeSettings* settings) override { | 142 void InitializeSettings(LayerTreeSettings* settings) override { |
133 settings->gpu_rasterization_forced = true; | 143 settings->gpu_rasterization_forced = true; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 bool did_post_commit_; | 322 bool did_post_commit_; |
313 FakeContentLayerClient client_; | 323 FakeContentLayerClient client_; |
314 scoped_refptr<FakePictureLayer> picture_; | 324 scoped_refptr<FakePictureLayer> picture_; |
315 }; | 325 }; |
316 | 326 |
317 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( | 327 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( |
318 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree); | 328 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree); |
319 | 329 |
320 } // namespace | 330 } // namespace |
321 } // namespace cc | 331 } // namespace cc |
OLD | NEW |