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/tiles/picture_layer_tiling.h" | 5 #include "cc/tiles/picture_layer_tiling.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
(...skipping 29 matching lines...) Expand all Loading... |
40 gfx::Rect(device_viewport)); | 40 gfx::Rect(device_viewport)); |
41 } | 41 } |
42 | 42 |
43 class TestablePictureLayerTiling : public PictureLayerTiling { | 43 class TestablePictureLayerTiling : public PictureLayerTiling { |
44 public: | 44 public: |
45 using PictureLayerTiling::SetLiveTilesRect; | 45 using PictureLayerTiling::SetLiveTilesRect; |
46 using PictureLayerTiling::TileAt; | 46 using PictureLayerTiling::TileAt; |
47 | 47 |
48 static std::unique_ptr<TestablePictureLayerTiling> Create( | 48 static std::unique_ptr<TestablePictureLayerTiling> Create( |
49 WhichTree tree, | 49 WhichTree tree, |
50 float contents_scale, | 50 const gfx::AxisTransform2d& raster_transform, |
51 scoped_refptr<RasterSource> raster_source, | 51 scoped_refptr<RasterSource> raster_source, |
52 PictureLayerTilingClient* client, | 52 PictureLayerTilingClient* client, |
53 const LayerTreeSettings& settings) { | 53 const LayerTreeSettings& settings) { |
54 return base::WrapUnique(new TestablePictureLayerTiling( | 54 return base::WrapUnique(new TestablePictureLayerTiling( |
55 tree, contents_scale, raster_source, client, | 55 tree, raster_transform, raster_source, client, |
56 settings.tiling_interest_area_padding, | 56 settings.tiling_interest_area_padding, |
57 settings.skewport_target_time_in_seconds, | 57 settings.skewport_target_time_in_seconds, |
58 settings.skewport_extrapolation_limit_in_screen_pixels, | 58 settings.skewport_extrapolation_limit_in_screen_pixels, |
59 312.f, /* min_preraster_distance */ | 59 312.f, /* min_preraster_distance */ |
60 settings.max_preraster_distance_in_screen_pixels)); | 60 settings.max_preraster_distance_in_screen_pixels)); |
61 } | 61 } |
62 | 62 |
63 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 63 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
64 PriorityRectType visible_rect_type() const { | 64 PriorityRectType visible_rect_type() const { |
65 return PriorityRectType::VISIBLE_RECT; | 65 return PriorityRectType::VISIBLE_RECT; |
66 } | 66 } |
67 | 67 |
68 using PictureLayerTiling::RemoveTileAt; | 68 using PictureLayerTiling::RemoveTileAt; |
69 using PictureLayerTiling::RemoveTilesInRegion; | 69 using PictureLayerTiling::RemoveTilesInRegion; |
70 using PictureLayerTiling::ComputePriorityRectTypeForTile; | 70 using PictureLayerTiling::ComputePriorityRectTypeForTile; |
71 | 71 |
72 protected: | 72 protected: |
73 TestablePictureLayerTiling(WhichTree tree, | 73 TestablePictureLayerTiling(WhichTree tree, |
74 float contents_scale, | 74 const gfx::AxisTransform2d& raster_transform, |
75 scoped_refptr<RasterSource> raster_source, | 75 scoped_refptr<RasterSource> raster_source, |
76 PictureLayerTilingClient* client, | 76 PictureLayerTilingClient* client, |
77 size_t tiling_interest_area_padding, | 77 size_t tiling_interest_area_padding, |
78 float skewport_target_time, | 78 float skewport_target_time, |
79 int skewport_extrapolation_limit, | 79 int skewport_extrapolation_limit, |
80 float min_preraster_distance, | 80 float min_preraster_distance, |
81 float max_preraster_distance) | 81 float max_preraster_distance) |
82 : PictureLayerTiling(tree, | 82 : PictureLayerTiling(tree, |
83 contents_scale, | 83 raster_transform, |
84 raster_source, | 84 raster_source, |
85 client, | 85 client, |
86 min_preraster_distance, | 86 min_preraster_distance, |
87 max_preraster_distance) {} | 87 max_preraster_distance) {} |
88 }; | 88 }; |
89 | 89 |
90 class PictureLayerTilingIteratorTest : public testing::Test { | 90 class PictureLayerTilingIteratorTest : public testing::Test { |
91 public: | 91 public: |
92 PictureLayerTilingIteratorTest() {} | 92 PictureLayerTilingIteratorTest() {} |
93 ~PictureLayerTilingIteratorTest() override {} | 93 ~PictureLayerTilingIteratorTest() override {} |
94 | 94 |
95 void Initialize(const gfx::Size& tile_size, | 95 void Initialize(const gfx::Size& tile_size, |
96 float contents_scale, | 96 float contents_scale, |
97 const gfx::Size& layer_bounds) { | 97 const gfx::Size& layer_bounds) { |
98 client_.SetTileSize(tile_size); | 98 client_.SetTileSize(tile_size); |
99 scoped_refptr<FakeRasterSource> raster_source = | 99 scoped_refptr<FakeRasterSource> raster_source = |
100 FakeRasterSource::CreateFilled(layer_bounds); | 100 FakeRasterSource::CreateFilled(layer_bounds); |
101 tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, contents_scale, | 101 tiling_ = TestablePictureLayerTiling::Create( |
| 102 PENDING_TREE, gfx::AxisTransform2d(contents_scale, gfx::Vector2dF()), |
| 103 raster_source, &client_, LayerTreeSettings()); |
| 104 tiling_->set_resolution(HIGH_RESOLUTION); |
| 105 } |
| 106 |
| 107 void InitializeWithTranslation(const gfx::Size& tile_size, |
| 108 const gfx::AxisTransform2d& raster_transform, |
| 109 const gfx::Size& layer_bounds) { |
| 110 client_.SetTileSize(tile_size); |
| 111 scoped_refptr<FakeRasterSource> raster_source = |
| 112 FakeRasterSource::CreateFilled(layer_bounds); |
| 113 tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, raster_transform, |
102 raster_source, &client_, | 114 raster_source, &client_, |
103 LayerTreeSettings()); | 115 LayerTreeSettings()); |
104 tiling_->set_resolution(HIGH_RESOLUTION); | 116 tiling_->set_resolution(HIGH_RESOLUTION); |
105 } | 117 } |
106 | 118 |
107 void InitializeActive(const gfx::Size& tile_size, | 119 void InitializeActive(const gfx::Size& tile_size, |
108 float contents_scale, | 120 float contents_scale, |
109 const gfx::Size& layer_bounds) { | 121 const gfx::Size& layer_bounds) { |
110 client_.SetTileSize(tile_size); | 122 client_.SetTileSize(tile_size); |
111 scoped_refptr<FakeRasterSource> raster_source = | 123 scoped_refptr<FakeRasterSource> raster_source = |
112 FakeRasterSource::CreateFilled(layer_bounds); | 124 FakeRasterSource::CreateFilled(layer_bounds); |
113 tiling_ = TestablePictureLayerTiling::Create(ACTIVE_TREE, contents_scale, | 125 tiling_ = TestablePictureLayerTiling::Create( |
114 raster_source, &client_, | 126 ACTIVE_TREE, gfx::AxisTransform2d(contents_scale, gfx::Vector2dF()), |
115 LayerTreeSettings()); | 127 raster_source, &client_, LayerTreeSettings()); |
116 tiling_->set_resolution(HIGH_RESOLUTION); | 128 tiling_->set_resolution(HIGH_RESOLUTION); |
117 } | 129 } |
118 | 130 |
119 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { | 131 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { |
120 tiling_->SetLiveTilesRect(live_tiles_rect); | 132 tiling_->SetLiveTilesRect(live_tiles_rect); |
121 | 133 |
122 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 134 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
123 for (std::vector<Tile*>::iterator iter = tiles.begin(); | 135 for (std::vector<Tile*>::iterator iter = tiles.begin(); |
124 iter != tiles.end(); | 136 iter != tiles.end(); |
125 ++iter) { | 137 ++iter) { |
126 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | 138 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); |
127 } | 139 } |
128 } | 140 } |
129 | 141 |
130 void VerifyTilesExactlyCoverRect( | 142 void VerifyTilesExactlyCoverRect( |
131 float rect_scale, | 143 float rect_scale, |
132 const gfx::Rect& request_rect, | 144 const gfx::Rect& request_rect, |
133 const gfx::Rect& expect_rect) { | 145 const gfx::Rect& expect_rect) { |
134 EXPECT_TRUE(request_rect.Contains(expect_rect)); | 146 EXPECT_TRUE(request_rect.Contains(expect_rect)); |
135 | 147 |
136 // Iterators are not valid if the destination scale is smaller than the | 148 // Iterators are not valid if the destination scale is smaller than the |
137 // tiling scale. This is because coverage computation is done in integer | 149 // tiling scale. This is because coverage computation is done in integer |
138 // grids in the dest space, and the overlap between tiles may not guarantee | 150 // grids in the dest space, and the overlap between tiles may not guarantee |
139 // to enclose an integer grid line to round to if scaled down. | 151 // to enclose an integer grid line to round to if scaled down. |
140 ASSERT_GE(rect_scale, tiling_->contents_scale()); | 152 ASSERT_GE(rect_scale, tiling_->contents_scale_key()); |
141 | 153 |
142 Region remaining = expect_rect; | 154 Region remaining = expect_rect; |
143 for (PictureLayerTiling::CoverageIterator | 155 for (PictureLayerTiling::CoverageIterator |
144 iter(tiling_.get(), rect_scale, request_rect); | 156 iter(tiling_.get(), rect_scale, request_rect); |
145 iter; | 157 iter; |
146 ++iter) { | 158 ++iter) { |
147 // Geometry cannot overlap previous geometry at all | 159 // Geometry cannot overlap previous geometry at all |
148 gfx::Rect geometry = iter.geometry_rect(); | 160 gfx::Rect geometry = iter.geometry_rect(); |
149 EXPECT_TRUE(expect_rect.Contains(geometry)); | 161 EXPECT_TRUE(expect_rect.Contains(geometry)); |
150 EXPECT_TRUE(remaining.Contains(geometry)); | 162 EXPECT_TRUE(remaining.Contains(geometry)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 iter; | 210 iter; |
199 ++iter) { | 211 ++iter) { |
200 remaining.Subtract(iter.geometry_rect()); | 212 remaining.Subtract(iter.geometry_rect()); |
201 callback.Run(*iter, iter.geometry_rect()); | 213 callback.Run(*iter, iter.geometry_rect()); |
202 } | 214 } |
203 EXPECT_TRUE(remaining.IsEmpty()); | 215 EXPECT_TRUE(remaining.IsEmpty()); |
204 } | 216 } |
205 | 217 |
206 void VerifyTilesCoverNonContainedRect(float rect_scale, | 218 void VerifyTilesCoverNonContainedRect(float rect_scale, |
207 const gfx::Rect& dest_rect) { | 219 const gfx::Rect& dest_rect) { |
208 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 220 float dest_to_contents_scale = tiling_->contents_scale_key() / rect_scale; |
209 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( | 221 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( |
210 gfx::Rect(tiling_->tiling_size()), 1.f / dest_to_contents_scale); | 222 gfx::Rect(tiling_->tiling_size()), 1.f / dest_to_contents_scale); |
211 clamped_rect.Intersect(dest_rect); | 223 clamped_rect.Intersect(dest_rect); |
212 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 224 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
213 } | 225 } |
214 | 226 |
215 protected: | 227 protected: |
216 FakePictureLayerTilingClient client_; | 228 FakePictureLayerTilingClient client_; |
217 std::unique_ptr<TestablePictureLayerTiling> tiling_; | 229 std::unique_ptr<TestablePictureLayerTiling> tiling_; |
218 bool loose_texel_extent_check_ = false; | 230 bool loose_texel_extent_check_ = false; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 TEST_F(PictureLayerTilingIteratorTest, CreateTileJustCoverBorderUp) { | 503 TEST_F(PictureLayerTilingIteratorTest, CreateTileJustCoverBorderUp) { |
492 float content_scale = 1.2000000476837158f; | 504 float content_scale = 1.2000000476837158f; |
493 gfx::Size tile_size(512, 512); | 505 gfx::Size tile_size(512, 512); |
494 gfx::Size layer_size(1440, 4560); | 506 gfx::Size layer_size(1440, 4560); |
495 FakePictureLayerTilingClient active_client; | 507 FakePictureLayerTilingClient active_client; |
496 | 508 |
497 active_client.SetTileSize(tile_size); | 509 active_client.SetTileSize(tile_size); |
498 scoped_refptr<FakeRasterSource> raster_source = | 510 scoped_refptr<FakeRasterSource> raster_source = |
499 FakeRasterSource::CreateFilled(layer_size); | 511 FakeRasterSource::CreateFilled(layer_size); |
500 std::unique_ptr<TestablePictureLayerTiling> active_tiling = | 512 std::unique_ptr<TestablePictureLayerTiling> active_tiling = |
501 TestablePictureLayerTiling::Create(ACTIVE_TREE, content_scale, | 513 TestablePictureLayerTiling::Create( |
502 raster_source, &active_client, | 514 ACTIVE_TREE, gfx::AxisTransform2d(content_scale, gfx::Vector2dF()), |
503 LayerTreeSettings()); | 515 raster_source, &active_client, LayerTreeSettings()); |
504 active_tiling->set_resolution(HIGH_RESOLUTION); | 516 active_tiling->set_resolution(HIGH_RESOLUTION); |
505 | 517 |
506 gfx::Rect invalid_rect(0, 750, 220, 100); | 518 gfx::Rect invalid_rect(0, 750, 220, 100); |
507 Initialize(tile_size, content_scale, layer_size); | 519 Initialize(tile_size, content_scale, layer_size); |
508 client_.set_twin_tiling(active_tiling.get()); | 520 client_.set_twin_tiling(active_tiling.get()); |
509 client_.set_invalidation(invalid_rect); | 521 client_.set_invalidation(invalid_rect); |
510 SetLiveRectAndVerifyTiles(gfx::Rect(layer_size)); | 522 SetLiveRectAndVerifyTiles(gfx::Rect(layer_size)); |
511 // When it creates a tile in pending tree, verify that tiles are invalidated | 523 // When it creates a tile in pending tree, verify that tiles are invalidated |
512 // even if only their border pixels intersect the invalidation rect | 524 // even if only their border pixels intersect the invalidation rect |
513 EXPECT_TRUE(tiling_->TileAt(0, 1)); | 525 EXPECT_TRUE(tiling_->TileAt(0, 1)); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 720 |
709 TEST_F(PictureLayerTilingIteratorTest, | 721 TEST_F(PictureLayerTilingIteratorTest, |
710 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 722 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
711 gfx::Size layer_bounds(10000, 10000); | 723 gfx::Size layer_bounds(10000, 10000); |
712 client_.SetTileSize(gfx::Size(100, 100)); | 724 client_.SetTileSize(gfx::Size(100, 100)); |
713 LayerTreeSettings settings; | 725 LayerTreeSettings settings; |
714 settings.tiling_interest_area_padding = 1; | 726 settings.tiling_interest_area_padding = 1; |
715 | 727 |
716 scoped_refptr<FakeRasterSource> raster_source = | 728 scoped_refptr<FakeRasterSource> raster_source = |
717 FakeRasterSource::CreateFilled(layer_bounds); | 729 FakeRasterSource::CreateFilled(layer_bounds); |
718 tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, 1.f, raster_source, | 730 tiling_ = TestablePictureLayerTiling::Create( |
719 &client_, settings); | 731 PENDING_TREE, gfx::AxisTransform2d(), raster_source, &client_, settings); |
720 tiling_->set_resolution(HIGH_RESOLUTION); | 732 tiling_->set_resolution(HIGH_RESOLUTION); |
721 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 733 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
722 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 734 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
723 | 735 |
724 gfx::Rect visible_rect(8000, 8000, 50, 50); | 736 gfx::Rect visible_rect(8000, 8000, 50, 50); |
725 | 737 |
726 tiling_->ComputeTilePriorityRects(visible_rect, // visible rect | 738 tiling_->ComputeTilePriorityRects(visible_rect, // visible rect |
727 visible_rect, // skewport | 739 visible_rect, // skewport |
728 visible_rect, // soon border rect | 740 visible_rect, // soon border rect |
729 visible_rect, // eventually rect | 741 visible_rect, // eventually rect |
(...skipping 16 matching lines...) Expand all Loading... |
746 gfx::Transform current_screen_transform; | 758 gfx::Transform current_screen_transform; |
747 | 759 |
748 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 760 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
749 current_screen_transform, device_viewport); | 761 current_screen_transform, device_viewport); |
750 | 762 |
751 client.SetTileSize(gfx::Size(100, 100)); | 763 client.SetTileSize(gfx::Size(100, 100)); |
752 | 764 |
753 scoped_refptr<FakeRasterSource> raster_source = | 765 scoped_refptr<FakeRasterSource> raster_source = |
754 FakeRasterSource::CreateFilled(current_layer_bounds); | 766 FakeRasterSource::CreateFilled(current_layer_bounds); |
755 std::unique_ptr<TestablePictureLayerTiling> tiling = | 767 std::unique_ptr<TestablePictureLayerTiling> tiling = |
756 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source, | 768 TestablePictureLayerTiling::Create(ACTIVE_TREE, gfx::AxisTransform2d(), |
757 &client, LayerTreeSettings()); | 769 raster_source, &client, |
| 770 LayerTreeSettings()); |
758 tiling->set_resolution(HIGH_RESOLUTION); | 771 tiling->set_resolution(HIGH_RESOLUTION); |
759 | 772 |
760 LayerTreeSettings settings; | 773 LayerTreeSettings settings; |
761 gfx::Rect eventually_rect = viewport_in_layer_space; | 774 gfx::Rect eventually_rect = viewport_in_layer_space; |
762 eventually_rect.Inset(-settings.tiling_interest_area_padding, | 775 eventually_rect.Inset(-settings.tiling_interest_area_padding, |
763 -settings.tiling_interest_area_padding); | 776 -settings.tiling_interest_area_padding); |
764 tiling->ComputeTilePriorityRects( | 777 tiling->ComputeTilePriorityRects( |
765 viewport_in_layer_space, viewport_in_layer_space, viewport_in_layer_space, | 778 viewport_in_layer_space, viewport_in_layer_space, viewport_in_layer_space, |
766 eventually_rect, current_layer_contents_scale, Occlusion()); | 779 eventually_rect, current_layer_contents_scale, Occlusion()); |
767 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | 780 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 last_screen_transform = current_screen_transform; | 817 last_screen_transform = current_screen_transform; |
805 | 818 |
806 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 819 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
807 current_screen_transform, device_viewport); | 820 current_screen_transform, device_viewport); |
808 | 821 |
809 client.SetTileSize(gfx::Size(100, 100)); | 822 client.SetTileSize(gfx::Size(100, 100)); |
810 | 823 |
811 scoped_refptr<FakeRasterSource> raster_source = | 824 scoped_refptr<FakeRasterSource> raster_source = |
812 FakeRasterSource::CreateFilled(current_layer_bounds); | 825 FakeRasterSource::CreateFilled(current_layer_bounds); |
813 std::unique_ptr<TestablePictureLayerTiling> tiling = | 826 std::unique_ptr<TestablePictureLayerTiling> tiling = |
814 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source, | 827 TestablePictureLayerTiling::Create(ACTIVE_TREE, gfx::AxisTransform2d(), |
815 &client, LayerTreeSettings()); | 828 raster_source, &client, |
| 829 LayerTreeSettings()); |
816 tiling->set_resolution(HIGH_RESOLUTION); | 830 tiling->set_resolution(HIGH_RESOLUTION); |
817 | 831 |
818 LayerTreeSettings settings; | 832 LayerTreeSettings settings; |
819 gfx::Rect eventually_rect = viewport_in_layer_space; | 833 gfx::Rect eventually_rect = viewport_in_layer_space; |
820 eventually_rect.Inset(-settings.tiling_interest_area_padding, | 834 eventually_rect.Inset(-settings.tiling_interest_area_padding, |
821 -settings.tiling_interest_area_padding); | 835 -settings.tiling_interest_area_padding); |
822 tiling->ComputeTilePriorityRects( | 836 tiling->ComputeTilePriorityRects( |
823 viewport_in_layer_space, viewport_in_layer_space, viewport_in_layer_space, | 837 viewport_in_layer_space, viewport_in_layer_space, viewport_in_layer_space, |
824 eventually_rect, current_layer_contents_scale, Occlusion()); | 838 eventually_rect, current_layer_contents_scale, Occlusion()); |
825 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | 839 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 last_screen_transform = current_screen_transform; | 886 last_screen_transform = current_screen_transform; |
873 | 887 |
874 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 888 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
875 current_screen_transform, device_viewport); | 889 current_screen_transform, device_viewport); |
876 | 890 |
877 client.SetTileSize(gfx::Size(100, 100)); | 891 client.SetTileSize(gfx::Size(100, 100)); |
878 | 892 |
879 scoped_refptr<FakeRasterSource> raster_source = | 893 scoped_refptr<FakeRasterSource> raster_source = |
880 FakeRasterSource::CreateFilled(current_layer_bounds); | 894 FakeRasterSource::CreateFilled(current_layer_bounds); |
881 std::unique_ptr<TestablePictureLayerTiling> tiling = | 895 std::unique_ptr<TestablePictureLayerTiling> tiling = |
882 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source, | 896 TestablePictureLayerTiling::Create(ACTIVE_TREE, gfx::AxisTransform2d(), |
883 &client, LayerTreeSettings()); | 897 raster_source, &client, |
| 898 LayerTreeSettings()); |
884 tiling->set_resolution(HIGH_RESOLUTION); | 899 tiling->set_resolution(HIGH_RESOLUTION); |
885 | 900 |
886 LayerTreeSettings settings; | 901 LayerTreeSettings settings; |
887 gfx::Rect eventually_rect = viewport_in_layer_space; | 902 gfx::Rect eventually_rect = viewport_in_layer_space; |
888 eventually_rect.Inset(-settings.tiling_interest_area_padding, | 903 eventually_rect.Inset(-settings.tiling_interest_area_padding, |
889 -settings.tiling_interest_area_padding); | 904 -settings.tiling_interest_area_padding); |
890 tiling->ComputeTilePriorityRects( | 905 tiling->ComputeTilePriorityRects( |
891 viewport_in_layer_space, viewport_in_layer_space, viewport_in_layer_space, | 906 viewport_in_layer_space, viewport_in_layer_space, viewport_in_layer_space, |
892 eventually_rect, current_layer_contents_scale, Occlusion()); | 907 eventually_rect, current_layer_contents_scale, Occlusion()); |
893 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | 908 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); |
(...skipping 20 matching lines...) Expand all Loading... |
914 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 929 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
915 } | 930 } |
916 | 931 |
917 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { | 932 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { |
918 FakePictureLayerTilingClient active_client; | 933 FakePictureLayerTilingClient active_client; |
919 active_client.SetTileSize(gfx::Size(100, 100)); | 934 active_client.SetTileSize(gfx::Size(100, 100)); |
920 | 935 |
921 scoped_refptr<FakeRasterSource> raster_source = | 936 scoped_refptr<FakeRasterSource> raster_source = |
922 FakeRasterSource::CreateFilled(gfx::Size(100, 100)); | 937 FakeRasterSource::CreateFilled(gfx::Size(100, 100)); |
923 std::unique_ptr<TestablePictureLayerTiling> active_tiling = | 938 std::unique_ptr<TestablePictureLayerTiling> active_tiling = |
924 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source, | 939 TestablePictureLayerTiling::Create(ACTIVE_TREE, gfx::AxisTransform2d(), |
925 &active_client, LayerTreeSettings()); | 940 raster_source, &active_client, |
| 941 LayerTreeSettings()); |
926 active_tiling->set_resolution(HIGH_RESOLUTION); | 942 active_tiling->set_resolution(HIGH_RESOLUTION); |
927 // Create all tiles on this tiling. | 943 // Create all tiles on this tiling. |
928 gfx::Rect visible_rect = gfx::Rect(0, 0, 100, 100); | 944 gfx::Rect visible_rect = gfx::Rect(0, 0, 100, 100); |
929 active_tiling->ComputeTilePriorityRects( | 945 active_tiling->ComputeTilePriorityRects( |
930 visible_rect, visible_rect, visible_rect, visible_rect, 1.f, Occlusion()); | 946 visible_rect, visible_rect, visible_rect, visible_rect, 1.f, Occlusion()); |
931 | 947 |
932 FakePictureLayerTilingClient recycle_client; | 948 FakePictureLayerTilingClient recycle_client; |
933 recycle_client.SetTileSize(gfx::Size(100, 100)); | 949 recycle_client.SetTileSize(gfx::Size(100, 100)); |
934 recycle_client.set_twin_tiling(active_tiling.get()); | 950 recycle_client.set_twin_tiling(active_tiling.get()); |
935 | 951 |
936 LayerTreeSettings settings; | 952 LayerTreeSettings settings; |
937 | 953 |
938 raster_source = FakeRasterSource::CreateFilled(gfx::Size(100, 100)); | 954 raster_source = FakeRasterSource::CreateFilled(gfx::Size(100, 100)); |
939 std::unique_ptr<TestablePictureLayerTiling> recycle_tiling = | 955 std::unique_ptr<TestablePictureLayerTiling> recycle_tiling = |
940 TestablePictureLayerTiling::Create(PENDING_TREE, 1.0f, raster_source, | 956 TestablePictureLayerTiling::Create(PENDING_TREE, gfx::AxisTransform2d(), |
941 &recycle_client, settings); | 957 raster_source, &recycle_client, |
| 958 settings); |
942 recycle_tiling->set_resolution(HIGH_RESOLUTION); | 959 recycle_tiling->set_resolution(HIGH_RESOLUTION); |
943 | 960 |
944 // Create all tiles on the recycle tiling. | 961 // Create all tiles on the recycle tiling. |
945 recycle_tiling->ComputeTilePriorityRects(visible_rect, visible_rect, | 962 recycle_tiling->ComputeTilePriorityRects(visible_rect, visible_rect, |
946 visible_rect, visible_rect, 1.0f, | 963 visible_rect, visible_rect, 1.0f, |
947 Occlusion()); | 964 Occlusion()); |
948 | 965 |
949 // Set the second tiling as recycled. | 966 // Set the second tiling as recycled. |
950 active_client.set_twin_tiling(NULL); | 967 active_client.set_twin_tiling(NULL); |
951 recycle_client.set_twin_tiling(NULL); | 968 recycle_client.set_twin_tiling(NULL); |
952 | 969 |
953 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | 970 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
954 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | 971 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
955 | 972 |
956 // Reset the active tiling. The recycle tiles should be released too. | 973 // Reset the active tiling. The recycle tiles should be released too. |
957 active_tiling->Reset(); | 974 active_tiling->Reset(); |
958 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | 975 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
959 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | 976 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
960 } | 977 } |
961 | 978 |
962 TEST(PictureLayerTilingTest, EdgeCaseTileNowAndRequired) { | 979 TEST(PictureLayerTilingTest, EdgeCaseTileNowAndRequired) { |
963 FakePictureLayerTilingClient pending_client; | 980 FakePictureLayerTilingClient pending_client; |
964 pending_client.SetTileSize(gfx::Size(100, 100)); | 981 pending_client.SetTileSize(gfx::Size(100, 100)); |
965 | 982 |
966 scoped_refptr<FakeRasterSource> raster_source = | 983 scoped_refptr<FakeRasterSource> raster_source = |
967 FakeRasterSource::CreateFilled(gfx::Size(500, 500)); | 984 FakeRasterSource::CreateFilled(gfx::Size(500, 500)); |
968 std::unique_ptr<TestablePictureLayerTiling> pending_tiling = | 985 std::unique_ptr<TestablePictureLayerTiling> pending_tiling = |
969 TestablePictureLayerTiling::Create(PENDING_TREE, 1.0f, raster_source, | 986 TestablePictureLayerTiling::Create(PENDING_TREE, gfx::AxisTransform2d(), |
970 &pending_client, LayerTreeSettings()); | 987 raster_source, &pending_client, |
| 988 LayerTreeSettings()); |
971 pending_tiling->set_resolution(HIGH_RESOLUTION); | 989 pending_tiling->set_resolution(HIGH_RESOLUTION); |
972 pending_tiling->set_can_require_tiles_for_activation(true); | 990 pending_tiling->set_can_require_tiles_for_activation(true); |
973 | 991 |
974 // The tile at (1, 0) should be touching the visible rect, but not | 992 // The tile at (1, 0) should be touching the visible rect, but not |
975 // intersecting it. | 993 // intersecting it. |
976 gfx::Rect visible_rect = gfx::Rect(0, 0, 99, 99); | 994 gfx::Rect visible_rect = gfx::Rect(0, 0, 99, 99); |
977 gfx::Rect eventually_rect = gfx::Rect(0, 0, 500, 500); | 995 gfx::Rect eventually_rect = gfx::Rect(0, 0, 500, 500); |
978 pending_tiling->ComputeTilePriorityRects(visible_rect, visible_rect, | 996 pending_tiling->ComputeTilePriorityRects(visible_rect, visible_rect, |
979 visible_rect, eventually_rect, 1.f, | 997 visible_rect, eventually_rect, 1.f, |
980 Occlusion()); | 998 Occlusion()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 TEST_F(PictureLayerTilingIteratorTest, GiantRect) { | 1049 TEST_F(PictureLayerTilingIteratorTest, GiantRect) { |
1032 loose_texel_extent_check_ = true; | 1050 loose_texel_extent_check_ = true; |
1033 | 1051 |
1034 gfx::Size tile_size(256, 256); | 1052 gfx::Size tile_size(256, 256); |
1035 gfx::Size layer_size(33554432, 33554432); | 1053 gfx::Size layer_size(33554432, 33554432); |
1036 float contents_scale = 1.f; | 1054 float contents_scale = 1.f; |
1037 | 1055 |
1038 client_.SetTileSize(tile_size); | 1056 client_.SetTileSize(tile_size); |
1039 scoped_refptr<FakeRasterSource> raster_source = | 1057 scoped_refptr<FakeRasterSource> raster_source = |
1040 FakeRasterSource::CreateEmpty(layer_size); | 1058 FakeRasterSource::CreateEmpty(layer_size); |
1041 tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, contents_scale, | 1059 tiling_ = TestablePictureLayerTiling::Create( |
1042 raster_source, &client_, | 1060 PENDING_TREE, gfx::AxisTransform2d(contents_scale, gfx::Vector2dF()), |
1043 LayerTreeSettings()); | 1061 raster_source, &client_, LayerTreeSettings()); |
1044 | 1062 |
1045 gfx::Rect content_rect(25554432, 25554432, 950, 860); | 1063 gfx::Rect content_rect(25554432, 25554432, 950, 860); |
1046 VerifyTilesExactlyCoverRect(contents_scale, content_rect); | 1064 VerifyTilesExactlyCoverRect(contents_scale, content_rect); |
1047 } | 1065 } |
1048 | 1066 |
1049 TEST_F(PictureLayerTilingIteratorTest, QuadShouldNotUseLastHalfTexel) { | 1067 TEST_F(PictureLayerTilingIteratorTest, QuadShouldNotUseLastHalfTexel) { |
1050 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(198, 198)); | 1068 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(198, 198)); |
1051 // Creates a situation that tile bounds get rounded up by almost 1px in the | 1069 // Creates a situation that tile bounds get rounded up by almost 1px in the |
1052 // dest space. This test verifies that even in such situation the coverage | 1070 // dest space. This test verifies that even in such situation the coverage |
1053 // iterator won't generate a texture rect that can potentially get clamped. | 1071 // iterator won't generate a texture rect that can potentially get clamped. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 EXPECT_TRUE(tiles.size()); | 1137 EXPECT_TRUE(tiles.size()); |
1120 for (const auto* tile : tiles) { | 1138 for (const auto* tile : tiles) { |
1121 EXPECT_EQ(tile->tiling(), tiling_.get()); | 1139 EXPECT_EQ(tile->tiling(), tiling_.get()); |
1122 } | 1140 } |
1123 | 1141 |
1124 // Create an active tiling, transfer tiles to that tiling, and ensure that | 1142 // Create an active tiling, transfer tiles to that tiling, and ensure that |
1125 // the tiles have their tiling updated. | 1143 // the tiles have their tiling updated. |
1126 scoped_refptr<FakeRasterSource> raster_source = | 1144 scoped_refptr<FakeRasterSource> raster_source = |
1127 FakeRasterSource::CreateFilled(bounds); | 1145 FakeRasterSource::CreateFilled(bounds); |
1128 auto active_tiling = TestablePictureLayerTiling::Create( | 1146 auto active_tiling = TestablePictureLayerTiling::Create( |
1129 ACTIVE_TREE, 1.f, raster_source, &client_, LayerTreeSettings()); | 1147 ACTIVE_TREE, gfx::AxisTransform2d(), raster_source, &client_, |
| 1148 LayerTreeSettings()); |
1130 active_tiling->set_resolution(HIGH_RESOLUTION); | 1149 active_tiling->set_resolution(HIGH_RESOLUTION); |
1131 | 1150 |
1132 active_tiling->TakeTilesAndPropertiesFrom(tiling_.get(), | 1151 active_tiling->TakeTilesAndPropertiesFrom(tiling_.get(), |
1133 Region(gfx::Rect(bounds))); | 1152 Region(gfx::Rect(bounds))); |
1134 for (const auto* tile : tiles) { | 1153 for (const auto* tile : tiles) { |
1135 EXPECT_EQ(tile->tiling(), active_tiling.get()); | 1154 EXPECT_EQ(tile->tiling(), active_tiling.get()); |
1136 } | 1155 } |
1137 } | 1156 } |
1138 | 1157 |
| 1158 TEST_F(PictureLayerTilingIteratorTest, FractionalTranslatedTiling) { |
| 1159 InitializeWithTranslation( |
| 1160 gfx::Size(256, 256), |
| 1161 gfx::AxisTransform2d(1.f, gfx::Vector2dF(0.125f, 0.125f)), |
| 1162 gfx::Size(1000, 1)); |
| 1163 EXPECT_EQ(tiling_->tiling_size(), gfx::Size(1001, 2)); |
| 1164 SetLiveRectAndVerifyTiles(gfx::Rect(1000, 1)); |
| 1165 |
| 1166 // Verifies the texture coordinate is correctly translated. |
| 1167 for (PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.f, |
| 1168 gfx::Rect(1000, 1)); |
| 1169 iter; ++iter) { |
| 1170 gfx::Rect geometry_rect = iter.geometry_rect(); |
| 1171 gfx::RectF texture_rect = iter.texture_rect(); |
| 1172 if (geometry_rect == gfx::Rect(0, 0, 255, 1)) { |
| 1173 EXPECT_EQ(gfx::RectF(0.125f, 0.125f, 255.f, 1.f), texture_rect); |
| 1174 } else if (geometry_rect == gfx::Rect(255, 0, 254, 1)) { |
| 1175 EXPECT_EQ(gfx::RectF(1.125f, 0.125f, 254.f, 1.f), texture_rect); |
| 1176 } else if (geometry_rect == gfx::Rect(509, 0, 254, 1)) { |
| 1177 EXPECT_EQ(gfx::RectF(1.125f, 0.125f, 254.f, 1.f), texture_rect); |
| 1178 } else { |
| 1179 EXPECT_EQ(gfx::Rect(763, 0, 237, 1), geometry_rect); |
| 1180 EXPECT_EQ(gfx::RectF(1.125f, 0.125f, 237.f, 1.f), texture_rect); |
| 1181 } |
| 1182 } |
| 1183 |
| 1184 // Similar to above, with a different coverage scale. |
| 1185 for (PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.375f, |
| 1186 gfx::Rect(1375, 2)); |
| 1187 iter; ++iter) { |
| 1188 gfx::Rect geometry_rect = iter.geometry_rect(); |
| 1189 gfx::RectF texture_rect = iter.texture_rect(); |
| 1190 if (geometry_rect == gfx::Rect(0, 0, 351, 2)) { |
| 1191 gfx::RectF expectation(geometry_rect); |
| 1192 expectation.Scale(1.f / 1.375f); |
| 1193 expectation.Offset(0.125f, 0.125f); |
| 1194 EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x()); |
| 1195 EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y()); |
| 1196 EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width()); |
| 1197 EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height()); |
| 1198 } else if (geometry_rect == gfx::Rect(351, 0, 349, 2)) { |
| 1199 gfx::RectF expectation(geometry_rect); |
| 1200 expectation.Scale(1.f / 1.375f); |
| 1201 expectation.Offset(0.125f - 254.f, 0.125f); |
| 1202 EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x()); |
| 1203 EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y()); |
| 1204 EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width()); |
| 1205 EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height()); |
| 1206 } else if (geometry_rect == gfx::Rect(700, 0, 349, 2)) { |
| 1207 gfx::RectF expectation(geometry_rect); |
| 1208 expectation.Scale(1.f / 1.375f); |
| 1209 expectation.Offset(0.125f - 254.f * 2.f, 0.125f); |
| 1210 EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x()); |
| 1211 EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y()); |
| 1212 EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width()); |
| 1213 EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height()); |
| 1214 } else { |
| 1215 EXPECT_EQ(gfx::Rect(1049, 0, 326, 2), geometry_rect); |
| 1216 gfx::RectF expectation(geometry_rect); |
| 1217 expectation.Scale(1.f / 1.375f); |
| 1218 expectation.Offset(0.125f - 254.f * 3.f, 0.125f); |
| 1219 EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x()); |
| 1220 EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y()); |
| 1221 EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width()); |
| 1222 EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height()); |
| 1223 } |
| 1224 } |
| 1225 } |
| 1226 |
| 1227 TEST_F(PictureLayerTilingIteratorTest, FractionalTranslatedTilingOverflow) { |
| 1228 // This tests a corner case where the coverage rect is slightly greater |
| 1229 // than the layer rect due to rounding up, and the bottom right edge of |
| 1230 // the tiling coincide with actual layer bound. That is, the requested |
| 1231 // coverage rect slightly exceed the valid extent, but we still return |
| 1232 // full coverage as a special case for external edges. |
| 1233 |
| 1234 // The layer bounds is (9, 9), which after scale and translation |
| 1235 // becomes (l=0.5, t=0.5, r=14, b=14) in the contents space. |
| 1236 InitializeWithTranslation( |
| 1237 gfx::Size(256, 256), |
| 1238 gfx::AxisTransform2d(1.5f, gfx::Vector2dF(0.5f, 0.5f)), gfx::Size(9, 9)); |
| 1239 EXPECT_EQ(tiling_->tiling_size(), gfx::Size(14, 14)); |
| 1240 SetLiveRectAndVerifyTiles(gfx::Rect(9, 9)); |
| 1241 |
| 1242 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.56f, |
| 1243 gfx::Rect(15, 15)); |
| 1244 ASSERT_TRUE(iter); |
| 1245 gfx::Rect geometry_rect = iter.geometry_rect(); |
| 1246 gfx::RectF texture_rect = iter.texture_rect(); |
| 1247 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), geometry_rect); |
| 1248 gfx::RectF expectation(geometry_rect); |
| 1249 expectation.Scale(1.5f / 1.56f); |
| 1250 expectation.Offset(0.5f, 0.5f); |
| 1251 EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x()); |
| 1252 EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y()); |
| 1253 EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width()); |
| 1254 EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height()); |
| 1255 |
| 1256 EXPECT_FALSE(++iter); |
| 1257 } |
| 1258 |
1139 } // namespace | 1259 } // namespace |
1140 } // namespace cc | 1260 } // namespace cc |
OLD | NEW |