Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: cc/trees/layer_tree_host_unittest_picture.cc

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_unittest_no_message_loop.cc ('k') | cc/trees/single_thread_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "cc/trees/layer_tree_impl.h" 11 #include "cc/trees/layer_tree_impl.h"
12 12
13 namespace cc { 13 namespace cc {
14 namespace { 14 namespace {
15 15
16 // These tests deal with picture layers. 16 // These tests deal with picture layers.
17 class LayerTreeHostPictureTest : public LayerTreeTest { 17 class LayerTreeHostPictureTest : public LayerTreeTest {
18 protected: 18 protected:
19 void InitializeSettings(LayerTreeSettings* settings) override { 19 void SetupTreeWithSinglePictureLayer(const gfx::Size& size) {
20 // PictureLayer can only be used with impl side painting enabled. 20 scoped_refptr<Layer> root = Layer::Create();
21 settings->impl_side_painting = true; 21 root->SetBounds(size);
22
23 root_picture_layer_ = FakePictureLayer::Create(&client_);
24 root_picture_layer_->SetBounds(size);
25 root->AddChild(root_picture_layer_);
26
27 layer_tree_host()->SetRootLayer(root);
22 } 28 }
29
30 scoped_refptr<FakePictureLayer> root_picture_layer_;
31 FakeContentLayerClient client_;
23 }; 32 };
24 33
25 class LayerTreeHostPictureTestTwinLayer 34 class LayerTreeHostPictureTestTwinLayer
26 : public LayerTreeHostPictureTest { 35 : public LayerTreeHostPictureTest {
27 void SetupTree() override { 36 void SetupTree() override {
28 LayerTreeHostPictureTest::SetupTree(); 37 SetupTreeWithSinglePictureLayer(gfx::Size(1, 1));
29
30 scoped_refptr<FakePictureLayer> picture =
31 FakePictureLayer::Create(&client_);
32 layer_tree_host()->root_layer()->AddChild(picture);
33 } 38 }
34 39
35 void BeginTest() override { 40 void BeginTest() override {
36 activates_ = 0; 41 activates_ = 0;
37 PostSetNeedsCommitToMainThread(); 42 PostSetNeedsCommitToMainThread();
38 } 43 }
39 44
40 void DidCommit() override { 45 void DidCommit() override {
41 switch (layer_tree_host()->source_frame_number()) { 46 switch (layer_tree_host()->source_frame_number()) {
42 case 2: 47 case 2:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 115
111 ++activates_; 116 ++activates_;
112 if (activates_ <= 4) 117 if (activates_ <= 4)
113 PostSetNeedsCommitToMainThread(); 118 PostSetNeedsCommitToMainThread();
114 else 119 else
115 EndTest(); 120 EndTest();
116 } 121 }
117 122
118 void AfterTest() override {} 123 void AfterTest() override {}
119 124
120 FakeContentLayerClient client_;
121 int activates_; 125 int activates_;
122 }; 126 };
123 127
124 MULTI_THREAD_TEST_F(LayerTreeHostPictureTestTwinLayer); 128 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer);
129
130 class LayerTreeHostPictureTestResizeViewportWithGpuRaster
131 : public LayerTreeHostPictureTest {
132 void InitializeSettings(LayerTreeSettings* settings) override {
133 settings->gpu_rasterization_forced = true;
134 }
135
136 void SetupTree() override {
137 scoped_refptr<Layer> root = Layer::Create();
138 root->SetBounds(gfx::Size(768, 960));
139
140 client_.set_fill_with_nonsolid_color(true);
141 picture_ = FakePictureLayer::Create(&client_);
142 picture_->SetBounds(gfx::Size(768, 960));
143 root->AddChild(picture_);
144
145 layer_tree_host()->SetRootLayer(root);
146 LayerTreeHostPictureTest::SetupTree();
147 }
148
149 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
150
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();
157
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);
168 }
169 }
170
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();
181 }
182 }
183
184 void AfterTest() override {}
185
186 gfx::Size tile_size_;
187 FakeContentLayerClient client_;
188 scoped_refptr<FakePictureLayer> picture_;
189 };
190
191 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(
192 LayerTreeHostPictureTestResizeViewportWithGpuRaster);
193
194 class LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree
195 : public LayerTreeHostPictureTest {
196 void SetupTree() override {
197 frame_ = 0;
198 did_post_commit_ = false;
199
200 scoped_refptr<Layer> root = Layer::Create();
201 root->SetBounds(gfx::Size(100, 100));
202
203 // The layer is big enough that the live tiles rect won't cover the full
204 // layer.
205 client_.set_fill_with_nonsolid_color(true);
206 picture_ = FakePictureLayer::Create(&client_);
207 picture_->SetBounds(gfx::Size(100, 100000));
208 root->AddChild(picture_);
209
210 layer_tree_host()->SetRootLayer(root);
211 LayerTreeHostPictureTest::SetupTree();
212 }
213
214 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
215
216 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
217 LayerImpl* child = impl->active_tree()->root_layer()->children()[0];
218 FakePictureLayerImpl* picture_impl =
219 static_cast<FakePictureLayerImpl*>(child);
220 FakePictureLayerImpl* recycled_impl = static_cast<FakePictureLayerImpl*>(
221 picture_impl->GetRecycledTwinLayer());
222
223 switch (++frame_) {
224 case 1: {
225 PictureLayerTiling* tiling = picture_impl->HighResTiling();
226 PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling();
227 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
228
229 // There should be tiles at the top of the picture layer but not at the
230 // bottom.
231 EXPECT_TRUE(tiling->TileAt(0, 0));
232 EXPECT_FALSE(tiling->TileAt(0, num_tiles_y));
233
234 // The recycled tiling matches it.
235 EXPECT_TRUE(recycled_tiling->TileAt(0, 0));
236 EXPECT_FALSE(recycled_tiling->TileAt(0, num_tiles_y));
237
238 // The live tiles rect matches on the recycled tree.
239 EXPECT_EQ(tiling->live_tiles_rect(),
240 recycled_tiling->live_tiles_rect());
241
242 // Make the bottom of the layer visible.
243 picture_impl->SetPosition(gfx::PointF(0.f, -100000.f + 100.f));
244 impl->SetNeedsRedraw();
245 break;
246 }
247 case 2: {
248 PictureLayerTiling* tiling = picture_impl->HighResTiling();
249 PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling();
250
251 // There not be tiles at the top of the layer now.
252 EXPECT_FALSE(tiling->TileAt(0, 0));
253
254 // The recycled twin tiling should not have unshared tiles at the top
255 // either.
256 EXPECT_FALSE(recycled_tiling->TileAt(0, 0));
257
258 // The live tiles rect matches on the recycled tree.
259 EXPECT_EQ(tiling->live_tiles_rect(),
260 recycled_tiling->live_tiles_rect());
261
262 // Make the top of the layer visible again.
263 picture_impl->SetPosition(gfx::PointF());
264 impl->SetNeedsRedraw();
265 break;
266 }
267 case 3: {
268 PictureLayerTiling* tiling = picture_impl->HighResTiling();
269 PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling();
270 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
271
272 // There should be tiles at the top of the picture layer again.
273 EXPECT_TRUE(tiling->TileAt(0, 0));
274 EXPECT_FALSE(tiling->TileAt(0, num_tiles_y));
275
276 // The recycled tiling should also have tiles at the top.
277 EXPECT_TRUE(recycled_tiling->TileAt(0, 0));
278 EXPECT_FALSE(recycled_tiling->TileAt(0, num_tiles_y));
279
280 // The live tiles rect matches on the recycled tree.
281 EXPECT_EQ(tiling->live_tiles_rect(),
282 recycled_tiling->live_tiles_rect());
283
284 // Make a new main frame without changing the picture layer at all, so
285 // it won't need to update or push properties.
286 did_post_commit_ = true;
287 PostSetNeedsCommitToMainThread();
288 break;
289 }
290 }
291 }
292
293 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
294 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
295 FakePictureLayerImpl* picture_impl =
296 static_cast<FakePictureLayerImpl*>(child);
297 PictureLayerTiling* tiling = picture_impl->HighResTiling();
298 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
299
300 // The pending layer should always have tiles at the top of it each commit.
301 // The tile is part of the required for activation set so it should exist.
302 EXPECT_TRUE(tiling->TileAt(0, 0));
303 EXPECT_FALSE(tiling->TileAt(0, num_tiles_y));
304
305 if (did_post_commit_)
306 EndTest();
307 }
308
309 void AfterTest() override {}
310
311 int frame_;
312 bool did_post_commit_;
313 FakeContentLayerClient client_;
314 scoped_refptr<FakePictureLayer> picture_;
315 };
316
317 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(
318 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree);
125 319
126 } // namespace 320 } // namespace
127 } // namespace cc 321 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_no_message_loop.cc ('k') | cc/trees/single_thread_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698