| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 201 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
| 202 | 202 |
| 203 // Tiling only has one tile, since its total size is less than one. | 203 // Tiling only has one tile, since its total size is less than one. |
| 204 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 204 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 205 | 205 |
| 206 // Stop creating tiles so that any invalidations are left as holes. | 206 // Stop creating tiles so that any invalidations are left as holes. |
| 207 client_.set_allow_create_tile(false); | 207 client_.set_allow_create_tile(false); |
| 208 | 208 |
| 209 Region invalidation = | 209 Region invalidation = |
| 210 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 210 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
| 211 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), | 211 tiling_->Resize(gfx::Size(200, 200)); |
| 212 invalidation, gfx::Size(200, 200)); | 212 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 213 tiling_->Invalidate(invalidation); |
| 213 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 214 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
| 214 } | 215 } |
| 215 | 216 |
| 216 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { | 217 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { |
| 217 // The tiling has three rows and columns. | 218 // The tiling has three rows and columns. |
| 218 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | 219 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); |
| 219 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 220 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
| 220 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 221 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
| 221 | 222 |
| 222 // The live tiles rect is at the very edge of the right-most and | 223 // The live tiles rect is at the very edge of the right-most and |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_TRUE(tiling_->TileAt(2, 2)); | 257 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
| 257 EXPECT_TRUE(tiling_->TileAt(2, 3)); | 258 EXPECT_TRUE(tiling_->TileAt(2, 3)); |
| 258 EXPECT_TRUE(tiling_->TileAt(1, 3)); | 259 EXPECT_TRUE(tiling_->TileAt(1, 3)); |
| 259 EXPECT_TRUE(tiling_->TileAt(0, 3)); | 260 EXPECT_TRUE(tiling_->TileAt(0, 3)); |
| 260 | 261 |
| 261 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | 262 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); |
| 262 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); | 263 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); |
| 263 | 264 |
| 264 // Shrink the tiling so that the last tile row/column is entirely in the | 265 // Shrink the tiling so that the last tile row/column is entirely in the |
| 265 // border pixels of the interior tiles. That row/column is removed. | 266 // border pixels of the interior tiles. That row/column is removed. |
| 266 Region invalidation; | 267 tiling_->Resize(gfx::Size(right + 1, bottom + 1)); |
| 267 tiling_->UpdateTilesToCurrentRasterSource( | |
| 268 client_.raster_source(), invalidation, gfx::Size(right + 1, bottom + 1)); | |
| 269 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); | 268 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); |
| 270 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 269 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
| 271 | 270 |
| 272 // The live tiles rect was clamped to the pile size. | 271 // The live tiles rect was clamped to the pile size. |
| 273 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | 272 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); |
| 274 | 273 |
| 275 // Since the row/column is gone, the tiles should be gone too. | 274 // Since the row/column is gone, the tiles should be gone too. |
| 276 EXPECT_FALSE(tiling_->TileAt(2, 0)); | 275 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
| 277 EXPECT_FALSE(tiling_->TileAt(2, 1)); | 276 EXPECT_FALSE(tiling_->TileAt(2, 1)); |
| 278 EXPECT_FALSE(tiling_->TileAt(2, 2)); | 277 EXPECT_FALSE(tiling_->TileAt(2, 2)); |
| 279 EXPECT_FALSE(tiling_->TileAt(2, 3)); | 278 EXPECT_FALSE(tiling_->TileAt(2, 3)); |
| 280 EXPECT_FALSE(tiling_->TileAt(1, 3)); | 279 EXPECT_FALSE(tiling_->TileAt(1, 3)); |
| 281 EXPECT_FALSE(tiling_->TileAt(0, 3)); | 280 EXPECT_FALSE(tiling_->TileAt(0, 3)); |
| 282 | 281 |
| 283 // Growing outside the current right/bottom tiles border pixels should create | 282 // Growing outside the current right/bottom tiles border pixels should create |
| 284 // the tiles again, even though the live rect has not changed size. | 283 // the tiles again, even though the live rect has not changed size. |
| 285 tiling_->UpdateTilesToCurrentRasterSource( | 284 tiling_->Resize(gfx::Size(right + 2, bottom + 2)); |
| 286 client_.raster_source(), invalidation, gfx::Size(right + 2, bottom + 2)); | |
| 287 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 285 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
| 288 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | 286 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); |
| 289 | 287 |
| 290 // Not changed. | 288 // Not changed. |
| 291 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | 289 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); |
| 292 | 290 |
| 293 // The last row/column tiles are inside the live tiles rect. | 291 // The last row/column tiles are inside the live tiles rect. |
| 294 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | 292 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( |
| 295 tiling_->TilingDataForTesting().TileBounds(2, 0))); | 293 tiling_->TilingDataForTesting().TileBounds(2, 0))); |
| 296 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | 294 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 410 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
| 413 | 411 |
| 414 // Tiling only has one tile, since its total size is less than one. | 412 // Tiling only has one tile, since its total size is less than one. |
| 415 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 413 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 416 | 414 |
| 417 // Stop creating tiles so that any invalidations are left as holes. | 415 // Stop creating tiles so that any invalidations are left as holes. |
| 418 client_.set_allow_create_tile(false); | 416 client_.set_allow_create_tile(false); |
| 419 | 417 |
| 420 Region invalidation = | 418 Region invalidation = |
| 421 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 419 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
| 422 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), | 420 tiling_->Resize(gfx::Size(200, 200)); |
| 423 invalidation, gfx::Size(200, 200)); | 421 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 422 tiling_->Invalidate(invalidation); |
| 424 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 423 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
| 425 | 424 |
| 426 // The original tile was the same size after resize, but it would include new | 425 // The original tile was the same size after resize, but it would include new |
| 427 // border pixels. | 426 // border pixels. |
| 428 EXPECT_EQ(gfx::Rect(original_layer_size), | 427 EXPECT_EQ(gfx::Rect(original_layer_size), |
| 429 tiling_->TilingDataForTesting().TileBounds(0, 0)); | 428 tiling_->TilingDataForTesting().TileBounds(0, 0)); |
| 430 } | 429 } |
| 431 | 430 |
| 432 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | 431 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { |
| 433 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 432 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 1.f, // current contents scale | 1361 1.f, // current contents scale |
| 1363 1.0); // current frame time | 1362 1.0); // current frame time |
| 1364 | 1363 |
| 1365 // The active tiling has tiles now. | 1364 // The active tiling has tiles now. |
| 1366 VerifyTiles(active_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), | 1365 VerifyTiles(active_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), |
| 1367 base::Bind(&TileExists, true)); | 1366 base::Bind(&TileExists, true)); |
| 1368 | 1367 |
| 1369 // Add the same tilings to the pending set. | 1368 // Add the same tilings to the pending set. |
| 1370 auto pending_set = PictureLayerTilingSet::Create(&client_); | 1369 auto pending_set = PictureLayerTilingSet::Create(&client_); |
| 1371 Region invalidation; | 1370 Region invalidation; |
| 1372 pending_set->SyncTilings(*active_set, layer_bounds, invalidation, 0.f, | 1371 pending_set->SyncTilingsForTesting(*active_set, layer_bounds, invalidation, |
| 1373 client_.raster_source()); | 1372 0.f, client_.raster_source()); |
| 1374 | 1373 |
| 1375 // The pending tiling starts with no tiles. | 1374 // The pending tiling starts with no tiles. |
| 1376 VerifyTiles(pending_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), | 1375 VerifyTiles(pending_set->tiling_at(0), 1.f, gfx::Rect(layer_bounds), |
| 1377 base::Bind(&TileExists, false)); | 1376 base::Bind(&TileExists, false)); |
| 1378 | 1377 |
| 1379 // ComputeTilePriorityRects on the pending tiling at the same frame time. The | 1378 // ComputeTilePriorityRects on the pending tiling at the same frame time. The |
| 1380 // pending tiling should get tiles. | 1379 // pending tiling should get tiles. |
| 1381 UpdateAllTilePriorities(pending_set.get(), | 1380 UpdateAllTilePriorities(pending_set.get(), |
| 1382 gfx::Rect(layer_bounds), // visible content rect | 1381 gfx::Rect(layer_bounds), // visible content rect |
| 1383 1.f, // current contents scale | 1382 1.f, // current contents scale |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2043 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2042 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2044 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); | 2043 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); |
| 2045 | 2044 |
| 2046 client_.SetTileSize(gfx::Size(250, 200)); | 2045 client_.SetTileSize(gfx::Size(250, 200)); |
| 2047 client_.set_tree(PENDING_TREE); | 2046 client_.set_tree(PENDING_TREE); |
| 2048 | 2047 |
| 2049 // Tile size in the tiling should still be 150x100. | 2048 // Tile size in the tiling should still be 150x100. |
| 2050 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | 2049 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); |
| 2051 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2050 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2052 | 2051 |
| 2053 Region invalidation; | 2052 tiling_->Resize(gfx::Size(250, 150)); |
| 2054 tiling_->UpdateTilesToCurrentRasterSource(client_.raster_source(), | |
| 2055 invalidation, gfx::Size(250, 150)); | |
| 2056 | 2053 |
| 2057 // Tile size in the tiling should be resized to 250x200. | 2054 // Tile size in the tiling should be resized to 250x200. |
| 2058 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 2055 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
| 2059 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 2056 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2060 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 2057 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
| 2061 } | 2058 } |
| 2062 | 2059 |
| 2063 } // namespace | 2060 } // namespace |
| 2064 } // namespace cc | 2061 } // namespace cc |
| OLD | NEW |