Index: cc/layers/picture_layer_impl_unittest.cc |
diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc |
index fc7c918ac0226ac59318b7c6eeda069e1fd889f1..26201739ce5bc13d7ee54a41f3517a79a08a43ee 100644 |
--- a/cc/layers/picture_layer_impl_unittest.cc |
+++ b/cc/layers/picture_layer_impl_unittest.cc |
@@ -2924,6 +2924,54 @@ class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
public: |
OcclusionTrackingPictureLayerImplTest() |
: PictureLayerImplTest(OcclusionTrackingSettings()) {} |
+ |
+ void VerifyEvictionConsidersOcclusion( |
+ PictureLayerImpl* layer, |
+ size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { |
+ for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; |
+ ++priority_count) { |
+ TreePriority tree_priority = static_cast<TreePriority>(priority_count); |
+ size_t occluded_tile_count = 0u; |
+ Tile* last_tile = NULL; |
+ |
+ for (PictureLayerImpl::LayerEvictionTileIterator it = |
+ PictureLayerImpl::LayerEvictionTileIterator(layer, |
+ tree_priority); |
+ it; |
+ ++it) { |
+ Tile* tile = *it; |
+ if (!last_tile) |
+ last_tile = tile; |
+ |
+ // The only way we will encounter an occluded tile after an unoccluded |
+ // tile is if the priorty bin decreased, the tile is required for |
+ // activation, or the scale changed. |
+ bool tile_is_occluded = |
+ tile->is_occluded_for_tree_priority(tree_priority); |
+ if (tile_is_occluded) { |
+ occluded_tile_count++; |
+ |
+ bool last_tile_is_occluded = |
+ last_tile->is_occluded_for_tree_priority(tree_priority); |
+ if (!last_tile_is_occluded) { |
+ TilePriority::PriorityBin tile_priority_bin = |
+ tile->priority_for_tree_priority(tree_priority).priority_bin; |
+ TilePriority::PriorityBin last_tile_priority_bin = |
+ last_tile->priority_for_tree_priority(tree_priority) |
+ .priority_bin; |
+ |
+ EXPECT_TRUE( |
+ (tile_priority_bin < last_tile_priority_bin) || |
+ tile->required_for_activation() || |
+ (tile->contents_scale() != last_tile->contents_scale())); |
+ } |
+ } |
+ last_tile = tile; |
+ } |
+ EXPECT_EQ(expected_occluded_tile_count[priority_count], |
+ occluded_tile_count); |
+ } |
+ } |
}; |
#if defined(OS_WIN) |
@@ -3319,5 +3367,158 @@ TEST_F(OcclusionTrackingPictureLayerImplTest, DifferentOcclusionOnTrees) { |
} |
} |
} |
+ |
+TEST_F(OcclusionTrackingPictureLayerImplTest, |
+ OccludedTilesConsideredDuringEviction) { |
+ gfx::Size tile_size(102, 102); |
+ gfx::Size layer_bounds(1000, 1000); |
+ gfx::Size viewport_size(500, 500); |
+ gfx::Point pending_occluding_layer_position(310, 0); |
+ gfx::Point active_occluding_layer_position(0, 310); |
+ gfx::Rect invalidation_rect(230, 230, 102, 102); |
+ |
+ scoped_refptr<FakePicturePileImpl> pending_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ scoped_refptr<FakePicturePileImpl> active_pile = |
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
+ SetupTrees(pending_pile, active_pile); |
+ |
+ pending_layer_->set_fixed_tile_size(tile_size); |
+ active_layer_->set_fixed_tile_size(tile_size); |
+ |
+ float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
+ |
+ std::vector<PictureLayerTiling*> tilings; |
+ tilings.push_back(pending_layer_->AddTiling(low_res_factor)); |
+ tilings.push_back(pending_layer_->AddTiling(0.3f)); |
+ tilings.push_back(pending_layer_->AddTiling(0.7f)); |
+ tilings.push_back(pending_layer_->AddTiling(1.0f)); |
+ tilings.push_back(pending_layer_->AddTiling(2.0f)); |
+ |
+ EXPECT_EQ(5u, pending_layer_->num_tilings()); |
+ EXPECT_EQ(5u, active_layer_->num_tilings()); |
+ |
+ // Partially occlude the pending layer. |
+ pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); |
+ LayerImpl* pending_occluding_layer = pending_layer_->children()[0]; |
+ pending_occluding_layer->SetBounds(layer_bounds); |
+ pending_occluding_layer->SetContentBounds(layer_bounds); |
+ pending_occluding_layer->SetDrawsContent(true); |
+ pending_occluding_layer->SetContentsOpaque(true); |
+ pending_occluding_layer->SetPosition(pending_occluding_layer_position); |
+ |
+ // Partially occlude the active layer. |
+ active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2)); |
+ LayerImpl* active_occluding_layer = active_layer_->children()[0]; |
+ active_occluding_layer->SetBounds(layer_bounds); |
+ active_occluding_layer->SetContentBounds(layer_bounds); |
+ active_occluding_layer->SetDrawsContent(true); |
+ active_occluding_layer->SetContentsOpaque(true); |
+ active_occluding_layer->SetPosition(active_occluding_layer_position); |
+ |
+ // Partially invalidate the pending layer. Tiles inside the invalidation rect |
+ // are not shared between trees. |
+ pending_layer_->set_invalidation(invalidation_rect); |
+ |
+ host_impl_.SetViewportSize(viewport_size); |
+ host_impl_.active_tree()->UpdateDrawProperties(); |
+ host_impl_.pending_tree()->UpdateDrawProperties(); |
+ |
+ // The expected number of occluded tiles on each of the 5 tilings for each of |
+ // the 3 tree priorities. |
+ size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; |
+ size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; |
+ size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; |
+ |
+ // The total expected number of occluded tiles on all tilings for each of the |
+ // 3 tree priorities. |
+ size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u}; |
+ |
+ ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES); |
+ |
+ // Verify number of occluded tiles on the pending layer for each tiling. |
+ for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
+ PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
+ tiling->CreateAllTilesForTesting(); |
+ |
+ size_t occluded_tile_count_on_pending = 0u; |
+ size_t occluded_tile_count_on_active = 0u; |
+ size_t occluded_tile_count_on_both = 0u; |
+ for (PictureLayerTiling::CoverageIterator iter( |
+ tiling, |
+ pending_layer_->contents_scale_x(), |
+ gfx::Rect(layer_bounds)); |
+ iter; |
+ ++iter) { |
+ Tile* tile = *iter; |
+ |
+ if (tile->is_occluded(PENDING_TREE)) |
+ occluded_tile_count_on_pending++; |
+ if (tile->is_occluded(ACTIVE_TREE)) |
+ occluded_tile_count_on_active++; |
+ if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) |
+ occluded_tile_count_on_both++; |
+ } |
+ EXPECT_EQ(expected_occluded_tile_count_on_pending[i], |
+ occluded_tile_count_on_pending) |
+ << i; |
+ EXPECT_EQ(expected_occluded_tile_count_on_active[i], |
+ occluded_tile_count_on_active) |
+ << i; |
+ EXPECT_EQ(expected_occluded_tile_count_on_both[i], |
+ occluded_tile_count_on_both) |
+ << i; |
+ } |
+ |
+ // Verify number of occluded tiles on the active layer for each tiling. |
+ for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { |
+ PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i); |
+ tiling->CreateAllTilesForTesting(); |
+ |
+ size_t occluded_tile_count_on_pending = 0u; |
+ size_t occluded_tile_count_on_active = 0u; |
+ size_t occluded_tile_count_on_both = 0u; |
+ for (PictureLayerTiling::CoverageIterator iter( |
+ tiling, |
+ pending_layer_->contents_scale_x(), |
+ gfx::Rect(layer_bounds)); |
+ iter; |
+ ++iter) { |
+ Tile* tile = *iter; |
+ |
+ if (tile->is_occluded(PENDING_TREE)) |
+ occluded_tile_count_on_pending++; |
+ if (tile->is_occluded(ACTIVE_TREE)) |
+ occluded_tile_count_on_active++; |
+ if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) |
+ occluded_tile_count_on_both++; |
+ } |
+ EXPECT_EQ(expected_occluded_tile_count_on_pending[i], |
+ occluded_tile_count_on_pending) |
+ << i; |
+ EXPECT_EQ(expected_occluded_tile_count_on_active[i], |
+ occluded_tile_count_on_active) |
+ << i; |
+ EXPECT_EQ(expected_occluded_tile_count_on_both[i], |
+ occluded_tile_count_on_both) |
+ << i; |
+ } |
+ |
+ std::vector<Tile*> all_tiles; |
+ for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
+ tilings.begin(); |
+ tiling_iterator != tilings.end(); |
+ ++tiling_iterator) { |
+ std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
+ std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
+ } |
+ |
+ host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
+ |
+ VerifyEvictionConsidersOcclusion(pending_layer_, |
+ total_expected_occluded_tile_count); |
+ VerifyEvictionConsidersOcclusion(active_layer_, |
+ total_expected_occluded_tile_count); |
+} |
} // namespace |
} // namespace cc |