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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 204 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
205 | 205 |
206 // Tiling only has one tile, since its total size is less than one. | 206 // Tiling only has one tile, since its total size is less than one. |
207 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 207 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
208 | 208 |
209 // Stop creating tiles so that any invalidations are left as holes. | 209 // Stop creating tiles so that any invalidations are left as holes. |
210 client_.set_allow_create_tile(false); | 210 client_.set_allow_create_tile(false); |
211 | 211 |
212 Region invalidation = | 212 Region invalidation = |
213 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 213 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
214 tiling_->UpdateTilesToCurrentRasterSource(invalidation, gfx::Size(200, 200)); | 214 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), |
| 215 invalidation, gfx::Size(200, 200)); |
215 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 216 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
216 } | 217 } |
217 | 218 |
218 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { | 219 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { |
219 // The tiling has three rows and columns. | 220 // The tiling has three rows and columns. |
220 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | 221 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); |
221 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 222 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
222 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 223 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
223 | 224 |
224 // The live tiles rect is at the very edge of the right-most and | 225 // The live tiles rect is at the very edge of the right-most and |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 EXPECT_TRUE(tiling_->TileAt(2, 3)); | 260 EXPECT_TRUE(tiling_->TileAt(2, 3)); |
260 EXPECT_TRUE(tiling_->TileAt(1, 3)); | 261 EXPECT_TRUE(tiling_->TileAt(1, 3)); |
261 EXPECT_TRUE(tiling_->TileAt(0, 3)); | 262 EXPECT_TRUE(tiling_->TileAt(0, 3)); |
262 | 263 |
263 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | 264 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); |
264 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); | 265 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); |
265 | 266 |
266 // Shrink the tiling so that the last tile row/column is entirely in the | 267 // Shrink the tiling so that the last tile row/column is entirely in the |
267 // border pixels of the interior tiles. That row/column is removed. | 268 // border pixels of the interior tiles. That row/column is removed. |
268 Region invalidation; | 269 Region invalidation; |
269 tiling_->UpdateTilesToCurrentRasterSource(invalidation, | 270 tiling_->UpdateTilesToCurrentRasterSource( |
270 gfx::Size(right + 1, bottom + 1)); | 271 client_.raster_source(), invalidation, gfx::Size(right + 1, bottom + 1)); |
271 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); | 272 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); |
272 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 273 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
273 | 274 |
274 // The live tiles rect was clamped to the pile size. | 275 // The live tiles rect was clamped to the pile size. |
275 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | 276 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); |
276 | 277 |
277 // Since the row/column is gone, the tiles should be gone too. | 278 // Since the row/column is gone, the tiles should be gone too. |
278 EXPECT_FALSE(tiling_->TileAt(2, 0)); | 279 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
279 EXPECT_FALSE(tiling_->TileAt(2, 1)); | 280 EXPECT_FALSE(tiling_->TileAt(2, 1)); |
280 EXPECT_FALSE(tiling_->TileAt(2, 2)); | 281 EXPECT_FALSE(tiling_->TileAt(2, 2)); |
281 EXPECT_FALSE(tiling_->TileAt(2, 3)); | 282 EXPECT_FALSE(tiling_->TileAt(2, 3)); |
282 EXPECT_FALSE(tiling_->TileAt(1, 3)); | 283 EXPECT_FALSE(tiling_->TileAt(1, 3)); |
283 EXPECT_FALSE(tiling_->TileAt(0, 3)); | 284 EXPECT_FALSE(tiling_->TileAt(0, 3)); |
284 | 285 |
285 // Growing outside the current right/bottom tiles border pixels should create | 286 // Growing outside the current right/bottom tiles border pixels should create |
286 // the tiles again, even though the live rect has not changed size. | 287 // the tiles again, even though the live rect has not changed size. |
287 tiling_->UpdateTilesToCurrentRasterSource(invalidation, | 288 tiling_->UpdateTilesToCurrentRasterSource( |
288 gfx::Size(right + 2, bottom + 2)); | 289 client_.raster_source(), invalidation, gfx::Size(right + 2, bottom + 2)); |
289 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 290 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
290 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | 291 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); |
291 | 292 |
292 // Not changed. | 293 // Not changed. |
293 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | 294 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); |
294 | 295 |
295 // The last row/column tiles are inside the live tiles rect. | 296 // The last row/column tiles are inside the live tiles rect. |
296 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | 297 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( |
297 tiling_->TilingDataForTesting().TileBounds(2, 0))); | 298 tiling_->TilingDataForTesting().TileBounds(2, 0))); |
298 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | 299 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 415 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
415 | 416 |
416 // Tiling only has one tile, since its total size is less than one. | 417 // Tiling only has one tile, since its total size is less than one. |
417 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 418 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
418 | 419 |
419 // Stop creating tiles so that any invalidations are left as holes. | 420 // Stop creating tiles so that any invalidations are left as holes. |
420 client_.set_allow_create_tile(false); | 421 client_.set_allow_create_tile(false); |
421 | 422 |
422 Region invalidation = | 423 Region invalidation = |
423 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 424 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
424 tiling_->UpdateTilesToCurrentRasterSource(invalidation, gfx::Size(200, 200)); | 425 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), |
| 426 invalidation, gfx::Size(200, 200)); |
425 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 427 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
426 | 428 |
427 // The original tile was the same size after resize, but it would include new | 429 // The original tile was the same size after resize, but it would include new |
428 // border pixels. | 430 // border pixels. |
429 EXPECT_EQ(gfx::Rect(original_layer_size), | 431 EXPECT_EQ(gfx::Rect(original_layer_size), |
430 tiling_->TilingDataForTesting().TileBounds(0, 0)); | 432 tiling_->TilingDataForTesting().TileBounds(0, 0)); |
431 } | 433 } |
432 | 434 |
433 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | 435 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { |
434 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 436 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 1459 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
1458 } | 1460 } |
1459 | 1461 |
1460 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { | 1462 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { |
1461 gfx::Size layer_bounds(1099, 801); | 1463 gfx::Size layer_bounds(1099, 801); |
1462 gfx::Size tile_size(100, 100); | 1464 gfx::Size tile_size(100, 100); |
1463 | 1465 |
1464 client_.SetTileSize(tile_size); | 1466 client_.SetTileSize(tile_size); |
1465 client_.set_tree(PENDING_TREE); | 1467 client_.set_tree(PENDING_TREE); |
1466 | 1468 |
1467 PictureLayerTilingSet active_set(&client_); | 1469 auto active_set = PictureLayerTilingSet::Create(&client_); |
1468 | 1470 |
1469 active_set.AddTiling(1.f, layer_bounds); | 1471 active_set->AddTiling(1.f, layer_bounds); |
1470 | 1472 |
1471 VerifyTiles(active_set.tiling_at(0), | 1473 VerifyTiles(active_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), |
1472 1.f, | |
1473 gfx::Rect(layer_bounds), | |
1474 base::Bind(&TileExists, false)); | 1474 base::Bind(&TileExists, false)); |
1475 | 1475 |
1476 UpdateAllTilePriorities(&active_set, | 1476 UpdateAllTilePriorities(active_set.get(), |
1477 PENDING_TREE, | 1477 PENDING_TREE, // WhichTree |
1478 gfx::Rect(layer_bounds), // visible content rect | 1478 gfx::Rect(layer_bounds), // visible content rect |
1479 1.f, // current contents scale | 1479 1.f, // current contents scale |
1480 1.0); // current frame time | 1480 1.0); // current frame time |
1481 | 1481 |
1482 // The active tiling has tiles now. | 1482 // The active tiling has tiles now. |
1483 VerifyTiles(active_set.tiling_at(0), | 1483 VerifyTiles(active_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), |
1484 1.f, | |
1485 gfx::Rect(layer_bounds), | |
1486 base::Bind(&TileExists, true)); | 1484 base::Bind(&TileExists, true)); |
1487 | 1485 |
1488 // Add the same tilings to the pending set. | 1486 // Add the same tilings to the pending set. |
1489 PictureLayerTilingSet pending_set(&client_); | 1487 auto pending_set = PictureLayerTilingSet::Create(&client_); |
1490 Region invalidation; | 1488 Region invalidation; |
1491 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 1489 pending_set->SyncTilings(*active_set, layer_bounds, invalidation, 0.f, |
| 1490 client_.raster_source()); |
1492 | 1491 |
1493 // The pending tiling starts with no tiles. | 1492 // The pending tiling starts with no tiles. |
1494 VerifyTiles(pending_set.tiling_at(0), | 1493 VerifyTiles(pending_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), |
1495 1.f, | |
1496 gfx::Rect(layer_bounds), | |
1497 base::Bind(&TileExists, false)); | 1494 base::Bind(&TileExists, false)); |
1498 | 1495 |
1499 // ComputeTilePriorityRects on the pending tiling at the same frame time. The | 1496 // ComputeTilePriorityRects on the pending tiling at the same frame time. The |
1500 // pending tiling should get tiles. | 1497 // pending tiling should get tiles. |
1501 UpdateAllTilePriorities(&pending_set, | 1498 UpdateAllTilePriorities(pending_set.get(), |
1502 PENDING_TREE, | 1499 PENDING_TREE, // WhichTree |
1503 gfx::Rect(layer_bounds), // visible content rect | 1500 gfx::Rect(layer_bounds), // visible content rect |
1504 1.f, // current contents scale | 1501 1.f, // current contents scale |
1505 1.0); // current frame time | 1502 1.0); // current frame time |
1506 | 1503 |
1507 VerifyTiles(pending_set.tiling_at(0), | 1504 VerifyTiles(pending_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), |
1508 1.f, | |
1509 gfx::Rect(layer_bounds), | |
1510 base::Bind(&TileExists, true)); | 1505 base::Bind(&TileExists, true)); |
1511 } | 1506 } |
1512 | 1507 |
1513 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { | 1508 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { |
1514 // The TilePriority of visible tiles should have zero distance_to_visible | 1509 // The TilePriority of visible tiles should have zero distance_to_visible |
1515 // and time_to_visible. | 1510 // and time_to_visible. |
1516 | 1511 |
1517 FakePictureLayerTilingClient client; | 1512 FakePictureLayerTilingClient client; |
1518 scoped_ptr<TestablePictureLayerTiling> tiling; | 1513 scoped_ptr<TestablePictureLayerTiling> tiling; |
1519 | 1514 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); | 2182 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); |
2188 | 2183 |
2189 client_.SetTileSize(gfx::Size(250, 200)); | 2184 client_.SetTileSize(gfx::Size(250, 200)); |
2190 client_.set_tree(PENDING_TREE); | 2185 client_.set_tree(PENDING_TREE); |
2191 | 2186 |
2192 // Tile size in the tiling should still be 150x100. | 2187 // Tile size in the tiling should still be 150x100. |
2193 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | 2188 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); |
2194 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2189 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
2195 | 2190 |
2196 Region invalidation; | 2191 Region invalidation; |
2197 tiling_->UpdateTilesToCurrentRasterSource(invalidation, gfx::Size(250, 150)); | 2192 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), |
| 2193 invalidation, gfx::Size(250, 150)); |
2198 | 2194 |
2199 // Tile size in the tiling should be resized to 250x200. | 2195 // Tile size in the tiling should be resized to 250x200. |
2200 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 2196 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
2201 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 2197 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
2202 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 2198 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
2203 } | 2199 } |
2204 | 2200 |
2205 } // namespace | 2201 } // namespace |
2206 } // namespace cc | 2202 } // namespace cc |
OLD | NEW |