OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 tiling->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200)); | 584 tiling->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200)); |
585 | 585 |
586 // x and y moved by -75 (-50 - 75 = -125). | 586 // x and y moved by -75 (-50 - 75 = -125). |
587 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75]. | 587 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75]. |
588 EXPECT_EQ(-125, expand_skewport.x()); | 588 EXPECT_EQ(-125, expand_skewport.x()); |
589 EXPECT_EQ(-125, expand_skewport.y()); | 589 EXPECT_EQ(-125, expand_skewport.y()); |
590 EXPECT_EQ(350, expand_skewport.width()); | 590 EXPECT_EQ(350, expand_skewport.width()); |
591 EXPECT_EQ(350, expand_skewport.height()); | 591 EXPECT_EQ(350, expand_skewport.height()); |
592 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200))); | 592 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200))); |
593 | 593 |
594 // Expand the viewport past the limit. | 594 // Expand the viewport past the limit in all directions. |
595 gfx::Rect big_expand_skewport = | 595 gfx::Rect big_expand_skewport = |
596 tiling->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500)); | 596 tiling->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500)); |
597 | 597 |
598 EXPECT_EQ(-575, big_expand_skewport.x()); | 598 EXPECT_EQ(-575, big_expand_skewport.x()); |
599 EXPECT_EQ(-575, big_expand_skewport.y()); | 599 EXPECT_EQ(-575, big_expand_skewport.y()); |
600 EXPECT_EQ(1650, big_expand_skewport.width()); | 600 EXPECT_EQ(1650, big_expand_skewport.width()); |
601 EXPECT_EQ(1650, big_expand_skewport.height()); | 601 EXPECT_EQ(1650, big_expand_skewport.height()); |
602 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500))); | 602 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500))); |
| 603 |
| 604 // Shrink the skewport in all directions. |
| 605 gfx::Rect shrink_viewport = |
| 606 tiling->ComputeSkewport(1.5, gfx::Rect(0, 0, 100, 100)); |
| 607 EXPECT_EQ(0, shrink_viewport.x()); |
| 608 EXPECT_EQ(0, shrink_viewport.y()); |
| 609 EXPECT_EQ(100, shrink_viewport.width()); |
| 610 EXPECT_EQ(100, shrink_viewport.height()); |
| 611 |
| 612 // Move the skewport really far in one direction. |
| 613 gfx::Rect move_skewport_far = |
| 614 tiling->ComputeSkewport(1.5, gfx::Rect(0, 5000, 100, 100)); |
| 615 EXPECT_EQ(0, move_skewport_far.x()); |
| 616 EXPECT_EQ(5000, move_skewport_far.y()); |
| 617 EXPECT_EQ(100, move_skewport_far.width()); |
| 618 EXPECT_EQ(175, move_skewport_far.height()); |
| 619 EXPECT_TRUE(move_skewport_far.Contains(gfx::Rect(0, 5000, 100, 100))); |
603 } | 620 } |
604 | 621 |
605 TEST(PictureLayerTilingTest, ComputeSkewport) { | 622 TEST(PictureLayerTilingTest, ComputeSkewport) { |
606 FakePictureLayerTilingClient client; | 623 FakePictureLayerTilingClient client; |
607 | 624 |
608 gfx::Rect viewport(0, 0, 100, 100); | 625 gfx::Rect viewport(0, 0, 100, 100); |
609 gfx::Size layer_bounds(200, 200); | 626 gfx::Size layer_bounds(200, 200); |
610 | 627 |
611 client.SetTileSize(gfx::Size(100, 100)); | 628 client.SetTileSize(gfx::Size(100, 100)); |
612 client.set_tree(ACTIVE_TREE); | 629 client.set_tree(ACTIVE_TREE); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // Expand viewport in 0.2 seconds. | 675 // Expand viewport in 0.2 seconds. |
659 gfx::Rect expanded_skewport = | 676 gfx::Rect expanded_skewport = |
660 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); | 677 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); |
661 | 678 |
662 EXPECT_EQ(-30, expanded_skewport.x()); | 679 EXPECT_EQ(-30, expanded_skewport.x()); |
663 EXPECT_EQ(-30, expanded_skewport.y()); | 680 EXPECT_EQ(-30, expanded_skewport.y()); |
664 EXPECT_EQ(160, expanded_skewport.width()); | 681 EXPECT_EQ(160, expanded_skewport.width()); |
665 EXPECT_EQ(160, expanded_skewport.height()); | 682 EXPECT_EQ(160, expanded_skewport.height()); |
666 } | 683 } |
667 | 684 |
| 685 TEST(PictureLayerTilingTest, SkewportThroughUpdateTilePriorities) { |
| 686 FakePictureLayerTilingClient client; |
| 687 |
| 688 gfx::Rect viewport(0, 0, 100, 100); |
| 689 gfx::Size layer_bounds(200, 200); |
| 690 |
| 691 client.SetTileSize(gfx::Size(100, 100)); |
| 692 client.set_tree(ACTIVE_TREE); |
| 693 |
| 694 scoped_refptr<FakePicturePileImpl> pile = |
| 695 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 696 scoped_ptr<TestablePictureLayerTiling> tiling = |
| 697 TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 698 LayerTreeSettings()); |
| 699 |
| 700 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); |
| 701 |
| 702 // Move viewport down 50 pixels in 0.5 seconds. |
| 703 gfx::Rect viewport_50 = gfx::Rect(0, 50, 100, 100); |
| 704 gfx::Rect skewport_50 = tiling->ComputeSkewport(1.5, viewport_50); |
| 705 |
| 706 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50); |
| 707 tiling->ComputeTilePriorityRects(viewport_50, 1.f, 1.5, Occlusion()); |
| 708 |
| 709 gfx::Rect viewport_100 = gfx::Rect(0, 100, 100, 100); |
| 710 gfx::Rect skewport_100 = tiling->ComputeSkewport(2.0, viewport_100); |
| 711 |
| 712 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100); |
| 713 tiling->ComputeTilePriorityRects(viewport_100, 1.f, 2.0, Occlusion()); |
| 714 |
| 715 // Advance time, but not the viewport. |
| 716 gfx::Rect result = tiling->ComputeSkewport(2.5, viewport_100); |
| 717 // Since the history did advance, we should still get a skewport but a smaller |
| 718 // one. |
| 719 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result); |
| 720 tiling->ComputeTilePriorityRects(viewport_100, 1.f, 2.5, Occlusion()); |
| 721 |
| 722 // Advance time again. |
| 723 result = tiling->ComputeSkewport(3.0, viewport_100); |
| 724 EXPECT_EQ(viewport_100, result); |
| 725 tiling->ComputeTilePriorityRects(viewport_100, 1.f, 3.0, Occlusion()); |
| 726 |
| 727 // Ensure we have a skewport. |
| 728 gfx::Rect viewport_150 = gfx::Rect(0, 150, 100, 100); |
| 729 gfx::Rect skewport_150 = tiling->ComputeSkewport(3.5, viewport_150); |
| 730 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150); |
| 731 tiling->ComputeTilePriorityRects(viewport_150, 1.f, 3.5, Occlusion()); |
| 732 |
| 733 // Advance the viewport, but not the time. |
| 734 gfx::Rect viewport_200 = gfx::Rect(0, 200, 100, 100); |
| 735 gfx::Rect skewport_200 = tiling->ComputeSkewport(3.5, viewport_200); |
| 736 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200); |
| 737 |
| 738 // Ensure that continued calls with the same value, produce the same skewport. |
| 739 tiling->ComputeTilePriorityRects(viewport_150, 1.f, 3.5, Occlusion()); |
| 740 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200); |
| 741 tiling->ComputeTilePriorityRects(viewport_150, 1.f, 3.5, Occlusion()); |
| 742 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200); |
| 743 |
| 744 tiling->ComputeTilePriorityRects(viewport_200, 1.f, 3.5, Occlusion()); |
| 745 |
| 746 // This should never happen, but advance the viewport yet again keeping the |
| 747 // time the same. |
| 748 gfx::Rect viewport_250 = gfx::Rect(0, 250, 100, 100); |
| 749 gfx::Rect skewport_250 = tiling->ComputeSkewport(3.5, viewport_250); |
| 750 EXPECT_EQ(viewport_250, skewport_250); |
| 751 tiling->ComputeTilePriorityRects(viewport_250, 1.f, 3.5, Occlusion()); |
| 752 } |
| 753 |
668 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { | 754 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { |
669 FakePictureLayerTilingClient client; | 755 FakePictureLayerTilingClient client; |
670 | 756 |
671 gfx::Rect viewport(0, 0, 100, 100); | 757 gfx::Rect viewport(0, 0, 100, 100); |
672 gfx::Size layer_bounds(1500, 1500); | 758 gfx::Size layer_bounds(1500, 1500); |
673 | 759 |
674 client.SetTileSize(gfx::Size(10, 10)); | 760 client.SetTileSize(gfx::Size(10, 10)); |
675 client.set_tree(ACTIVE_TREE); | 761 client.set_tree(ACTIVE_TREE); |
676 LayerTreeSettings settings; | 762 LayerTreeSettings settings; |
677 settings.max_tiles_for_interest_area = 10000; | 763 settings.max_tiles_for_interest_area = 10000; |
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 tiling_->SetRasterSourceAndResize(pile); | 1976 tiling_->SetRasterSourceAndResize(pile); |
1891 | 1977 |
1892 // Tile size in the tiling should be resized to 250x200. | 1978 // Tile size in the tiling should be resized to 250x200. |
1893 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 1979 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
1894 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 1980 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
1895 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 1981 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
1896 } | 1982 } |
1897 | 1983 |
1898 } // namespace | 1984 } // namespace |
1899 } // namespace cc | 1985 } // namespace cc |
OLD | NEW |