| 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 = |
| 1470 PictureLayerTilingSet::Create(&client_, client_.raster_source()); |
| 1468 | 1471 |
| 1469 active_set.AddTiling(1.f, layer_bounds); | 1472 active_set->AddTiling(1.f, layer_bounds); |
| 1470 | 1473 |
| 1471 VerifyTiles(active_set.tiling_at(0), | 1474 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)); | 1475 base::Bind(&TileExists, false)); |
| 1475 | 1476 |
| 1476 UpdateAllTilePriorities(&active_set, | 1477 UpdateAllTilePriorities(active_set.get(), |
| 1477 PENDING_TREE, | 1478 PENDING_TREE, // WhichTree |
| 1478 gfx::Rect(layer_bounds), // visible content rect | 1479 gfx::Rect(layer_bounds), // visible content rect |
| 1479 1.f, // current contents scale | 1480 1.f, // current contents scale |
| 1480 1.0); // current frame time | 1481 1.0); // current frame time |
| 1481 | 1482 |
| 1482 // The active tiling has tiles now. | 1483 // The active tiling has tiles now. |
| 1483 VerifyTiles(active_set.tiling_at(0), | 1484 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)); | 1485 base::Bind(&TileExists, true)); |
| 1487 | 1486 |
| 1488 // Add the same tilings to the pending set. | 1487 // Add the same tilings to the pending set. |
| 1489 PictureLayerTilingSet pending_set(&client_); | 1488 auto pending_set = |
| 1489 PictureLayerTilingSet::Create(&client_, client_.raster_source()); |
| 1490 Region invalidation; | 1490 Region invalidation; |
| 1491 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 1491 pending_set->SyncTilings(*active_set, layer_bounds, invalidation, 0.f); |
| 1492 | 1492 |
| 1493 // The pending tiling starts with no tiles. | 1493 // The pending tiling starts with no tiles. |
| 1494 VerifyTiles(pending_set.tiling_at(0), | 1494 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)); | 1495 base::Bind(&TileExists, false)); |
| 1498 | 1496 |
| 1499 // ComputeTilePriorityRects on the pending tiling at the same frame time. The | 1497 // ComputeTilePriorityRects on the pending tiling at the same frame time. The |
| 1500 // pending tiling should get tiles. | 1498 // pending tiling should get tiles. |
| 1501 UpdateAllTilePriorities(&pending_set, | 1499 UpdateAllTilePriorities(pending_set.get(), |
| 1502 PENDING_TREE, | 1500 PENDING_TREE, // WhichTree |
| 1503 gfx::Rect(layer_bounds), // visible content rect | 1501 gfx::Rect(layer_bounds), // visible content rect |
| 1504 1.f, // current contents scale | 1502 1.f, // current contents scale |
| 1505 1.0); // current frame time | 1503 1.0); // current frame time |
| 1506 | 1504 |
| 1507 VerifyTiles(pending_set.tiling_at(0), | 1505 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)); | 1506 base::Bind(&TileExists, true)); |
| 1511 } | 1507 } |
| 1512 | 1508 |
| 1513 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { | 1509 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { |
| 1514 // The TilePriority of visible tiles should have zero distance_to_visible | 1510 // The TilePriority of visible tiles should have zero distance_to_visible |
| 1515 // and time_to_visible. | 1511 // and time_to_visible. |
| 1516 | 1512 |
| 1517 FakePictureLayerTilingClient client; | 1513 FakePictureLayerTilingClient client; |
| 1518 scoped_ptr<TestablePictureLayerTiling> tiling; | 1514 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1519 | 1515 |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2187 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); | 2183 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); |
| 2188 | 2184 |
| 2189 client_.SetTileSize(gfx::Size(250, 200)); | 2185 client_.SetTileSize(gfx::Size(250, 200)); |
| 2190 client_.set_tree(PENDING_TREE); | 2186 client_.set_tree(PENDING_TREE); |
| 2191 | 2187 |
| 2192 // Tile size in the tiling should still be 150x100. | 2188 // Tile size in the tiling should still be 150x100. |
| 2193 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | 2189 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); |
| 2194 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2190 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2195 | 2191 |
| 2196 Region invalidation; | 2192 Region invalidation; |
| 2197 tiling_->UpdateTilesToCurrentRasterSource(invalidation, gfx::Size(250, 150)); | 2193 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), |
| 2194 invalidation, gfx::Size(250, 150)); |
| 2198 | 2195 |
| 2199 // Tile size in the tiling should be resized to 250x200. | 2196 // Tile size in the tiling should be resized to 250x200. |
| 2200 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 2197 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
| 2201 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 2198 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2202 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 2199 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
| 2203 } | 2200 } |
| 2204 | 2201 |
| 2205 } // namespace | 2202 } // namespace |
| 2206 } // namespace cc | 2203 } // namespace cc |
| OLD | NEW |