cc: Don't swap PictureLayerTilingSet on activate.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_picture.cc
blob4f49bb3a72d64088ebd24180f1b41eb362bbe2a7
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"
13 namespace cc {
14 namespace {
16 // These tests deal with picture layers.
17 class LayerTreeHostPictureTest : public LayerTreeTest {
18 protected:
19 void SetupTreeWithSinglePictureLayer(const gfx::Size& size) {
20 scoped_refptr<Layer> root = Layer::Create();
21 root->SetBounds(size);
23 root_picture_layer_ = FakePictureLayer::Create(&client_);
24 root_picture_layer_->SetBounds(size);
25 root->AddChild(root_picture_layer_);
27 layer_tree_host()->SetRootLayer(root);
30 scoped_refptr<FakePictureLayer> root_picture_layer_;
31 FakeContentLayerClient client_;
34 class LayerTreeHostPictureTestTwinLayer
35 : public LayerTreeHostPictureTest {
36 void SetupTree() override {
37 SetupTreeWithSinglePictureLayer(gfx::Size(1, 1));
40 void BeginTest() override {
41 activates_ = 0;
42 PostSetNeedsCommitToMainThread();
45 void DidCommit() override {
46 switch (layer_tree_host()->source_frame_number()) {
47 case 2:
48 // Drop the picture layer from the tree.
49 layer_tree_host()->root_layer()->children()[0]->RemoveFromParent();
50 break;
51 case 3:
52 // Add a new picture layer.
53 scoped_refptr<FakePictureLayer> picture =
54 FakePictureLayer::Create(&client_);
55 layer_tree_host()->root_layer()->AddChild(picture);
56 break;
60 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
61 LayerImpl* pending_root_impl = impl->pending_tree()->root_layer();
62 LayerImpl* active_root_impl = impl->active_tree()->root_layer();
64 if (pending_root_impl->children().empty()) {
65 EXPECT_EQ(2, activates_);
66 return;
69 FakePictureLayerImpl* pending_picture_impl =
70 static_cast<FakePictureLayerImpl*>(pending_root_impl->children()[0]);
72 if (!active_root_impl) {
73 EXPECT_EQ(0, activates_);
74 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer());
75 return;
78 if (active_root_impl->children().empty()) {
79 EXPECT_EQ(3, activates_);
80 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer());
81 return;
84 FakePictureLayerImpl* active_picture_impl =
85 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]);
87 // 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
89 // and the next commit will have a pending and active twin again.
90 EXPECT_TRUE(activates_ == 1 || activates_ == 4);
92 EXPECT_EQ(pending_picture_impl,
93 active_picture_impl->GetPendingOrActiveTwinLayer());
94 EXPECT_EQ(active_picture_impl,
95 pending_picture_impl->GetPendingOrActiveTwinLayer());
96 EXPECT_EQ(nullptr, active_picture_impl->GetRecycledTwinLayer());
99 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
100 LayerImpl* active_root_impl = impl->active_tree()->root_layer();
101 LayerImpl* recycle_root_impl = impl->recycle_tree()->root_layer();
103 if (active_root_impl->children().empty()) {
104 EXPECT_EQ(2, activates_);
105 } else {
106 FakePictureLayerImpl* active_picture_impl =
107 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]);
108 FakePictureLayerImpl* recycle_picture_impl =
109 static_cast<FakePictureLayerImpl*>(recycle_root_impl->children()[0]);
111 EXPECT_EQ(nullptr, active_picture_impl->GetPendingOrActiveTwinLayer());
112 EXPECT_EQ(recycle_picture_impl,
113 active_picture_impl->GetRecycledTwinLayer());
116 ++activates_;
117 if (activates_ <= 4)
118 PostSetNeedsCommitToMainThread();
119 else
120 EndTest();
123 void AfterTest() override {}
125 int activates_;
128 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer);
130 class LayerTreeHostPictureTestResizeViewportWithGpuRaster
131 : public LayerTreeHostPictureTest {
132 void InitializeSettings(LayerTreeSettings* settings) override {
133 settings->gpu_rasterization_forced = true;
136 void SetupTree() override {
137 scoped_refptr<Layer> root = Layer::Create();
138 root->SetBounds(gfx::Size(768, 960));
140 client_.set_fill_with_nonsolid_color(true);
141 picture_ = FakePictureLayer::Create(&client_);
142 picture_->SetBounds(gfx::Size(768, 960));
143 root->AddChild(picture_);
145 layer_tree_host()->SetRootLayer(root);
146 LayerTreeHostPictureTest::SetupTree();
149 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
151 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
152 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
153 FakePictureLayerImpl* picture_impl =
154 static_cast<FakePictureLayerImpl*>(child);
155 gfx::Size tile_size =
156 picture_impl->HighResTiling()->TileAt(0, 0)->content_rect().size();
158 switch (impl->sync_tree()->source_frame_number()) {
159 case 0:
160 tile_size_ = tile_size;
161 // GPU Raster picks a tile size based on the viewport size.
162 EXPECT_EQ(gfx::Size(768, 256), tile_size);
163 break;
164 case 1:
165 // When the viewport changed size, the new frame's tiles should change
166 // along with it.
167 EXPECT_NE(gfx::Size(768, 256), tile_size);
171 void DidCommit() override {
172 switch (layer_tree_host()->source_frame_number()) {
173 case 1:
174 // Change the picture layer's size along with the viewport, so it will
175 // consider picking a new tile size.
176 picture_->SetBounds(gfx::Size(768, 1056));
177 layer_tree_host()->SetViewportSize(gfx::Size(768, 1056));
178 break;
179 case 2:
180 EndTest();
184 void AfterTest() override {}
186 gfx::Size tile_size_;
187 FakeContentLayerClient client_;
188 scoped_refptr<FakePictureLayer> picture_;
191 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(
192 LayerTreeHostPictureTestResizeViewportWithGpuRaster);
194 } // namespace
195 } // namespace cc