OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <map> | 5 #include <map> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "cc/resources/picture_pile.h" | 8 #include "cc/resources/picture_pile.h" |
9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
10 #include "cc/test/fake_rendering_stats_instrumentation.h" | 10 #include "cc/test/fake_rendering_stats_instrumentation.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 }; | 37 }; |
38 | 38 |
39 class PicturePileTest : public testing::Test { | 39 class PicturePileTest : public testing::Test { |
40 public: | 40 public: |
41 PicturePileTest() | 41 PicturePileTest() |
42 : pile_(new TestPicturePile()), | 42 : pile_(new TestPicturePile()), |
43 background_color_(SK_ColorBLUE), | 43 background_color_(SK_ColorBLUE), |
44 min_scale_(0.125), | 44 min_scale_(0.125), |
45 frame_number_(0), | 45 frame_number_(0), |
46 contents_opaque_(false) { | 46 contents_opaque_(false) { |
47 pile_->SetTilingRect(gfx::Rect(pile_->tiling().max_texture_size())); | |
48 pile_->SetTileGridSize(gfx::Size(1000, 1000)); | 47 pile_->SetTileGridSize(gfx::Size(1000, 1000)); |
49 pile_->SetMinContentsScale(min_scale_); | 48 pile_->SetMinContentsScale(min_scale_); |
| 49 SetTilingRect(gfx::Rect(pile_->tiling().max_texture_size())); |
| 50 } |
| 51 |
| 52 void SetTilingRect(const gfx::Rect& tiling_rect) { |
| 53 Region invalidation; |
| 54 UpdateAndExpandInvalidation(&invalidation, tiling_rect, tiling_rect); |
50 } | 55 } |
51 | 56 |
52 gfx::Rect tiling_rect() const { return pile_->tiling_rect(); } | 57 gfx::Rect tiling_rect() const { return pile_->tiling_rect(); } |
53 | 58 |
54 bool UpdateAndExpandInvalidation(Region* invalidation, | 59 bool UpdateAndExpandInvalidation(Region* invalidation, |
| 60 const gfx::Rect& layer_bounds_rect, |
55 const gfx::Rect& visible_layer_rect) { | 61 const gfx::Rect& visible_layer_rect) { |
56 frame_number_++; | 62 frame_number_++; |
57 return pile_->UpdateAndExpandInvalidation(&client_, | 63 return pile_->UpdateAndExpandInvalidation(&client_, |
58 invalidation, | 64 invalidation, |
59 background_color_, | 65 background_color_, |
60 contents_opaque_, | 66 contents_opaque_, |
61 false, | 67 false, |
| 68 layer_bounds_rect, |
62 visible_layer_rect, | 69 visible_layer_rect, |
63 frame_number_, | 70 frame_number_, |
64 Picture::RECORD_NORMALLY, | 71 Picture::RECORD_NORMALLY, |
65 &stats_instrumentation_); | 72 &stats_instrumentation_); |
66 } | 73 } |
67 | 74 |
68 bool UpdateWholePile() { | 75 bool UpdateWholePile() { |
69 Region invalidation = tiling_rect(); | 76 Region invalidation = tiling_rect(); |
70 bool result = UpdateAndExpandInvalidation(&invalidation, tiling_rect()); | 77 bool result = UpdateAndExpandInvalidation( |
| 78 &invalidation, tiling_rect(), tiling_rect()); |
71 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 79 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
72 return result; | 80 return result; |
73 } | 81 } |
74 | 82 |
75 FakeContentLayerClient client_; | 83 FakeContentLayerClient client_; |
76 FakeRenderingStatsInstrumentation stats_instrumentation_; | 84 FakeRenderingStatsInstrumentation stats_instrumentation_; |
77 scoped_refptr<TestPicturePile> pile_; | 85 scoped_refptr<TestPicturePile> pile_; |
78 SkColor background_color_; | 86 SkColor background_color_; |
79 float min_scale_; | 87 float min_scale_; |
80 int frame_number_; | 88 int frame_number_; |
81 bool contents_opaque_; | 89 bool contents_opaque_; |
82 }; | 90 }; |
83 | 91 |
84 TEST_F(PicturePileTest, SmallInvalidateInflated) { | 92 TEST_F(PicturePileTest, SmallInvalidateInflated) { |
85 UpdateWholePile(); | |
86 | |
87 // Invalidate something inside a tile. | 93 // Invalidate something inside a tile. |
88 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); | 94 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); |
89 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); | 95 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect(), tiling_rect()); |
90 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); | 96 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); |
91 | 97 |
92 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 98 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
93 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 99 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
94 | 100 |
95 TestPicturePile::PictureInfo& picture_info = | 101 TestPicturePile::PictureInfo& picture_info = |
96 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 102 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
97 // We should have a picture. | 103 // We should have a picture. |
98 EXPECT_TRUE(!!picture_info.GetPicture()); | 104 EXPECT_TRUE(!!picture_info.GetPicture()); |
99 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( | 105 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( |
100 picture_info.GetPicture()->LayerRect(), min_scale_); | 106 picture_info.GetPicture()->LayerRect(), min_scale_); |
101 | 107 |
102 // The the picture should be large enough that scaling it never makes a rect | 108 // The the picture should be large enough that scaling it never makes a rect |
103 // smaller than 1 px wide or tall. | 109 // smaller than 1 px wide or tall. |
104 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | 110 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
105 picture_rect.ToString(); | 111 picture_rect.ToString(); |
106 } | 112 } |
107 | 113 |
108 TEST_F(PicturePileTest, LargeInvalidateInflated) { | 114 TEST_F(PicturePileTest, LargeInvalidateInflated) { |
109 UpdateWholePile(); | |
110 | |
111 // Invalidate something inside a tile. | 115 // Invalidate something inside a tile. |
112 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); | 116 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); |
113 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); | 117 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect(), tiling_rect()); |
114 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); | 118 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); |
115 | 119 |
116 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 120 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
117 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 121 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
118 | 122 |
119 TestPicturePile::PictureInfo& picture_info = | 123 TestPicturePile::PictureInfo& picture_info = |
120 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 124 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
121 EXPECT_TRUE(!!picture_info.GetPicture()); | 125 EXPECT_TRUE(!!picture_info.GetPicture()); |
122 | 126 |
123 int expected_inflation = pile_->buffer_pixels(); | 127 int expected_inflation = pile_->buffer_pixels(); |
124 | 128 |
125 Picture* base_picture = picture_info.GetPicture(); | 129 Picture* base_picture = picture_info.GetPicture(); |
126 gfx::Rect base_picture_rect = pile_->tiling_rect(); | 130 gfx::Rect base_picture_rect = pile_->tiling_rect(); |
127 base_picture_rect.Inset(-expected_inflation, -expected_inflation); | 131 base_picture_rect.Inset(-expected_inflation, -expected_inflation); |
128 EXPECT_EQ(base_picture_rect.ToString(), | 132 EXPECT_EQ(base_picture_rect.ToString(), |
129 base_picture->LayerRect().ToString()); | 133 base_picture->LayerRect().ToString()); |
130 } | 134 } |
131 | 135 |
132 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { | 136 TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) { |
133 gfx::Rect new_tiling_rect = | 137 gfx::Rect new_tiling_rect = |
134 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 2.f)); | 138 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 2.f)); |
135 pile_->SetTilingRect(new_tiling_rect); | 139 // This creates initial pictures. |
| 140 SetTilingRect(new_tiling_rect); |
136 | 141 |
137 // Due to border pixels, we should have 3 tiles. | 142 // Due to border pixels, we should have 3 tiles. |
138 EXPECT_EQ(3, pile_->tiling().num_tiles_x()); | 143 EXPECT_EQ(3, pile_->tiling().num_tiles_x()); |
139 EXPECT_EQ(3, pile_->tiling().num_tiles_y()); | 144 EXPECT_EQ(3, pile_->tiling().num_tiles_y()); |
140 | 145 |
141 // We should have 1/.125 - 1 = 7 border pixels. | 146 // We should have 1/.125 - 1 = 7 border pixels. |
142 EXPECT_EQ(7, pile_->buffer_pixels()); | 147 EXPECT_EQ(7, pile_->buffer_pixels()); |
143 EXPECT_EQ(7, pile_->tiling().border_texels()); | 148 EXPECT_EQ(7, pile_->tiling().border_texels()); |
144 | 149 |
145 // Update the whole layer to create initial pictures. | 150 // Invalidate everything to have a non zero invalidation frequency. |
146 UpdateWholePile(); | |
147 | |
148 // Invalidate everything again to have a non zero invalidation | |
149 // frequency. | |
150 UpdateWholePile(); | 151 UpdateWholePile(); |
151 | 152 |
152 // Invalidate something just over a tile boundary by a single pixel. | 153 // Invalidate something just over a tile boundary by a single pixel. |
153 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). | 154 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). |
154 Region invalidate_rect( | 155 Region invalidate_rect( |
155 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), | 156 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), |
156 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, | 157 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, |
157 50, | 158 50, |
158 50)); | 159 50)); |
159 Region expected_invalidation = invalidate_rect; | 160 Region expected_invalidation = invalidate_rect; |
160 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); | 161 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect(), tiling_rect()); |
161 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); | 162 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); |
162 | 163 |
163 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 164 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
164 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 165 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
165 TestPicturePile::PictureInfo& picture_info = | 166 TestPicturePile::PictureInfo& picture_info = |
166 pile_->picture_map() | 167 pile_->picture_map() |
167 .find(TestPicturePile::PictureMapKey(i, j)) | 168 .find(TestPicturePile::PictureMapKey(i, j)) |
168 ->second; | 169 ->second; |
169 | 170 |
170 // Expect (1, 1) and (1, 0) to be invalidated once more | 171 // Expect (1, 1) and (1, 0) to be invalidated once more |
171 // than the rest of the tiles. | 172 // than the rest of the tiles. |
172 if (i == 1 && (j == 0 || j == 1)) { | 173 if (i == 1 && (j == 0 || j == 1)) { |
173 EXPECT_FLOAT_EQ( | 174 EXPECT_FLOAT_EQ( |
174 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 175 2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
175 picture_info.GetInvalidationFrequencyForTesting()); | 176 picture_info.GetInvalidationFrequencyForTesting()); |
176 } else { | 177 } else { |
177 EXPECT_FLOAT_EQ( | 178 EXPECT_FLOAT_EQ( |
178 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, | 179 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED, |
179 picture_info.GetInvalidationFrequencyForTesting()); | 180 picture_info.GetInvalidationFrequencyForTesting()); |
180 } | 181 } |
181 } | 182 } |
182 } | 183 } |
183 } | 184 } |
184 | 185 |
185 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { | 186 TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) { |
186 gfx::Rect new_tiling_rect = | 187 gfx::Rect new_tiling_rect = |
187 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); | 188 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); |
188 pile_->SetTilingRect(new_tiling_rect); | 189 SetTilingRect(new_tiling_rect); |
189 | 190 |
190 gfx::Rect viewport( | 191 gfx::Rect viewport( |
191 tiling_rect().x(), tiling_rect().y(), tiling_rect().width(), 1); | 192 tiling_rect().x(), tiling_rect().y(), tiling_rect().width(), 1); |
192 | 193 |
193 // Update the whole pile until the invalidation frequency is high. | 194 // Update the whole pile until the invalidation frequency is high. |
194 for (int frame = 0; frame < 33; ++frame) { | 195 for (int frame = 0; frame < 33; ++frame) { |
195 UpdateWholePile(); | 196 UpdateWholePile(); |
196 } | 197 } |
197 | 198 |
198 // Make sure we have a high invalidation frequency. | 199 // Make sure we have a high invalidation frequency. |
199 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 200 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
200 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 201 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
201 TestPicturePile::PictureInfo& picture_info = | 202 TestPicturePile::PictureInfo& picture_info = |
202 pile_->picture_map() | 203 pile_->picture_map() |
203 .find(TestPicturePile::PictureMapKey(i, j)) | 204 .find(TestPicturePile::PictureMapKey(i, j)) |
204 ->second; | 205 ->second; |
205 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) | 206 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) |
206 << "i " << i << " j " << j; | 207 << "i " << i << " j " << j; |
207 } | 208 } |
208 } | 209 } |
209 | 210 |
210 // Update once more with a small viewport. | 211 // Update once more with a small viewport. |
211 Region invalidation = tiling_rect(); | 212 Region invalidation = tiling_rect(); |
212 UpdateAndExpandInvalidation(&invalidation, viewport); | 213 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), viewport); |
213 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 214 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
214 | 215 |
215 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 216 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
216 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 217 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
217 TestPicturePile::PictureInfo& picture_info = | 218 TestPicturePile::PictureInfo& picture_info = |
218 pile_->picture_map() | 219 pile_->picture_map() |
219 .find(TestPicturePile::PictureMapKey(i, j)) | 220 .find(TestPicturePile::PictureMapKey(i, j)) |
220 ->second; | 221 ->second; |
221 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); | 222 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); |
222 | 223 |
223 // If the y far enough away we expect to find no picture (no re-recording | 224 // If the y far enough away we expect to find no picture (no re-recording |
224 // happened). For close y, the picture should change. | 225 // happened). For close y, the picture should change. |
225 if (j >= 2) | 226 if (j >= 2) |
226 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; | 227 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; |
227 else | 228 else |
228 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 229 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
229 } | 230 } |
230 } | 231 } |
231 | 232 |
232 // Update a partial tile that doesn't get recorded. We should expand the | 233 // Update a partial tile that doesn't get recorded. We should expand the |
233 // invalidation to the entire tiles that overlap it. | 234 // invalidation to the entire tiles that overlap it. |
234 Region small_invalidation = | 235 Region small_invalidation = |
235 gfx::Rect(pile_->tiling().TileBounds(3, 4).x(), | 236 gfx::Rect(pile_->tiling().TileBounds(3, 4).x(), |
236 pile_->tiling().TileBounds(3, 4).y() + 10, | 237 pile_->tiling().TileBounds(3, 4).y() + 10, |
237 1, | 238 1, |
238 1); | 239 1); |
239 UpdateAndExpandInvalidation(&small_invalidation, viewport); | 240 UpdateAndExpandInvalidation(&small_invalidation, tiling_rect(), viewport); |
240 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( | 241 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( |
241 pile_->tiling().TileBounds(2, 4), pile_->tiling().TileBounds(3, 4)))) | 242 pile_->tiling().TileBounds(2, 4), pile_->tiling().TileBounds(3, 4)))) |
242 << small_invalidation.ToString(); | 243 << small_invalidation.ToString(); |
243 | 244 |
244 // Now update with no invalidation and full viewport | 245 // Now update with no invalidation and full viewport |
245 Region empty_invalidation; | 246 Region empty_invalidation; |
246 UpdateAndExpandInvalidation(&empty_invalidation, tiling_rect()); | 247 UpdateAndExpandInvalidation( |
| 248 &empty_invalidation, tiling_rect(), tiling_rect()); |
247 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); | 249 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); |
248 | 250 |
249 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 251 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
250 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 252 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
251 TestPicturePile::PictureInfo& picture_info = | 253 TestPicturePile::PictureInfo& picture_info = |
252 pile_->picture_map() | 254 pile_->picture_map() |
253 .find(TestPicturePile::PictureMapKey(i, j)) | 255 .find(TestPicturePile::PictureMapKey(i, j)) |
254 ->second; | 256 ->second; |
255 // Expect the invalidation frequency to be less than 1, since we just | 257 // Expect the invalidation frequency to be less than 1, since we just |
256 // updated with no invalidations. | 258 // updated with no invalidations. |
257 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); | 259 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); |
258 | 260 |
259 // We expect that there are pictures everywhere now. | 261 // We expect that there are pictures everywhere now. |
260 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 262 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
261 } | 263 } |
262 } | 264 } |
263 } | 265 } |
264 | 266 |
265 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { | 267 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { |
266 UpdateWholePile(); | |
267 | |
268 gfx::Rect rect(0, 0, 5, 5); | 268 gfx::Rect rect(0, 0, 5, 5); |
269 EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); | 269 EXPECT_TRUE(pile_->CanRasterLayerRect(rect)); |
270 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); | 270 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect)); |
271 | 271 |
272 pile_->Clear(); | 272 pile_->Clear(); |
273 | 273 |
274 // Make sure both the cache-aware check (using recorded region) and the normal | 274 // Make sure both the cache-aware check (using recorded region) and the normal |
275 // check are both false after clearing. | 275 // check are both false after clearing. |
276 EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); | 276 EXPECT_FALSE(pile_->CanRasterLayerRect(rect)); |
277 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); | 277 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect)); |
278 } | 278 } |
279 | 279 |
280 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { | 280 TEST_F(PicturePileTest, FrequentInvalidationCanRaster) { |
281 // This test makes sure that if part of the page is frequently invalidated | 281 // This test makes sure that if part of the page is frequently invalidated |
282 // and doesn't get re-recorded, then CanRaster is not true for any | 282 // and doesn't get re-recorded, then CanRaster is not true for any |
283 // tiles touching it, but is true for adjacent tiles, even if it | 283 // tiles touching it, but is true for adjacent tiles, even if it |
284 // overlaps on borders (edge case). | 284 // overlaps on borders (edge case). |
285 gfx::Rect new_tiling_rect = | 285 gfx::Rect new_tiling_rect = |
286 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); | 286 gfx::ToEnclosedRect(gfx::ScaleRect(pile_->tiling_rect(), 4.f)); |
287 pile_->SetTilingRect(new_tiling_rect); | 287 SetTilingRect(new_tiling_rect); |
288 | 288 |
289 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); | 289 gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1); |
290 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); | 290 gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2); |
291 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); | 291 gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1); |
292 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); | 292 gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2); |
293 | 293 |
294 // Sanity check these two tiles are overlapping with borders, since this is | 294 // Sanity check these two tiles are overlapping with borders, since this is |
295 // what the test is trying to repro. | 295 // what the test is trying to repro. |
296 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); | 296 EXPECT_TRUE(tile01_borders.Intersects(tile02_borders)); |
297 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); | 297 EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders)); |
298 UpdateWholePile(); | 298 UpdateWholePile(); |
299 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 299 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
300 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 300 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
301 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); | 301 EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders)); |
302 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 302 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
303 // Sanity check that an initial paint goes down the fast path of having | 303 // Sanity check that an initial paint goes down the fast path of having |
304 // a valid recorded viewport. | 304 // a valid recorded viewport. |
305 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 305 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
306 | 306 |
307 // Update the whole layer until the invalidation frequency is high. | 307 // Update the whole layer until the invalidation frequency is high. |
308 for (int frame = 0; frame < 33; ++frame) { | 308 for (int frame = 0; frame < 33; ++frame) { |
309 UpdateWholePile(); | 309 UpdateWholePile(); |
310 } | 310 } |
311 | 311 |
312 // Update once more with a small viewport. | 312 // Update once more with a small viewport. |
313 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); | 313 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); |
314 Region invalidation(tiling_rect()); | 314 Region invalidation(tiling_rect()); |
315 UpdateAndExpandInvalidation(&invalidation, viewport); | 315 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), viewport); |
316 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); | 316 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
317 | 317 |
318 // Sanity check some pictures exist and others don't. | 318 // Sanity check some pictures exist and others don't. |
319 EXPECT_TRUE(pile_->picture_map() | 319 EXPECT_TRUE(pile_->picture_map() |
320 .find(TestPicturePile::PictureMapKey(0, 1)) | 320 .find(TestPicturePile::PictureMapKey(0, 1)) |
321 ->second.GetPicture()); | 321 ->second.GetPicture()); |
322 EXPECT_FALSE(pile_->picture_map() | 322 EXPECT_FALSE(pile_->picture_map() |
323 .find(TestPicturePile::PictureMapKey(0, 2)) | 323 .find(TestPicturePile::PictureMapKey(0, 2)) |
324 ->second.GetPicture()); | 324 ->second.GetPicture()); |
325 | 325 |
326 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 326 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
327 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 327 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
328 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); | 328 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); |
329 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 329 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
330 } | 330 } |
331 | 331 |
332 TEST_F(PicturePileTest, NoInvalidationValidViewport) { | 332 TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
333 // This test validates that the recorded_viewport cache of full tiles | 333 // This test validates that the recorded_viewport cache of full tiles |
334 // is still valid for some use cases. If it's not, it's a performance | 334 // is still valid for some use cases. If it's not, it's a performance |
335 // issue because CanRaster checks will go down the slow path. | 335 // issue because CanRaster checks will go down the slow path. |
336 UpdateWholePile(); | |
337 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 336 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
338 | 337 |
339 // No invalidation, same viewport. | 338 // No invalidation, same viewport. |
340 Region invalidation; | 339 Region invalidation; |
341 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); | 340 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), tiling_rect()); |
342 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 341 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
343 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 342 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
344 | 343 |
345 // Partial invalidation, same viewport. | 344 // Partial invalidation, same viewport. |
346 invalidation = gfx::Rect(0, 0, 1, 1); | 345 invalidation = gfx::Rect(0, 0, 1, 1); |
347 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); | 346 UpdateAndExpandInvalidation(&invalidation, tiling_rect(), tiling_rect()); |
348 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 347 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
349 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); | 348 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); |
350 | 349 |
351 // No invalidation, changing viewport. | 350 // No invalidation, changing viewport. |
352 invalidation = Region(); | 351 invalidation = Region(); |
353 UpdateAndExpandInvalidation(&invalidation, gfx::Rect(5, 5, 5, 5)); | 352 UpdateAndExpandInvalidation( |
| 353 &invalidation, tiling_rect(), gfx::Rect(5, 5, 5, 5)); |
354 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 354 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
355 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 355 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
356 } | 356 } |
357 | 357 |
358 TEST_F(PicturePileTest, InvalidationOutsideRecordingRect) { | 358 TEST_F(PicturePileTest, InvalidationOutsideRecordingRect) { |
359 gfx::Rect huge_layer_rect(10000000, 20000000); | 359 gfx::Rect huge_layer_rect(10000000, 20000000); |
360 gfx::Rect viewport(300000, 400000, 5000, 6000); | 360 gfx::Rect viewport(300000, 400000, 5000, 6000); |
361 | 361 |
362 pile_->SetTilingRect(huge_layer_rect); | 362 // Resize the pile and set up the interest rect. |
| 363 Region invalidation; |
| 364 UpdateAndExpandInvalidation(&invalidation, huge_layer_rect, viewport); |
363 | 365 |
364 // Invalidation inside the recording rect does not need to be expanded. | 366 // Invalidation inside the recording rect does not need to be expanded. |
365 Region invalidation = viewport; | 367 invalidation = viewport; |
366 UpdateAndExpandInvalidation(&invalidation, viewport); | 368 UpdateAndExpandInvalidation(&invalidation, huge_layer_rect, viewport); |
367 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); | 369 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); |
368 | 370 |
369 // Invalidation outside the recording rect should expand to the tiles it | 371 // Invalidation outside the recording rect should expand to the tiles it |
370 // covers. | 372 // covers. |
371 gfx::Rect recorded_over_tiles = | 373 gfx::Rect recorded_over_tiles = |
372 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); | 374 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); |
373 gfx::Rect invalidation_outside( | 375 gfx::Rect invalidation_outside( |
374 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); | 376 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); |
375 invalidation = invalidation_outside; | 377 invalidation = invalidation_outside; |
376 UpdateAndExpandInvalidation(&invalidation, viewport); | 378 UpdateAndExpandInvalidation(&invalidation, huge_layer_rect, viewport); |
377 gfx::Rect expanded_recorded_viewport = | 379 gfx::Rect expanded_recorded_viewport = |
378 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); | 380 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); |
379 Region expected_invalidation = | 381 Region expected_invalidation = |
380 pile_->tiling().ExpandRectToTileBounds(invalidation_outside); | 382 pile_->tiling().ExpandRectToTileBounds(invalidation_outside); |
381 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); | 383 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
382 } | 384 } |
383 | 385 |
384 TEST_F(PicturePileTest, ResizePile) { | 386 TEST_F(PicturePileTest, ResizePileOutsideInterestRect) { |
385 gfx::Size tile_size(100, 100); | 387 // This size chosen to be larger than the interest rect size, which is |
386 gfx::Rect base_tiling_rect(5 * 100, 5 * 100); | 388 // at least kPixelDistanceToRecord * 2 in each dimension. |
387 gfx::Rect grow_down_tiling_rect(5 * 100, 7 * 100); | 389 int tile_size = 100000; |
388 gfx::Rect grow_right_tiling_rect(7 * 100, 5 * 100); | 390 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
389 gfx::Rect grow_both_tiling_rect(7 * 100, 7 * 100); | 391 gfx::Rect grow_down_tiling_rect(5 * tile_size, 7 * tile_size); |
| 392 gfx::Rect grow_right_tiling_rect(7 * tile_size, 5 * tile_size); |
| 393 gfx::Rect grow_both_tiling_rect(7 * tile_size, 7 * tile_size); |
390 | 394 |
391 pile_->tiling().SetMaxTextureSize(tile_size); | 395 Region invalidation; |
392 pile_->SetTilingRect(base_tiling_rect); | 396 Region expected_invalidation; |
393 UpdateWholePile(); | 397 |
| 398 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 399 SetTilingRect(base_tiling_rect); |
394 | 400 |
395 // We should have a recording for every tile. | 401 // We should have a recording for every tile. |
396 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 402 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
397 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 403 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
398 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 404 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
399 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 405 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
400 TestPicturePile::PictureMapKey key(i, j); | 406 TestPicturePile::PictureMapKey key(i, j); |
401 TestPicturePile::PictureMap& map = pile_->picture_map(); | 407 TestPicturePile::PictureMap& map = pile_->picture_map(); |
402 TestPicturePile::PictureMap::iterator it = map.find(key); | 408 TestPicturePile::PictureMap::iterator it = map.find(key); |
403 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 409 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
404 } | 410 } |
405 } | 411 } |
406 | 412 |
407 UpdateWholePile(); | 413 UpdateAndExpandInvalidation( |
408 pile_->SetTilingRect(grow_down_tiling_rect); | 414 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
409 | 415 |
410 // We should have lost the recordings in the bottom row. | 416 // We should have lost the recordings in the bottom row. |
411 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 417 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
412 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 418 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
413 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 419 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
414 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 420 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
415 TestPicturePile::PictureMapKey key(i, j); | 421 TestPicturePile::PictureMapKey key(i, j); |
416 TestPicturePile::PictureMap& map = pile_->picture_map(); | 422 TestPicturePile::PictureMap& map = pile_->picture_map(); |
417 TestPicturePile::PictureMap::iterator it = map.find(key); | 423 TestPicturePile::PictureMap::iterator it = map.find(key); |
418 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); | 424 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); |
419 } | 425 } |
420 } | 426 } |
421 | 427 |
| 428 // We invalidated the old bottom row. |
| 429 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), |
| 430 pile_->tiling().TileBounds(5, 5)); |
| 431 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 432 invalidation.Clear(); |
| 433 |
422 UpdateWholePile(); | 434 UpdateWholePile(); |
423 pile_->SetTilingRect(base_tiling_rect); | 435 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
424 | 436 |
425 // We should have lost the recordings that are now outside the tiling only. | 437 // We should have lost the recordings that are now outside the tiling only. |
426 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 438 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
427 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 439 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
428 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 440 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
429 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 441 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
430 TestPicturePile::PictureMapKey key(i, j); | 442 TestPicturePile::PictureMapKey key(i, j); |
431 TestPicturePile::PictureMap& map = pile_->picture_map(); | 443 TestPicturePile::PictureMap& map = pile_->picture_map(); |
432 TestPicturePile::PictureMap::iterator it = map.find(key); | 444 TestPicturePile::PictureMap::iterator it = map.find(key); |
433 EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); | 445 EXPECT_EQ(j < 6, it != map.end() && it->second.GetPicture()); |
434 } | 446 } |
435 } | 447 } |
436 | 448 |
| 449 // No invalidation when shrinking. |
| 450 expected_invalidation.Clear(); |
| 451 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 452 invalidation.Clear(); |
| 453 |
437 UpdateWholePile(); | 454 UpdateWholePile(); |
438 pile_->SetTilingRect(grow_right_tiling_rect); | 455 UpdateAndExpandInvalidation( |
| 456 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
439 | 457 |
440 // We should have lost the recordings in the right column. | 458 // We should have lost the recordings in the right column. |
441 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 459 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
442 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 460 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
443 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 461 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
444 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 462 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
445 TestPicturePile::PictureMapKey key(i, j); | 463 TestPicturePile::PictureMapKey key(i, j); |
446 TestPicturePile::PictureMap& map = pile_->picture_map(); | 464 TestPicturePile::PictureMap& map = pile_->picture_map(); |
447 TestPicturePile::PictureMap::iterator it = map.find(key); | 465 TestPicturePile::PictureMap::iterator it = map.find(key); |
448 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); | 466 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); |
449 } | 467 } |
450 } | 468 } |
451 | 469 |
| 470 // We invalidated the old right column. |
| 471 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 472 pile_->tiling().TileBounds(5, 5)); |
| 473 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 474 invalidation.Clear(); |
| 475 |
452 UpdateWholePile(); | 476 UpdateWholePile(); |
453 pile_->SetTilingRect(base_tiling_rect); | 477 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
454 | 478 |
455 // We should have lost the recordings that are now outside the tiling only. | 479 // We should have lost the recordings that are now outside the tiling only. |
456 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 480 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
457 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 481 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
458 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 482 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
459 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 483 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
460 TestPicturePile::PictureMapKey key(i, j); | 484 TestPicturePile::PictureMapKey key(i, j); |
461 TestPicturePile::PictureMap& map = pile_->picture_map(); | 485 TestPicturePile::PictureMap& map = pile_->picture_map(); |
462 TestPicturePile::PictureMap::iterator it = map.find(key); | 486 TestPicturePile::PictureMap::iterator it = map.find(key); |
463 EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); | 487 EXPECT_EQ(i < 6, it != map.end() && it->second.GetPicture()); |
464 } | 488 } |
465 } | 489 } |
466 | 490 |
| 491 // No invalidation when shrinking. |
| 492 expected_invalidation.Clear(); |
| 493 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 494 invalidation.Clear(); |
| 495 |
467 UpdateWholePile(); | 496 UpdateWholePile(); |
468 pile_->SetTilingRect(grow_both_tiling_rect); | 497 UpdateAndExpandInvalidation( |
| 498 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
469 | 499 |
470 // We should have lost the recordings in the right column and bottom row. | 500 // We should have lost the recordings in the right column and bottom row. |
471 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); | 501 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
472 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); | 502 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
473 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 503 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
474 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 504 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
475 TestPicturePile::PictureMapKey key(i, j); | 505 TestPicturePile::PictureMapKey key(i, j); |
476 TestPicturePile::PictureMap& map = pile_->picture_map(); | 506 TestPicturePile::PictureMap& map = pile_->picture_map(); |
477 TestPicturePile::PictureMap::iterator it = map.find(key); | 507 TestPicturePile::PictureMap::iterator it = map.find(key); |
478 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); | 508 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); |
479 } | 509 } |
480 } | 510 } |
481 | 511 |
| 512 // We invalidated the old right column and the old bottom row. |
| 513 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 514 pile_->tiling().TileBounds(5, 5)); |
| 515 expected_invalidation.Union(gfx::UnionRects( |
| 516 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); |
| 517 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 518 invalidation.Clear(); |
| 519 |
482 UpdateWholePile(); | 520 UpdateWholePile(); |
483 pile_->SetTilingRect(base_tiling_rect); | 521 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect()); |
484 | 522 |
485 // We should have lost the recordings that are now outside the tiling only. | 523 // We should have lost the recordings that are now outside the tiling only. |
486 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 524 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
487 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 525 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
488 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 526 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
489 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 527 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
490 TestPicturePile::PictureMapKey key(i, j); | 528 TestPicturePile::PictureMapKey key(i, j); |
491 TestPicturePile::PictureMap& map = pile_->picture_map(); | 529 TestPicturePile::PictureMap& map = pile_->picture_map(); |
492 TestPicturePile::PictureMap::iterator it = map.find(key); | 530 TestPicturePile::PictureMap::iterator it = map.find(key); |
493 EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); | 531 EXPECT_EQ(i < 6 && j < 6, it != map.end() && it->second.GetPicture()); |
494 } | 532 } |
495 } | 533 } |
| 534 |
| 535 // No invalidation when shrinking. |
| 536 expected_invalidation.Clear(); |
| 537 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 538 invalidation.Clear(); |
496 } | 539 } |
497 | 540 |
498 TEST_F(PicturePileTest, SmallResizePile) { | 541 TEST_F(PicturePileTest, SmallResizePileOutsideInterestRect) { |
499 gfx::Size tile_size(100, 100); | 542 // This size chosen to be larger than the interest rect size, which is |
500 gfx::Rect base_tiling_rect(5 * 100, 5 * 100); | 543 // at least kPixelDistanceToRecord * 2 in each dimension. |
501 gfx::Rect grow_down_tiling_rect(5 * 100, 5 * 100 + 5); | 544 int tile_size = 100000; |
502 gfx::Rect grow_right_tiling_rect(5 * 100 + 5, 5 * 100); | 545 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
503 gfx::Rect grow_both_tiling_rect(5 * 100 + 5, 5 * 100 + 5); | 546 gfx::Rect grow_down_tiling_rect(5 * tile_size, 5 * tile_size + 5); |
| 547 gfx::Rect grow_right_tiling_rect(5 * tile_size + 5, 5 * tile_size); |
| 548 gfx::Rect grow_both_tiling_rect(5 * tile_size + 5, 5 * tile_size + 5); |
504 | 549 |
505 pile_->tiling().SetMaxTextureSize(tile_size); | 550 Region invalidation; |
506 pile_->SetTilingRect(base_tiling_rect); | 551 Region expected_invalidation; |
507 UpdateWholePile(); | 552 |
| 553 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 554 SetTilingRect(base_tiling_rect); |
508 | 555 |
509 // We should have a recording for every tile. | 556 // We should have a recording for every tile. |
510 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 557 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
511 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 558 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
512 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 559 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
513 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 560 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
514 TestPicturePile::PictureMapKey key(i, j); | 561 TestPicturePile::PictureMapKey key(i, j); |
515 TestPicturePile::PictureMap& map = pile_->picture_map(); | 562 TestPicturePile::PictureMap& map = pile_->picture_map(); |
516 TestPicturePile::PictureMap::iterator it = map.find(key); | 563 TestPicturePile::PictureMap::iterator it = map.find(key); |
517 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 564 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
518 } | 565 } |
519 } | 566 } |
520 | 567 |
521 UpdateWholePile(); | 568 UpdateAndExpandInvalidation( |
522 pile_->SetTilingRect(grow_down_tiling_rect); | 569 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
523 | 570 |
524 // We should have lost the recordings in the bottom row. | 571 // We should have lost the recordings in the bottom row. |
525 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 572 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
526 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 573 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
527 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 574 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
528 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 575 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
529 TestPicturePile::PictureMapKey key(i, j); | 576 TestPicturePile::PictureMapKey key(i, j); |
530 TestPicturePile::PictureMap& map = pile_->picture_map(); | 577 TestPicturePile::PictureMap& map = pile_->picture_map(); |
531 TestPicturePile::PictureMap::iterator it = map.find(key); | 578 TestPicturePile::PictureMap::iterator it = map.find(key); |
532 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); | 579 EXPECT_EQ(j < 5, it != map.end() && it->second.GetPicture()); |
533 } | 580 } |
534 } | 581 } |
535 | 582 |
| 583 // We invalidated the bottom row. |
| 584 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), |
| 585 pile_->tiling().TileBounds(5, 5)); |
| 586 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 587 invalidation.Clear(); |
| 588 |
536 UpdateWholePile(); | 589 UpdateWholePile(); |
537 pile_->SetTilingRect(base_tiling_rect); | 590 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
538 | 591 |
539 // We should have lost nothing. | 592 // We should have lost nothing. |
540 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 593 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
541 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 594 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
542 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 595 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
543 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 596 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
544 TestPicturePile::PictureMapKey key(i, j); | 597 TestPicturePile::PictureMapKey key(i, j); |
545 TestPicturePile::PictureMap& map = pile_->picture_map(); | 598 TestPicturePile::PictureMap& map = pile_->picture_map(); |
546 TestPicturePile::PictureMap::iterator it = map.find(key); | 599 TestPicturePile::PictureMap::iterator it = map.find(key); |
547 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 600 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
548 } | 601 } |
549 } | 602 } |
550 | 603 |
| 604 // We invalidated nothing. |
| 605 expected_invalidation.Clear(); |
| 606 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 607 invalidation.Clear(); |
| 608 |
551 UpdateWholePile(); | 609 UpdateWholePile(); |
552 pile_->SetTilingRect(grow_right_tiling_rect); | 610 UpdateAndExpandInvalidation( |
| 611 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
553 | 612 |
554 // We should have lost the recordings in the right column. | 613 // We should have lost the recordings in the right column. |
555 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 614 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
556 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 615 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
557 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 616 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
558 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 617 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
559 TestPicturePile::PictureMapKey key(i, j); | 618 TestPicturePile::PictureMapKey key(i, j); |
560 TestPicturePile::PictureMap& map = pile_->picture_map(); | 619 TestPicturePile::PictureMap& map = pile_->picture_map(); |
561 TestPicturePile::PictureMap::iterator it = map.find(key); | 620 TestPicturePile::PictureMap::iterator it = map.find(key); |
562 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); | 621 EXPECT_EQ(i < 5, it != map.end() && it->second.GetPicture()); |
563 } | 622 } |
564 } | 623 } |
565 | 624 |
| 625 // We invalidated the right column. |
| 626 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 627 pile_->tiling().TileBounds(5, 5)); |
| 628 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 629 invalidation.Clear(); |
| 630 |
566 UpdateWholePile(); | 631 UpdateWholePile(); |
567 pile_->SetTilingRect(base_tiling_rect); | 632 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
568 | 633 |
569 // We should have lost nothing. | 634 // We should have lost nothing. |
570 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 635 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
571 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 636 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
572 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 637 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
573 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 638 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
574 TestPicturePile::PictureMapKey key(i, j); | 639 TestPicturePile::PictureMapKey key(i, j); |
575 TestPicturePile::PictureMap& map = pile_->picture_map(); | 640 TestPicturePile::PictureMap& map = pile_->picture_map(); |
576 TestPicturePile::PictureMap::iterator it = map.find(key); | 641 TestPicturePile::PictureMap::iterator it = map.find(key); |
577 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 642 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
578 } | 643 } |
579 } | 644 } |
580 | 645 |
| 646 // We invalidated nothing. |
| 647 expected_invalidation.Clear(); |
| 648 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 649 invalidation.Clear(); |
| 650 |
581 UpdateWholePile(); | 651 UpdateWholePile(); |
582 pile_->SetTilingRect(grow_both_tiling_rect); | 652 UpdateAndExpandInvalidation( |
| 653 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
583 | 654 |
584 // We should have lost the recordings in the right column and bottom row. | 655 // We should have lost the recordings in the right column and bottom row. |
585 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 656 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
586 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 657 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
587 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 658 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
588 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 659 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
589 TestPicturePile::PictureMapKey key(i, j); | 660 TestPicturePile::PictureMapKey key(i, j); |
590 TestPicturePile::PictureMap& map = pile_->picture_map(); | 661 TestPicturePile::PictureMap& map = pile_->picture_map(); |
591 TestPicturePile::PictureMap::iterator it = map.find(key); | 662 TestPicturePile::PictureMap::iterator it = map.find(key); |
592 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); | 663 EXPECT_EQ(i < 5 && j < 5, it != map.end() && it->second.GetPicture()); |
593 } | 664 } |
594 } | 665 } |
595 | 666 |
| 667 // We invalidated the right column and the bottom row. |
| 668 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 669 pile_->tiling().TileBounds(5, 5)); |
| 670 expected_invalidation.Union(gfx::UnionRects( |
| 671 pile_->tiling().TileBounds(0, 5), pile_->tiling().TileBounds(5, 5))); |
| 672 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 673 invalidation.Clear(); |
| 674 |
596 UpdateWholePile(); | 675 UpdateWholePile(); |
597 pile_->SetTilingRect(base_tiling_rect); | 676 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
598 | 677 |
599 // We should have lost nothing. | 678 // We should have lost nothing. |
600 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); | 679 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
601 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); | 680 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
602 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 681 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
603 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 682 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
604 TestPicturePile::PictureMapKey key(i, j); | 683 TestPicturePile::PictureMapKey key(i, j); |
605 TestPicturePile::PictureMap& map = pile_->picture_map(); | 684 TestPicturePile::PictureMap& map = pile_->picture_map(); |
606 TestPicturePile::PictureMap::iterator it = map.find(key); | 685 TestPicturePile::PictureMap::iterator it = map.find(key); |
607 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 686 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
608 } | 687 } |
609 } | 688 } |
| 689 |
| 690 // We invalidated nothing. |
| 691 expected_invalidation.Clear(); |
| 692 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 693 invalidation.Clear(); |
610 } | 694 } |
611 | 695 |
| 696 TEST_F(PicturePileTest, ResizePileInsideInterestRect) { |
| 697 // This size chosen to be small enough that all the rects below fit inside the |
| 698 // the interest rect, so they are smaller than kPixelDistanceToRecord in each |
| 699 // dimension. |
| 700 int tile_size = 100; |
| 701 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
| 702 gfx::Rect grow_down_tiling_rect(5 * tile_size, 7 * tile_size); |
| 703 gfx::Rect grow_right_tiling_rect(7 * tile_size, 5 * tile_size); |
| 704 gfx::Rect grow_both_tiling_rect(7 * tile_size, 7 * tile_size); |
| 705 |
| 706 Region invalidation; |
| 707 Region expected_invalidation; |
| 708 |
| 709 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 710 SetTilingRect(base_tiling_rect); |
| 711 |
| 712 // We should have a recording for every tile. |
| 713 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 714 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 715 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 716 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 717 TestPicturePile::PictureMapKey key(i, j); |
| 718 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 719 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 720 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 721 } |
| 722 } |
| 723 |
| 724 UpdateAndExpandInvalidation( |
| 725 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
| 726 |
| 727 // We should have a recording for every tile. |
| 728 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 729 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
| 730 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 731 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 732 TestPicturePile::PictureMapKey key(i, j); |
| 733 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 734 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 735 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 736 } |
| 737 } |
| 738 |
| 739 // We invalidated the newly exposed pixels on the bottom row of tiles. |
| 740 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(0, 5), |
| 741 pile_->tiling().TileBounds(5, 5)); |
| 742 expected_invalidation.Subtract(base_tiling_rect); |
| 743 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 744 invalidation.Clear(); |
| 745 |
| 746 UpdateWholePile(); |
| 747 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 748 |
| 749 // We should have a recording for every tile. |
| 750 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 751 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 752 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 753 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 754 TestPicturePile::PictureMapKey key(i, j); |
| 755 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 756 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 757 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 758 } |
| 759 } |
| 760 |
| 761 // No invalidation when shrinking. |
| 762 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 763 invalidation.Clear(); |
| 764 |
| 765 UpdateWholePile(); |
| 766 UpdateAndExpandInvalidation( |
| 767 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
| 768 |
| 769 // We should have a recording for every tile. |
| 770 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
| 771 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 772 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 773 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 774 TestPicturePile::PictureMapKey key(i, j); |
| 775 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 776 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 777 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 778 } |
| 779 } |
| 780 |
| 781 // We invalidated the newly exposed pixels on the right column of tiles. |
| 782 expected_invalidation = gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 783 pile_->tiling().TileBounds(5, 5)); |
| 784 expected_invalidation.Subtract(base_tiling_rect); |
| 785 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 786 invalidation.Clear(); |
| 787 |
| 788 UpdateWholePile(); |
| 789 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 790 |
| 791 // We should have lost the recordings that are now outside the tiling only. |
| 792 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 793 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 794 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 795 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 796 TestPicturePile::PictureMapKey key(i, j); |
| 797 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 798 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 799 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 800 } |
| 801 } |
| 802 |
| 803 // No invalidation when shrinking. |
| 804 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 805 invalidation.Clear(); |
| 806 |
| 807 UpdateWholePile(); |
| 808 UpdateAndExpandInvalidation( |
| 809 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
| 810 |
| 811 // We should have a recording for every tile. |
| 812 EXPECT_EQ(8, pile_->tiling().num_tiles_x()); |
| 813 EXPECT_EQ(8, pile_->tiling().num_tiles_y()); |
| 814 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 815 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 816 TestPicturePile::PictureMapKey key(i, j); |
| 817 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 818 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 819 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 820 } |
| 821 } |
| 822 |
| 823 // We invalidated the newly exposed pixels on the bottom row and right column |
| 824 // of tiles. |
| 825 expected_invalidation = |
| 826 UnionRegions(gfx::UnionRects(pile_->tiling().TileBounds(5, 0), |
| 827 pile_->tiling().TileBounds(5, 5)), |
| 828 gfx::UnionRects(pile_->tiling().TileBounds(0, 5), |
| 829 pile_->tiling().TileBounds(5, 5))); |
| 830 expected_invalidation.Subtract(base_tiling_rect); |
| 831 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 832 invalidation.Clear(); |
| 833 |
| 834 UpdateWholePile(); |
| 835 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect()); |
| 836 |
| 837 // We should have lost the recordings that are now outside the tiling only. |
| 838 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 839 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 840 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 841 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 842 TestPicturePile::PictureMapKey key(i, j); |
| 843 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 844 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 845 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 846 } |
| 847 } |
| 848 |
| 849 // No invalidation when shrinking. |
| 850 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 851 invalidation.Clear(); |
| 852 } |
| 853 |
| 854 TEST_F(PicturePileTest, SmallResizePileInsideInterestRect) { |
| 855 // This size chosen to be small enough that all the rects below fit inside the |
| 856 // the interest rect, so they are smaller than kPixelDistanceToRecord in each |
| 857 // dimension. |
| 858 int tile_size = 100; |
| 859 gfx::Rect base_tiling_rect(5 * tile_size, 5 * tile_size); |
| 860 gfx::Rect grow_down_tiling_rect(5 * tile_size, 5 * tile_size + 5); |
| 861 gfx::Rect grow_right_tiling_rect(5 * tile_size + 5, 5 * tile_size); |
| 862 gfx::Rect grow_both_tiling_rect(5 * tile_size + 5, 5 * tile_size + 5); |
| 863 |
| 864 Region invalidation; |
| 865 Region expected_invalidation; |
| 866 |
| 867 pile_->tiling().SetMaxTextureSize(gfx::Size(tile_size, tile_size)); |
| 868 SetTilingRect(base_tiling_rect); |
| 869 |
| 870 // We should have a recording for every tile. |
| 871 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 872 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 873 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 874 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 875 TestPicturePile::PictureMapKey key(i, j); |
| 876 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 877 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 878 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 879 } |
| 880 } |
| 881 |
| 882 UpdateAndExpandInvalidation( |
| 883 &invalidation, grow_down_tiling_rect, gfx::Rect(1, 1)); |
| 884 |
| 885 // We should have a recording for every tile. |
| 886 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 887 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 888 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 889 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 890 TestPicturePile::PictureMapKey key(i, j); |
| 891 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 892 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 893 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 894 } |
| 895 } |
| 896 |
| 897 // We invalidated the newly exposed pixels. |
| 898 expected_invalidation = |
| 899 SubtractRegions(grow_down_tiling_rect, base_tiling_rect); |
| 900 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 901 invalidation.Clear(); |
| 902 |
| 903 UpdateWholePile(); |
| 904 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 905 |
| 906 // We should have a recording for every tile. |
| 907 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 908 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 909 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 910 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 911 TestPicturePile::PictureMapKey key(i, j); |
| 912 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 913 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 914 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 915 } |
| 916 } |
| 917 |
| 918 // No invalidation when shrinking. |
| 919 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 920 invalidation.Clear(); |
| 921 |
| 922 UpdateWholePile(); |
| 923 UpdateAndExpandInvalidation( |
| 924 &invalidation, grow_right_tiling_rect, gfx::Rect(1, 1)); |
| 925 |
| 926 // We should have a recording for every tile. |
| 927 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 928 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 929 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 930 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 931 TestPicturePile::PictureMapKey key(i, j); |
| 932 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 933 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 934 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 935 } |
| 936 } |
| 937 |
| 938 // We invalidated the newly exposed pixels. |
| 939 expected_invalidation = |
| 940 SubtractRegions(grow_right_tiling_rect, base_tiling_rect); |
| 941 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 942 invalidation.Clear(); |
| 943 |
| 944 UpdateWholePile(); |
| 945 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect(1, 1)); |
| 946 |
| 947 // We should have lost the recordings that are now outside the tiling only. |
| 948 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 949 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 950 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 951 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 952 TestPicturePile::PictureMapKey key(i, j); |
| 953 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 954 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 955 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 956 } |
| 957 } |
| 958 |
| 959 // No invalidation when shrinking. |
| 960 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 961 invalidation.Clear(); |
| 962 |
| 963 UpdateWholePile(); |
| 964 UpdateAndExpandInvalidation( |
| 965 &invalidation, grow_both_tiling_rect, gfx::Rect(1, 1)); |
| 966 |
| 967 // We should have a recording for every tile. |
| 968 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 969 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 970 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 971 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 972 TestPicturePile::PictureMapKey key(i, j); |
| 973 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 974 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 975 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 976 } |
| 977 } |
| 978 |
| 979 // We invalidated the newly exposed pixels. |
| 980 expected_invalidation = |
| 981 SubtractRegions(grow_both_tiling_rect, base_tiling_rect); |
| 982 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 983 invalidation.Clear(); |
| 984 |
| 985 UpdateWholePile(); |
| 986 UpdateAndExpandInvalidation(&invalidation, base_tiling_rect, gfx::Rect()); |
| 987 |
| 988 // We should have lost the recordings that are now outside the tiling only. |
| 989 EXPECT_EQ(6, pile_->tiling().num_tiles_x()); |
| 990 EXPECT_EQ(6, pile_->tiling().num_tiles_y()); |
| 991 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
| 992 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
| 993 TestPicturePile::PictureMapKey key(i, j); |
| 994 TestPicturePile::PictureMap& map = pile_->picture_map(); |
| 995 TestPicturePile::PictureMap::iterator it = map.find(key); |
| 996 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
| 997 } |
| 998 } |
| 999 |
| 1000 // No invalidation when shrinking. |
| 1001 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 1002 invalidation.Clear(); |
| 1003 } |
| 1004 |
612 } // namespace | 1005 } // namespace |
613 } // namespace cc | 1006 } // namespace cc |
OLD | NEW |