OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 current_frame_time_in_seconds, | 46 current_frame_time_in_seconds, |
47 NULL, | 47 NULL, |
48 NULL, | 48 NULL, |
49 gfx::Transform()); | 49 gfx::Transform()); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 class TestablePictureLayerTiling : public PictureLayerTiling { | 53 class TestablePictureLayerTiling : public PictureLayerTiling { |
54 public: | 54 public: |
55 using PictureLayerTiling::SetLiveTilesRect; | 55 using PictureLayerTiling::SetLiveTilesRect; |
56 using PictureLayerTiling::UpdateTilesToCurrentPile; | |
56 using PictureLayerTiling::TileAt; | 57 using PictureLayerTiling::TileAt; |
57 | 58 |
58 static scoped_ptr<TestablePictureLayerTiling> Create( | 59 static scoped_ptr<TestablePictureLayerTiling> Create( |
59 float contents_scale, | 60 float contents_scale, |
60 const gfx::Size& layer_bounds, | 61 const gfx::Size& layer_bounds, |
61 PictureLayerTilingClient* client) { | 62 PictureLayerTilingClient* client) { |
62 return make_scoped_ptr(new TestablePictureLayerTiling( | 63 return make_scoped_ptr(new TestablePictureLayerTiling( |
63 contents_scale, | 64 contents_scale, |
64 layer_bounds, | 65 layer_bounds, |
65 client)); | 66 client)); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 | 204 |
204 // Stop creating tiles so that any invalidations are left as holes. | 205 // Stop creating tiles so that any invalidations are left as holes. |
205 client_.set_allow_create_tile(false); | 206 client_.set_allow_create_tile(false); |
206 | 207 |
207 Region invalidation = | 208 Region invalidation = |
208 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 209 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
209 tiling_->UpdateTilesToCurrentPile(invalidation, gfx::Size(200, 200)); | 210 tiling_->UpdateTilesToCurrentPile(invalidation, gfx::Size(200, 200)); |
210 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 211 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
211 } | 212 } |
212 | 213 |
214 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverTileBorders) { | |
215 // The tiling has three rows and columns. | |
216 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | |
217 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
218 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | |
219 | |
220 // The live tiles rect covers the whole tiling. | |
221 SetLiveRectAndVerifyTiles(gfx::Rect(250, 250)); | |
222 | |
223 // Tiles in the right row and column exist. | |
224 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
225 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
226 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
227 EXPECT_TRUE(tiling_->TileAt(1, 2)); | |
228 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
229 | |
230 // Shrink the live tiles rect to the very edge of the right-most and | |
231 // bottom-most tiles. Their border pixels would still be inside the live | |
232 // tiles rect, but the tiles should not exist just for that. | |
233 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | |
234 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 2).y(); | |
235 | |
236 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); | |
237 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
238 EXPECT_FALSE(tiling_->TileAt(2, 1)); | |
239 EXPECT_FALSE(tiling_->TileAt(2, 2)); | |
240 EXPECT_FALSE(tiling_->TileAt(1, 2)); | |
241 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
242 | |
243 // Including the bottom row and right column again, should create the tiles. | |
244 SetLiveRectAndVerifyTiles(gfx::Rect(right + 1, bottom + 1)); | |
danakj
2014/08/26 19:00:11
This is the test from https://codereview.chromium.
vmpstr
2014/08/26 19:02:15
Ah ok. No this is fine, it's just I couldn't repro
danakj
2014/08/26 19:28:34
Oh, I lied slightly. It doesn't crash in here. But
| |
245 | |
246 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
247 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
248 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
249 EXPECT_TRUE(tiling_->TileAt(1, 2)); | |
250 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
251 | |
252 // Shrink the live tiles rect to the very edge of the left-most and | |
253 // top-most tiles. Their border pixels would still be inside the live | |
254 // tiles rect, but the tiles should not exist just for that. | |
255 int left = tiling_->TilingDataForTesting().TileBounds(0, 0).right(); | |
256 int top = tiling_->TilingDataForTesting().TileBounds(0, 0).bottom(); | |
257 | |
258 SetLiveRectAndVerifyTiles(gfx::Rect(left, top, 250 - left, 250 - top)); | |
259 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
260 EXPECT_FALSE(tiling_->TileAt(0, 1)); | |
261 EXPECT_FALSE(tiling_->TileAt(0, 0)); | |
262 EXPECT_FALSE(tiling_->TileAt(1, 0)); | |
263 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
264 | |
265 // Including the top row and left column again, should create the tiles. | |
266 SetLiveRectAndVerifyTiles( | |
267 gfx::Rect(left - 1, top - 1, 250 - left, 250 - top)); | |
268 | |
269 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
270 EXPECT_TRUE(tiling_->TileAt(0, 1)); | |
271 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
272 EXPECT_TRUE(tiling_->TileAt(1, 0)); | |
273 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
274 } | |
275 | |
276 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverSameTiles) { | |
277 // The tiling has three rows and columns. | |
278 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | |
279 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
280 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | |
281 | |
282 // The live tiles rect covers the whole tiling. | |
283 SetLiveRectAndVerifyTiles(gfx::Rect(250, 250)); | |
284 | |
285 // All tiles exist. | |
286 for (int i = 0; i < 3; ++i) { | |
287 for (int j = 0; j < 3; ++j) | |
288 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
289 } | |
290 | |
291 // Shrink the live tiles rect, but still cover all the tiles. | |
292 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 249)); | |
293 | |
294 // All tiles still exist. | |
295 for (int i = 0; i < 3; ++i) { | |
296 for (int j = 0; j < 3; ++j) | |
297 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
298 } | |
299 | |
300 // Grow the live tiles rect, but still cover all the same tiles. | |
301 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 250)); | |
302 | |
303 // All tiles still exist. | |
304 for (int i = 0; i < 3; ++i) { | |
305 for (int j = 0; j < 3; ++j) | |
306 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
307 } | |
308 } | |
309 | |
213 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { | 310 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { |
214 // Verifies that a resize with invalidation for newly exposed pixels will | 311 // Verifies that a resize with invalidation for newly exposed pixels will |
215 // deletes tiles that intersect that invalidation. | 312 // deletes tiles that intersect that invalidation. |
216 gfx::Size tile_size(100, 100); | 313 gfx::Size tile_size(100, 100); |
217 gfx::Size original_layer_size(99, 99); | 314 gfx::Size original_layer_size(99, 99); |
218 Initialize(tile_size, 1.f, original_layer_size); | 315 Initialize(tile_size, 1.f, original_layer_size); |
219 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 316 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
220 | 317 |
221 // Tiling only has one tile, since its total size is less than one. | 318 // Tiling only has one tile, since its total size is less than one. |
222 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 319 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 for (std::vector<scoped_refptr<Tile> >::const_iterator it = tiles.begin(); | 2040 for (std::vector<scoped_refptr<Tile> >::const_iterator it = tiles.begin(); |
1944 it != tiles.end(); | 2041 it != tiles.end(); |
1945 ++it) { | 2042 ++it) { |
1946 EXPECT_EQ(TilePriority(), (*it)->priority(ACTIVE_TREE)); | 2043 EXPECT_EQ(TilePriority(), (*it)->priority(ACTIVE_TREE)); |
1947 } | 2044 } |
1948 tiles.clear(); | 2045 tiles.clear(); |
1949 } | 2046 } |
1950 | 2047 |
1951 } // namespace | 2048 } // namespace |
1952 } // namespace cc | 2049 } // namespace cc |
OLD | NEW |