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