| Index: cc/resources/tile_manager_unittest.cc
|
| diff --git a/cc/resources/tile_manager_unittest.cc b/cc/resources/tile_manager_unittest.cc
|
| index 3dba49b45558c24c372fd64c4f609861f8d9f3cc..a23152b7f546ba69c78a5310f76342e258feaaf7 100644
|
| --- a/cc/resources/tile_manager_unittest.cc
|
| +++ b/cc/resources/tile_manager_unittest.cc
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "cc/resources/eviction_tile_priority_queue.h"
|
| +#include "cc/resources/raster_tile_priority_queue.h"
|
| #include "cc/resources/tile.h"
|
| #include "cc/resources/tile_priority.h"
|
| #include "cc/test/fake_impl_proxy.h"
|
| @@ -83,11 +85,16 @@ class TileManagerTest : public testing::TestWithParam<bool>,
|
| }
|
|
|
| // TileManagerClient implementation.
|
| - virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() OVERRIDE {
|
| + virtual const std::vector<PictureLayerImpl*>& GetPictureLayers()
|
| + const OVERRIDE {
|
| return picture_layers_;
|
| }
|
| virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; }
|
| virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {}
|
| + virtual void BuildRasterQueue(RasterTilePriorityQueue* queue,
|
| + TreePriority priority) OVERRIDE {}
|
| + virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue,
|
| + TreePriority priority) OVERRIDE {}
|
|
|
| TileVector CreateTilesWithSize(int count,
|
| TilePriority active_priority,
|
| @@ -424,9 +431,9 @@ INSTANTIATE_TEST_CASE_P(TileManagerTests,
|
| TileManagerTest,
|
| ::testing::Values(true, false));
|
|
|
| -class TileManagerTileIteratorTest : public testing::Test {
|
| +class TileManagerTilePriorityQueueTest : public testing::Test {
|
| public:
|
| - TileManagerTileIteratorTest()
|
| + TileManagerTilePriorityQueueTest()
|
| : memory_limit_policy_(ALLOW_ANYTHING),
|
| max_tiles_(10000),
|
| ready_to_activate_(false),
|
| @@ -537,75 +544,23 @@ class TileManagerTileIteratorTest : public testing::Test {
|
| FakePictureLayerImpl* active_layer_;
|
| };
|
|
|
| -TEST_F(TileManagerTileIteratorTest, PairedPictureLayers) {
|
| - host_impl_.CreatePendingTree();
|
| - host_impl_.ActivateSyncTree();
|
| - host_impl_.CreatePendingTree();
|
| -
|
| - LayerTreeImpl* active_tree = host_impl_.active_tree();
|
| - LayerTreeImpl* pending_tree = host_impl_.pending_tree();
|
| - EXPECT_NE(active_tree, pending_tree);
|
| -
|
| - scoped_ptr<FakePictureLayerImpl> active_layer =
|
| - FakePictureLayerImpl::Create(active_tree, 10);
|
| - scoped_ptr<FakePictureLayerImpl> pending_layer =
|
| - FakePictureLayerImpl::Create(pending_tree, 10);
|
| -
|
| - TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager();
|
| - EXPECT_TRUE(tile_manager);
|
| -
|
| - std::vector<TileManager::PairedPictureLayer> paired_layers;
|
| - tile_manager->GetPairedPictureLayers(&paired_layers);
|
| -
|
| - EXPECT_EQ(2u, paired_layers.size());
|
| - if (paired_layers[0].active_layer) {
|
| - EXPECT_EQ(active_layer.get(), paired_layers[0].active_layer);
|
| - EXPECT_EQ(NULL, paired_layers[0].pending_layer);
|
| - } else {
|
| - EXPECT_EQ(pending_layer.get(), paired_layers[0].pending_layer);
|
| - EXPECT_EQ(NULL, paired_layers[0].active_layer);
|
| - }
|
| -
|
| - if (paired_layers[1].active_layer) {
|
| - EXPECT_EQ(active_layer.get(), paired_layers[1].active_layer);
|
| - EXPECT_EQ(NULL, paired_layers[1].pending_layer);
|
| - } else {
|
| - EXPECT_EQ(pending_layer.get(), paired_layers[1].pending_layer);
|
| - EXPECT_EQ(NULL, paired_layers[1].active_layer);
|
| - }
|
| -
|
| - active_layer->set_twin_layer(pending_layer.get());
|
| - pending_layer->set_twin_layer(active_layer.get());
|
| -
|
| - tile_manager->GetPairedPictureLayers(&paired_layers);
|
| - EXPECT_EQ(1u, paired_layers.size());
|
| -
|
| - EXPECT_EQ(active_layer.get(), paired_layers[0].active_layer);
|
| - EXPECT_EQ(pending_layer.get(), paired_layers[0].pending_layer);
|
| -}
|
| -
|
| -TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
| +TEST_F(TileManagerTilePriorityQueueTest, RasterTilePriorityQueue) {
|
| SetupDefaultTrees(gfx::Size(1000, 1000));
|
| - TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager();
|
| - EXPECT_TRUE(tile_manager);
|
|
|
| active_layer_->CreateDefaultTilingsAndTiles();
|
| pending_layer_->CreateDefaultTilingsAndTiles();
|
|
|
| - std::vector<TileManager::PairedPictureLayer> paired_layers;
|
| - tile_manager->GetPairedPictureLayers(&paired_layers);
|
| - EXPECT_EQ(1u, paired_layers.size());
|
| -
|
| - TileManager::RasterTileIterator it(tile_manager,
|
| - SAME_PRIORITY_FOR_BOTH_TREES);
|
| - EXPECT_TRUE(it);
|
| + RasterTilePriorityQueue queue;
|
| + host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES);
|
| + EXPECT_FALSE(queue.IsEmpty());
|
|
|
| size_t tile_count = 0;
|
| std::set<Tile*> all_tiles;
|
| - for (; it; ++it) {
|
| - EXPECT_TRUE(*it);
|
| - all_tiles.insert(*it);
|
| + while (!queue.IsEmpty()) {
|
| + EXPECT_TRUE(queue.Top());
|
| + all_tiles.insert(queue.Top());
|
| ++tile_count;
|
| + queue.Pop();
|
| }
|
|
|
| EXPECT_EQ(tile_count, all_tiles.size());
|
| @@ -613,15 +568,15 @@ TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
|
|
| // Sanity check, all tiles should be visible.
|
| std::set<Tile*> smoothness_tiles;
|
| - for (TileManager::RasterTileIterator it(tile_manager,
|
| - SMOOTHNESS_TAKES_PRIORITY);
|
| - it;
|
| - ++it) {
|
| - Tile* tile = *it;
|
| + queue.Reset();
|
| + host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY);
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| EXPECT_TRUE(tile);
|
| EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin);
|
| EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin);
|
| smoothness_tiles.insert(tile);
|
| + queue.Pop();
|
| }
|
| EXPECT_EQ(all_tiles, smoothness_tiles);
|
|
|
| @@ -699,11 +654,10 @@ TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
| tile_count = 0;
|
| size_t increasing_distance_tiles = 0u;
|
| // Here we expect to get increasing ACTIVE_TREE priority_bin.
|
| - for (TileManager::RasterTileIterator it(tile_manager,
|
| - SMOOTHNESS_TAKES_PRIORITY);
|
| - it;
|
| - ++it) {
|
| - Tile* tile = *it;
|
| + queue.Reset();
|
| + host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY);
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| EXPECT_TRUE(tile);
|
|
|
| if (!last_tile)
|
| @@ -728,6 +682,7 @@ TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
| last_tile = tile;
|
| ++tile_count;
|
| smoothness_tiles.insert(tile);
|
| + queue.Pop();
|
| }
|
|
|
| EXPECT_EQ(tile_count, smoothness_tiles.size());
|
| @@ -740,11 +695,10 @@ TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
| last_tile = NULL;
|
| increasing_distance_tiles = 0u;
|
| // Here we expect to get increasing PENDING_TREE priority_bin.
|
| - for (TileManager::RasterTileIterator it(tile_manager,
|
| - NEW_CONTENT_TAKES_PRIORITY);
|
| - it;
|
| - ++it) {
|
| - Tile* tile = *it;
|
| + queue.Reset();
|
| + host_impl_.BuildRasterQueue(&queue, NEW_CONTENT_TAKES_PRIORITY);
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| EXPECT_TRUE(tile);
|
|
|
| if (!last_tile)
|
| @@ -768,6 +722,7 @@ TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
|
|
| last_tile = tile;
|
| new_content_tiles.insert(tile);
|
| + queue.Pop();
|
| }
|
|
|
| EXPECT_EQ(tile_count, new_content_tiles.size());
|
| @@ -777,55 +732,51 @@ TEST_F(TileManagerTileIteratorTest, RasterTileIterator) {
|
| EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4);
|
| }
|
|
|
| -TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) {
|
| +TEST_F(TileManagerTilePriorityQueueTest, EvictionTilePriorityQueue) {
|
| SetupDefaultTrees(gfx::Size(1000, 1000));
|
| - TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager();
|
| - EXPECT_TRUE(tile_manager);
|
|
|
| active_layer_->CreateDefaultTilingsAndTiles();
|
| pending_layer_->CreateDefaultTilingsAndTiles();
|
|
|
| - std::vector<TileManager::PairedPictureLayer> paired_layers;
|
| - tile_manager->GetPairedPictureLayers(&paired_layers);
|
| - EXPECT_EQ(1u, paired_layers.size());
|
| -
|
| - TileManager::EvictionTileIterator empty_it(tile_manager,
|
| - SAME_PRIORITY_FOR_BOTH_TREES);
|
| - EXPECT_FALSE(empty_it);
|
| + EvictionTilePriorityQueue empty_queue;
|
| + host_impl_.BuildEvictionQueue(&empty_queue, SAME_PRIORITY_FOR_BOTH_TREES);
|
| + EXPECT_TRUE(empty_queue.IsEmpty());
|
| std::set<Tile*> all_tiles;
|
| size_t tile_count = 0;
|
|
|
| - for (TileManager::RasterTileIterator raster_it(tile_manager,
|
| - SAME_PRIORITY_FOR_BOTH_TREES);
|
| - raster_it;
|
| - ++raster_it) {
|
| + RasterTilePriorityQueue raster_queue;
|
| + host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES);
|
| + while (!raster_queue.IsEmpty()) {
|
| ++tile_count;
|
| - EXPECT_TRUE(*raster_it);
|
| - all_tiles.insert(*raster_it);
|
| + EXPECT_TRUE(raster_queue.Top());
|
| + all_tiles.insert(raster_queue.Top());
|
| + raster_queue.Pop();
|
| }
|
|
|
| EXPECT_EQ(tile_count, all_tiles.size());
|
| EXPECT_EQ(17u, tile_count);
|
|
|
| - tile_manager->InitializeTilesWithResourcesForTesting(
|
| + tile_manager()->InitializeTilesWithResourcesForTesting(
|
| std::vector<Tile*>(all_tiles.begin(), all_tiles.end()));
|
|
|
| - TileManager::EvictionTileIterator it(tile_manager, SMOOTHNESS_TAKES_PRIORITY);
|
| - EXPECT_TRUE(it);
|
| + EvictionTilePriorityQueue queue;
|
| + host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY);
|
| + EXPECT_FALSE(queue.IsEmpty());
|
|
|
| // Sanity check, all tiles should be visible.
|
| std::set<Tile*> smoothness_tiles;
|
| - for (; it; ++it) {
|
| - Tile* tile = *it;
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| EXPECT_TRUE(tile);
|
| EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin);
|
| EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin);
|
| EXPECT_TRUE(tile->HasResources());
|
| smoothness_tiles.insert(tile);
|
| + queue.Pop();
|
| }
|
| EXPECT_EQ(all_tiles, smoothness_tiles);
|
|
|
| - tile_manager->ReleaseTileResourcesForTesting(
|
| + tile_manager()->ReleaseTileResourcesForTesting(
|
| std::vector<Tile*>(all_tiles.begin(), all_tiles.end()));
|
|
|
| Region invalidation(gfx::Rect(0, 0, 500, 500));
|
| @@ -897,18 +848,17 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) {
|
| for (size_t i = 0; i < active_low_res_tiles.size(); ++i)
|
| all_tiles.insert(active_low_res_tiles[i]);
|
|
|
| - tile_manager->InitializeTilesWithResourcesForTesting(
|
| + tile_manager()->InitializeTilesWithResourcesForTesting(
|
| std::vector<Tile*>(all_tiles.begin(), all_tiles.end()));
|
|
|
| Tile* last_tile = NULL;
|
| smoothness_tiles.clear();
|
| tile_count = 0;
|
| // Here we expect to get increasing ACTIVE_TREE priority_bin.
|
| - for (TileManager::EvictionTileIterator it(tile_manager,
|
| - SMOOTHNESS_TAKES_PRIORITY);
|
| - it;
|
| - ++it) {
|
| - Tile* tile = *it;
|
| + queue.Reset();
|
| + host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY);
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| EXPECT_TRUE(tile);
|
| EXPECT_TRUE(tile->HasResources());
|
|
|
| @@ -926,6 +876,7 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) {
|
| last_tile = tile;
|
| ++tile_count;
|
| smoothness_tiles.insert(tile);
|
| + queue.Pop();
|
| }
|
|
|
| EXPECT_EQ(tile_count, smoothness_tiles.size());
|
| @@ -934,11 +885,10 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) {
|
| std::set<Tile*> new_content_tiles;
|
| last_tile = NULL;
|
| // Here we expect to get increasing PENDING_TREE priority_bin.
|
| - for (TileManager::EvictionTileIterator it(tile_manager,
|
| - NEW_CONTENT_TAKES_PRIORITY);
|
| - it;
|
| - ++it) {
|
| - Tile* tile = *it;
|
| + queue.Reset();
|
| + host_impl_.BuildEvictionQueue(&queue, NEW_CONTENT_TAKES_PRIORITY);
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| EXPECT_TRUE(tile);
|
|
|
| if (!last_tile)
|
| @@ -954,13 +904,15 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) {
|
|
|
| last_tile = tile;
|
| new_content_tiles.insert(tile);
|
| + queue.Pop();
|
| }
|
|
|
| EXPECT_EQ(tile_count, new_content_tiles.size());
|
| EXPECT_EQ(all_tiles, new_content_tiles);
|
| }
|
|
|
| -TEST_F(TileManagerTileIteratorTest, EvictionTileIteratorWithOcclusion) {
|
| +TEST_F(TileManagerTilePriorityQueueTest,
|
| + EvictionTilePriorityQueueWithOcclusion) {
|
| gfx::Size tile_size(102, 102);
|
| gfx::Size layer_bounds(1000, 1000);
|
|
|
| @@ -980,22 +932,15 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIteratorWithOcclusion) {
|
| pending_child_layer->DoPostCommitInitializationIfNeeded();
|
| pending_child_layer->CreateDefaultTilingsAndTiles();
|
|
|
| - TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager();
|
| - EXPECT_TRUE(tile_manager);
|
| -
|
| - std::vector<TileManager::PairedPictureLayer> paired_layers;
|
| - tile_manager->GetPairedPictureLayers(&paired_layers);
|
| - EXPECT_EQ(2u, paired_layers.size());
|
| -
|
| std::set<Tile*> all_tiles;
|
| size_t tile_count = 0;
|
| - for (TileManager::RasterTileIterator raster_it(tile_manager,
|
| - NEW_CONTENT_TAKES_PRIORITY);
|
| - raster_it;
|
| - ++raster_it) {
|
| + RasterTilePriorityQueue raster_queue;
|
| + host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES);
|
| + while (!raster_queue.IsEmpty()) {
|
| ++tile_count;
|
| - EXPECT_TRUE(*raster_it);
|
| - all_tiles.insert(*raster_it);
|
| + EXPECT_TRUE(raster_queue.Top());
|
| + all_tiles.insert(raster_queue.Top());
|
| + raster_queue.Pop();
|
| }
|
| EXPECT_EQ(tile_count, all_tiles.size());
|
| EXPECT_EQ(34u, tile_count);
|
| @@ -1064,16 +1009,17 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIteratorWithOcclusion) {
|
| all_tiles.insert(pending_child_low_res_tiles[i]);
|
| }
|
|
|
| - tile_manager->InitializeTilesWithResourcesForTesting(
|
| + tile_manager()->InitializeTilesWithResourcesForTesting(
|
| std::vector<Tile*>(all_tiles.begin(), all_tiles.end()));
|
|
|
| - // Verify occlusion is considered by EvictionTileIterator.
|
| + // Verify occlusion is considered by EvictionTilePriorityQueue.
|
| TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY;
|
| size_t occluded_count = 0u;
|
| Tile* last_tile = NULL;
|
| - for (TileManager::EvictionTileIterator it(tile_manager, tree_priority); it;
|
| - ++it) {
|
| - Tile* tile = *it;
|
| + EvictionTilePriorityQueue queue;
|
| + host_impl_.BuildEvictionQueue(&queue, tree_priority);
|
| + while (!queue.IsEmpty()) {
|
| + Tile* tile = queue.Top();
|
| if (!last_tile)
|
| last_tile = tile;
|
|
|
| @@ -1099,6 +1045,7 @@ TEST_F(TileManagerTileIteratorTest, EvictionTileIteratorWithOcclusion) {
|
| }
|
| }
|
| last_tile = tile;
|
| + queue.Pop();
|
| }
|
| size_t expected_occluded_count =
|
| pending_child_high_res_tiles.size() + pending_child_low_res_tiles.size();
|
|
|