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 2893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2904 EXPECT_EQ(91u, all_tiles.size()); | 2904 EXPECT_EQ(91u, all_tiles.size()); |
2905 EXPECT_EQ(91u, all_tiles_set.size()); | 2905 EXPECT_EQ(91u, all_tiles_set.size()); |
2906 EXPECT_GT(number_of_marked_tiles, 1u); | 2906 EXPECT_GT(number_of_marked_tiles, 1u); |
2907 EXPECT_GT(number_of_unmarked_tiles, 1u); | 2907 EXPECT_GT(number_of_unmarked_tiles, 1u); |
2908 | 2908 |
2909 // Empty iterator. | 2909 // Empty iterator. |
2910 PictureLayerImpl::LayerEvictionTileIterator it; | 2910 PictureLayerImpl::LayerEvictionTileIterator it; |
2911 EXPECT_FALSE(it); | 2911 EXPECT_FALSE(it); |
2912 | 2912 |
2913 // Tiles don't have resources yet. | 2913 // Tiles don't have resources yet. |
2914 it = PictureLayerImpl::LayerEvictionTileIterator( | 2914 it = PictureLayerImpl::LayerEvictionTileIterator(pending_layer_); |
2915 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | |
2916 EXPECT_FALSE(it); | 2915 EXPECT_FALSE(it); |
2917 | 2916 |
2918 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 2917 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
2919 | 2918 |
2920 std::set<Tile*> unique_tiles; | 2919 std::set<Tile*> unique_tiles; |
2921 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; | 2920 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; |
2922 size_t scale_index = 0; | 2921 size_t scale_index = 0; |
2923 bool reached_visible = false; | 2922 bool reached_visible = false; |
2924 Tile* last_tile = nullptr; | 2923 Tile* last_tile = nullptr; |
2925 for (it = PictureLayerImpl::LayerEvictionTileIterator( | 2924 int distance_decreasing = 0; |
2926 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | 2925 int distance_increasing = 0; |
2927 it; | 2926 for (it = PictureLayerImpl::LayerEvictionTileIterator(pending_layer_); it; |
2928 ++it) { | 2927 ++it) { |
2929 Tile* tile = *it; | 2928 Tile* tile = *it; |
2930 if (!last_tile) | 2929 if (!last_tile) |
2931 last_tile = tile; | 2930 last_tile = tile; |
2932 | 2931 |
2933 EXPECT_TRUE(tile); | 2932 EXPECT_TRUE(tile); |
2934 | 2933 |
2935 TilePriority priority = tile->priority(PENDING_TREE); | 2934 TilePriority priority = tile->priority(PENDING_TREE); |
2936 | 2935 |
2937 if (priority.priority_bin == TilePriority::NOW) { | 2936 if (priority.priority_bin == TilePriority::NOW) { |
2938 reached_visible = true; | 2937 reached_visible = true; |
2939 last_tile = tile; | 2938 last_tile = tile; |
2940 break; | 2939 break; |
2941 } | 2940 } |
2942 | 2941 |
2943 EXPECT_FALSE(tile->required_for_activation()); | 2942 EXPECT_FALSE(tile->required_for_activation()); |
2944 | 2943 |
2945 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > | 2944 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > |
2946 std::numeric_limits<float>::epsilon()) { | 2945 std::numeric_limits<float>::epsilon()) { |
2947 ++scale_index; | 2946 ++scale_index; |
2948 ASSERT_LT(scale_index, arraysize(expected_scales)); | 2947 ASSERT_LT(scale_index, arraysize(expected_scales)); |
2949 } | 2948 } |
2950 | 2949 |
2951 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); | 2950 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); |
2952 unique_tiles.insert(tile); | 2951 unique_tiles.insert(tile); |
2953 | 2952 |
2954 // If the tile is the same rough bin as last tile (same activation, bin, and | |
2955 // scale), then distance should be decreasing. | |
2956 if (tile->required_for_activation() == | 2953 if (tile->required_for_activation() == |
2957 last_tile->required_for_activation() && | 2954 last_tile->required_for_activation() && |
2958 priority.priority_bin == | 2955 priority.priority_bin == |
2959 last_tile->priority(PENDING_TREE).priority_bin && | 2956 last_tile->priority(PENDING_TREE).priority_bin && |
2960 std::abs(tile->contents_scale() - last_tile->contents_scale()) < | 2957 std::abs(tile->contents_scale() - last_tile->contents_scale()) < |
2961 std::numeric_limits<float>::epsilon()) { | 2958 std::numeric_limits<float>::epsilon()) { |
2962 EXPECT_LE(priority.distance_to_visible, | 2959 if (priority.distance_to_visible <= |
2963 last_tile->priority(PENDING_TREE).distance_to_visible); | 2960 last_tile->priority(PENDING_TREE).distance_to_visible) { |
| 2961 ++distance_decreasing; |
| 2962 } else { |
| 2963 ++distance_increasing; |
| 2964 } |
2964 } | 2965 } |
2965 | 2966 |
2966 last_tile = tile; | 2967 last_tile = tile; |
2967 } | 2968 } |
2968 | 2969 |
| 2970 EXPECT_EQ(7, distance_increasing); |
| 2971 EXPECT_EQ(55, distance_decreasing); |
| 2972 |
2969 EXPECT_TRUE(reached_visible); | 2973 EXPECT_TRUE(reached_visible); |
2970 EXPECT_EQ(65u, unique_tiles.size()); | 2974 EXPECT_EQ(65u, unique_tiles.size()); |
2971 | 2975 |
2972 scale_index = 0; | 2976 scale_index = 0; |
2973 bool reached_required = false; | 2977 bool reached_required = false; |
2974 for (; it; ++it) { | 2978 for (; it; ++it) { |
2975 Tile* tile = *it; | 2979 Tile* tile = *it; |
2976 EXPECT_TRUE(tile); | 2980 EXPECT_TRUE(tile); |
2977 | 2981 |
2978 TilePriority priority = tile->priority(PENDING_TREE); | 2982 TilePriority priority = tile->priority(PENDING_TREE); |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3766 class OcclusionTrackingSettings : public LowResTilingsSettings { | 3770 class OcclusionTrackingSettings : public LowResTilingsSettings { |
3767 public: | 3771 public: |
3768 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } | 3772 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } |
3769 }; | 3773 }; |
3770 | 3774 |
3771 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { | 3775 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
3772 public: | 3776 public: |
3773 OcclusionTrackingPictureLayerImplTest() | 3777 OcclusionTrackingPictureLayerImplTest() |
3774 : PictureLayerImplTest(OcclusionTrackingSettings()) {} | 3778 : PictureLayerImplTest(OcclusionTrackingSettings()) {} |
3775 | 3779 |
3776 void VerifyEvictionConsidersOcclusion( | 3780 void VerifyEvictionConsidersOcclusion(PictureLayerImpl* layer, |
3777 PictureLayerImpl* layer, | 3781 WhichTree tree, |
3778 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { | 3782 size_t expected_occluded_tile_count) { |
3779 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; | 3783 size_t occluded_tile_count = 0u; |
3780 ++priority_count) { | 3784 Tile* last_tile = nullptr; |
3781 TreePriority tree_priority = static_cast<TreePriority>(priority_count); | |
3782 size_t occluded_tile_count = 0u; | |
3783 Tile* last_tile = nullptr; | |
3784 | 3785 |
3785 for (PictureLayerImpl::LayerEvictionTileIterator it = | 3786 for (PictureLayerImpl::LayerEvictionTileIterator it = |
3786 PictureLayerImpl::LayerEvictionTileIterator(layer, | 3787 PictureLayerImpl::LayerEvictionTileIterator(layer); |
3787 tree_priority); | 3788 it; |
3788 it; | 3789 ++it) { |
3789 ++it) { | 3790 Tile* tile = *it; |
3790 Tile* tile = *it; | 3791 if (!last_tile) |
3791 if (!last_tile) | 3792 last_tile = tile; |
3792 last_tile = tile; | |
3793 | 3793 |
3794 // The only way we will encounter an occluded tile after an unoccluded | 3794 // The only way we will encounter an occluded tile after an unoccluded |
3795 // tile is if the priorty bin decreased, the tile is required for | 3795 // tile is if the priorty bin decreased, the tile is required for |
3796 // activation, or the scale changed. | 3796 // activation, or the scale changed. |
3797 bool tile_is_occluded = | 3797 bool tile_is_occluded = tile->is_occluded(tree); |
3798 tile->is_occluded_for_tree_priority(tree_priority); | 3798 if (tile_is_occluded) { |
3799 if (tile_is_occluded) { | 3799 occluded_tile_count++; |
3800 occluded_tile_count++; | |
3801 | 3800 |
3802 bool last_tile_is_occluded = | 3801 bool last_tile_is_occluded = last_tile->is_occluded(tree); |
3803 last_tile->is_occluded_for_tree_priority(tree_priority); | 3802 if (!last_tile_is_occluded) { |
3804 if (!last_tile_is_occluded) { | 3803 TilePriority::PriorityBin tile_priority_bin = |
3805 TilePriority::PriorityBin tile_priority_bin = | 3804 tile->priority(tree).priority_bin; |
3806 tile->priority_for_tree_priority(tree_priority).priority_bin; | 3805 TilePriority::PriorityBin last_tile_priority_bin = |
3807 TilePriority::PriorityBin last_tile_priority_bin = | 3806 last_tile->priority(tree).priority_bin; |
3808 last_tile->priority_for_tree_priority(tree_priority) | |
3809 .priority_bin; | |
3810 | 3807 |
3811 EXPECT_TRUE( | 3808 EXPECT_TRUE((tile_priority_bin < last_tile_priority_bin) || |
3812 (tile_priority_bin < last_tile_priority_bin) || | 3809 tile->required_for_activation() || |
3813 tile->required_for_activation() || | 3810 (tile->contents_scale() != last_tile->contents_scale())); |
3814 (tile->contents_scale() != last_tile->contents_scale())); | |
3815 } | |
3816 } | 3811 } |
3817 last_tile = tile; | |
3818 } | 3812 } |
3819 EXPECT_EQ(expected_occluded_tile_count[priority_count], | 3813 last_tile = tile; |
3820 occluded_tile_count); | |
3821 } | 3814 } |
| 3815 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count); |
3822 } | 3816 } |
3823 }; | 3817 }; |
3824 | 3818 |
3825 TEST_F(OcclusionTrackingPictureLayerImplTest, | 3819 TEST_F(OcclusionTrackingPictureLayerImplTest, |
3826 OccludedTilesSkippedDuringRasterization) { | 3820 OccludedTilesSkippedDuringRasterization) { |
3827 base::TimeTicks time_ticks; | 3821 base::TimeTicks time_ticks; |
3828 time_ticks += base::TimeDelta::FromMilliseconds(1); | 3822 time_ticks += base::TimeDelta::FromMilliseconds(1); |
3829 host_impl_.SetCurrentBeginFrameArgs( | 3823 host_impl_.SetCurrentBeginFrameArgs( |
3830 CreateBeginFrameArgsForTesting(time_ticks)); | 3824 CreateBeginFrameArgsForTesting(time_ticks)); |
3831 | 3825 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4284 host_impl_.SetViewportSize(viewport_size); | 4278 host_impl_.SetViewportSize(viewport_size); |
4285 host_impl_.active_tree()->UpdateDrawProperties(); | 4279 host_impl_.active_tree()->UpdateDrawProperties(); |
4286 host_impl_.pending_tree()->UpdateDrawProperties(); | 4280 host_impl_.pending_tree()->UpdateDrawProperties(); |
4287 | 4281 |
4288 // The expected number of occluded tiles on each of the 5 tilings for each of | 4282 // The expected number of occluded tiles on each of the 5 tilings for each of |
4289 // the 3 tree priorities. | 4283 // the 3 tree priorities. |
4290 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; | 4284 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; |
4291 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; | 4285 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; |
4292 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; | 4286 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; |
4293 | 4287 |
4294 // The total expected number of occluded tiles on all tilings for each of the | 4288 size_t total_expected_occluded_count_on_trees[] = {43u, 43u}; |
4295 // 3 tree priorities. | |
4296 size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u}; | |
4297 | |
4298 ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES); | |
4299 | 4289 |
4300 // Verify number of occluded tiles on the pending layer for each tiling. | 4290 // Verify number of occluded tiles on the pending layer for each tiling. |
4301 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 4291 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
4302 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 4292 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
4303 tiling->CreateAllTilesForTesting(); | 4293 tiling->CreateAllTilesForTesting(); |
4304 tiling->UpdateAllTilePrioritiesForTesting(); | 4294 tiling->UpdateAllTilePrioritiesForTesting(); |
4305 | 4295 |
4306 size_t occluded_tile_count_on_pending = 0u; | 4296 size_t occluded_tile_count_on_pending = 0u; |
4307 size_t occluded_tile_count_on_active = 0u; | 4297 size_t occluded_tile_count_on_active = 0u; |
4308 size_t occluded_tile_count_on_both = 0u; | 4298 size_t occluded_tile_count_on_both = 0u; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4371 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 4361 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
4372 tilings.begin(); | 4362 tilings.begin(); |
4373 tiling_iterator != tilings.end(); | 4363 tiling_iterator != tilings.end(); |
4374 ++tiling_iterator) { | 4364 ++tiling_iterator) { |
4375 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 4365 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
4376 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | 4366 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
4377 } | 4367 } |
4378 | 4368 |
4379 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 4369 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
4380 | 4370 |
4381 VerifyEvictionConsidersOcclusion(pending_layer_, | 4371 VerifyEvictionConsidersOcclusion( |
4382 total_expected_occluded_tile_count); | 4372 pending_layer_, |
4383 VerifyEvictionConsidersOcclusion(active_layer_, | 4373 PENDING_TREE, |
4384 total_expected_occluded_tile_count); | 4374 total_expected_occluded_count_on_trees[PENDING_TREE]); |
| 4375 VerifyEvictionConsidersOcclusion( |
| 4376 active_layer_, |
| 4377 ACTIVE_TREE, |
| 4378 total_expected_occluded_count_on_trees[ACTIVE_TREE]); |
4385 } | 4379 } |
4386 | 4380 |
4387 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { | 4381 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { |
4388 gfx::Size tile_size(102, 102); | 4382 gfx::Size tile_size(102, 102); |
4389 gfx::Size layer_bounds(1000, 1000); | 4383 gfx::Size layer_bounds(1000, 1000); |
4390 | 4384 |
4391 scoped_refptr<FakePicturePileImpl> pile = | 4385 scoped_refptr<FakePicturePileImpl> pile = |
4392 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 4386 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
4393 SetupPendingTree(pile); | 4387 SetupPendingTree(pile); |
4394 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); | 4388 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4704 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4698 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4705 EXPECT_EQ(result.width(), 448); | 4699 EXPECT_EQ(result.width(), 448); |
4706 EXPECT_EQ(result.height(), 448); | 4700 EXPECT_EQ(result.height(), 448); |
4707 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4701 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4708 EXPECT_EQ(result.width(), 512); | 4702 EXPECT_EQ(result.width(), 512); |
4709 EXPECT_EQ(result.height(), 500 + 2); | 4703 EXPECT_EQ(result.height(), 500 + 2); |
4710 } | 4704 } |
4711 | 4705 |
4712 } // namespace | 4706 } // namespace |
4713 } // namespace cc | 4707 } // namespace cc |
OLD | NEW |