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