Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Side by Side Diff: cc/resources/tile_manager_unittest.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/tile_manager_perftest.cc ('k') | cc/scheduler/begin_frame_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/eviction_tile_priority_queue.h" 5 #include "cc/resources/eviction_tile_priority_queue.h"
6 #include "cc/resources/raster_tile_priority_queue.h" 6 #include "cc/resources/raster_tile_priority_queue.h"
7 #include "cc/resources/tile.h" 7 #include "cc/resources/tile.h"
8 #include "cc/resources/tile_priority.h" 8 #include "cc/resources/tile_priority.h"
9 #include "cc/test/fake_impl_proxy.h" 9 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host_impl.h" 10 #include "cc/test/fake_layer_tree_host_impl.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); 102 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
103 103
104 // Steal from the recycled tree. 104 // Steal from the recycled tree.
105 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); 105 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree();
106 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_); 106 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_);
107 107
108 scoped_ptr<FakePictureLayerImpl> pending_layer; 108 scoped_ptr<FakePictureLayerImpl> pending_layer;
109 if (old_pending_root) { 109 if (old_pending_root) {
110 pending_layer.reset( 110 pending_layer.reset(
111 static_cast<FakePictureLayerImpl*>(old_pending_root.release())); 111 static_cast<FakePictureLayerImpl*>(old_pending_root.release()));
112 pending_layer->SetPile(pile); 112 pending_layer->SetRasterSource(pile);
113 } else { 113 } else {
114 pending_layer = 114 pending_layer =
115 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); 115 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_, pile);
116 pending_layer->SetDrawsContent(true); 116 pending_layer->SetDrawsContent(true);
117 } 117 }
118 // The bounds() just mirror the pile size. 118 // The bounds() just mirror the pile size.
119 pending_layer->SetBounds(pending_layer->pile()->tiling_size()); 119 pending_layer->SetBounds(pending_layer->raster_source()->GetSize());
120 pending_tree->SetRootLayer(pending_layer.Pass()); 120 pending_tree->SetRootLayer(pending_layer.Pass());
121 121
122 pending_layer_ = static_cast<FakePictureLayerImpl*>( 122 pending_layer_ = static_cast<FakePictureLayerImpl*>(
123 host_impl_.pending_tree()->LayerById(id_)); 123 host_impl_.pending_tree()->LayerById(id_));
124 pending_layer_->DoPostCommitInitializationIfNeeded(); 124 pending_layer_->DoPostCommitInitializationIfNeeded();
125 } 125 }
126 126
127 void CreateHighLowResAndSetAllTilesVisible() { 127 void CreateHighLowResAndSetAllTilesVisible() {
128 // Active layer must get updated first so pending layer can share from it. 128 // Active layer must get updated first so pending layer can share from it.
129 active_layer_->CreateDefaultTilingsAndTiles(); 129 active_layer_->CreateDefaultTilingsAndTiles();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 smoothness_tiles.insert(tile); 186 smoothness_tiles.insert(tile);
187 queue.Pop(); 187 queue.Pop();
188 } 188 }
189 EXPECT_EQ(all_tiles, smoothness_tiles); 189 EXPECT_EQ(all_tiles, smoothness_tiles);
190 EXPECT_TRUE(had_low_res); 190 EXPECT_TRUE(had_low_res);
191 191
192 Region invalidation(gfx::Rect(0, 0, 500, 500)); 192 Region invalidation(gfx::Rect(0, 0, 500, 500));
193 193
194 // Invalidate the pending tree. 194 // Invalidate the pending tree.
195 pending_layer_->set_invalidation(invalidation); 195 pending_layer_->set_invalidation(invalidation);
196 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( 196 pending_layer_->HighResTiling()->UpdateTilesToCurrentRasterSource(
197 invalidation, gfx::Size(1000, 1000)); 197 invalidation, gfx::Size(1000, 1000));
198 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( 198 pending_layer_->LowResTiling()->UpdateTilesToCurrentRasterSource(
199 invalidation, gfx::Size(1000, 1000)); 199 invalidation, gfx::Size(1000, 1000));
200 200
201 active_layer_->ResetAllTilesPriorities(); 201 active_layer_->ResetAllTilesPriorities();
202 pending_layer_->ResetAllTilesPriorities(); 202 pending_layer_->ResetAllTilesPriorities();
203 203
204 // Renew all of the tile priorities. 204 // Renew all of the tile priorities.
205 gfx::Rect viewport(50, 50, 100, 100); 205 gfx::Rect viewport(50, 50, 100, 100);
206 pending_layer_->HighResTiling()->ComputeTilePriorityRects( 206 pending_layer_->HighResTiling()->ComputeTilePriorityRects(
207 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); 207 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion());
208 pending_layer_->LowResTiling()->ComputeTilePriorityRects( 208 pending_layer_->LowResTiling()->ComputeTilePriorityRects(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 SetupDefaultTrees(gfx::Size(1000, 1000)); 337 SetupDefaultTrees(gfx::Size(1000, 1000));
338 338
339 active_layer_->CreateDefaultTilingsAndTiles(); 339 active_layer_->CreateDefaultTilingsAndTiles();
340 pending_layer_->CreateDefaultTilingsAndTiles(); 340 pending_layer_->CreateDefaultTilingsAndTiles();
341 341
342 // Create a pending child layer. 342 // Create a pending child layer.
343 gfx::Size tile_size(256, 256); 343 gfx::Size tile_size(256, 256);
344 scoped_refptr<FakePicturePileImpl> pending_pile = 344 scoped_refptr<FakePicturePileImpl> pending_pile =
345 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000)); 345 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000));
346 scoped_ptr<FakePictureLayerImpl> pending_child = 346 scoped_ptr<FakePictureLayerImpl> pending_child =
347 FakePictureLayerImpl::CreateWithPile( 347 FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(),
348 host_impl_.pending_tree(), id_ + 1, pending_pile); 348 id_ + 1, pending_pile);
349 pending_layer_->AddChild(pending_child.Pass()); 349 pending_layer_->AddChild(pending_child.Pass());
350 FakePictureLayerImpl* pending_child_raw = static_cast<FakePictureLayerImpl*>( 350 FakePictureLayerImpl* pending_child_raw = static_cast<FakePictureLayerImpl*>(
351 host_impl_.pending_tree()->LayerById(id_ + 1)); 351 host_impl_.pending_tree()->LayerById(id_ + 1));
352 ASSERT_TRUE(pending_child_raw); 352 ASSERT_TRUE(pending_child_raw);
353 353
354 pending_child_raw->SetDrawsContent(true); 354 pending_child_raw->SetDrawsContent(true);
355 pending_child_raw->DoPostCommitInitializationIfNeeded(); 355 pending_child_raw->DoPostCommitInitializationIfNeeded();
356 pending_child_raw->CreateDefaultTilingsAndTiles(); 356 pending_child_raw->CreateDefaultTilingsAndTiles();
357 ASSERT_TRUE(pending_child_raw->HighResTiling()); 357 ASSERT_TRUE(pending_child_raw->HighResTiling());
358 358
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 434 }
435 EXPECT_EQ(all_tiles, smoothness_tiles); 435 EXPECT_EQ(all_tiles, smoothness_tiles);
436 436
437 tile_manager()->ReleaseTileResourcesForTesting( 437 tile_manager()->ReleaseTileResourcesForTesting(
438 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); 438 std::vector<Tile*>(all_tiles.begin(), all_tiles.end()));
439 439
440 Region invalidation(gfx::Rect(0, 0, 500, 500)); 440 Region invalidation(gfx::Rect(0, 0, 500, 500));
441 441
442 // Invalidate the pending tree. 442 // Invalidate the pending tree.
443 pending_layer_->set_invalidation(invalidation); 443 pending_layer_->set_invalidation(invalidation);
444 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( 444 pending_layer_->HighResTiling()->UpdateTilesToCurrentRasterSource(
445 invalidation, gfx::Size(1000, 1000)); 445 invalidation, gfx::Size(1000, 1000));
446 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( 446 pending_layer_->LowResTiling()->UpdateTilesToCurrentRasterSource(
447 invalidation, gfx::Size(1000, 1000)); 447 invalidation, gfx::Size(1000, 1000));
448 448
449 active_layer_->ResetAllTilesPriorities(); 449 active_layer_->ResetAllTilesPriorities();
450 pending_layer_->ResetAllTilesPriorities(); 450 pending_layer_->ResetAllTilesPriorities();
451 451
452 // Renew all of the tile priorities. 452 // Renew all of the tile priorities.
453 gfx::Rect viewport(50, 50, 100, 100); 453 gfx::Rect viewport(50, 50, 100, 100);
454 pending_layer_->HighResTiling()->ComputeTilePriorityRects( 454 pending_layer_->HighResTiling()->ComputeTilePriorityRects(
455 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); 455 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion());
456 pending_layer_->LowResTiling()->ComputeTilePriorityRects( 456 pending_layer_->LowResTiling()->ComputeTilePriorityRects(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 EvictionTilePriorityQueueWithOcclusion) { 559 EvictionTilePriorityQueueWithOcclusion) {
560 gfx::Size tile_size(102, 102); 560 gfx::Size tile_size(102, 102);
561 gfx::Size layer_bounds(1000, 1000); 561 gfx::Size layer_bounds(1000, 1000);
562 562
563 scoped_refptr<FakePicturePileImpl> pending_pile = 563 scoped_refptr<FakePicturePileImpl> pending_pile =
564 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 564 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
565 SetupPendingTree(pending_pile); 565 SetupPendingTree(pending_pile);
566 pending_layer_->CreateDefaultTilingsAndTiles(); 566 pending_layer_->CreateDefaultTilingsAndTiles();
567 567
568 scoped_ptr<FakePictureLayerImpl> pending_child = 568 scoped_ptr<FakePictureLayerImpl> pending_child =
569 FakePictureLayerImpl::CreateWithPile( 569 FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 2,
570 host_impl_.pending_tree(), 2, pending_pile); 570 pending_pile);
571 pending_layer_->AddChild(pending_child.Pass()); 571 pending_layer_->AddChild(pending_child.Pass());
572 572
573 FakePictureLayerImpl* pending_child_layer = 573 FakePictureLayerImpl* pending_child_layer =
574 static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]); 574 static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]);
575 pending_child_layer->SetDrawsContent(true); 575 pending_child_layer->SetDrawsContent(true);
576 pending_child_layer->DoPostCommitInitializationIfNeeded(); 576 pending_child_layer->DoPostCommitInitializationIfNeeded();
577 pending_child_layer->CreateDefaultTilingsAndTiles(); 577 pending_child_layer->CreateDefaultTilingsAndTiles();
578 578
579 std::set<Tile*> all_tiles; 579 std::set<Tile*> all_tiles;
580 size_t tile_count = 0; 580 size_t tile_count = 0;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 } 662 }
663 } 663 }
664 last_tile = tile; 664 last_tile = tile;
665 queue.Pop(); 665 queue.Pop();
666 } 666 }
667 size_t expected_occluded_count = 667 size_t expected_occluded_count =
668 pending_child_high_res_tiles.size() + pending_child_low_res_tiles.size(); 668 pending_child_high_res_tiles.size() + pending_child_low_res_tiles.size();
669 EXPECT_EQ(expected_occluded_count, occluded_count); 669 EXPECT_EQ(expected_occluded_count, occluded_count);
670 } 670 }
671 671
672 TEST_F(TileManagerTilePriorityQueueTest,
673 EvictionTilePriorityQueueWithTransparentLayer) {
674 gfx::Size tile_size(102, 102);
675 gfx::Size layer_bounds(1000, 1000);
676
677 scoped_refptr<FakePicturePileImpl> pending_pile =
678 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
679 SetupPendingTree(pending_pile);
680 pending_layer_->CreateDefaultTilingsAndTiles();
681
682 scoped_ptr<FakePictureLayerImpl> pending_child =
683 FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 2,
684 pending_pile);
685 pending_layer_->AddChild(pending_child.Pass());
686
687 // Create a fully transparent child layer so that its tile priorities are not
688 // considered to be valid.
689 FakePictureLayerImpl* pending_child_layer =
690 static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]);
691 pending_child_layer->SetDrawsContent(true);
692 pending_child_layer->CreateDefaultTilingsAndTiles();
693 pending_child_layer->SetOpacity(0.0);
694 pending_child_layer->layer_tree_impl()->UpdateDrawProperties();
695 pending_child_layer->DoPostCommitInitializationIfNeeded();
696
697 // Renew all of the tile priorities.
698 gfx::Rect viewport(layer_bounds);
699 pending_layer_->HighResTiling()->ComputeTilePriorityRects(
700 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion());
701 pending_layer_->LowResTiling()->ComputeTilePriorityRects(
702 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion());
703 pending_child_layer->HighResTiling()->ComputeTilePriorityRects(
704 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion());
705 pending_child_layer->LowResTiling()->ComputeTilePriorityRects(
706 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion());
707
708 // Populate all tiles directly from the tilings.
709 std::set<Tile*> all_pending_tiles;
710 std::vector<Tile*> pending_high_res_tiles =
711 pending_layer_->HighResTiling()->AllTilesForTesting();
712 all_pending_tiles.insert(pending_high_res_tiles.begin(),
713 pending_high_res_tiles.end());
714 EXPECT_EQ(16u, pending_high_res_tiles.size());
715
716 std::vector<Tile*> pending_low_res_tiles =
717 pending_layer_->LowResTiling()->AllTilesForTesting();
718 all_pending_tiles.insert(pending_low_res_tiles.begin(),
719 pending_low_res_tiles.end());
720 EXPECT_EQ(1u, pending_low_res_tiles.size());
721
722 std::set<Tile*> all_pending_child_tiles;
723 std::vector<Tile*> pending_child_high_res_tiles =
724 pending_child_layer->HighResTiling()->AllTilesForTesting();
725 all_pending_child_tiles.insert(pending_child_high_res_tiles.begin(),
726 pending_child_high_res_tiles.end());
727 EXPECT_EQ(16u, pending_child_high_res_tiles.size());
728
729 std::vector<Tile*> pending_child_low_res_tiles =
730 pending_child_layer->LowResTiling()->AllTilesForTesting();
731 all_pending_child_tiles.insert(pending_child_low_res_tiles.begin(),
732 pending_child_low_res_tiles.end());
733 EXPECT_EQ(1u, pending_child_low_res_tiles.size());
734
735 std::set<Tile*> all_tiles = all_pending_tiles;
736 all_tiles.insert(all_pending_child_tiles.begin(),
737 all_pending_child_tiles.end());
738
739 tile_manager()->InitializeTilesWithResourcesForTesting(
740 std::vector<Tile*>(all_tiles.begin(), all_tiles.end()));
741
742 EXPECT_TRUE(pending_layer_->HasValidTilePriorities());
743 EXPECT_FALSE(pending_child_layer->HasValidTilePriorities());
744
745 // Verify that eviction queue returns tiles also from layers without valid
746 // tile priorities and that the tile priority bin of those tiles is (at most)
747 // EVENTUALLY.
748 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY;
749 std::set<Tile*> new_content_tiles;
750 size_t tile_count = 0;
751 EvictionTilePriorityQueue queue;
752 host_impl_.BuildEvictionQueue(&queue, tree_priority);
753 while (!queue.IsEmpty()) {
754 Tile* tile = queue.Top();
755 const TilePriority& pending_priority = tile->priority(PENDING_TREE);
756 EXPECT_NE(std::numeric_limits<float>::infinity(),
757 pending_priority.distance_to_visible);
758 if (all_pending_child_tiles.find(tile) != all_pending_child_tiles.end())
759 EXPECT_EQ(TilePriority::EVENTUALLY, pending_priority.priority_bin);
760 else
761 EXPECT_EQ(TilePriority::NOW, pending_priority.priority_bin);
762 new_content_tiles.insert(tile);
763 ++tile_count;
764 queue.Pop();
765 }
766 EXPECT_EQ(tile_count, new_content_tiles.size());
767 EXPECT_EQ(all_tiles, new_content_tiles);
768 }
769
672 TEST_F(TileManagerTilePriorityQueueTest, RasterTilePriorityQueueEmptyLayers) { 770 TEST_F(TileManagerTilePriorityQueueTest, RasterTilePriorityQueueEmptyLayers) {
673 SetupDefaultTrees(gfx::Size(1000, 1000)); 771 SetupDefaultTrees(gfx::Size(1000, 1000));
674 772
675 active_layer_->CreateDefaultTilingsAndTiles(); 773 active_layer_->CreateDefaultTilingsAndTiles();
676 pending_layer_->CreateDefaultTilingsAndTiles(); 774 pending_layer_->CreateDefaultTilingsAndTiles();
677 775
678 RasterTilePriorityQueue queue; 776 RasterTilePriorityQueue queue;
679 host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); 777 host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES);
680 EXPECT_FALSE(queue.IsEmpty()); 778 EXPECT_FALSE(queue.IsEmpty());
681 779
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 all_tiles.insert(queue.Top()); 858 all_tiles.insert(queue.Top());
761 ++tile_count; 859 ++tile_count;
762 queue.Pop(); 860 queue.Pop();
763 } 861 }
764 EXPECT_EQ(tile_count, all_tiles.size()); 862 EXPECT_EQ(tile_count, all_tiles.size());
765 EXPECT_EQ(16u, tile_count); 863 EXPECT_EQ(16u, tile_count);
766 } 864 }
767 865
768 } // namespace 866 } // namespace
769 } // namespace cc 867 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_manager_perftest.cc ('k') | cc/scheduler/begin_frame_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698