Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: trunk/src/cc/resources/picture_pile_unittest.cc

Issue 347493002: Revert 277964 "cc: In SyncFromActiveLayer, drop all tiles not in..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/cc/resources/picture_pile_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 UpdateAndExpandInvalidation(Region* invalidation, 54 bool Update(const Region& invalidation, const gfx::Rect& visible_layer_rect) {
55 const gfx::Rect& visible_layer_rect) {
56 frame_number_++; 55 frame_number_++;
57 return pile_->UpdateAndExpandInvalidation(&client_, 56 return pile_->Update(&client_,
58 invalidation, 57 background_color_,
59 background_color_, 58 contents_opaque_,
60 contents_opaque_, 59 false,
61 false, 60 invalidation,
62 visible_layer_rect, 61 visible_layer_rect,
63 frame_number_, 62 frame_number_,
64 Picture::RECORD_NORMALLY, 63 Picture::RECORD_NORMALLY,
65 &stats_instrumentation_); 64 &stats_instrumentation_);
66 } 65 }
67 66
68 bool UpdateWholePile() { 67 bool UpdateWholePile() { return Update(tiling_rect(), tiling_rect()); }
69 Region invalidation = tiling_rect();
70 bool result = UpdateAndExpandInvalidation(&invalidation, tiling_rect());
71 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString());
72 return result;
73 }
74 68
75 FakeContentLayerClient client_; 69 FakeContentLayerClient client_;
76 FakeRenderingStatsInstrumentation stats_instrumentation_; 70 FakeRenderingStatsInstrumentation stats_instrumentation_;
77 scoped_refptr<TestPicturePile> pile_; 71 scoped_refptr<TestPicturePile> pile_;
78 SkColor background_color_; 72 SkColor background_color_;
79 float min_scale_; 73 float min_scale_;
80 int frame_number_; 74 int frame_number_;
81 bool contents_opaque_; 75 bool contents_opaque_;
82 }; 76 };
83 77
84 TEST_F(PicturePileTest, SmallInvalidateInflated) { 78 TEST_F(PicturePileTest, SmallInvalidateInflated) {
85 UpdateWholePile(); 79 UpdateWholePile();
86 80
87 // Invalidate something inside a tile. 81 // Invalidate something inside a tile.
88 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); 82 gfx::Rect invalidate_rect(50, 50, 1, 1);
89 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); 83 Update(invalidate_rect, tiling_rect());
90 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString());
91 84
92 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); 85 EXPECT_EQ(1, pile_->tiling().num_tiles_x());
93 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); 86 EXPECT_EQ(1, pile_->tiling().num_tiles_y());
94 87
95 TestPicturePile::PictureInfo& picture_info = 88 TestPicturePile::PictureInfo& picture_info =
96 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; 89 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second;
97 // We should have a picture. 90 // We should have a picture.
98 EXPECT_TRUE(!!picture_info.GetPicture()); 91 EXPECT_TRUE(!!picture_info.GetPicture());
99 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect( 92 gfx::Rect picture_rect = gfx::ScaleToEnclosedRect(
100 picture_info.GetPicture()->LayerRect(), min_scale_); 93 picture_info.GetPicture()->LayerRect(), min_scale_);
101 94
102 // The the picture should be large enough that scaling it never makes a rect 95 // The the picture should be large enough that scaling it never makes a rect
103 // smaller than 1 px wide or tall. 96 // smaller than 1 px wide or tall.
104 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << 97 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " <<
105 picture_rect.ToString(); 98 picture_rect.ToString();
106 } 99 }
107 100
108 TEST_F(PicturePileTest, LargeInvalidateInflated) { 101 TEST_F(PicturePileTest, LargeInvalidateInflated) {
109 UpdateWholePile(); 102 UpdateWholePile();
110 103
111 // Invalidate something inside a tile. 104 // Invalidate something inside a tile.
112 Region invalidate_rect(gfx::Rect(50, 50, 100, 100)); 105 gfx::Rect invalidate_rect(50, 50, 100, 100);
113 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect()); 106 Update(invalidate_rect, tiling_rect());
114 EXPECT_EQ(gfx::Rect(50, 50, 100, 100).ToString(), invalidate_rect.ToString());
115 107
116 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); 108 EXPECT_EQ(1, pile_->tiling().num_tiles_x());
117 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); 109 EXPECT_EQ(1, pile_->tiling().num_tiles_y());
118 110
119 TestPicturePile::PictureInfo& picture_info = 111 TestPicturePile::PictureInfo& picture_info =
120 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second; 112 pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second;
121 EXPECT_TRUE(!!picture_info.GetPicture()); 113 EXPECT_TRUE(!!picture_info.GetPicture());
122 114
123 int expected_inflation = pile_->buffer_pixels(); 115 int expected_inflation = pile_->buffer_pixels();
124 116
(...skipping 19 matching lines...) Expand all
144 136
145 // Update the whole layer to create initial pictures. 137 // Update the whole layer to create initial pictures.
146 UpdateWholePile(); 138 UpdateWholePile();
147 139
148 // Invalidate everything again to have a non zero invalidation 140 // Invalidate everything again to have a non zero invalidation
149 // frequency. 141 // frequency.
150 UpdateWholePile(); 142 UpdateWholePile();
151 143
152 // Invalidate something just over a tile boundary by a single pixel. 144 // 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). 145 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0).
154 Region invalidate_rect( 146 gfx::Rect invalidate_rect(
155 gfx::Rect(pile_->tiling().TileBoundsWithBorder(0, 0).right(), 147 pile_->tiling().TileBoundsWithBorder(0, 0).right(),
156 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, 148 pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1,
157 50, 149 50,
158 50)); 150 50);
159 Region expected_invalidation = invalidate_rect; 151 Update(invalidate_rect, tiling_rect());
160 UpdateAndExpandInvalidation(&invalidate_rect, tiling_rect());
161 EXPECT_EQ(expected_invalidation.ToString(), invalidate_rect.ToString());
162 152
163 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { 153 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
164 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { 154 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
165 TestPicturePile::PictureInfo& picture_info = 155 TestPicturePile::PictureInfo& picture_info =
166 pile_->picture_map() 156 pile_->picture_map()
167 .find(TestPicturePile::PictureMapKey(i, j)) 157 .find(TestPicturePile::PictureMapKey(i, j))
168 ->second; 158 ->second;
169 159
170 // Expect (1, 1) and (1, 0) to be invalidated once more 160 // Expect (1, 1) and (1, 0) to be invalidated once more
171 // than the rest of the tiles. 161 // than the rest of the tiles.
(...skipping 28 matching lines...) Expand all
200 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { 190 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
201 TestPicturePile::PictureInfo& picture_info = 191 TestPicturePile::PictureInfo& picture_info =
202 pile_->picture_map() 192 pile_->picture_map()
203 .find(TestPicturePile::PictureMapKey(i, j)) 193 .find(TestPicturePile::PictureMapKey(i, j))
204 ->second; 194 ->second;
205 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()) 195 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting())
206 << "i " << i << " j " << j; 196 << "i " << i << " j " << j;
207 } 197 }
208 } 198 }
209 199
210 // Update once more with a small viewport. 200 // Update once more with a small viewport tiilng_rect.x(), tiilng_rect.y(),
211 Region invalidation = tiling_rect(); 201 // tiling_rect.width() by 1
212 UpdateAndExpandInvalidation(&invalidation, viewport); 202 Update(tiling_rect(), viewport);
213 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString());
214 203
215 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { 204 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
216 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { 205 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
217 TestPicturePile::PictureInfo& picture_info = 206 TestPicturePile::PictureInfo& picture_info =
218 pile_->picture_map() 207 pile_->picture_map()
219 .find(TestPicturePile::PictureMapKey(i, j)) 208 .find(TestPicturePile::PictureMapKey(i, j))
220 ->second; 209 ->second;
221 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting()); 210 EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting());
222 211
223 // If the y far enough away we expect to find no picture (no re-recording 212 // If the y far enough away we expect to find no picture (no re-recording
224 // happened). For close y, the picture should change. 213 // happened). For close y, the picture should change.
225 if (j >= 2) 214 if (j >= 2)
226 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j; 215 EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j;
227 else 216 else
228 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; 217 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j;
229 } 218 }
230 } 219 }
231 220
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
244 // Now update with no invalidation and full viewport 221 // Now update with no invalidation and full viewport
245 Region empty_invalidation; 222 Update(gfx::Rect(), tiling_rect());
246 UpdateAndExpandInvalidation(&empty_invalidation, tiling_rect());
247 EXPECT_EQ(Region().ToString(), empty_invalidation.ToString());
248 223
249 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) { 224 for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
250 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) { 225 for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
251 TestPicturePile::PictureInfo& picture_info = 226 TestPicturePile::PictureInfo& picture_info =
252 pile_->picture_map() 227 pile_->picture_map()
253 .find(TestPicturePile::PictureMapKey(i, j)) 228 .find(TestPicturePile::PictureMapKey(i, j))
254 ->second; 229 ->second;
255 // Expect the invalidation frequency to be less than 1, since we just 230 // Expect the invalidation frequency to be less than 1, since we just
256 // updated with no invalidations. 231 // updated with no invalidations.
257 EXPECT_LT(picture_info.GetInvalidationFrequencyForTesting(), 1.f); 232 float expected_frequency =
233 1.0f -
234 1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED;
235
236 EXPECT_FLOAT_EQ(expected_frequency,
237 picture_info.GetInvalidationFrequencyForTesting());
258 238
259 // We expect that there are pictures everywhere now. 239 // We expect that there are pictures everywhere now.
260 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j; 240 EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j;
261 } 241 }
262 } 242 }
263 } 243 }
264 244
265 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) { 245 TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) {
266 UpdateWholePile(); 246 UpdateWholePile();
267 247
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // a valid recorded viewport. 284 // a valid recorded viewport.
305 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); 285 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
306 286
307 // Update the whole layer until the invalidation frequency is high. 287 // Update the whole layer until the invalidation frequency is high.
308 for (int frame = 0; frame < 33; ++frame) { 288 for (int frame = 0; frame < 33; ++frame) {
309 UpdateWholePile(); 289 UpdateWholePile();
310 } 290 }
311 291
312 // Update once more with a small viewport. 292 // Update once more with a small viewport.
313 gfx::Rect viewport(0, 0, tiling_rect().width(), 1); 293 gfx::Rect viewport(0, 0, tiling_rect().width(), 1);
314 Region invalidation(tiling_rect()); 294 Update(tiling_rect(), viewport);
315 UpdateAndExpandInvalidation(&invalidation, viewport);
316 EXPECT_EQ(tiling_rect().ToString(), invalidation.ToString());
317 295
318 // Sanity check some pictures exist and others don't. 296 // Sanity check some pictures exist and others don't.
319 EXPECT_TRUE(pile_->picture_map() 297 EXPECT_TRUE(pile_->picture_map()
320 .find(TestPicturePile::PictureMapKey(0, 1)) 298 .find(TestPicturePile::PictureMapKey(0, 1))
321 ->second.GetPicture()); 299 ->second.GetPicture());
322 EXPECT_FALSE(pile_->picture_map() 300 EXPECT_FALSE(pile_->picture_map()
323 .find(TestPicturePile::PictureMapKey(0, 2)) 301 .find(TestPicturePile::PictureMapKey(0, 2))
324 ->second.GetPicture()); 302 ->second.GetPicture());
325 303
326 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders)); 304 EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders));
327 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders)); 305 EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders));
328 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders)); 306 EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders));
329 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders)); 307 EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders));
330 } 308 }
331 309
332 TEST_F(PicturePileTest, NoInvalidationValidViewport) { 310 TEST_F(PicturePileTest, NoInvalidationValidViewport) {
333 // This test validates that the recorded_viewport cache of full tiles 311 // 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 312 // 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. 313 // issue because CanRaster checks will go down the slow path.
336 UpdateWholePile(); 314 UpdateWholePile();
337 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); 315 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
338 316
339 // No invalidation, same viewport. 317 // No invalidation, same viewport.
340 Region invalidation; 318 Update(gfx::Rect(), tiling_rect());
341 UpdateAndExpandInvalidation(&invalidation, tiling_rect());
342 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); 319 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
343 EXPECT_EQ(Region().ToString(), invalidation.ToString());
344 320
345 // Partial invalidation, same viewport. 321 // Partial invalidation, same viewport.
346 invalidation = gfx::Rect(0, 0, 1, 1); 322 Update(gfx::Rect(gfx::Rect(0, 0, 1, 1)), tiling_rect());
347 UpdateAndExpandInvalidation(&invalidation, tiling_rect());
348 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); 323 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
349 EXPECT_EQ(gfx::Rect(0, 0, 1, 1).ToString(), invalidation.ToString());
350 324
351 // No invalidation, changing viewport. 325 // No invalidation, changing viewport.
352 invalidation = Region(); 326 Update(gfx::Rect(), gfx::Rect(5, 5, 5, 5));
353 UpdateAndExpandInvalidation(&invalidation, gfx::Rect(5, 5, 5, 5));
354 EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty()); 327 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());
382 } 328 }
383 329
384 } // namespace 330 } // namespace
385 } // namespace cc 331 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/resources/picture_pile_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698