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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 int frame_; | 321 int frame_; |
322 bool did_post_commit_; | 322 bool did_post_commit_; |
323 FakeContentLayerClient client_; | 323 FakeContentLayerClient client_; |
324 scoped_refptr<FakePictureLayer> picture_; | 324 scoped_refptr<FakePictureLayer> picture_; |
325 }; | 325 }; |
326 | 326 |
327 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( | 327 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( |
328 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree); | 328 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree); |
329 | 329 |
| 330 class LayerTreeHostPictureTestRSLLMembership : public LayerTreeHostPictureTest { |
| 331 void SetupTree() override { |
| 332 scoped_refptr<Layer> root = Layer::Create(); |
| 333 root->SetBounds(gfx::Size(100, 100)); |
| 334 |
| 335 child_ = Layer::Create(); |
| 336 root->AddChild(child_); |
| 337 |
| 338 // Don't be solid color so the layer has tilings/tiles. |
| 339 client_.set_fill_with_nonsolid_color(true); |
| 340 picture_ = FakePictureLayer::Create(&client_); |
| 341 picture_->SetBounds(gfx::Size(100, 100)); |
| 342 child_->AddChild(picture_); |
| 343 |
| 344 layer_tree_host()->SetRootLayer(root); |
| 345 LayerTreeHostPictureTest::SetupTree(); |
| 346 } |
| 347 |
| 348 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 349 |
| 350 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 351 LayerImpl* root = impl->sync_tree()->root_layer(); |
| 352 LayerImpl* child = root->children()[0]; |
| 353 LayerImpl* gchild = child->children()[0]; |
| 354 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); |
| 355 |
| 356 switch (impl->sync_tree()->source_frame_number()) { |
| 357 case 0: |
| 358 // On 1st commit the layer has tilings. |
| 359 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 360 break; |
| 361 case 1: |
| 362 // On 2nd commit, the layer is transparent, but its tilings are left |
| 363 // there. |
| 364 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 365 break; |
| 366 case 2: |
| 367 // On 3rd commit, the layer is visible again, so has tilings. |
| 368 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 369 } |
| 370 } |
| 371 |
| 372 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 373 LayerImpl* root = impl->active_tree()->root_layer(); |
| 374 LayerImpl* child = root->children()[0]; |
| 375 LayerImpl* gchild = child->children()[0]; |
| 376 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); |
| 377 |
| 378 switch (impl->active_tree()->source_frame_number()) { |
| 379 case 0: |
| 380 // On 1st commit the layer has tilings. |
| 381 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 382 break; |
| 383 case 1: |
| 384 // On 2nd commit, the layer is transparent, but its tilings are left |
| 385 // there. |
| 386 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 387 break; |
| 388 case 2: |
| 389 // On 3rd commit, the layer is visible again, so has tilings. |
| 390 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 391 EndTest(); |
| 392 } |
| 393 } |
| 394 |
| 395 void DidCommit() override { |
| 396 switch (layer_tree_host()->source_frame_number()) { |
| 397 case 1: |
| 398 // For the 2nd commit, change opacity to 0 so that the layer will not be |
| 399 // part of the visible frame. |
| 400 child_->SetOpacity(0.f); |
| 401 break; |
| 402 case 2: |
| 403 // For the 3rd commit, change opacity to 1 so that the layer will again |
| 404 // be part of the visible frame. |
| 405 child_->SetOpacity(1.f); |
| 406 } |
| 407 } |
| 408 |
| 409 void AfterTest() override {} |
| 410 |
| 411 FakeContentLayerClient client_; |
| 412 scoped_refptr<Layer> child_; |
| 413 scoped_refptr<FakePictureLayer> picture_; |
| 414 }; |
| 415 |
| 416 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestRSLLMembership); |
| 417 |
| 418 class LayerTreeHostPictureTestRSLLMembershipWithScale |
| 419 : public LayerTreeHostPictureTest { |
| 420 void SetupTree() override { |
| 421 scoped_refptr<Layer> root = Layer::Create(); |
| 422 root->SetBounds(gfx::Size(100, 100)); |
| 423 |
| 424 pinch_ = Layer::Create(); |
| 425 pinch_->SetBounds(gfx::Size(500, 500)); |
| 426 pinch_->SetScrollClipLayerId(root->id()); |
| 427 pinch_->SetIsContainerForFixedPositionLayers(true); |
| 428 root->AddChild(pinch_); |
| 429 |
| 430 // Don't be solid color so the layer has tilings/tiles. |
| 431 client_.set_fill_with_nonsolid_color(true); |
| 432 picture_ = FakePictureLayer::Create(&client_); |
| 433 picture_->SetBounds(gfx::Size(100, 100)); |
| 434 pinch_->AddChild(picture_); |
| 435 |
| 436 layer_tree_host()->RegisterViewportLayers(NULL, root, pinch_, pinch_); |
| 437 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f); |
| 438 layer_tree_host()->SetRootLayer(root); |
| 439 LayerTreeHostPictureTest::SetupTree(); |
| 440 } |
| 441 |
| 442 void InitializeSettings(LayerTreeSettings* settings) override { |
| 443 settings->layer_transforms_should_scale_layer_contents = true; |
| 444 } |
| 445 |
| 446 void BeginTest() override { |
| 447 frame_ = 0; |
| 448 draws_in_frame_ = 0; |
| 449 last_frame_drawn_ = -1; |
| 450 PostSetNeedsCommitToMainThread(); |
| 451 } |
| 452 |
| 453 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 454 LayerImpl* root = impl->sync_tree()->root_layer(); |
| 455 LayerImpl* pinch = root->children()[0]; |
| 456 LayerImpl* gchild = pinch->children()[0]; |
| 457 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); |
| 458 |
| 459 switch (frame_) { |
| 460 case 0: |
| 461 // On 1st commit the layer has tilings. |
| 462 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 463 break; |
| 464 case 1: |
| 465 // On 2nd commit, the layer is transparent, so does not have tilings. |
| 466 EXPECT_EQ(0u, picture->tilings()->num_tilings()); |
| 467 break; |
| 468 case 2: |
| 469 // On 3rd commit, the layer is visible again, so has tilings. |
| 470 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 471 } |
| 472 } |
| 473 |
| 474 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 475 LayerImpl* root = impl->active_tree()->root_layer(); |
| 476 LayerImpl* pinch = root->children()[0]; |
| 477 LayerImpl* gchild = pinch->children()[0]; |
| 478 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); |
| 479 |
| 480 if (frame_ != last_frame_drawn_) |
| 481 draws_in_frame_ = 0; |
| 482 ++draws_in_frame_; |
| 483 last_frame_drawn_ = frame_; |
| 484 |
| 485 switch (frame_) { |
| 486 case 0: |
| 487 if (draws_in_frame_ == 1) { |
| 488 // On 1st commit the layer has tilings. |
| 489 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 490 EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale()); |
| 491 |
| 492 // Pinch zoom in to change the scale on the active tree. |
| 493 impl->PinchGestureBegin(); |
| 494 impl->PinchGestureUpdate(2.f, gfx::Point(1, 1)); |
| 495 impl->PinchGestureEnd(); |
| 496 } else if (picture->tilings()->num_tilings() == 1) { |
| 497 // If the pinch gesture caused a commit we could get here with a |
| 498 // pending tree. |
| 499 EXPECT_FALSE(impl->pending_tree()); |
| 500 // The active layer now has only a 2.f scale tiling, which means the |
| 501 // recycled layer's tiling is destroyed. |
| 502 EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale()); |
| 503 EXPECT_EQ(0u, picture->GetRecycledTwinLayer() |
| 504 ->picture_layer_tiling_set() |
| 505 ->num_tilings()); |
| 506 |
| 507 ++frame_; |
| 508 MainThreadTaskRunner()->PostTask( |
| 509 FROM_HERE, |
| 510 base::Bind( |
| 511 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep, |
| 512 base::Unretained(this))); |
| 513 } |
| 514 break; |
| 515 case 1: |
| 516 EXPECT_EQ(1, draws_in_frame_); |
| 517 // On 2nd commit, the layer is transparent, so does not create |
| 518 // tilings. Since the 1.f tiling was destroyed in the recycle tree, it |
| 519 // has no tilings left. This is propogated to the active tree. |
| 520 EXPECT_EQ(0u, picture->picture_layer_tiling_set()->num_tilings()); |
| 521 EXPECT_EQ(0u, picture->GetRecycledTwinLayer() |
| 522 ->picture_layer_tiling_set() |
| 523 ->num_tilings()); |
| 524 ++frame_; |
| 525 MainThreadTaskRunner()->PostTask( |
| 526 FROM_HERE, |
| 527 base::Bind( |
| 528 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep, |
| 529 base::Unretained(this))); |
| 530 break; |
| 531 case 2: |
| 532 EXPECT_EQ(1, draws_in_frame_); |
| 533 // On 3rd commit, the layer is visible again, so has tilings. |
| 534 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 535 EndTest(); |
| 536 } |
| 537 } |
| 538 |
| 539 void NextStep() { |
| 540 switch (frame_) { |
| 541 case 1: |
| 542 // For the 2nd commit, change opacity to 0 so that the layer will not be |
| 543 // part of the visible frame. |
| 544 pinch_->SetOpacity(0.f); |
| 545 break; |
| 546 case 2: |
| 547 // For the 3rd commit, change opacity to 1 so that the layer will again |
| 548 // be part of the visible frame. |
| 549 pinch_->SetOpacity(1.f); |
| 550 break; |
| 551 } |
| 552 } |
| 553 |
| 554 void AfterTest() override {} |
| 555 |
| 556 FakeContentLayerClient client_; |
| 557 scoped_refptr<Layer> pinch_; |
| 558 scoped_refptr<FakePictureLayer> picture_; |
| 559 int frame_; |
| 560 int draws_in_frame_; |
| 561 int last_frame_drawn_; |
| 562 }; |
| 563 |
| 564 // Multi-thread only because in single thread you can't pinch zoom on the |
| 565 // compositor thread. |
| 566 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestRSLLMembershipWithScale); |
| 567 |
330 } // namespace | 568 } // namespace |
331 } // namespace cc | 569 } // namespace cc |
OLD | NEW |