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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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())); | 47 pile_->SetTilingRect(gfx::Rect(pile_->tiling().max_texture_size())); |
48 pile_->SetTileGridSize(gfx::Size(1000, 1000)); | 48 pile_->SetTileGridSize(gfx::Size(1000, 1000)); |
49 pile_->SetMinContentsScale(min_scale_); | 49 pile_->SetMinContentsScale(min_scale_); |
50 } | 50 } |
51 | 51 |
52 gfx::Rect tiling_rect() const { return pile_->tiling_rect(); } | 52 gfx::Rect tiling_rect() const { return pile_->tiling_rect(); } |
53 | 53 |
54 bool Update(const Region& invalidation, const gfx::Rect& visible_layer_rect) { | 54 bool UpdateAndExpandInvalidation(Region* invalidation, |
| 55 const gfx::Rect& visible_layer_rect) { |
55 frame_number_++; | 56 frame_number_++; |
56 return pile_->Update(&client_, | 57 return pile_->UpdateAndExpandInvalidation(&client_, |
57 background_color_, | 58 invalidation, |
58 contents_opaque_, | 59 background_color_, |
59 false, | 60 contents_opaque_, |
60 invalidation, | 61 false, |
61 visible_layer_rect, | 62 visible_layer_rect, |
62 frame_number_, | 63 frame_number_, |
63 Picture::RECORD_NORMALLY, | 64 Picture::RECORD_NORMALLY, |
64 &stats_instrumentation_); | 65 &stats_instrumentation_); |
65 } | 66 } |
66 | 67 |
67 bool UpdateWholePile() { return Update(tiling_rect(), tiling_rect()); } | 68 bool UpdateWholePile() { |
| 69 Region invalidation = tiling_rect(); |
| 70 bool result = UpdateAndExpandInvalidation(&invalidation, tiling_rect()); |
| 71 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
| 72 return result; |
| 73 } |
68 | 74 |
69 FakeContentLayerClient client_; | 75 FakeContentLayerClient client_; |
70 FakeRenderingStatsInstrumentation stats_instrumentation_; | 76 FakeRenderingStatsInstrumentation stats_instrumentation_; |
71 scoped_refptr<TestPicturePile> pile_; | 77 scoped_refptr<TestPicturePile> pile_; |
72 SkColor background_color_; | 78 SkColor background_color_; |
73 float min_scale_; | 79 float min_scale_; |
74 int frame_number_; | 80 int frame_number_; |
75 bool contents_opaque_; | 81 bool contents_opaque_; |
76 }; | 82 }; |
77 | 83 |
78 TEST_F(PicturePileTest, SmallInvalidateInflated) { | 84 TEST_F(PicturePileTest, SmallInvalidateInflated) { |
79 UpdateWholePile(); | 85 UpdateWholePile(); |
80 | 86 |
81 // Invalidate something inside a tile. | 87 // Invalidate something inside a tile. |
82 gfx::Rect invalidate_rect(50, 50, 1, 1); | 88 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); |
83 Update(invalidate_rect, tiling_rect()); | 89 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); |
| 90 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); |
84 | 91 |
85 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 92 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
86 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 93 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
87 | 94 |
88 TestPicturePile::PictureInfo& picture_info = | 95 TestPicturePile::PictureInfo& picture_info = |
89 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 96 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
90 // We should have a picture. | 97 // We should have a picture. |
91 EXPECT_TRUE(!!picture_info.GetPicture()); | 98 EXPECT_TRUE(!!picture_info.GetPicture()); |
92 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( | 99 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( |
93 picture_info.GetPicture()->LayerRect(), min_scale_); | 100 picture_info.GetPicture()->LayerRect(), min_scale_); |
94 | 101 |
95 // The the picture should be large enough that scaling it never makes a rect | 102 // The the picture should be large enough that scaling it never makes a rect |
96 // smaller than 1 px wide or tall. | 103 // smaller than 1 px wide or tall. |
97 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | 104 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << |
98 picture_rect.ToString(); | 105 picture_rect.ToString(); |
99 } | 106 } |
100 | 107 |
101 TEST_F(PicturePileTest, LargeInvalidateInflated) { | 108 TEST_F(PicturePileTest, LargeInvalidateInflated) { |
102 UpdateWholePile(); | 109 UpdateWholePile(); |
103 | 110 |
104 // Invalidate something inside a tile. | 111 // Invalidate something inside a tile. |
105 gfx::Rect invalidate_rect(50, 50, 100, 100); | 112 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); |
106 Update(invalidate_rect, tiling_rect()); | 113 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); |
| 114 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString()); |
107 | 115 |
108 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 116 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
109 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 117 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
110 | 118 |
111 TestPicturePile::PictureInfo& picture_info = | 119 TestPicturePile::PictureInfo& picture_info = |
112 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; | 120 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; |
113 EXPECT_TRUE(!!picture_info.GetPicture()); | 121 EXPECT_TRUE(!!picture_info.GetPicture()); |
114 | 122 |
115 int expected_inflation = pile_->buffer_pixels(); | 123 int expected_inflation = pile_->buffer_pixels(); |
116 | 124 |
(...skipping 19 matching lines...) Expand all Loading... |
136 | 144 |
137 // Update the whole layer to create initial pictures. | 145 // Update the whole layer to create initial pictures. |
138 UpdateWholePile(); | 146 UpdateWholePile(); |
139 | 147 |
140 // Invalidate everything again to have a non zero invalidation | 148 // Invalidate everything again to have a non zero invalidation |
141 // frequency. | 149 // frequency. |
142 UpdateWholePile(); | 150 UpdateWholePile(); |
143 | 151 |
144 // Invalidate something just over a tile boundary by a single pixel. | 152 // Invalidate something just over a tile boundary by a single pixel. |
145 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). | 153 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). |
146 gfx::Rect invalidate_rect( | 154 Region invalidate_rect( |
147 pile_->tiling().TileBoundsWithBorder(0, 0).right(), | 155 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), |
148 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, | 156 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, |
149 50, | 157 50, |
150 50); | 158 50)); |
151 Update(invalidate_rect, tiling_rect()); | 159 Region expected_invalidation = invalidate_rect; |
| 160 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); |
| 161 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); |
152 | 162 |
153 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 163 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
154 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 164 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
155 TestPicturePile::PictureInfo& picture_info = | 165 TestPicturePile::PictureInfo& picture_info = |
156 pile_->picture_map() | 166 pile_->picture_map() |
157 .find(TestPicturePile::PictureMapKey(i, j)) | 167 .find(TestPicturePile::PictureMapKey(i, j)) |
158 ->second; | 168 ->second; |
159 | 169 |
160 // Expect (1, 1) and (1, 0) to be invalidated once more | 170 // Expect (1, 1) and (1, 0) to be invalidated once more |
161 // than the rest of the tiles. | 171 // than the rest of the tiles. |
(...skipping 28 matching lines...) Expand all Loading... |
190 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 200 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
191 TestPicturePile::PictureInfo& picture_info = | 201 TestPicturePile::PictureInfo& picture_info = |
192 pile_->picture_map() | 202 pile_->picture_map() |
193 .find(TestPicturePile::PictureMapKey(i, j)) | 203 .find(TestPicturePile::PictureMapKey(i, j)) |
194 ->second; | 204 ->second; |
195 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) | 205 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) |
196 << "i " << i << " j " << j; | 206 << "i " << i << " j " << j; |
197 } | 207 } |
198 } | 208 } |
199 | 209 |
200 // Update once more with a small viewport tiilng_rect.x(), tiilng_rect.y(), | 210 // Update once more with a small viewport. |
201 // tiling_rect.width() by 1 | 211 Region invalidation = tiling_rect(); |
202 Update(tiling_rect(), viewport); | 212 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 213 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
203 | 214 |
204 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 215 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
205 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 216 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
206 TestPicturePile::PictureInfo& picture_info = | 217 TestPicturePile::PictureInfo& picture_info = |
207 pile_->picture_map() | 218 pile_->picture_map() |
208 .find(TestPicturePile::PictureMapKey(i, j)) | 219 .find(TestPicturePile::PictureMapKey(i, j)) |
209 ->second; | 220 ->second; |
210 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); | 221 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); |
211 | 222 |
212 // If the y far enough away we expect to find no picture (no re-recording | 223 // If the y far enough away we expect to find no picture (no re-recording |
213 // happened). For close y, the picture should change. | 224 // happened). For close y, the picture should change. |
214 if (j >= 2) | 225 if (j >= 2) |
215 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; | 226 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; |
216 else | 227 else |
217 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 228 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
218 } | 229 } |
219 } | 230 } |
220 | 231 |
| 232 // Update a partial tile that doesn't get recorded. We should expand the |
| 233 // invalidation to the entire tiles that overlap it. |
| 234 Region small_invalidation = |
| 235 gfx::Rect(pile_->tiling().TileBounds(3, 4).x(), |
| 236 pile_->tiling().TileBounds(3, 4).y() + 10, |
| 237 1, |
| 238 1); |
| 239 UpdateAndExpandInvalidation(&small_invalidation, viewport); |
| 240 EXPECT_TRUE(small_invalidation.Contains(gfx::UnionRects( |
| 241 pile_->tiling().TileBounds(2, 4), pile_->tiling().TileBounds(3, 4)))) |
| 242 << small_invalidation.ToString(); |
| 243 |
221 // Now update with no invalidation and full viewport | 244 // Now update with no invalidation and full viewport |
222 Update(gfx::Rect(), tiling_rect()); | 245 Region empty_invalidation; |
| 246 UpdateAndExpandInvalidation(&empty_invalidation, tiling_rect()); |
| 247 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); |
223 | 248 |
224 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 249 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
225 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 250 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
226 TestPicturePile::PictureInfo& picture_info = | 251 TestPicturePile::PictureInfo& picture_info = |
227 pile_->picture_map() | 252 pile_->picture_map() |
228 .find(TestPicturePile::PictureMapKey(i, j)) | 253 .find(TestPicturePile::PictureMapKey(i, j)) |
229 ->second; | 254 ->second; |
230 // Expect the invalidation frequency to be less than 1, since we just | 255 // Expect the invalidation frequency to be less than 1, since we just |
231 // updated with no invalidations. | 256 // updated with no invalidations. |
232 float expected_frequency = | 257 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); |
233 1.0f - | |
234 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED; | |
235 | |
236 EXPECT_FLOAT_EQ(expected_frequency, | |
237 picture_info.GetInvalidationFrequencyForTesting()); | |
238 | 258 |
239 // We expect that there are pictures everywhere now. | 259 // We expect that there are pictures everywhere now. |
240 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 260 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
241 } | 261 } |
242 } | 262 } |
243 } | 263 } |
244 | 264 |
245 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { | 265 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { |
246 UpdateWholePile(); | 266 UpdateWholePile(); |
247 | 267 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // a valid recorded viewport. | 304 // a valid recorded viewport. |
285 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 305 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
286 | 306 |
287 // Update the whole layer until the invalidation frequency is high. | 307 // Update the whole layer until the invalidation frequency is high. |
288 for (int frame = 0; frame < 33; ++frame) { | 308 for (int frame = 0; frame < 33; ++frame) { |
289 UpdateWholePile(); | 309 UpdateWholePile(); |
290 } | 310 } |
291 | 311 |
292 // Update once more with a small viewport. | 312 // Update once more with a small viewport. |
293 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); | 313 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); |
294 Update(tiling_rect(), viewport); | 314 Region invalidation(tiling_rect()); |
| 315 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 316 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
295 | 317 |
296 // Sanity check some pictures exist and others don't. | 318 // Sanity check some pictures exist and others don't. |
297 EXPECT_TRUE(pile_->picture_map() | 319 EXPECT_TRUE(pile_->picture_map() |
298 .find(TestPicturePile::PictureMapKey(0, 1)) | 320 .find(TestPicturePile::PictureMapKey(0, 1)) |
299 ->second.GetPicture()); | 321 ->second.GetPicture()); |
300 EXPECT_FALSE(pile_->picture_map() | 322 EXPECT_FALSE(pile_->picture_map() |
301 .find(TestPicturePile::PictureMapKey(0, 2)) | 323 .find(TestPicturePile::PictureMapKey(0, 2)) |
302 ->second.GetPicture()); | 324 ->second.GetPicture()); |
303 | 325 |
304 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 326 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
305 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 327 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
306 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); | 328 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); |
307 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 329 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
308 } | 330 } |
309 | 331 |
310 TEST_F(PicturePileTest, NoInvalidationValidViewport) { | 332 TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
311 // This test validates that the recorded_viewport cache of full tiles | 333 // This test validates that the recorded_viewport cache of full tiles |
312 // 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 |
313 // issue because CanRaster checks will go down the slow path. | 335 // issue because CanRaster checks will go down the slow path. |
314 UpdateWholePile(); | 336 UpdateWholePile(); |
315 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 337 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
316 | 338 |
317 // No invalidation, same viewport. | 339 // No invalidation, same viewport. |
318 Update(gfx::Rect(), tiling_rect()); | 340 Region invalidation; |
| 341 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); |
319 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 342 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 343 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
320 | 344 |
321 // Partial invalidation, same viewport. | 345 // Partial invalidation, same viewport. |
322 Update(gfx::Rect(gfx::Rect(0, 0, 1, 1)), tiling_rect()); | 346 invalidation = gfx::Rect(0, 0, 1, 1); |
| 347 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); |
323 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 348 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 349 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString()); |
324 | 350 |
325 // No invalidation, changing viewport. | 351 // No invalidation, changing viewport. |
326 Update(gfx::Rect(), gfx::Rect(5, 5, 5, 5)); | 352 invalidation = Region(); |
| 353 UpdateAndExpandInvalidation(&invalidation, gfx::Rect(5, 5, 5, 5)); |
327 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 354 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 355 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 356 } |
| 357 |
| 358 TEST_F(PicturePileTest, InvalidationOutsideRecordingRect) { |
| 359 gfx::Rect huge_layer_rect(10000000, 20000000); |
| 360 gfx::Rect viewport(300000, 400000, 5000, 6000); |
| 361 |
| 362 pile_->SetTilingRect(huge_layer_rect); |
| 363 |
| 364 // Invalidation inside the recording rect does not need to be expanded. |
| 365 Region invalidation = viewport; |
| 366 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 367 EXPECT_EQ(viewport.ToString(), invalidation.ToString()); |
| 368 |
| 369 // Invalidation outside the recording rect should expand to the tiles it |
| 370 // covers. |
| 371 gfx::Rect recorded_over_tiles = |
| 372 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); |
| 373 gfx::Rect invalidation_outside( |
| 374 recorded_over_tiles.right(), recorded_over_tiles.y(), 30, 30); |
| 375 invalidation = invalidation_outside; |
| 376 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 377 gfx::Rect expanded_recorded_viewport = |
| 378 pile_->tiling().ExpandRectToTileBounds(pile_->recorded_viewport()); |
| 379 Region expected_invalidation = |
| 380 pile_->tiling().ExpandRectToTileBounds(invalidation_outside); |
| 381 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
328 } | 382 } |
329 | 383 |
330 } // namespace | 384 } // namespace |
331 } // namespace cc | 385 } // namespace cc |
OLD | NEW |