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