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(tiling_rect().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(tiling_rect().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 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); |
| 160 |
| 161 gfx::Rect expected_invalidation = |
| 162 gfx::UnionRects(pile_->tiling().TileBoundsWithBorder(1, 1), |
| 163 pile_->tiling().TileBoundsWithBorder(1, 0)); |
| 164 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString()); |
152 | 165 |
153 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 166 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
154 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 167 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
155 TestPicturePile::PictureInfo& picture_info = | 168 TestPicturePile::PictureInfo& picture_info = |
156 pile_->picture_map() | 169 pile_->picture_map() |
157 .find(TestPicturePile::PictureMapKey(i, j)) | 170 .find(TestPicturePile::PictureMapKey(i, j)) |
158 ->second; | 171 ->second; |
159 | 172 |
160 // Expect (1, 1) and (1, 0) to be invalidated once more | 173 // Expect (1, 1) and (1, 0) to be invalidated once more |
161 // than the rest of the tiles. | 174 // 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) { | 203 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
191 TestPicturePile::PictureInfo& picture_info = | 204 TestPicturePile::PictureInfo& picture_info = |
192 pile_->picture_map() | 205 pile_->picture_map() |
193 .find(TestPicturePile::PictureMapKey(i, j)) | 206 .find(TestPicturePile::PictureMapKey(i, j)) |
194 ->second; | 207 ->second; |
195 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) | 208 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) |
196 << "i " << i << " j " << j; | 209 << "i " << i << " j " << j; |
197 } | 210 } |
198 } | 211 } |
199 | 212 |
200 // Update once more with a small viewport tiilng_rect.x(), tiilng_rect.y(), | 213 // Update once more with a small viewport tiilng_rect.x(), tiling_rect.y(), |
201 // tiling_rect.width() by 1 | 214 // tiling_rect.width() by 1. |
202 Update(tiling_rect(), viewport); | 215 Region invalidation = tiling_rect(); |
| 216 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 217 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
203 | 218 |
204 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 219 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
205 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 220 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
206 TestPicturePile::PictureInfo& picture_info = | 221 TestPicturePile::PictureInfo& picture_info = |
207 pile_->picture_map() | 222 pile_->picture_map() |
208 .find(TestPicturePile::PictureMapKey(i, j)) | 223 .find(TestPicturePile::PictureMapKey(i, j)) |
209 ->second; | 224 ->second; |
210 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); | 225 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); |
211 | 226 |
212 // If the y far enough away we expect to find no picture (no re-recording | 227 // If the y far enough away we expect to find no picture (no re-recording |
213 // happened). For close y, the picture should change. | 228 // happened). For close y, the picture should change. |
214 if (j >= 2) | 229 if (j >= 2) |
215 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; | 230 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; |
216 else | 231 else |
217 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; | 232 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; |
218 } | 233 } |
219 } | 234 } |
220 | 235 |
221 // Now update with no invalidation and full viewport | 236 // Now update with no invalidation and full viewport |
222 Update(gfx::Rect(), tiling_rect()); | 237 Region empty_invalidation; |
| 238 UpdateAndExpandInvalidation(&empty_invalidation, tiling_rect()); |
| 239 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString()); |
223 | 240 |
224 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { | 241 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { |
225 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { | 242 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { |
226 TestPicturePile::PictureInfo& picture_info = | 243 TestPicturePile::PictureInfo& picture_info = |
227 pile_->picture_map() | 244 pile_->picture_map() |
228 .find(TestPicturePile::PictureMapKey(i, j)) | 245 .find(TestPicturePile::PictureMapKey(i, j)) |
229 ->second; | 246 ->second; |
230 // Expect the invalidation frequency to be less than 1, since we just | 247 // Expect the invalidation frequency to be less than 1, since we just |
231 // updated with no invalidations. | 248 // updated with no invalidations. |
232 float expected_frequency = | 249 float expected_frequency = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // a valid recorded viewport. | 301 // a valid recorded viewport. |
285 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 302 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
286 | 303 |
287 // Update the whole layer until the invalidation frequency is high. | 304 // Update the whole layer until the invalidation frequency is high. |
288 for (int frame = 0; frame < 33; ++frame) { | 305 for (int frame = 0; frame < 33; ++frame) { |
289 UpdateWholePile(); | 306 UpdateWholePile(); |
290 } | 307 } |
291 | 308 |
292 // Update once more with a small viewport. | 309 // Update once more with a small viewport. |
293 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); | 310 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); |
294 Update(tiling_rect(), viewport); | 311 Region invalidation(tiling_rect()); |
| 312 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 313 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString()); |
295 | 314 |
296 // Sanity check some pictures exist and others don't. | 315 // Sanity check some pictures exist and others don't. |
297 EXPECT_TRUE(pile_->picture_map() | 316 EXPECT_TRUE(pile_->picture_map() |
298 .find(TestPicturePile::PictureMapKey(0, 1)) | 317 .find(TestPicturePile::PictureMapKey(0, 1)) |
299 ->second.GetPicture()); | 318 ->second.GetPicture()); |
300 EXPECT_FALSE(pile_->picture_map() | 319 EXPECT_FALSE(pile_->picture_map() |
301 .find(TestPicturePile::PictureMapKey(0, 2)) | 320 .find(TestPicturePile::PictureMapKey(0, 2)) |
302 ->second.GetPicture()); | 321 ->second.GetPicture()); |
303 | 322 |
304 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); | 323 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); |
305 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); | 324 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); |
306 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); | 325 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); |
307 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); | 326 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); |
308 } | 327 } |
309 | 328 |
310 TEST_F(PicturePileTest, NoInvalidationValidViewport) { | 329 TEST_F(PicturePileTest, NoInvalidationValidViewport) { |
311 // This test validates that the recorded_viewport cache of full tiles | 330 // 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 | 331 // 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. | 332 // issue because CanRaster checks will go down the slow path. |
314 UpdateWholePile(); | 333 UpdateWholePile(); |
315 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 334 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
316 | 335 |
317 // No invalidation, same viewport. | 336 // No invalidation, same viewport. |
318 Update(gfx::Rect(), tiling_rect()); | 337 Region invalidation; |
| 338 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); |
319 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 339 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 340 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
320 | 341 |
321 // Partial invalidation, same viewport. | 342 // Partial invalidation, same viewport. |
322 Update(gfx::Rect(gfx::Rect(0, 0, 1, 1)), tiling_rect()); | 343 invalidation = gfx::Rect(0, 0, 1, 1); |
| 344 UpdateAndExpandInvalidation(&invalidation, tiling_rect()); |
323 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 345 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 346 EXPECT_EQ(pile_->tiling().TileBounds(0, 0).ToString(), |
| 347 invalidation.ToString()); |
324 | 348 |
325 // No invalidation, changing viewport. | 349 // No invalidation, changing viewport. |
326 Update(gfx::Rect(), gfx::Rect(5, 5, 5, 5)); | 350 invalidation = Region(); |
| 351 UpdateAndExpandInvalidation(&invalidation, gfx::Rect(5, 5, 5, 5)); |
327 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); | 352 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); |
| 353 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
| 354 } |
| 355 |
| 356 TEST_F(PicturePileTest, InvalidateOutsideRecordingViewport) { |
| 357 gfx::Rect huge_page(10000000, 20000000); |
| 358 pile_->SetTilingRect(huge_page); |
| 359 |
| 360 gfx::Rect viewport(8000, 9000, 2000, 2000); |
| 361 |
| 362 // For no invalidation, only the recorded viewport should be |
| 363 // considered as not-potentially-invalid. |
| 364 Region invalidation; |
| 365 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 366 |
| 367 gfx::Rect recording_viewport = pile_->recorded_viewport(); |
| 368 Region expected_invalidation = SubtractRegions(huge_page, recording_viewport); |
| 369 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
| 370 |
| 371 // With some invalidation, that should also be included and expanded to cover |
| 372 // the entire recording tiles it overlaps. |
| 373 gfx::Rect invalid_rect(7080, 10000, 200, 1000); |
| 374 invalidation = invalid_rect; |
| 375 UpdateAndExpandInvalidation(&invalidation, viewport); |
| 376 |
| 377 int left_tile = |
| 378 pile_->tiling().FirstBorderTileXIndexFromSrcCoord(invalid_rect.x()); |
| 379 int top_tile = |
| 380 pile_->tiling().FirstBorderTileYIndexFromSrcCoord(invalid_rect.y()); |
| 381 int right_tile = pile_->tiling().LastBorderTileXIndexFromSrcCoord( |
| 382 invalid_rect.right() - 1); |
| 383 int bottom_tile = pile_->tiling().LastBorderTileYIndexFromSrcCoord( |
| 384 invalid_rect.bottom() - 1); |
| 385 int left = pile_->tiling().TileBoundsWithBorder(left_tile, top_tile).x(); |
| 386 int top = pile_->tiling().TileBoundsWithBorder(left_tile, top_tile).y(); |
| 387 int right = |
| 388 pile_->tiling().TileBoundsWithBorder(right_tile, bottom_tile).right(); |
| 389 int bottom = |
| 390 pile_->tiling().TileBoundsWithBorder(right_tile, bottom_tile).bottom(); |
| 391 expected_invalidation.Union(gfx::Rect(left, top, right - left, bottom - top)); |
| 392 EXPECT_EQ(expected_invalidation.ToString(), invalidation.ToString()); |
328 } | 393 } |
329 | 394 |
330 } // namespace | 395 } // namespace |
331 } // namespace cc | 396 } // namespace cc |
OLD | NEW |