OLD | NEW |
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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 2944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2955 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | 2955 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); |
2956 EXPECT_FALSE(it); | 2956 EXPECT_FALSE(it); |
2957 | 2957 |
2958 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 2958 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
2959 | 2959 |
2960 std::set<Tile*> unique_tiles; | 2960 std::set<Tile*> unique_tiles; |
2961 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; | 2961 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; |
2962 size_t scale_index = 0; | 2962 size_t scale_index = 0; |
2963 bool reached_visible = false; | 2963 bool reached_visible = false; |
2964 Tile* last_tile = nullptr; | 2964 Tile* last_tile = nullptr; |
| 2965 int distance_decreasing = 0; |
| 2966 int distance_increasing = 0; |
2965 for (it = PictureLayerImpl::LayerEvictionTileIterator( | 2967 for (it = PictureLayerImpl::LayerEvictionTileIterator( |
2966 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | 2968 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); |
2967 it; | 2969 it; |
2968 ++it) { | 2970 ++it) { |
2969 Tile* tile = *it; | 2971 Tile* tile = *it; |
2970 if (!last_tile) | 2972 if (!last_tile) |
2971 last_tile = tile; | 2973 last_tile = tile; |
2972 | 2974 |
2973 EXPECT_TRUE(tile); | 2975 EXPECT_TRUE(tile); |
2974 | 2976 |
2975 TilePriority priority = tile->priority(PENDING_TREE); | 2977 TilePriority priority = tile->priority(PENDING_TREE); |
2976 | 2978 |
2977 if (priority.priority_bin == TilePriority::NOW) { | 2979 if (priority.priority_bin == TilePriority::NOW) { |
2978 reached_visible = true; | 2980 reached_visible = true; |
2979 last_tile = tile; | 2981 last_tile = tile; |
2980 break; | 2982 break; |
2981 } | 2983 } |
2982 | 2984 |
2983 EXPECT_FALSE(tile->required_for_activation()); | 2985 EXPECT_FALSE(tile->required_for_activation()); |
2984 | 2986 |
2985 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > | 2987 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > |
2986 std::numeric_limits<float>::epsilon()) { | 2988 std::numeric_limits<float>::epsilon()) { |
2987 ++scale_index; | 2989 ++scale_index; |
2988 ASSERT_LT(scale_index, arraysize(expected_scales)); | 2990 ASSERT_LT(scale_index, arraysize(expected_scales)); |
2989 } | 2991 } |
2990 | 2992 |
2991 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); | 2993 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); |
2992 unique_tiles.insert(tile); | 2994 unique_tiles.insert(tile); |
2993 | 2995 |
2994 // If the tile is the same rough bin as last tile (same activation, bin, and | |
2995 // scale), then distance should be decreasing. | |
2996 if (tile->required_for_activation() == | 2996 if (tile->required_for_activation() == |
2997 last_tile->required_for_activation() && | 2997 last_tile->required_for_activation() && |
2998 priority.priority_bin == | 2998 priority.priority_bin == |
2999 last_tile->priority(PENDING_TREE).priority_bin && | 2999 last_tile->priority(PENDING_TREE).priority_bin && |
3000 std::abs(tile->contents_scale() - last_tile->contents_scale()) < | 3000 std::abs(tile->contents_scale() - last_tile->contents_scale()) < |
3001 std::numeric_limits<float>::epsilon()) { | 3001 std::numeric_limits<float>::epsilon()) { |
3002 EXPECT_LE(priority.distance_to_visible, | 3002 if (priority.distance_to_visible <= |
3003 last_tile->priority(PENDING_TREE).distance_to_visible); | 3003 last_tile->priority(PENDING_TREE).distance_to_visible) |
| 3004 ++distance_decreasing; |
| 3005 else |
| 3006 ++distance_increasing; |
3004 } | 3007 } |
3005 | 3008 |
3006 last_tile = tile; | 3009 last_tile = tile; |
3007 } | 3010 } |
3008 | 3011 |
| 3012 EXPECT_EQ(7, distance_increasing); |
| 3013 EXPECT_EQ(55, distance_decreasing); |
| 3014 |
3009 EXPECT_TRUE(reached_visible); | 3015 EXPECT_TRUE(reached_visible); |
3010 EXPECT_EQ(65u, unique_tiles.size()); | 3016 EXPECT_EQ(65u, unique_tiles.size()); |
3011 | 3017 |
3012 scale_index = 0; | 3018 scale_index = 0; |
3013 bool reached_required = false; | 3019 bool reached_required = false; |
3014 for (; it; ++it) { | 3020 for (; it; ++it) { |
3015 Tile* tile = *it; | 3021 Tile* tile = *it; |
3016 EXPECT_TRUE(tile); | 3022 EXPECT_TRUE(tile); |
3017 | 3023 |
3018 TilePriority priority = tile->priority(PENDING_TREE); | 3024 TilePriority priority = tile->priority(PENDING_TREE); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3807 class OcclusionTrackingSettings : public LowResTilingsSettings { | 3813 class OcclusionTrackingSettings : public LowResTilingsSettings { |
3808 public: | 3814 public: |
3809 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } | 3815 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } |
3810 }; | 3816 }; |
3811 | 3817 |
3812 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { | 3818 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
3813 public: | 3819 public: |
3814 OcclusionTrackingPictureLayerImplTest() | 3820 OcclusionTrackingPictureLayerImplTest() |
3815 : PictureLayerImplTest(OcclusionTrackingSettings()) {} | 3821 : PictureLayerImplTest(OcclusionTrackingSettings()) {} |
3816 | 3822 |
3817 void VerifyEvictionConsidersOcclusion( | 3823 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer, |
3818 PictureLayerImpl* layer, | 3824 FakePictureLayerImpl* twin_layer, |
3819 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { | 3825 WhichTree tree, |
| 3826 size_t expected_occluded_tile_count) { |
| 3827 twin_layer->set_has_valid_tile_priorities(false); |
3820 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; | 3828 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; |
3821 ++priority_count) { | 3829 ++priority_count) { |
3822 TreePriority tree_priority = static_cast<TreePriority>(priority_count); | 3830 TreePriority tree_priority = static_cast<TreePriority>(priority_count); |
3823 size_t occluded_tile_count = 0u; | 3831 size_t occluded_tile_count = 0u; |
3824 Tile* last_tile = nullptr; | 3832 Tile* last_tile = nullptr; |
| 3833 std::set<Tile*> shared_tiles; |
3825 | 3834 |
3826 for (PictureLayerImpl::LayerEvictionTileIterator it = | 3835 for (PictureLayerImpl::LayerEvictionTileIterator it = |
3827 PictureLayerImpl::LayerEvictionTileIterator(layer, | 3836 PictureLayerImpl::LayerEvictionTileIterator(layer, |
3828 tree_priority); | 3837 tree_priority); |
3829 it; | 3838 it; ++it) { |
3830 ++it) { | |
3831 Tile* tile = *it; | 3839 Tile* tile = *it; |
3832 if (!last_tile) | 3840 if (!last_tile) |
3833 last_tile = tile; | 3841 last_tile = tile; |
| 3842 if (tile->is_shared()) |
| 3843 EXPECT_TRUE(shared_tiles.insert(tile).second); |
3834 | 3844 |
3835 // The only way we will encounter an occluded tile after an unoccluded | 3845 // The only way we will encounter an occluded tile after an unoccluded |
3836 // tile is if the priorty bin decreased, the tile is required for | 3846 // tile is if the priorty bin decreased, the tile is required for |
3837 // activation, or the scale changed. | 3847 // activation, or the scale changed. |
3838 bool tile_is_occluded = | 3848 bool tile_is_occluded = tile->is_occluded(tree); |
3839 tile->is_occluded_for_tree_priority(tree_priority); | |
3840 if (tile_is_occluded) { | 3849 if (tile_is_occluded) { |
3841 occluded_tile_count++; | 3850 occluded_tile_count++; |
3842 | 3851 |
3843 bool last_tile_is_occluded = | 3852 bool last_tile_is_occluded = last_tile->is_occluded(tree); |
3844 last_tile->is_occluded_for_tree_priority(tree_priority); | |
3845 if (!last_tile_is_occluded) { | 3853 if (!last_tile_is_occluded) { |
3846 TilePriority::PriorityBin tile_priority_bin = | 3854 TilePriority::PriorityBin tile_priority_bin = |
3847 tile->priority_for_tree_priority(tree_priority).priority_bin; | 3855 tile->priority(tree).priority_bin; |
3848 TilePriority::PriorityBin last_tile_priority_bin = | 3856 TilePriority::PriorityBin last_tile_priority_bin = |
3849 last_tile->priority_for_tree_priority(tree_priority) | 3857 last_tile->priority(tree).priority_bin; |
3850 .priority_bin; | |
3851 | 3858 |
3852 EXPECT_TRUE( | 3859 EXPECT_TRUE( |
3853 (tile_priority_bin < last_tile_priority_bin) || | 3860 (tile_priority_bin < last_tile_priority_bin) || |
3854 tile->required_for_activation() || | 3861 tile->required_for_activation() || |
3855 (tile->contents_scale() != last_tile->contents_scale())); | 3862 (tile->contents_scale() != last_tile->contents_scale())); |
3856 } | 3863 } |
3857 } | 3864 } |
3858 last_tile = tile; | 3865 last_tile = tile; |
3859 } | 3866 } |
3860 EXPECT_EQ(expected_occluded_tile_count[priority_count], | 3867 for (PictureLayerImpl::LayerEvictionTileIterator it = |
3861 occluded_tile_count); | 3868 PictureLayerImpl::LayerEvictionTileIterator(twin_layer, |
| 3869 tree_priority); |
| 3870 it; ++it) { |
| 3871 Tile* tile = *it; |
| 3872 if (tile->is_shared()) |
| 3873 EXPECT_TRUE(shared_tiles.insert(tile).second); |
| 3874 else |
| 3875 continue; |
| 3876 if (tile->is_occluded(tree)) |
| 3877 ++occluded_tile_count; |
| 3878 } |
| 3879 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count); |
3862 } | 3880 } |
| 3881 twin_layer->set_has_valid_tile_priorities(true); |
3863 } | 3882 } |
3864 }; | 3883 }; |
3865 | 3884 |
3866 TEST_F(OcclusionTrackingPictureLayerImplTest, | 3885 TEST_F(OcclusionTrackingPictureLayerImplTest, |
3867 OccludedTilesSkippedDuringRasterization) { | 3886 OccludedTilesSkippedDuringRasterization) { |
3868 base::TimeTicks time_ticks; | 3887 base::TimeTicks time_ticks; |
3869 time_ticks += base::TimeDelta::FromMilliseconds(1); | 3888 time_ticks += base::TimeDelta::FromMilliseconds(1); |
3870 host_impl_.SetCurrentBeginFrameArgs( | 3889 host_impl_.SetCurrentBeginFrameArgs( |
3871 CreateBeginFrameArgsForTesting(time_ticks)); | 3890 CreateBeginFrameArgsForTesting(time_ticks)); |
3872 | 3891 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4325 host_impl_.SetViewportSize(viewport_size); | 4344 host_impl_.SetViewportSize(viewport_size); |
4326 host_impl_.active_tree()->UpdateDrawProperties(); | 4345 host_impl_.active_tree()->UpdateDrawProperties(); |
4327 host_impl_.pending_tree()->UpdateDrawProperties(); | 4346 host_impl_.pending_tree()->UpdateDrawProperties(); |
4328 | 4347 |
4329 // The expected number of occluded tiles on each of the 5 tilings for each of | 4348 // The expected number of occluded tiles on each of the 5 tilings for each of |
4330 // the 3 tree priorities. | 4349 // the 3 tree priorities. |
4331 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; | 4350 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; |
4332 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; | 4351 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; |
4333 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; | 4352 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; |
4334 | 4353 |
4335 // The total expected number of occluded tiles on all tilings for each of the | 4354 size_t total_expected_occluded_tile_count_on_trees[] = {43u, 43u}; |
4336 // 3 tree priorities. | |
4337 size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u}; | |
4338 | |
4339 ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES); | |
4340 | 4355 |
4341 // Verify number of occluded tiles on the pending layer for each tiling. | 4356 // Verify number of occluded tiles on the pending layer for each tiling. |
4342 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 4357 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
4343 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 4358 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
4344 tiling->CreateAllTilesForTesting(); | 4359 tiling->CreateAllTilesForTesting(); |
4345 tiling->UpdateAllTilePrioritiesForTesting(); | 4360 tiling->UpdateAllTilePrioritiesForTesting(); |
4346 | 4361 |
4347 size_t occluded_tile_count_on_pending = 0u; | 4362 size_t occluded_tile_count_on_pending = 0u; |
4348 size_t occluded_tile_count_on_active = 0u; | 4363 size_t occluded_tile_count_on_active = 0u; |
4349 size_t occluded_tile_count_on_both = 0u; | 4364 size_t occluded_tile_count_on_both = 0u; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4412 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 4427 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
4413 tilings.begin(); | 4428 tilings.begin(); |
4414 tiling_iterator != tilings.end(); | 4429 tiling_iterator != tilings.end(); |
4415 ++tiling_iterator) { | 4430 ++tiling_iterator) { |
4416 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 4431 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
4417 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | 4432 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
4418 } | 4433 } |
4419 | 4434 |
4420 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 4435 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
4421 | 4436 |
4422 VerifyEvictionConsidersOcclusion(pending_layer_, | 4437 VerifyEvictionConsidersOcclusion( |
4423 total_expected_occluded_tile_count); | 4438 pending_layer_, active_layer_, PENDING_TREE, |
4424 VerifyEvictionConsidersOcclusion(active_layer_, | 4439 total_expected_occluded_tile_count_on_trees[PENDING_TREE]); |
4425 total_expected_occluded_tile_count); | 4440 VerifyEvictionConsidersOcclusion( |
| 4441 active_layer_, pending_layer_, ACTIVE_TREE, |
| 4442 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE]); |
4426 } | 4443 } |
4427 | 4444 |
4428 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { | 4445 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { |
4429 gfx::Size tile_size(102, 102); | 4446 gfx::Size tile_size(102, 102); |
4430 gfx::Size layer_bounds(1000, 1000); | 4447 gfx::Size layer_bounds(1000, 1000); |
4431 | 4448 |
4432 scoped_refptr<FakePicturePileImpl> pile = | 4449 scoped_refptr<FakePicturePileImpl> pile = |
4433 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 4450 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
4434 SetupPendingTree(pile); | 4451 SetupPendingTree(pile); |
4435 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); | 4452 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4722 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4739 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4723 EXPECT_EQ(result.width(), 448); | 4740 EXPECT_EQ(result.width(), 448); |
4724 EXPECT_EQ(result.height(), 448); | 4741 EXPECT_EQ(result.height(), 448); |
4725 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4742 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4726 EXPECT_EQ(result.width(), 512); | 4743 EXPECT_EQ(result.width(), 512); |
4727 EXPECT_EQ(result.height(), 500 + 2); | 4744 EXPECT_EQ(result.height(), 500 + 2); |
4728 } | 4745 } |
4729 | 4746 |
4730 } // namespace | 4747 } // namespace |
4731 } // namespace cc | 4748 } // namespace cc |
OLD | NEW |