| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 float contents_scale, | 58 float contents_scale, |
| 59 const gfx::Size& layer_bounds, | 59 const gfx::Size& layer_bounds, |
| 60 PictureLayerTilingClient* client) { | 60 PictureLayerTilingClient* client) { |
| 61 return make_scoped_ptr(new TestablePictureLayerTiling( | 61 return make_scoped_ptr(new TestablePictureLayerTiling( |
| 62 contents_scale, | 62 contents_scale, |
| 63 layer_bounds, | 63 layer_bounds, |
| 64 client)); | 64 client)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 67 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 68 bool eviction_tiles_cache_valid() const { | |
| 69 return eviction_tiles_cache_valid_; | |
| 70 } | |
| 71 | 68 |
| 72 using PictureLayerTiling::ComputeSkewport; | 69 using PictureLayerTiling::ComputeSkewport; |
| 73 using PictureLayerTiling::RemoveTileAt; | 70 using PictureLayerTiling::RemoveTileAt; |
| 74 | 71 |
| 75 protected: | 72 protected: |
| 76 TestablePictureLayerTiling(float contents_scale, | 73 TestablePictureLayerTiling(float contents_scale, |
| 77 const gfx::Size& layer_bounds, | 74 const gfx::Size& layer_bounds, |
| 78 PictureLayerTilingClient* client) | 75 PictureLayerTilingClient* client) |
| 79 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 76 : PictureLayerTiling(contents_scale, layer_bounds, client) { } |
| 80 }; | 77 }; |
| (...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | 1275 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
| 1279 tiling->ComputeTilePriorityRects( | 1276 tiling->ComputeTilePriorityRects( |
| 1280 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); | 1277 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 1281 tiling->UpdateAllTilePrioritiesForTesting(); | 1278 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1282 | 1279 |
| 1283 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | 1280 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
| 1284 EXPECT_FALSE(empty_iterator); | 1281 EXPECT_FALSE(empty_iterator); |
| 1285 | 1282 |
| 1286 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | 1283 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
| 1287 | 1284 |
| 1288 PictureLayerTiling::TilingEvictionTileIterator it( | 1285 PictureLayerTiling::TilingEvictionTileIterator it(tiling.get(), |
| 1289 tiling.get(), SMOOTHNESS_TAKES_PRIORITY, PictureLayerTiling::NOW); | 1286 PictureLayerTiling::NOW); |
| 1290 | 1287 |
| 1291 // Tiles don't have resources to evict. | 1288 // Tiles don't have resources to evict. |
| 1292 EXPECT_FALSE(it); | 1289 EXPECT_FALSE(it); |
| 1293 | 1290 |
| 1294 // Sanity check. | 1291 // Sanity check. |
| 1295 EXPECT_EQ(5184u, all_tiles.size()); | 1292 EXPECT_EQ(5184u, all_tiles.size()); |
| 1296 | 1293 |
| 1297 client.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 1294 client.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
| 1298 | 1295 |
| 1299 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end()); | 1296 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end()); |
| 1300 | 1297 |
| 1301 std::set<Tile*> eviction_tiles; | 1298 std::set<Tile*> eviction_tiles; |
| 1302 | 1299 |
| 1303 it = PictureLayerTiling::TilingEvictionTileIterator( | 1300 it = PictureLayerTiling::TilingEvictionTileIterator( |
| 1304 tiling.get(), SMOOTHNESS_TAKES_PRIORITY, PictureLayerTiling::EVENTUALLY); | 1301 tiling.get(), PictureLayerTiling::EVENTUALLY); |
| 1305 EXPECT_TRUE(it); | 1302 EXPECT_TRUE(it); |
| 1306 for (; it; ++it) { | 1303 for (; it; ++it) { |
| 1307 Tile* tile = *it; | 1304 Tile* tile = *it; |
| 1308 EXPECT_TRUE(tile); | 1305 EXPECT_TRUE(tile); |
| 1309 EXPECT_EQ(TilePriority::EVENTUALLY, | 1306 EXPECT_EQ(TilePriority::EVENTUALLY, |
| 1310 tile->priority(ACTIVE_TREE).priority_bin); | 1307 tile->priority(ACTIVE_TREE).priority_bin); |
| 1311 EXPECT_FALSE(tile->required_for_activation()); | 1308 EXPECT_FALSE(tile->required_for_activation()); |
| 1312 eviction_tiles.insert(tile); | 1309 eviction_tiles.insert(tile); |
| 1313 } | 1310 } |
| 1314 | 1311 |
| 1315 it = PictureLayerTiling::TilingEvictionTileIterator( | 1312 it = PictureLayerTiling::TilingEvictionTileIterator(tiling.get(), |
| 1316 tiling.get(), SMOOTHNESS_TAKES_PRIORITY, PictureLayerTiling::SOON); | 1313 PictureLayerTiling::SOON); |
| 1317 EXPECT_TRUE(it); | 1314 EXPECT_TRUE(it); |
| 1318 for (; it; ++it) { | 1315 for (; it; ++it) { |
| 1319 Tile* tile = *it; | 1316 Tile* tile = *it; |
| 1320 EXPECT_TRUE(tile); | 1317 EXPECT_TRUE(tile); |
| 1321 EXPECT_EQ(TilePriority::SOON, tile->priority(ACTIVE_TREE).priority_bin); | 1318 EXPECT_EQ(TilePriority::SOON, tile->priority(ACTIVE_TREE).priority_bin); |
| 1322 EXPECT_FALSE(tile->required_for_activation()); | 1319 EXPECT_FALSE(tile->required_for_activation()); |
| 1323 eviction_tiles.insert(tile); | 1320 eviction_tiles.insert(tile); |
| 1324 } | 1321 } |
| 1325 | 1322 |
| 1326 it = PictureLayerTiling::TilingEvictionTileIterator( | 1323 it = PictureLayerTiling::TilingEvictionTileIterator(tiling.get(), |
| 1327 tiling.get(), SMOOTHNESS_TAKES_PRIORITY, PictureLayerTiling::NOW); | 1324 PictureLayerTiling::NOW); |
| 1328 EXPECT_TRUE(it); | 1325 EXPECT_TRUE(it); |
| 1329 for (; it; ++it) { | 1326 for (; it; ++it) { |
| 1330 Tile* tile = *it; | 1327 Tile* tile = *it; |
| 1331 EXPECT_TRUE(tile); | 1328 EXPECT_TRUE(tile); |
| 1332 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); | 1329 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 1333 EXPECT_FALSE(tile->required_for_activation()); | 1330 EXPECT_FALSE(tile->required_for_activation()); |
| 1334 eviction_tiles.insert(tile); | 1331 eviction_tiles.insert(tile); |
| 1335 } | 1332 } |
| 1336 | 1333 |
| 1337 it = PictureLayerTiling::TilingEvictionTileIterator( | 1334 it = PictureLayerTiling::TilingEvictionTileIterator( |
| 1338 tiling.get(), | 1335 tiling.get(), |
| 1339 SMOOTHNESS_TAKES_PRIORITY, | |
| 1340 PictureLayerTiling::NOW_AND_REQUIRED_FOR_ACTIVATION); | 1336 PictureLayerTiling::NOW_AND_REQUIRED_FOR_ACTIVATION); |
| 1341 EXPECT_FALSE(it); | 1337 EXPECT_FALSE(it); |
| 1342 | 1338 |
| 1343 EXPECT_GT(all_tiles_set.size(), 0u); | 1339 EXPECT_GT(all_tiles_set.size(), 0u); |
| 1344 EXPECT_EQ(all_tiles_set, eviction_tiles); | 1340 EXPECT_EQ(all_tiles_set, eviction_tiles); |
| 1345 | |
| 1346 EXPECT_TRUE(tiling->eviction_tiles_cache_valid()); | |
| 1347 tiling->RemoveTileAt(0, 0, nullptr); | |
| 1348 EXPECT_FALSE(tiling->eviction_tiles_cache_valid()); | |
| 1349 } | 1341 } |
| 1350 | 1342 |
| 1351 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 1343 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
| 1352 gfx::Size layer_bounds(1099, 801); | 1344 gfx::Size layer_bounds(1099, 801); |
| 1353 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1345 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 1354 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1346 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 1355 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1347 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 1356 | 1348 |
| 1357 client_.set_tree(ACTIVE_TREE); | 1349 client_.set_tree(ACTIVE_TREE); |
| 1358 tiling_->ComputeTilePriorityRects( | 1350 tiling_->ComputeTilePriorityRects( |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2166 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); | 2158 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
| 2167 | 2159 |
| 2168 // Reset the active tiling. The recycle tiles should be released too. | 2160 // Reset the active tiling. The recycle tiles should be released too. |
| 2169 active_tiling->Reset(); | 2161 active_tiling->Reset(); |
| 2170 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | 2162 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
| 2171 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | 2163 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
| 2172 } | 2164 } |
| 2173 | 2165 |
| 2174 } // namespace | 2166 } // namespace |
| 2175 } // namespace cc | 2167 } // namespace cc |
| OLD | NEW |