| 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 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
| 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
| 29 | 29 |
| 30 return ToEnclosingRect(viewport_in_layer_space); | 30 return ToEnclosingRect(viewport_in_layer_space); |
| 31 } | 31 } |
| 32 | 32 |
| 33 class TestablePictureLayerTiling : public PictureLayerTiling { | 33 class TestablePictureLayerTiling : public PictureLayerTiling { |
| 34 public: | 34 public: |
| 35 using PictureLayerTiling::SetLiveTilesRect; | 35 using PictureLayerTiling::SetLiveTilesRect; |
| 36 using PictureLayerTiling::TileAt; | 36 using PictureLayerTiling::TileAt; |
| 37 using PictureLayerTiling::TileBundleAt; |
| 37 | 38 |
| 38 static scoped_ptr<TestablePictureLayerTiling> Create( | 39 static scoped_ptr<TestablePictureLayerTiling> Create( |
| 39 float contents_scale, | 40 float contents_scale, |
| 40 gfx::Size layer_bounds, | 41 gfx::Size layer_bounds, |
| 41 PictureLayerTilingClient* client) { | 42 PictureLayerTilingClient* client) { |
| 42 return make_scoped_ptr(new TestablePictureLayerTiling( | 43 return make_scoped_ptr(new TestablePictureLayerTiling( |
| 43 contents_scale, | 44 contents_scale, |
| 44 layer_bounds, | 45 layer_bounds, |
| 45 client)); | 46 client)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 protected: | 49 protected: |
| 49 TestablePictureLayerTiling(float contents_scale, | 50 TestablePictureLayerTiling(float contents_scale, |
| 50 gfx::Size layer_bounds, | 51 gfx::Size layer_bounds, |
| 51 PictureLayerTilingClient* client) | 52 PictureLayerTilingClient* client) |
| 52 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 53 : PictureLayerTiling(contents_scale, layer_bounds, client) { } |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 class PictureLayerTilingIteratorTest : public testing::Test { | 56 class PictureLayerTilingIteratorTest : public testing::Test { |
| 56 public: | 57 public: |
| 57 PictureLayerTilingIteratorTest() {} | 58 PictureLayerTilingIteratorTest() {} |
| 58 virtual ~PictureLayerTilingIteratorTest() {} | 59 virtual ~PictureLayerTilingIteratorTest() {} |
| 59 | 60 |
| 60 void Initialize(gfx::Size tile_size, | 61 void Initialize(gfx::Size tile_size, |
| 61 float contents_scale, | 62 float contents_scale, |
| 62 gfx::Size layer_bounds) { | 63 gfx::Size layer_bounds) { |
| 63 client_.SetTileSize(tile_size); | 64 client_.SetTileSize(tile_size); |
| 65 client_.MarkActive(); |
| 64 tiling_ = TestablePictureLayerTiling::Create(contents_scale, | 66 tiling_ = TestablePictureLayerTiling::Create(contents_scale, |
| 65 layer_bounds, | 67 layer_bounds, |
| 66 &client_); | 68 &client_); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) { | 71 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) { |
| 72 tiling_->SetTreeForTesting(ACTIVE_TREE); |
| 70 tiling_->SetLiveTilesRect(live_tiles_rect); | 73 tiling_->SetLiveTilesRect(live_tiles_rect); |
| 71 | 74 |
| 72 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 75 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
| 73 for (std::vector<Tile*>::iterator iter = tiles.begin(); | 76 for (std::vector<Tile*>::iterator iter = tiles.begin(); |
| 74 iter != tiles.end(); | 77 iter != tiles.end(); |
| 75 ++iter) { | 78 ++iter) { |
| 76 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | 79 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 visible_layer_rect, | 768 visible_layer_rect, |
| 766 last_layer_bounds, | 769 last_layer_bounds, |
| 767 current_layer_bounds, | 770 current_layer_bounds, |
| 768 last_layer_contents_scale, | 771 last_layer_contents_scale, |
| 769 current_layer_contents_scale, | 772 current_layer_contents_scale, |
| 770 last_screen_transform, | 773 last_screen_transform, |
| 771 current_screen_transform, | 774 current_screen_transform, |
| 772 current_frame_time_in_seconds, | 775 current_frame_time_in_seconds, |
| 773 max_tiles_for_interest_area); | 776 max_tiles_for_interest_area); |
| 774 | 777 |
| 775 ASSERT_TRUE(tiling->TileAt(0, 0)); | 778 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); |
| 776 ASSERT_TRUE(tiling->TileAt(0, 1)); | 779 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); |
| 777 ASSERT_TRUE(tiling->TileAt(1, 0)); | 780 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); |
| 778 ASSERT_TRUE(tiling->TileAt(1, 1)); | 781 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); |
| 782 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 779 | 783 |
| 780 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 784 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 781 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | |
| 782 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | |
| 783 | |
| 784 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | |
| 785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | |
| 786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | |
| 787 | |
| 788 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | |
| 789 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | |
| 790 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | |
| 791 | |
| 792 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | |
| 793 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 795 } | 787 } |
| 796 | 788 |
| 797 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 789 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
| 798 // The TilePriority of offscreen tiles (without movement) should have nonzero | 790 // The TilePriority of offscreen tiles (without movement) should have nonzero |
| 799 // distance_to_visible and infinite time_to_visible. | 791 // distance_to_visible and infinite time_to_visible. |
| 800 | 792 |
| 801 FakePictureLayerTilingClient client; | 793 FakePictureLayerTilingClient client; |
| 802 scoped_ptr<TestablePictureLayerTiling> tiling; | 794 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 803 | 795 |
| 804 gfx::Size device_viewport(800, 600); | 796 gfx::Size device_viewport(800, 600); |
| 805 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. | 797 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. |
| 806 gfx::Size last_layer_bounds(200, 200); | 798 gfx::Size last_layer_bounds(400, 400); |
| 807 gfx::Size current_layer_bounds(200, 200); | 799 gfx::Size current_layer_bounds(400, 400); |
| 808 float last_layer_contents_scale = 1.f; | 800 float last_layer_contents_scale = 1.f; |
| 809 float current_layer_contents_scale = 1.f; | 801 float current_layer_contents_scale = 1.f; |
| 810 gfx::Transform last_screen_transform; | 802 gfx::Transform last_screen_transform; |
| 811 gfx::Transform current_screen_transform; | 803 gfx::Transform current_screen_transform; |
| 812 double current_frame_time_in_seconds = 1.0; | 804 double current_frame_time_in_seconds = 1.0; |
| 813 size_t max_tiles_for_interest_area = 10000; | 805 size_t max_tiles_for_interest_area = 10000; |
| 814 | 806 |
| 815 current_screen_transform.Translate(850, 0); | 807 current_screen_transform.Translate(850, 0); |
| 816 last_screen_transform = current_screen_transform; | 808 last_screen_transform = current_screen_transform; |
| 817 | 809 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 830 visible_layer_rect, | 822 visible_layer_rect, |
| 831 last_layer_bounds, | 823 last_layer_bounds, |
| 832 current_layer_bounds, | 824 current_layer_bounds, |
| 833 last_layer_contents_scale, | 825 last_layer_contents_scale, |
| 834 current_layer_contents_scale, | 826 current_layer_contents_scale, |
| 835 last_screen_transform, | 827 last_screen_transform, |
| 836 current_screen_transform, | 828 current_screen_transform, |
| 837 current_frame_time_in_seconds, | 829 current_frame_time_in_seconds, |
| 838 max_tiles_for_interest_area); | 830 max_tiles_for_interest_area); |
| 839 | 831 |
| 840 ASSERT_TRUE(tiling->TileAt(0, 0)); | 832 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); |
| 841 ASSERT_TRUE(tiling->TileAt(0, 1)); | 833 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); |
| 842 ASSERT_TRUE(tiling->TileAt(1, 0)); | 834 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); |
| 843 ASSERT_TRUE(tiling->TileAt(1, 1)); | 835 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); |
| 836 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 844 | 837 |
| 845 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 838 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 846 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 839 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 847 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 840 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 848 priority.time_to_visible_in_seconds); | 841 priority.time_to_visible_in_seconds); |
| 849 | 842 |
| 850 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 843 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 2, 2)); |
| 851 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 844 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 2, 3)); |
| 852 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 845 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 3, 2)); |
| 853 priority.time_to_visible_in_seconds); | 846 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 3, 3)); |
| 847 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 848 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 849 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 854 | 850 |
| 855 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 851 // Furthermore, in this scenario bundles on the right hand side should have a |
| 856 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | |
| 857 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | |
| 858 priority.time_to_visible_in_seconds); | |
| 859 | |
| 860 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | |
| 861 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | |
| 862 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | |
| 863 priority.time_to_visible_in_seconds); | |
| 864 | |
| 865 // Furthermore, in this scenario tiles on the right hand side should have a | |
| 866 // larger distance to visible. | 852 // larger distance to visible. |
| 867 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 853 TilePriority left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 868 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 854 TilePriority right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 869 EXPECT_GT(right.distance_to_visible_in_pixels, | 855 EXPECT_GT(right.distance_to_visible_in_pixels, |
| 870 left.distance_to_visible_in_pixels); | 856 left.distance_to_visible_in_pixels); |
| 871 | 857 |
| 872 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 858 left = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 873 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 859 right = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 874 EXPECT_GT(right.distance_to_visible_in_pixels, | 860 EXPECT_GT(right.distance_to_visible_in_pixels, |
| 875 left.distance_to_visible_in_pixels); | 861 left.distance_to_visible_in_pixels); |
| 876 } | 862 } |
| 877 | 863 |
| 878 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 864 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
| 879 // Sanity check that a layer with some tiles visible and others offscreen has | 865 // Sanity check that a layer with some tiles visible and others offscreen has |
| 880 // correct TilePriorities for each tile. | 866 // correct TilePriorities for each tile. |
| 881 | 867 |
| 882 FakePictureLayerTilingClient client; | 868 FakePictureLayerTilingClient client; |
| 883 scoped_ptr<TestablePictureLayerTiling> tiling; | 869 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 884 | 870 |
| 885 gfx::Size device_viewport(800, 600); | 871 gfx::Size device_viewport(800, 600); |
| 886 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. | 872 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. |
| 887 gfx::Size last_layer_bounds(200, 200); | 873 gfx::Size last_layer_bounds(400, 400); |
| 888 gfx::Size current_layer_bounds(200, 200); | 874 gfx::Size current_layer_bounds(400, 400); |
| 889 float last_layer_contents_scale = 1.f; | 875 float last_layer_contents_scale = 1.f; |
| 890 float current_layer_contents_scale = 1.f; | 876 float current_layer_contents_scale = 1.f; |
| 891 gfx::Transform last_screen_transform; | 877 gfx::Transform last_screen_transform; |
| 892 gfx::Transform current_screen_transform; | 878 gfx::Transform current_screen_transform; |
| 893 double current_frame_time_in_seconds = 1.0; | 879 double current_frame_time_in_seconds = 1.0; |
| 894 size_t max_tiles_for_interest_area = 10000; | 880 size_t max_tiles_for_interest_area = 10000; |
| 895 | 881 |
| 896 current_screen_transform.Translate(705, 505); | 882 current_screen_transform.Translate(705, 505); |
| 897 last_screen_transform = current_screen_transform; | 883 last_screen_transform = current_screen_transform; |
| 898 | 884 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 911 visible_layer_rect, | 897 visible_layer_rect, |
| 912 last_layer_bounds, | 898 last_layer_bounds, |
| 913 current_layer_bounds, | 899 current_layer_bounds, |
| 914 last_layer_contents_scale, | 900 last_layer_contents_scale, |
| 915 current_layer_contents_scale, | 901 current_layer_contents_scale, |
| 916 last_screen_transform, | 902 last_screen_transform, |
| 917 current_screen_transform, | 903 current_screen_transform, |
| 918 current_frame_time_in_seconds, | 904 current_frame_time_in_seconds, |
| 919 max_tiles_for_interest_area); | 905 max_tiles_for_interest_area); |
| 920 | 906 |
| 921 ASSERT_TRUE(tiling->TileAt(0, 0)); | 907 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); |
| 922 ASSERT_TRUE(tiling->TileAt(0, 1)); | 908 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); |
| 923 ASSERT_TRUE(tiling->TileAt(1, 0)); | 909 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); |
| 924 ASSERT_TRUE(tiling->TileAt(1, 1)); | 910 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); |
| 911 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 912 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 913 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 914 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 925 | 915 |
| 926 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 916 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 927 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 917 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 928 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 918 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 929 | 919 |
| 930 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 920 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 931 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 921 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 932 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 922 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 933 priority.time_to_visible_in_seconds); | 923 priority.time_to_visible_in_seconds); |
| 934 | 924 |
| 935 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 925 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 936 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 926 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 937 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 927 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 938 priority.time_to_visible_in_seconds); | 928 priority.time_to_visible_in_seconds); |
| 939 | 929 |
| 940 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 930 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 941 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 931 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 942 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 932 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 943 priority.time_to_visible_in_seconds); | 933 priority.time_to_visible_in_seconds); |
| 944 } | 934 } |
| 945 | 935 |
| 946 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 936 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
| 947 // Each tile of a layer may be affected differently by a transform; Check | 937 // Each tile of a layer may be affected differently by a transform; Check |
| 948 // that UpdateTilePriorities correctly accounts for the transform between | 938 // that UpdateTilePriorities correctly accounts for the transform between |
| 949 // layer space and screen space. | 939 // layer space and screen space. |
| 950 | 940 |
| 951 FakePictureLayerTilingClient client; | 941 FakePictureLayerTilingClient client; |
| 952 scoped_ptr<TestablePictureLayerTiling> tiling; | 942 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 953 | 943 |
| 954 gfx::Size device_viewport(800, 600); | 944 gfx::Size device_viewport(800, 600); |
| 955 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. | 945 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. |
| 956 gfx::Size last_layer_bounds(200, 200); | 946 gfx::Size last_layer_bounds(400, 400); |
| 957 gfx::Size current_layer_bounds(200, 200); | 947 gfx::Size current_layer_bounds(400, 400); |
| 958 float last_layer_contents_scale = 1.f; | 948 float last_layer_contents_scale = 1.f; |
| 959 float current_layer_contents_scale = 1.f; | 949 float current_layer_contents_scale = 1.f; |
| 960 gfx::Transform last_screen_transform; | 950 gfx::Transform last_screen_transform; |
| 961 gfx::Transform current_screen_transform; | 951 gfx::Transform current_screen_transform; |
| 962 double current_frame_time_in_seconds = 1.0; | 952 double current_frame_time_in_seconds = 1.0; |
| 963 size_t max_tiles_for_interest_area = 10000; | 953 size_t max_tiles_for_interest_area = 10000; |
| 964 | 954 |
| 965 // A diagonally rotated layer that is partially off the bottom of the screen. | 955 // A diagonally rotated layer that is partially off the bottom of the screen. |
| 966 // In this configuration, only the top-left tile would be visible. | 956 // In this configuration, only the top-left tile would be visible. |
| 967 current_screen_transform.Translate(400, 550); | 957 current_screen_transform.Translate(400, 550); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 983 visible_layer_rect, | 973 visible_layer_rect, |
| 984 last_layer_bounds, | 974 last_layer_bounds, |
| 985 current_layer_bounds, | 975 current_layer_bounds, |
| 986 last_layer_contents_scale, | 976 last_layer_contents_scale, |
| 987 current_layer_contents_scale, | 977 current_layer_contents_scale, |
| 988 last_screen_transform, | 978 last_screen_transform, |
| 989 current_screen_transform, | 979 current_screen_transform, |
| 990 current_frame_time_in_seconds, | 980 current_frame_time_in_seconds, |
| 991 max_tiles_for_interest_area); | 981 max_tiles_for_interest_area); |
| 992 | 982 |
| 993 ASSERT_TRUE(tiling->TileAt(0, 0)); | 983 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 994 ASSERT_TRUE(tiling->TileAt(0, 1)); | 984 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 995 ASSERT_TRUE(tiling->TileAt(1, 0)); | 985 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 996 ASSERT_TRUE(tiling->TileAt(1, 1)); | 986 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 997 | 987 |
| 998 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 988 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 999 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 989 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1000 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 990 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1001 | 991 |
| 1002 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 992 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1003 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 993 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1004 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 994 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1005 priority.time_to_visible_in_seconds); | 995 priority.time_to_visible_in_seconds); |
| 1006 | 996 |
| 1007 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 997 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1008 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 998 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1009 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 999 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1010 priority.time_to_visible_in_seconds); | 1000 priority.time_to_visible_in_seconds); |
| 1011 | 1001 |
| 1012 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1002 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1013 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1003 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1014 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1004 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1015 priority.time_to_visible_in_seconds); | 1005 priority.time_to_visible_in_seconds); |
| 1016 | 1006 |
| 1017 // Furthermore, in this scenario the bottom-right tile should have the larger | 1007 // Furthermore, in this scenario the bottom-right tile should have the larger |
| 1018 // distance to visible. | 1008 // distance to visible. |
| 1019 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1009 TilePriority top_left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1020 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1010 TilePriority top_right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1021 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1011 TilePriority bottom_left = |
| 1022 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1012 tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1013 TilePriority bottom_right = |
| 1014 tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1023 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1015 EXPECT_GT(top_right.distance_to_visible_in_pixels, |
| 1024 top_left.distance_to_visible_in_pixels); | 1016 top_left.distance_to_visible_in_pixels); |
| 1025 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1017 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, |
| 1026 top_left.distance_to_visible_in_pixels); | 1018 top_left.distance_to_visible_in_pixels); |
| 1027 | 1019 |
| 1028 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1020 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1029 bottom_left.distance_to_visible_in_pixels); | 1021 bottom_left.distance_to_visible_in_pixels); |
| 1030 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1022 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1031 top_right.distance_to_visible_in_pixels); | 1023 top_right.distance_to_visible_in_pixels); |
| 1032 } | 1024 } |
| 1033 | 1025 |
| 1034 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 1026 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
| 1035 // Perspective transforms need to take a different code path. | 1027 // Perspective transforms need to take a different code path. |
| 1036 // This test checks tile priorities of a perspective layer. | 1028 // This test checks tile priorities of a perspective layer. |
| 1037 | 1029 |
| 1038 FakePictureLayerTilingClient client; | 1030 FakePictureLayerTilingClient client; |
| 1039 scoped_ptr<TestablePictureLayerTiling> tiling; | 1031 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1040 | 1032 |
| 1041 gfx::Size device_viewport(800, 600); | 1033 gfx::Size device_viewport(800, 600); |
| 1042 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1034 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1043 gfx::Size last_layer_bounds(200, 200); | 1035 gfx::Size last_layer_bounds(400, 400); |
| 1044 gfx::Size current_layer_bounds(200, 200); | 1036 gfx::Size current_layer_bounds(400, 400); |
| 1045 float last_layer_contents_scale = 1.f; | 1037 float last_layer_contents_scale = 1.f; |
| 1046 float current_layer_contents_scale = 1.f; | 1038 float current_layer_contents_scale = 1.f; |
| 1047 gfx::Transform last_screen_transform; | 1039 gfx::Transform last_screen_transform; |
| 1048 gfx::Transform current_screen_transform; | 1040 gfx::Transform current_screen_transform; |
| 1049 double current_frame_time_in_seconds = 1.0; | 1041 double current_frame_time_in_seconds = 1.0; |
| 1050 size_t max_tiles_for_interest_area = 10000; | 1042 size_t max_tiles_for_interest_area = 10000; |
| 1051 | 1043 |
| 1052 // A 3d perspective layer rotated about its Y axis, translated to almost | 1044 // A 3d perspective layer rotated about its Y axis, translated to almost |
| 1053 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1045 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
| 1054 // the right side, so the top-left tile will technically be closer than the | 1046 // the right side, so the top-left tile will technically be closer than the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1085 visible_layer_rect, | 1077 visible_layer_rect, |
| 1086 last_layer_bounds, | 1078 last_layer_bounds, |
| 1087 current_layer_bounds, | 1079 current_layer_bounds, |
| 1088 last_layer_contents_scale, | 1080 last_layer_contents_scale, |
| 1089 current_layer_contents_scale, | 1081 current_layer_contents_scale, |
| 1090 last_screen_transform, | 1082 last_screen_transform, |
| 1091 current_screen_transform, | 1083 current_screen_transform, |
| 1092 current_frame_time_in_seconds, | 1084 current_frame_time_in_seconds, |
| 1093 max_tiles_for_interest_area); | 1085 max_tiles_for_interest_area); |
| 1094 | 1086 |
| 1095 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1087 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1096 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1088 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1097 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1089 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1098 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1090 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1099 | 1091 |
| 1100 // All tiles will have a positive distance_to_visible | 1092 // All tiles will have a positive distance_to_visible |
| 1101 // and an infinite time_to_visible. | 1093 // and an infinite time_to_visible. |
| 1102 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1094 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1103 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1095 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1104 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1096 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1105 priority.time_to_visible_in_seconds); | 1097 priority.time_to_visible_in_seconds); |
| 1106 | 1098 |
| 1107 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1099 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1108 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1100 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1109 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1101 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1110 priority.time_to_visible_in_seconds); | 1102 priority.time_to_visible_in_seconds); |
| 1111 | 1103 |
| 1112 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1104 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1113 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1105 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1114 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1106 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1115 priority.time_to_visible_in_seconds); | 1107 priority.time_to_visible_in_seconds); |
| 1116 | 1108 |
| 1117 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1109 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1118 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1110 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1119 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1111 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1120 priority.time_to_visible_in_seconds); | 1112 priority.time_to_visible_in_seconds); |
| 1121 | 1113 |
| 1122 // Furthermore, in this scenario the top-left distance_to_visible | 1114 // Furthermore, in this scenario the top-left distance_to_visible |
| 1123 // will be smallest, followed by top-right. The bottom layers | 1115 // will be smallest, followed by top-right. The bottom layers |
| 1124 // will of course be further than the top layers. | 1116 // will of course be further than the top layers. |
| 1125 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1117 TilePriority top_left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1126 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1118 TilePriority top_right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1127 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1119 TilePriority bottom_left = |
| 1128 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1120 tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1121 TilePriority bottom_right = |
| 1122 tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1129 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1123 EXPECT_GT(top_right.distance_to_visible_in_pixels, |
| 1130 top_left.distance_to_visible_in_pixels); | 1124 top_left.distance_to_visible_in_pixels); |
| 1131 | 1125 |
| 1132 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1126 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1133 top_right.distance_to_visible_in_pixels); | 1127 top_right.distance_to_visible_in_pixels); |
| 1134 | 1128 |
| 1135 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1129 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, |
| 1136 top_left.distance_to_visible_in_pixels); | 1130 top_left.distance_to_visible_in_pixels); |
| 1137 } | 1131 } |
| 1138 | 1132 |
| 1139 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1133 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
| 1140 // Perspective transforms need to take a different code path. | 1134 // Perspective transforms need to take a different code path. |
| 1141 // This test checks tile priorities of a perspective layer. | 1135 // This test checks tile priorities of a perspective layer. |
| 1142 | 1136 |
| 1143 FakePictureLayerTilingClient client; | 1137 FakePictureLayerTilingClient client; |
| 1144 scoped_ptr<TestablePictureLayerTiling> tiling; | 1138 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1145 | 1139 |
| 1146 gfx::Size device_viewport(800, 600); | 1140 gfx::Size device_viewport(800, 600); |
| 1147 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1141 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1148 gfx::Size last_layer_bounds(200, 200); | 1142 gfx::Size last_layer_bounds(400, 400); |
| 1149 gfx::Size current_layer_bounds(200, 200); | 1143 gfx::Size current_layer_bounds(400, 400); |
| 1150 float last_layer_contents_scale = 1.f; | 1144 float last_layer_contents_scale = 1.f; |
| 1151 float current_layer_contents_scale = 1.f; | 1145 float current_layer_contents_scale = 1.f; |
| 1152 gfx::Transform last_screen_transform; | 1146 gfx::Transform last_screen_transform; |
| 1153 gfx::Transform current_screen_transform; | 1147 gfx::Transform current_screen_transform; |
| 1154 double current_frame_time_in_seconds = 1.0; | 1148 double current_frame_time_in_seconds = 1.0; |
| 1155 size_t max_tiles_for_interest_area = 10000; | 1149 size_t max_tiles_for_interest_area = 10000; |
| 1156 | 1150 |
| 1157 // A 3d perspective layer rotated about its Y axis, translated to almost | 1151 // A 3d perspective layer rotated about its Y axis, translated to almost |
| 1158 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1152 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
| 1159 // the right side, so the top-left tile will technically be closer than the | 1153 // the right side, so the top-left tile will technically be closer than the |
| 1160 // top-right. | 1154 // top-right. |
| 1161 | 1155 |
| 1162 // Translate layer to offscreen | 1156 // Translate layer to offscreen |
| 1163 current_screen_transform.Translate(400.0, 970.0); | 1157 current_screen_transform.Translate(400.0, 970.0); |
| 1164 // Apply perspective and rotation about the center of the layer | 1158 // Apply perspective and rotation about the center of the layer |
| 1165 current_screen_transform.Translate(100.0, 100.0); | 1159 current_screen_transform.Translate(200.0, 200.0); |
| 1166 current_screen_transform.ApplyPerspectiveDepth(10.0); | 1160 current_screen_transform.ApplyPerspectiveDepth(10.0); |
| 1167 current_screen_transform.RotateAboutYAxis(10.0); | 1161 current_screen_transform.RotateAboutYAxis(10.0); |
| 1168 current_screen_transform.Translate(-100.0, -100.0); | 1162 current_screen_transform.Translate(-200.0, -200.0); |
| 1169 last_screen_transform = current_screen_transform; | 1163 last_screen_transform = current_screen_transform; |
| 1170 | 1164 |
| 1171 // Sanity check that this transform does cause w<0 clipping for the left side | 1165 // Sanity check that this transform does cause w<0 clipping for the left side |
| 1172 // of the layer, but not the right side. | 1166 // of the layer, but not the right side. |
| 1173 bool clipped; | 1167 bool clipped; |
| 1174 MathUtil::MapQuad(current_screen_transform, | 1168 MathUtil::MapQuad(current_screen_transform, |
| 1175 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), | 1169 gfx::QuadF(gfx::RectF(0, 0, 200, 400)), |
| 1176 &clipped); | 1170 &clipped); |
| 1177 ASSERT_TRUE(clipped); | 1171 ASSERT_TRUE(clipped); |
| 1178 | 1172 |
| 1179 MathUtil::MapQuad(current_screen_transform, | 1173 MathUtil::MapQuad(current_screen_transform, |
| 1180 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | 1174 gfx::QuadF(gfx::RectF(200, 0, 200, 400)), |
| 1181 &clipped); | 1175 &clipped); |
| 1182 ASSERT_FALSE(clipped); | 1176 ASSERT_FALSE(clipped); |
| 1183 | 1177 |
| 1184 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1178 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1185 current_screen_transform, device_viewport); | 1179 current_screen_transform, device_viewport); |
| 1186 | 1180 |
| 1187 client.SetTileSize(gfx::Size(100, 100)); | 1181 client.SetTileSize(gfx::Size(100, 100)); |
| 1188 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1182 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1189 current_layer_bounds, | 1183 current_layer_bounds, |
| 1190 &client); | 1184 &client); |
| 1191 | 1185 |
| 1192 tiling->UpdateTilePriorities( | 1186 tiling->UpdateTilePriorities( |
| 1193 ACTIVE_TREE, | 1187 ACTIVE_TREE, |
| 1194 device_viewport, | 1188 device_viewport, |
| 1195 viewport_in_layer_space, | 1189 viewport_in_layer_space, |
| 1196 visible_layer_rect, | 1190 visible_layer_rect, |
| 1197 last_layer_bounds, | 1191 last_layer_bounds, |
| 1198 current_layer_bounds, | 1192 current_layer_bounds, |
| 1199 last_layer_contents_scale, | 1193 last_layer_contents_scale, |
| 1200 current_layer_contents_scale, | 1194 current_layer_contents_scale, |
| 1201 last_screen_transform, | 1195 last_screen_transform, |
| 1202 current_screen_transform, | 1196 current_screen_transform, |
| 1203 current_frame_time_in_seconds, | 1197 current_frame_time_in_seconds, |
| 1204 max_tiles_for_interest_area); | 1198 max_tiles_for_interest_area); |
| 1205 | 1199 |
| 1206 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1200 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1207 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1201 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1208 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1202 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1209 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1203 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1210 | 1204 |
| 1211 // Left-side tiles will be clipped by the transform, so we have to assume | 1205 // Left-side tiles will be clipped by the transform, so we have to assume |
| 1212 // they are visible just in case. | 1206 // they are visible just in case. |
| 1213 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1207 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1214 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1208 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1215 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1209 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1216 | 1210 |
| 1217 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1211 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1212 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1213 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1220 | 1214 |
| 1221 // Right-side tiles will have a positive distance_to_visible | 1215 // Right-side tiles will have a positive distance_to_visible |
| 1222 // and an infinite time_to_visible. | 1216 // and an infinite time_to_visible. |
| 1223 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1217 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1224 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1218 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1225 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1219 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1226 priority.time_to_visible_in_seconds); | 1220 priority.time_to_visible_in_seconds); |
| 1227 | 1221 |
| 1228 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1222 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1229 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1223 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1230 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1224 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1231 priority.time_to_visible_in_seconds); | 1225 priority.time_to_visible_in_seconds); |
| 1232 } | 1226 } |
| 1233 | 1227 |
| 1234 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1228 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
| 1235 // Test that time_to_visible is computed correctly when | 1229 // Test that time_to_visible is computed correctly when |
| 1236 // there is some motion. | 1230 // there is some motion. |
| 1237 | 1231 |
| 1238 FakePictureLayerTilingClient client; | 1232 FakePictureLayerTilingClient client; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1250 double current_frame_time_in_seconds = 2.0; | 1244 double current_frame_time_in_seconds = 2.0; |
| 1251 size_t max_tiles_for_interest_area = 10000; | 1245 size_t max_tiles_for_interest_area = 10000; |
| 1252 | 1246 |
| 1253 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1247 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
| 1254 current_screen_transform.Translate(1800, 0); | 1248 current_screen_transform.Translate(1800, 0); |
| 1255 last_screen_transform.Translate(2800, 0); | 1249 last_screen_transform.Translate(2800, 0); |
| 1256 | 1250 |
| 1257 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1251 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1258 current_screen_transform, device_viewport); | 1252 current_screen_transform, device_viewport); |
| 1259 | 1253 |
| 1260 client.SetTileSize(gfx::Size(100, 100)); | 1254 client.SetTileSize(gfx::Size(50, 50)); |
| 1261 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1255 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1262 current_layer_bounds, | 1256 current_layer_bounds, |
| 1263 &client); | 1257 &client); |
| 1264 | 1258 |
| 1265 // previous ("last") frame | 1259 // previous ("last") frame |
| 1266 tiling->UpdateTilePriorities( | 1260 tiling->UpdateTilePriorities( |
| 1267 ACTIVE_TREE, | 1261 ACTIVE_TREE, |
| 1268 device_viewport, | 1262 device_viewport, |
| 1269 viewport_in_layer_space, | 1263 viewport_in_layer_space, |
| 1270 visible_layer_rect, | 1264 visible_layer_rect, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1285 visible_layer_rect, | 1279 visible_layer_rect, |
| 1286 last_layer_bounds, | 1280 last_layer_bounds, |
| 1287 current_layer_bounds, | 1281 current_layer_bounds, |
| 1288 last_layer_contents_scale, | 1282 last_layer_contents_scale, |
| 1289 current_layer_contents_scale, | 1283 current_layer_contents_scale, |
| 1290 last_screen_transform, | 1284 last_screen_transform, |
| 1291 current_screen_transform, | 1285 current_screen_transform, |
| 1292 current_frame_time_in_seconds, | 1286 current_frame_time_in_seconds, |
| 1293 max_tiles_for_interest_area); | 1287 max_tiles_for_interest_area); |
| 1294 | 1288 |
| 1295 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1289 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1296 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1290 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1297 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1291 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1298 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1292 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1299 | 1293 |
| 1300 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1294 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1301 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1295 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1302 EXPECT_FLOAT_EQ(1.f, | 1296 EXPECT_FLOAT_EQ(1.f, |
| 1303 priority.time_to_visible_in_seconds); | 1297 priority.time_to_visible_in_seconds); |
| 1304 | 1298 |
| 1305 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1299 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1306 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1300 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1307 EXPECT_FLOAT_EQ(1.f, | 1301 EXPECT_FLOAT_EQ(1.f, |
| 1308 priority.time_to_visible_in_seconds); | 1302 priority.time_to_visible_in_seconds); |
| 1309 | 1303 |
| 1310 // time_to_visible for the right hand side layers needs an extra 0.099 | 1304 // time_to_visible for the right hand side layers needs an extra 0.099 |
| 1311 // seconds because this tile is 99 pixels further away. | 1305 // seconds because this tile is 99 pixels further away. |
| 1312 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1306 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1313 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1307 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1314 EXPECT_FLOAT_EQ(1.099f, | 1308 EXPECT_FLOAT_EQ(1.099f, |
| 1315 priority.time_to_visible_in_seconds); | 1309 priority.time_to_visible_in_seconds); |
| 1316 | 1310 |
| 1317 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1311 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1318 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1312 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1319 EXPECT_FLOAT_EQ(1.099f, | 1313 EXPECT_FLOAT_EQ(1.099f, |
| 1320 priority.time_to_visible_in_seconds); | 1314 priority.time_to_visible_in_seconds); |
| 1321 } | 1315 } |
| 1322 | 1316 |
| 1323 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1317 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
| 1324 // Each tile of a layer may be affected differently by a transform; Check | 1318 // Each tile of a layer may be affected differently by a transform; Check |
| 1325 // that UpdateTilePriorities correctly accounts for the transform between | 1319 // that UpdateTilePriorities correctly accounts for the transform between |
| 1326 // layer space and screen space. | 1320 // layer space and screen space. |
| 1327 | 1321 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1348 // - bottom-left layer will have a positive non-zero time_to_visible | 1342 // - bottom-left layer will have a positive non-zero time_to_visible |
| 1349 // because it is rotating toward the viewport. | 1343 // because it is rotating toward the viewport. |
| 1350 current_screen_transform.Translate(400, 550); | 1344 current_screen_transform.Translate(400, 550); |
| 1351 current_screen_transform.RotateAboutZAxis(45); | 1345 current_screen_transform.RotateAboutZAxis(45); |
| 1352 | 1346 |
| 1353 last_screen_transform.Translate(400, 550); | 1347 last_screen_transform.Translate(400, 550); |
| 1354 | 1348 |
| 1355 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1349 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1356 current_screen_transform, device_viewport); | 1350 current_screen_transform, device_viewport); |
| 1357 | 1351 |
| 1358 client.SetTileSize(gfx::Size(100, 100)); | 1352 client.SetTileSize(gfx::Size(50, 50)); |
| 1359 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1353 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1360 current_layer_bounds, | 1354 current_layer_bounds, |
| 1361 &client); | 1355 &client); |
| 1362 | 1356 |
| 1363 // previous ("last") frame | 1357 // previous ("last") frame |
| 1364 tiling->UpdateTilePriorities( | 1358 tiling->UpdateTilePriorities( |
| 1365 ACTIVE_TREE, | 1359 ACTIVE_TREE, |
| 1366 device_viewport, | 1360 device_viewport, |
| 1367 viewport_in_layer_space, | 1361 viewport_in_layer_space, |
| 1368 visible_layer_rect, | 1362 visible_layer_rect, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1383 visible_layer_rect, | 1377 visible_layer_rect, |
| 1384 last_layer_bounds, | 1378 last_layer_bounds, |
| 1385 current_layer_bounds, | 1379 current_layer_bounds, |
| 1386 last_layer_contents_scale, | 1380 last_layer_contents_scale, |
| 1387 current_layer_contents_scale, | 1381 current_layer_contents_scale, |
| 1388 last_screen_transform, | 1382 last_screen_transform, |
| 1389 current_screen_transform, | 1383 current_screen_transform, |
| 1390 current_frame_time_in_seconds, | 1384 current_frame_time_in_seconds, |
| 1391 max_tiles_for_interest_area); | 1385 max_tiles_for_interest_area); |
| 1392 | 1386 |
| 1393 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1387 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1394 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1388 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1395 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1389 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1396 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1390 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1397 | 1391 |
| 1398 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1392 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1399 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1393 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1400 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1394 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1401 | 1395 |
| 1402 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1396 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1403 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1397 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1404 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1398 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); |
| 1405 | 1399 |
| 1406 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1400 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1401 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1408 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1402 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1409 priority.time_to_visible_in_seconds); | 1403 priority.time_to_visible_in_seconds); |
| 1410 } | 1404 } |
| 1411 | 1405 |
| 1412 } // namespace | 1406 } // namespace |
| 1413 } // namespace cc | 1407 } // namespace cc |
| OLD | NEW |