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 2933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2944 EXPECT_EQ(91u, all_tiles.size()); | 2944 EXPECT_EQ(91u, all_tiles.size()); |
2945 EXPECT_EQ(91u, all_tiles_set.size()); | 2945 EXPECT_EQ(91u, all_tiles_set.size()); |
2946 EXPECT_GT(number_of_marked_tiles, 1u); | 2946 EXPECT_GT(number_of_marked_tiles, 1u); |
2947 EXPECT_GT(number_of_unmarked_tiles, 1u); | 2947 EXPECT_GT(number_of_unmarked_tiles, 1u); |
2948 | 2948 |
2949 // Empty iterator. | 2949 // Empty iterator. |
2950 PictureLayerImpl::LayerEvictionTileIterator it; | 2950 PictureLayerImpl::LayerEvictionTileIterator it; |
2951 EXPECT_FALSE(it); | 2951 EXPECT_FALSE(it); |
2952 | 2952 |
2953 // Tiles don't have resources yet. | 2953 // Tiles don't have resources yet. |
2954 it = PictureLayerImpl::LayerEvictionTileIterator( | 2954 it = PictureLayerImpl::LayerEvictionTileIterator(pending_layer_); |
2955 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | |
2956 EXPECT_FALSE(it); | 2955 EXPECT_FALSE(it); |
2957 | 2956 |
2958 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 2957 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
2959 | 2958 |
2960 std::set<Tile*> unique_tiles; | 2959 std::set<Tile*> unique_tiles; |
2961 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; | 2960 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; |
2962 size_t scale_index = 0; | 2961 size_t scale_index = 0; |
2963 bool reached_visible = false; | 2962 bool reached_visible = false; |
2964 Tile* last_tile = nullptr; | 2963 Tile* last_tile = nullptr; |
2965 for (it = PictureLayerImpl::LayerEvictionTileIterator( | 2964 int distance_decreasing = 0; |
2966 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | 2965 int distance_increasing = 0; |
2967 it; | 2966 for (it = PictureLayerImpl::LayerEvictionTileIterator(pending_layer_); it; |
2968 ++it) { | 2967 ++it) { |
2969 Tile* tile = *it; | 2968 Tile* tile = *it; |
2970 if (!last_tile) | 2969 if (!last_tile) |
2971 last_tile = tile; | 2970 last_tile = tile; |
2972 | 2971 |
2973 EXPECT_TRUE(tile); | 2972 EXPECT_TRUE(tile); |
2974 | 2973 |
2975 TilePriority priority = tile->priority(PENDING_TREE); | 2974 TilePriority priority = tile->priority(PENDING_TREE); |
2976 | 2975 |
2977 if (priority.priority_bin == TilePriority::NOW) { | 2976 if (priority.priority_bin == TilePriority::NOW) { |
2978 reached_visible = true; | 2977 reached_visible = true; |
2979 last_tile = tile; | 2978 last_tile = tile; |
2980 break; | 2979 break; |
2981 } | 2980 } |
2982 | 2981 |
2983 EXPECT_FALSE(tile->required_for_activation()); | 2982 EXPECT_FALSE(tile->required_for_activation()); |
2984 | 2983 |
2985 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > | 2984 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > |
2986 std::numeric_limits<float>::epsilon()) { | 2985 std::numeric_limits<float>::epsilon()) { |
2987 ++scale_index; | 2986 ++scale_index; |
2988 ASSERT_LT(scale_index, arraysize(expected_scales)); | 2987 ASSERT_LT(scale_index, arraysize(expected_scales)); |
2989 } | 2988 } |
2990 | 2989 |
2991 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); | 2990 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); |
2992 unique_tiles.insert(tile); | 2991 unique_tiles.insert(tile); |
2993 | 2992 |
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() == | 2993 if (tile->required_for_activation() == |
2997 last_tile->required_for_activation() && | 2994 last_tile->required_for_activation() && |
2998 priority.priority_bin == | 2995 priority.priority_bin == |
2999 last_tile->priority(PENDING_TREE).priority_bin && | 2996 last_tile->priority(PENDING_TREE).priority_bin && |
3000 std::abs(tile->contents_scale() - last_tile->contents_scale()) < | 2997 std::abs(tile->contents_scale() - last_tile->contents_scale()) < |
3001 std::numeric_limits<float>::epsilon()) { | 2998 std::numeric_limits<float>::epsilon()) { |
3002 EXPECT_LE(priority.distance_to_visible, | 2999 if (priority.distance_to_visible <= |
3003 last_tile->priority(PENDING_TREE).distance_to_visible); | 3000 last_tile->priority(PENDING_TREE).distance_to_visible) { |
| 3001 ++distance_decreasing; |
| 3002 } else { |
| 3003 ++distance_increasing; |
| 3004 } |
3004 } | 3005 } |
3005 | 3006 |
3006 last_tile = tile; | 3007 last_tile = tile; |
3007 } | 3008 } |
3008 | 3009 |
| 3010 EXPECT_EQ(7, distance_increasing); |
| 3011 EXPECT_EQ(55, distance_decreasing); |
| 3012 |
3009 EXPECT_TRUE(reached_visible); | 3013 EXPECT_TRUE(reached_visible); |
3010 EXPECT_EQ(65u, unique_tiles.size()); | 3014 EXPECT_EQ(65u, unique_tiles.size()); |
3011 | 3015 |
3012 scale_index = 0; | 3016 scale_index = 0; |
3013 bool reached_required = false; | 3017 bool reached_required = false; |
3014 for (; it; ++it) { | 3018 for (; it; ++it) { |
3015 Tile* tile = *it; | 3019 Tile* tile = *it; |
3016 EXPECT_TRUE(tile); | 3020 EXPECT_TRUE(tile); |
3017 | 3021 |
3018 TilePriority priority = tile->priority(PENDING_TREE); | 3022 TilePriority priority = tile->priority(PENDING_TREE); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3807 class OcclusionTrackingSettings : public LowResTilingsSettings { | 3811 class OcclusionTrackingSettings : public LowResTilingsSettings { |
3808 public: | 3812 public: |
3809 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } | 3813 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } |
3810 }; | 3814 }; |
3811 | 3815 |
3812 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { | 3816 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
3813 public: | 3817 public: |
3814 OcclusionTrackingPictureLayerImplTest() | 3818 OcclusionTrackingPictureLayerImplTest() |
3815 : PictureLayerImplTest(OcclusionTrackingSettings()) {} | 3819 : PictureLayerImplTest(OcclusionTrackingSettings()) {} |
3816 | 3820 |
3817 void VerifyEvictionConsidersOcclusion( | 3821 void VerifyEvictionConsidersOcclusion(PictureLayerImpl* layer, |
3818 PictureLayerImpl* layer, | 3822 WhichTree tree, |
3819 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { | 3823 size_t expected_occluded_tile_count) { |
3820 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; | 3824 size_t occluded_tile_count = 0u; |
3821 ++priority_count) { | 3825 Tile* last_tile = nullptr; |
3822 TreePriority tree_priority = static_cast<TreePriority>(priority_count); | |
3823 size_t occluded_tile_count = 0u; | |
3824 Tile* last_tile = nullptr; | |
3825 | 3826 |
3826 for (PictureLayerImpl::LayerEvictionTileIterator it = | 3827 for (PictureLayerImpl::LayerEvictionTileIterator it = |
3827 PictureLayerImpl::LayerEvictionTileIterator(layer, | 3828 PictureLayerImpl::LayerEvictionTileIterator(layer); |
3828 tree_priority); | 3829 it; ++it) { |
3829 it; | 3830 Tile* tile = *it; |
3830 ++it) { | 3831 if (!last_tile) |
3831 Tile* tile = *it; | 3832 last_tile = tile; |
3832 if (!last_tile) | |
3833 last_tile = tile; | |
3834 | 3833 |
3835 // The only way we will encounter an occluded tile after an unoccluded | 3834 // 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 | 3835 // tile is if the priorty bin decreased, the tile is required for |
3837 // activation, or the scale changed. | 3836 // activation, or the scale changed. |
3838 bool tile_is_occluded = | 3837 bool tile_is_occluded = tile->is_occluded(tree); |
3839 tile->is_occluded_for_tree_priority(tree_priority); | 3838 if (tile_is_occluded) { |
3840 if (tile_is_occluded) { | 3839 occluded_tile_count++; |
3841 occluded_tile_count++; | |
3842 | 3840 |
3843 bool last_tile_is_occluded = | 3841 bool last_tile_is_occluded = last_tile->is_occluded(tree); |
3844 last_tile->is_occluded_for_tree_priority(tree_priority); | 3842 if (!last_tile_is_occluded) { |
3845 if (!last_tile_is_occluded) { | 3843 TilePriority::PriorityBin tile_priority_bin = |
3846 TilePriority::PriorityBin tile_priority_bin = | 3844 tile->priority(tree).priority_bin; |
3847 tile->priority_for_tree_priority(tree_priority).priority_bin; | 3845 TilePriority::PriorityBin last_tile_priority_bin = |
3848 TilePriority::PriorityBin last_tile_priority_bin = | 3846 last_tile->priority(tree).priority_bin; |
3849 last_tile->priority_for_tree_priority(tree_priority) | |
3850 .priority_bin; | |
3851 | 3847 |
3852 EXPECT_TRUE( | 3848 EXPECT_TRUE((tile_priority_bin < last_tile_priority_bin) || |
3853 (tile_priority_bin < last_tile_priority_bin) || | 3849 tile->required_for_activation() || |
3854 tile->required_for_activation() || | 3850 (tile->contents_scale() != last_tile->contents_scale())); |
3855 (tile->contents_scale() != last_tile->contents_scale())); | |
3856 } | |
3857 } | 3851 } |
3858 last_tile = tile; | |
3859 } | 3852 } |
3860 EXPECT_EQ(expected_occluded_tile_count[priority_count], | 3853 last_tile = tile; |
3861 occluded_tile_count); | |
3862 } | 3854 } |
| 3855 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count); |
3863 } | 3856 } |
3864 }; | 3857 }; |
3865 | 3858 |
3866 TEST_F(OcclusionTrackingPictureLayerImplTest, | 3859 TEST_F(OcclusionTrackingPictureLayerImplTest, |
3867 OccludedTilesSkippedDuringRasterization) { | 3860 OccludedTilesSkippedDuringRasterization) { |
3868 base::TimeTicks time_ticks; | 3861 base::TimeTicks time_ticks; |
3869 time_ticks += base::TimeDelta::FromMilliseconds(1); | 3862 time_ticks += base::TimeDelta::FromMilliseconds(1); |
3870 host_impl_.SetCurrentBeginFrameArgs( | 3863 host_impl_.SetCurrentBeginFrameArgs( |
3871 CreateBeginFrameArgsForTesting(time_ticks)); | 3864 CreateBeginFrameArgsForTesting(time_ticks)); |
3872 | 3865 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4325 host_impl_.SetViewportSize(viewport_size); | 4318 host_impl_.SetViewportSize(viewport_size); |
4326 host_impl_.active_tree()->UpdateDrawProperties(); | 4319 host_impl_.active_tree()->UpdateDrawProperties(); |
4327 host_impl_.pending_tree()->UpdateDrawProperties(); | 4320 host_impl_.pending_tree()->UpdateDrawProperties(); |
4328 | 4321 |
4329 // The expected number of occluded tiles on each of the 5 tilings for each of | 4322 // The expected number of occluded tiles on each of the 5 tilings for each of |
4330 // the 3 tree priorities. | 4323 // the 3 tree priorities. |
4331 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; | 4324 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}; | 4325 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}; | 4326 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; |
4334 | 4327 |
4335 // The total expected number of occluded tiles on all tilings for each of the | 4328 size_t total_expected_occluded_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 | 4329 |
4341 // Verify number of occluded tiles on the pending layer for each tiling. | 4330 // Verify number of occluded tiles on the pending layer for each tiling. |
4342 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 4331 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
4343 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 4332 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
4344 tiling->CreateAllTilesForTesting(); | 4333 tiling->CreateAllTilesForTesting(); |
4345 tiling->UpdateAllTilePrioritiesForTesting(); | 4334 tiling->UpdateAllTilePrioritiesForTesting(); |
4346 | 4335 |
4347 size_t occluded_tile_count_on_pending = 0u; | 4336 size_t occluded_tile_count_on_pending = 0u; |
4348 size_t occluded_tile_count_on_active = 0u; | 4337 size_t occluded_tile_count_on_active = 0u; |
4349 size_t occluded_tile_count_on_both = 0u; | 4338 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 = | 4401 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
4413 tilings.begin(); | 4402 tilings.begin(); |
4414 tiling_iterator != tilings.end(); | 4403 tiling_iterator != tilings.end(); |
4415 ++tiling_iterator) { | 4404 ++tiling_iterator) { |
4416 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 4405 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
4417 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | 4406 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
4418 } | 4407 } |
4419 | 4408 |
4420 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 4409 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
4421 | 4410 |
4422 VerifyEvictionConsidersOcclusion(pending_layer_, | 4411 VerifyEvictionConsidersOcclusion( |
4423 total_expected_occluded_tile_count); | 4412 pending_layer_, PENDING_TREE, |
4424 VerifyEvictionConsidersOcclusion(active_layer_, | 4413 total_expected_occluded_count_on_trees[PENDING_TREE]); |
4425 total_expected_occluded_tile_count); | 4414 VerifyEvictionConsidersOcclusion( |
| 4415 active_layer_, ACTIVE_TREE, |
| 4416 total_expected_occluded_count_on_trees[ACTIVE_TREE]); |
4426 } | 4417 } |
4427 | 4418 |
4428 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { | 4419 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { |
4429 gfx::Size tile_size(102, 102); | 4420 gfx::Size tile_size(102, 102); |
4430 gfx::Size layer_bounds(1000, 1000); | 4421 gfx::Size layer_bounds(1000, 1000); |
4431 | 4422 |
4432 scoped_refptr<FakePicturePileImpl> pile = | 4423 scoped_refptr<FakePicturePileImpl> pile = |
4433 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 4424 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
4434 SetupPendingTree(pile); | 4425 SetupPendingTree(pile); |
4435 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); | 4426 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)); | 4713 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4723 EXPECT_EQ(result.width(), 448); | 4714 EXPECT_EQ(result.width(), 448); |
4724 EXPECT_EQ(result.height(), 448); | 4715 EXPECT_EQ(result.height(), 448); |
4725 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4716 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4726 EXPECT_EQ(result.width(), 512); | 4717 EXPECT_EQ(result.width(), 512); |
4727 EXPECT_EQ(result.height(), 500 + 2); | 4718 EXPECT_EQ(result.height(), 500 + 2); |
4728 } | 4719 } |
4729 | 4720 |
4730 } // namespace | 4721 } // namespace |
4731 } // namespace cc | 4722 } // namespace cc |
OLD | NEW |