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

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

Issue 1801853002: Transfer LayerImpl ownership to LayerTreeImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more asan. Created 4 years, 9 months 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
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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 75 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
76 LayerImpl* pending_root_impl = impl->pending_tree()->root_layer(); 76 LayerImpl* pending_root_impl = impl->pending_tree()->root_layer();
77 LayerImpl* active_root_impl = impl->active_tree()->root_layer(); 77 LayerImpl* active_root_impl = impl->active_tree()->root_layer();
78 78
79 if (pending_root_impl->children().empty()) { 79 if (pending_root_impl->children().empty()) {
80 EXPECT_EQ(2, activates_); 80 EXPECT_EQ(2, activates_);
81 return; 81 return;
82 } 82 }
83 83
84 FakePictureLayerImpl* pending_picture_impl = 84 FakePictureLayerImpl* pending_picture_impl =
85 static_cast<FakePictureLayerImpl*>( 85 static_cast<FakePictureLayerImpl*>(pending_root_impl->children()[0]);
86 pending_root_impl->children()[0].get());
87 86
88 if (!active_root_impl) { 87 if (!active_root_impl) {
89 EXPECT_EQ(0, activates_); 88 EXPECT_EQ(0, activates_);
90 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer()); 89 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer());
91 return; 90 return;
92 } 91 }
93 92
94 if (active_root_impl->children().empty()) { 93 if (active_root_impl->children().empty()) {
95 EXPECT_EQ(3, activates_); 94 EXPECT_EQ(3, activates_);
96 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer()); 95 EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer());
97 return; 96 return;
98 } 97 }
99 98
100 FakePictureLayerImpl* active_picture_impl = 99 FakePictureLayerImpl* active_picture_impl =
101 static_cast<FakePictureLayerImpl*>( 100 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]);
102 active_root_impl->children()[0].get());
103 101
104 // After the first activation, when we commit again, we'll have a pending 102 // After the first activation, when we commit again, we'll have a pending
105 // and active layer. Then we recreate a picture layer in the 4th activate 103 // and active layer. Then we recreate a picture layer in the 4th activate
106 // and the next commit will have a pending and active twin again. 104 // and the next commit will have a pending and active twin again.
107 EXPECT_TRUE(activates_ == 1 || activates_ == 4) << activates_; 105 EXPECT_TRUE(activates_ == 1 || activates_ == 4) << activates_;
108 106
109 EXPECT_EQ(pending_picture_impl, 107 EXPECT_EQ(pending_picture_impl,
110 active_picture_impl->GetPendingOrActiveTwinLayer()); 108 active_picture_impl->GetPendingOrActiveTwinLayer());
111 EXPECT_EQ(active_picture_impl, 109 EXPECT_EQ(active_picture_impl,
112 pending_picture_impl->GetPendingOrActiveTwinLayer()); 110 pending_picture_impl->GetPendingOrActiveTwinLayer());
113 } 111 }
114 112
115 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 113 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
116 LayerImpl* active_root_impl = impl->active_tree()->root_layer(); 114 LayerImpl* active_root_impl = impl->active_tree()->root_layer();
117 if (active_root_impl->children().empty()) { 115 if (active_root_impl->children().empty()) {
118 EXPECT_EQ(2, activates_); 116 EXPECT_EQ(2, activates_);
119 } else { 117 } else {
120 FakePictureLayerImpl* active_picture_impl = 118 FakePictureLayerImpl* active_picture_impl =
121 static_cast<FakePictureLayerImpl*>( 119 static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]);
122 active_root_impl->children()[0].get());
123 EXPECT_EQ(nullptr, active_picture_impl->GetPendingOrActiveTwinLayer()); 120 EXPECT_EQ(nullptr, active_picture_impl->GetPendingOrActiveTwinLayer());
124 } 121 }
125 122
126 ++activates_; 123 ++activates_;
127 } 124 }
128 125
129 void AfterTest() override { EXPECT_EQ(5, activates_); } 126 void AfterTest() override { EXPECT_EQ(5, activates_); }
130 127
131 int activates_; 128 int activates_;
132 }; 129 };
(...skipping 16 matching lines...) Expand all
149 picture_->SetBounds(gfx::Size(768, 960)); 146 picture_->SetBounds(gfx::Size(768, 960));
150 root->AddChild(picture_); 147 root->AddChild(picture_);
151 148
152 layer_tree_host()->SetRootLayer(root); 149 layer_tree_host()->SetRootLayer(root);
153 LayerTreeHostPictureTest::SetupTree(); 150 LayerTreeHostPictureTest::SetupTree();
154 } 151 }
155 152
156 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 153 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
157 154
158 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 155 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
159 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0].get(); 156 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
160 FakePictureLayerImpl* picture_impl = 157 FakePictureLayerImpl* picture_impl =
161 static_cast<FakePictureLayerImpl*>(child); 158 static_cast<FakePictureLayerImpl*>(child);
162 gfx::Size tile_size = 159 gfx::Size tile_size =
163 picture_impl->HighResTiling()->TileAt(0, 0)->content_rect().size(); 160 picture_impl->HighResTiling()->TileAt(0, 0)->content_rect().size();
164 161
165 switch (impl->sync_tree()->source_frame_number()) { 162 switch (impl->sync_tree()->source_frame_number()) {
166 case 0: 163 case 0:
167 tile_size_ = tile_size; 164 tile_size_ = tile_size;
168 // GPU Raster picks a tile size based on the viewport size. 165 // GPU Raster picks a tile size based on the viewport size.
169 EXPECT_EQ(gfx::Size(768, 256), tile_size); 166 EXPECT_EQ(gfx::Size(768, 256), tile_size);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 picture_->SetScrollClipLayerId(root->id()); 215 picture_->SetScrollClipLayerId(root->id());
219 216
220 layer_tree_host()->SetRootLayer(root); 217 layer_tree_host()->SetRootLayer(root);
221 LayerTreeHostPictureTest::SetupTree(); 218 LayerTreeHostPictureTest::SetupTree();
222 client_.set_bounds(picture_->bounds()); 219 client_.set_bounds(picture_->bounds());
223 } 220 }
224 221
225 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 222 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
226 223
227 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 224 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
228 LayerImpl* child = impl->active_tree()->root_layer()->children()[0].get(); 225 LayerImpl* child = impl->active_tree()->root_layer()->children()[0];
229 FakePictureLayerImpl* picture_impl = 226 FakePictureLayerImpl* picture_impl =
230 static_cast<FakePictureLayerImpl*>(child); 227 static_cast<FakePictureLayerImpl*>(child);
231 switch (++frame_) { 228 switch (++frame_) {
232 case 1: { 229 case 1: {
233 PictureLayerTiling* tiling = picture_impl->HighResTiling(); 230 PictureLayerTiling* tiling = picture_impl->HighResTiling();
234 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y(); 231 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
235 232
236 // There should be tiles at the top of the picture layer but not at the 233 // There should be tiles at the top of the picture layer but not at the
237 // bottom. 234 // bottom.
238 EXPECT_TRUE(tiling->TileAt(0, 0)); 235 EXPECT_TRUE(tiling->TileAt(0, 0));
(...skipping 28 matching lines...) Expand all
267 // Make a new main frame without changing the picture layer at all, so 264 // Make a new main frame without changing the picture layer at all, so
268 // it won't need to update or push properties. 265 // it won't need to update or push properties.
269 did_post_commit_ = true; 266 did_post_commit_ = true;
270 PostSetNeedsCommitToMainThread(); 267 PostSetNeedsCommitToMainThread();
271 break; 268 break;
272 } 269 }
273 } 270 }
274 } 271 }
275 272
276 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 273 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
277 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0].get(); 274 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
278 FakePictureLayerImpl* picture_impl = 275 FakePictureLayerImpl* picture_impl =
279 static_cast<FakePictureLayerImpl*>(child); 276 static_cast<FakePictureLayerImpl*>(child);
280 PictureLayerTiling* tiling = picture_impl->HighResTiling(); 277 PictureLayerTiling* tiling = picture_impl->HighResTiling();
281 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y(); 278 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
282 279
283 if (!impl->active_tree()->root_layer()) { 280 if (!impl->active_tree()->root_layer()) {
284 // If active tree doesn't have the layer, then pending tree should have 281 // If active tree doesn't have the layer, then pending tree should have
285 // all needed tiles. 282 // all needed tiles.
286 EXPECT_TRUE(tiling->TileAt(0, 0)); 283 EXPECT_TRUE(tiling->TileAt(0, 0));
287 } else { 284 } else {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 child_->AddChild(picture_); 319 child_->AddChild(picture_);
323 320
324 layer_tree_host()->SetRootLayer(root); 321 layer_tree_host()->SetRootLayer(root);
325 LayerTreeHostPictureTest::SetupTree(); 322 LayerTreeHostPictureTest::SetupTree();
326 } 323 }
327 324
328 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 325 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
329 326
330 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 327 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
331 LayerImpl* root = impl->sync_tree()->root_layer(); 328 LayerImpl* root = impl->sync_tree()->root_layer();
332 LayerImpl* child = root->children()[0].get(); 329 LayerImpl* child = root->children()[0];
333 LayerImpl* gchild = child->children()[0].get(); 330 LayerImpl* gchild = child->children()[0];
334 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); 331 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
335 332
336 switch (impl->sync_tree()->source_frame_number()) { 333 switch (impl->sync_tree()->source_frame_number()) {
337 case 0: 334 case 0:
338 // On 1st commit the layer has tilings. 335 // On 1st commit the layer has tilings.
339 EXPECT_GT(picture->tilings()->num_tilings(), 0u); 336 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
340 break; 337 break;
341 case 1: 338 case 1:
342 // On 2nd commit, the layer is transparent, but its tilings are left 339 // On 2nd commit, the layer is transparent, but its tilings are left
343 // there. 340 // there.
344 EXPECT_GT(picture->tilings()->num_tilings(), 0u); 341 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
345 break; 342 break;
346 case 2: 343 case 2:
347 // On 3rd commit, the layer is visible again, so has tilings. 344 // On 3rd commit, the layer is visible again, so has tilings.
348 EXPECT_GT(picture->tilings()->num_tilings(), 0u); 345 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
349 } 346 }
350 } 347 }
351 348
352 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 349 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
353 LayerImpl* root = impl->active_tree()->root_layer(); 350 LayerImpl* root = impl->active_tree()->root_layer();
354 LayerImpl* child = root->children()[0].get(); 351 LayerImpl* child = root->children()[0];
355 LayerImpl* gchild = child->children()[0].get(); 352 LayerImpl* gchild = child->children()[0];
356 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); 353 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
357 354
358 switch (impl->active_tree()->source_frame_number()) { 355 switch (impl->active_tree()->source_frame_number()) {
359 case 0: 356 case 0:
360 // On 1st commit the layer has tilings. 357 // On 1st commit the layer has tilings.
361 EXPECT_GT(picture->tilings()->num_tilings(), 0u); 358 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
362 break; 359 break;
363 case 1: 360 case 1:
364 // On 2nd commit, the layer is transparent, but its tilings are left 361 // On 2nd commit, the layer is transparent, but its tilings are left
365 // there. 362 // there.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 void BeginTest() override { 428 void BeginTest() override {
432 frame_ = 0; 429 frame_ = 0;
433 draws_in_frame_ = 0; 430 draws_in_frame_ = 0;
434 last_frame_drawn_ = -1; 431 last_frame_drawn_ = -1;
435 ready_to_draw_ = false; 432 ready_to_draw_ = false;
436 PostSetNeedsCommitToMainThread(); 433 PostSetNeedsCommitToMainThread();
437 } 434 }
438 435
439 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 436 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
440 LayerImpl* root = impl->sync_tree()->root_layer(); 437 LayerImpl* root = impl->sync_tree()->root_layer();
441 LayerImpl* pinch = root->children()[0]->children()[0].get(); 438 LayerImpl* pinch = root->children()[0]->children()[0];
442 LayerImpl* gchild = pinch->children()[0].get(); 439 LayerImpl* gchild = pinch->children()[0];
443 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); 440 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
444 ready_to_draw_ = false; 441 ready_to_draw_ = false;
445 442
446 switch (frame_) { 443 switch (frame_) {
447 case 0: 444 case 0:
448 // On 1st commit the pending layer has tilings. 445 // On 1st commit the pending layer has tilings.
449 ASSERT_EQ(1u, picture->tilings()->num_tilings()); 446 ASSERT_EQ(1u, picture->tilings()->num_tilings());
450 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); 447 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale());
451 break; 448 break;
452 case 1: 449 case 1:
453 // On 2nd commit, the pending layer is transparent, so has a stale 450 // On 2nd commit, the pending layer is transparent, so has a stale
454 // value. 451 // value.
455 ASSERT_EQ(1u, picture->tilings()->num_tilings()); 452 ASSERT_EQ(1u, picture->tilings()->num_tilings());
456 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); 453 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale());
457 break; 454 break;
458 case 2: 455 case 2:
459 // On 3rd commit, the pending layer is visible again, so has tilings and 456 // On 3rd commit, the pending layer is visible again, so has tilings and
460 // is updated for the pinch. 457 // is updated for the pinch.
461 ASSERT_EQ(1u, picture->tilings()->num_tilings()); 458 ASSERT_EQ(1u, picture->tilings()->num_tilings());
462 EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale()); 459 EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale());
463 } 460 }
464 } 461 }
465 462
466 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 463 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
467 LayerImpl* root = impl->active_tree()->root_layer(); 464 LayerImpl* root = impl->active_tree()->root_layer();
468 LayerImpl* pinch = root->children()[0]->children()[0].get(); 465 LayerImpl* pinch = root->children()[0]->children()[0];
469 LayerImpl* gchild = pinch->children()[0].get(); 466 LayerImpl* gchild = pinch->children()[0];
470 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); 467 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
471 468
472 if (frame_ != last_frame_drawn_) 469 if (frame_ != last_frame_drawn_)
473 draws_in_frame_ = 0; 470 draws_in_frame_ = 0;
474 ++draws_in_frame_; 471 ++draws_in_frame_;
475 last_frame_drawn_ = frame_; 472 last_frame_drawn_ = frame_;
476 473
477 switch (frame_) { 474 switch (frame_) {
478 case 0: 475 case 0:
479 if (draws_in_frame_ == 1) { 476 if (draws_in_frame_ == 1) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 int last_frame_drawn_; 559 int last_frame_drawn_;
563 bool ready_to_draw_; 560 bool ready_to_draw_;
564 }; 561 };
565 562
566 // Multi-thread only because in single thread you can't pinch zoom on the 563 // Multi-thread only because in single thread you can't pinch zoom on the
567 // compositor thread. 564 // compositor thread.
568 MULTI_THREAD_TEST_F(LayerTreeHostPictureTestRSLLMembershipWithScale); 565 MULTI_THREAD_TEST_F(LayerTreeHostPictureTestRSLLMembershipWithScale);
569 566
570 } // namespace 567 } // namespace
571 } // namespace cc 568 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_occlusion.cc ('k') | cc/trees/layer_tree_host_unittest_scroll.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698