| 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 | 451 |
| 452 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 452 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 453 LayerImpl* gchild = impl->sync_tree()->LayerById(picture_->id()); | 453 LayerImpl* gchild = impl->sync_tree()->LayerById(picture_->id()); |
| 454 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); | 454 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); |
| 455 ready_to_draw_ = false; | 455 ready_to_draw_ = false; |
| 456 | 456 |
| 457 switch (frame_) { | 457 switch (frame_) { |
| 458 case 0: | 458 case 0: |
| 459 // On 1st commit the pending layer has tilings. | 459 // On 1st commit the pending layer has tilings. |
| 460 ASSERT_EQ(1u, picture->tilings()->num_tilings()); | 460 ASSERT_EQ(1u, picture->tilings()->num_tilings()); |
| 461 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale_key()); | 461 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); |
| 462 break; | 462 break; |
| 463 case 1: | 463 case 1: |
| 464 // On 2nd commit, the pending layer is transparent, so has a stale | 464 // On 2nd commit, the pending layer is transparent, so has a stale |
| 465 // value. | 465 // value. |
| 466 ASSERT_EQ(1u, picture->tilings()->num_tilings()); | 466 ASSERT_EQ(1u, picture->tilings()->num_tilings()); |
| 467 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale_key()); | 467 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); |
| 468 break; | 468 break; |
| 469 case 2: | 469 case 2: |
| 470 // On 3rd commit, the pending layer is visible again, so has tilings and | 470 // On 3rd commit, the pending layer is visible again, so has tilings and |
| 471 // is updated for the pinch. | 471 // is updated for the pinch. |
| 472 ASSERT_EQ(1u, picture->tilings()->num_tilings()); | 472 ASSERT_EQ(1u, picture->tilings()->num_tilings()); |
| 473 EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale_key()); | 473 EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale()); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { | 477 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 478 LayerImpl* gchild = impl->active_tree()->LayerById(picture_->id()); | 478 LayerImpl* gchild = impl->active_tree()->LayerById(picture_->id()); |
| 479 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); | 479 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); |
| 480 | 480 |
| 481 if (frame_ != last_frame_drawn_) | 481 if (frame_ != last_frame_drawn_) |
| 482 draws_in_frame_ = 0; | 482 draws_in_frame_ = 0; |
| 483 ++draws_in_frame_; | 483 ++draws_in_frame_; |
| 484 last_frame_drawn_ = frame_; | 484 last_frame_drawn_ = frame_; |
| 485 | 485 |
| 486 switch (frame_) { | 486 switch (frame_) { |
| 487 case 0: | 487 case 0: |
| 488 if (draws_in_frame_ == 1) { | 488 if (draws_in_frame_ == 1) { |
| 489 // On 1st commit the layer has tilings. | 489 // On 1st commit the layer has tilings. |
| 490 EXPECT_GT(picture->tilings()->num_tilings(), 0u); | 490 EXPECT_GT(picture->tilings()->num_tilings(), 0u); |
| 491 EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale_key()); | 491 EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale()); |
| 492 | 492 |
| 493 // Pinch zoom in to change the scale on the active tree. | 493 // Pinch zoom in to change the scale on the active tree. |
| 494 impl->PinchGestureBegin(); | 494 impl->PinchGestureBegin(); |
| 495 impl->PinchGestureUpdate(2.f, gfx::Point(1, 1)); | 495 impl->PinchGestureUpdate(2.f, gfx::Point(1, 1)); |
| 496 impl->PinchGestureEnd(); | 496 impl->PinchGestureEnd(); |
| 497 } else if (picture->tilings()->num_tilings() == 1) { | 497 } else if (picture->tilings()->num_tilings() == 1) { |
| 498 // If the pinch gesture caused a commit we could get here with a | 498 // If the pinch gesture caused a commit we could get here with a |
| 499 // pending tree. | 499 // pending tree. |
| 500 EXPECT_FALSE(impl->pending_tree()); | 500 EXPECT_FALSE(impl->pending_tree()); |
| 501 EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale_key()); | 501 EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale()); |
| 502 | 502 |
| 503 // Need to wait for ready to draw here so that the pinch is | 503 // Need to wait for ready to draw here so that the pinch is |
| 504 // entirely complete, otherwise another draw might come in before | 504 // entirely complete, otherwise another draw might come in before |
| 505 // the commit occurs. | 505 // the commit occurs. |
| 506 if (ready_to_draw_) { | 506 if (ready_to_draw_) { |
| 507 ++frame_; | 507 ++frame_; |
| 508 MainThreadTaskRunner()->PostTask( | 508 MainThreadTaskRunner()->PostTask( |
| 509 FROM_HERE, | 509 FROM_HERE, |
| 510 base::Bind( | 510 base::Bind( |
| 511 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep, | 511 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 FakePictureLayerImpl* will_change_layer = | 609 FakePictureLayerImpl* will_change_layer = |
| 610 static_cast<FakePictureLayerImpl*>( | 610 static_cast<FakePictureLayerImpl*>( |
| 611 impl->active_tree()->LayerById(will_change_layer_->id())); | 611 impl->active_tree()->LayerById(will_change_layer_->id())); |
| 612 FakePictureLayerImpl* normal_layer = static_cast<FakePictureLayerImpl*>( | 612 FakePictureLayerImpl* normal_layer = static_cast<FakePictureLayerImpl*>( |
| 613 impl->active_tree()->LayerById(normal_layer_->id())); | 613 impl->active_tree()->LayerById(normal_layer_->id())); |
| 614 | 614 |
| 615 switch (impl->sync_tree()->source_frame_number()) { | 615 switch (impl->sync_tree()->source_frame_number()) { |
| 616 case 0: | 616 case 0: |
| 617 // On first commit, both layers are at the default scale. | 617 // On first commit, both layers are at the default scale. |
| 618 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); | 618 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); |
| 619 EXPECT_EQ( | 619 EXPECT_EQ(1.f, |
| 620 1.f, | 620 will_change_layer->tilings()->tiling_at(0)->contents_scale()); |
| 621 will_change_layer->tilings()->tiling_at(0)->contents_scale_key()); | |
| 622 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); | 621 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); |
| 623 EXPECT_EQ(1.f, | 622 EXPECT_EQ(1.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); |
| 624 normal_layer->tilings()->tiling_at(0)->contents_scale_key()); | |
| 625 | 623 |
| 626 MainThreadTaskRunner()->PostTask( | 624 MainThreadTaskRunner()->PostTask( |
| 627 FROM_HERE, | 625 FROM_HERE, |
| 628 base::Bind( | 626 base::Bind( |
| 629 &LayerTreeHostPictureTestForceRecalculateScales::ScaleRootUp, | 627 &LayerTreeHostPictureTestForceRecalculateScales::ScaleRootUp, |
| 630 base::Unretained(this))); | 628 base::Unretained(this))); |
| 631 break; | 629 break; |
| 632 case 1: | 630 case 1: |
| 633 // On 2nd commit after scaling up to 2, the normal layer will adjust its | 631 // On 2nd commit after scaling up to 2, the normal layer will adjust its |
| 634 // scale and the will change layer should not (as it is will change. | 632 // scale and the will change layer should not (as it is will change. |
| 635 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); | 633 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); |
| 636 EXPECT_EQ( | 634 EXPECT_EQ(1.f, |
| 637 1.f, | 635 will_change_layer->tilings()->tiling_at(0)->contents_scale()); |
| 638 will_change_layer->tilings()->tiling_at(0)->contents_scale_key()); | |
| 639 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); | 636 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); |
| 640 EXPECT_EQ(2.f, | 637 EXPECT_EQ(2.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); |
| 641 normal_layer->tilings()->tiling_at(0)->contents_scale_key()); | |
| 642 | 638 |
| 643 MainThreadTaskRunner()->PostTask( | 639 MainThreadTaskRunner()->PostTask( |
| 644 FROM_HERE, | 640 FROM_HERE, |
| 645 base::Bind(&LayerTreeHostPictureTestForceRecalculateScales:: | 641 base::Bind(&LayerTreeHostPictureTestForceRecalculateScales:: |
| 646 ScaleRootUpAndRecalculateScales, | 642 ScaleRootUpAndRecalculateScales, |
| 647 base::Unretained(this))); | 643 base::Unretained(this))); |
| 648 break; | 644 break; |
| 649 case 2: | 645 case 2: |
| 650 // On 3rd commit, both layers should adjust scales due to forced | 646 // On 3rd commit, both layers should adjust scales due to forced |
| 651 // recalculating. | 647 // recalculating. |
| 652 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); | 648 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); |
| 653 EXPECT_EQ( | 649 EXPECT_EQ(4.f, |
| 654 4.f, | 650 will_change_layer->tilings()->tiling_at(0)->contents_scale()); |
| 655 will_change_layer->tilings()->tiling_at(0)->contents_scale_key()); | |
| 656 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); | 651 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); |
| 657 EXPECT_EQ(4.f, | 652 EXPECT_EQ(4.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); |
| 658 normal_layer->tilings()->tiling_at(0)->contents_scale_key()); | |
| 659 EndTest(); | 653 EndTest(); |
| 660 break; | 654 break; |
| 661 } | 655 } |
| 662 } | 656 } |
| 663 | 657 |
| 664 void ScaleRootUp() { | 658 void ScaleRootUp() { |
| 665 gfx::Transform transform; | 659 gfx::Transform transform; |
| 666 transform.Scale(2, 2); | 660 transform.Scale(2, 2); |
| 667 layer_tree_host()->GetLayerTree()->root_layer()->SetTransform(transform); | 661 layer_tree_host()->GetLayerTree()->root_layer()->SetTransform(transform); |
| 668 } | 662 } |
| 669 | 663 |
| 670 void ScaleRootUpAndRecalculateScales() { | 664 void ScaleRootUpAndRecalculateScales() { |
| 671 gfx::Transform transform; | 665 gfx::Transform transform; |
| 672 transform.Scale(4, 4); | 666 transform.Scale(4, 4); |
| 673 layer_tree_host()->GetLayerTree()->root_layer()->SetTransform(transform); | 667 layer_tree_host()->GetLayerTree()->root_layer()->SetTransform(transform); |
| 674 layer_tree_host()->SetNeedsRecalculateRasterScales(); | 668 layer_tree_host()->SetNeedsRecalculateRasterScales(); |
| 675 } | 669 } |
| 676 | 670 |
| 677 void AfterTest() override {} | 671 void AfterTest() override {} |
| 678 | 672 |
| 679 scoped_refptr<FakePictureLayer> will_change_layer_; | 673 scoped_refptr<FakePictureLayer> will_change_layer_; |
| 680 scoped_refptr<FakePictureLayer> normal_layer_; | 674 scoped_refptr<FakePictureLayer> normal_layer_; |
| 681 }; | 675 }; |
| 682 | 676 |
| 683 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostPictureTestForceRecalculateScales); | 677 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostPictureTestForceRecalculateScales); |
| 684 | 678 |
| 685 } // namespace | 679 } // namespace |
| 686 } // namespace cc | 680 } // namespace cc |
| OLD | NEW |