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 2798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2809 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | 2809 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); |
2810 EXPECT_FALSE(it); | 2810 EXPECT_FALSE(it); |
2811 | 2811 |
2812 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 2812 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
2813 | 2813 |
2814 std::set<Tile*> unique_tiles; | 2814 std::set<Tile*> unique_tiles; |
2815 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; | 2815 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; |
2816 size_t scale_index = 0; | 2816 size_t scale_index = 0; |
2817 bool reached_visible = false; | 2817 bool reached_visible = false; |
2818 Tile* last_tile = nullptr; | 2818 Tile* last_tile = nullptr; |
2819 int distance_decreasing = 0; | |
2820 int distance_increasing = 0; | |
2819 for (it = PictureLayerImpl::LayerEvictionTileIterator( | 2821 for (it = PictureLayerImpl::LayerEvictionTileIterator( |
2820 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); | 2822 pending_layer_, SAME_PRIORITY_FOR_BOTH_TREES); |
2821 it; | 2823 it; |
2822 ++it) { | 2824 ++it) { |
2823 Tile* tile = *it; | 2825 Tile* tile = *it; |
2824 if (!last_tile) | 2826 if (!last_tile) |
2825 last_tile = tile; | 2827 last_tile = tile; |
2826 | 2828 |
2827 EXPECT_TRUE(tile); | 2829 EXPECT_TRUE(tile); |
2828 | 2830 |
2829 TilePriority priority = tile->priority(PENDING_TREE); | 2831 TilePriority priority = tile->priority(PENDING_TREE); |
2830 | 2832 |
2831 if (priority.priority_bin == TilePriority::NOW) { | 2833 if (priority.priority_bin == TilePriority::NOW) { |
2832 reached_visible = true; | 2834 reached_visible = true; |
2833 last_tile = tile; | 2835 last_tile = tile; |
2834 break; | 2836 break; |
2835 } | 2837 } |
2836 | 2838 |
2837 EXPECT_FALSE(tile->required_for_activation()); | 2839 EXPECT_FALSE(tile->required_for_activation()); |
2838 | 2840 |
2839 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > | 2841 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > |
2840 std::numeric_limits<float>::epsilon()) { | 2842 std::numeric_limits<float>::epsilon()) { |
2841 ++scale_index; | 2843 ++scale_index; |
2842 ASSERT_LT(scale_index, arraysize(expected_scales)); | 2844 ASSERT_LT(scale_index, arraysize(expected_scales)); |
2843 } | 2845 } |
2844 | 2846 |
2845 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); | 2847 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); |
2846 unique_tiles.insert(tile); | 2848 unique_tiles.insert(tile); |
2847 | 2849 |
2848 // If the tile is the same rough bin as last tile (same activation, bin, and | |
2849 // scale), then distance should be decreasing. | |
2850 if (tile->required_for_activation() == | 2850 if (tile->required_for_activation() == |
2851 last_tile->required_for_activation() && | 2851 last_tile->required_for_activation() && |
2852 priority.priority_bin == | 2852 priority.priority_bin == |
2853 last_tile->priority(PENDING_TREE).priority_bin && | 2853 last_tile->priority(PENDING_TREE).priority_bin && |
2854 std::abs(tile->contents_scale() - last_tile->contents_scale()) < | 2854 std::abs(tile->contents_scale() - last_tile->contents_scale()) < |
2855 std::numeric_limits<float>::epsilon()) { | 2855 std::numeric_limits<float>::epsilon()) { |
2856 EXPECT_LE(priority.distance_to_visible, | 2856 if (priority.distance_to_visible <= |
2857 last_tile->priority(PENDING_TREE).distance_to_visible); | 2857 last_tile->priority(PENDING_TREE).distance_to_visible) { |
2858 ++distance_decreasing; | |
2859 } else { | |
2860 ++distance_increasing; | |
2861 } | |
2858 } | 2862 } |
2859 | 2863 |
2860 last_tile = tile; | 2864 last_tile = tile; |
2861 } | 2865 } |
2862 | 2866 |
2867 EXPECT_EQ(7, distance_increasing); | |
2868 EXPECT_EQ(55, distance_decreasing); | |
ajuma
2014/10/23 23:12:54
Is there an intuitive explanation for why we get t
vmpstr
2014/10/29 18:19:41
Well.. I'm not sure how intuitive it is, starting
ajuma
2014/10/29 19:42:39
Ok, I mostly wanted to find out if these specific
| |
2869 | |
2863 EXPECT_TRUE(reached_visible); | 2870 EXPECT_TRUE(reached_visible); |
2864 EXPECT_EQ(65u, unique_tiles.size()); | 2871 EXPECT_EQ(65u, unique_tiles.size()); |
2865 | 2872 |
2866 scale_index = 0; | 2873 scale_index = 0; |
2867 bool reached_required = false; | 2874 bool reached_required = false; |
2868 for (; it; ++it) { | 2875 for (; it; ++it) { |
2869 Tile* tile = *it; | 2876 Tile* tile = *it; |
2870 EXPECT_TRUE(tile); | 2877 EXPECT_TRUE(tile); |
2871 | 2878 |
2872 TilePriority priority = tile->priority(PENDING_TREE); | 2879 TilePriority priority = tile->priority(PENDING_TREE); |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3660 class OcclusionTrackingSettings : public LowResTilingsSettings { | 3667 class OcclusionTrackingSettings : public LowResTilingsSettings { |
3661 public: | 3668 public: |
3662 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } | 3669 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } |
3663 }; | 3670 }; |
3664 | 3671 |
3665 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { | 3672 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
3666 public: | 3673 public: |
3667 OcclusionTrackingPictureLayerImplTest() | 3674 OcclusionTrackingPictureLayerImplTest() |
3668 : PictureLayerImplTest(OcclusionTrackingSettings()) {} | 3675 : PictureLayerImplTest(OcclusionTrackingSettings()) {} |
3669 | 3676 |
3670 void VerifyEvictionConsidersOcclusion( | 3677 void VerifyEvictionConsidersOcclusion(PictureLayerImpl* layer, |
3671 PictureLayerImpl* layer, | 3678 WhichTree tree, |
3672 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { | 3679 size_t expected_occluded_tile_count) { |
3673 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; | 3680 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; |
3674 ++priority_count) { | 3681 ++priority_count) { |
3675 TreePriority tree_priority = static_cast<TreePriority>(priority_count); | 3682 TreePriority tree_priority = static_cast<TreePriority>(priority_count); |
3676 size_t occluded_tile_count = 0u; | 3683 size_t occluded_tile_count = 0u; |
3677 Tile* last_tile = nullptr; | 3684 Tile* last_tile = nullptr; |
3678 | 3685 |
3679 for (PictureLayerImpl::LayerEvictionTileIterator it = | 3686 for (PictureLayerImpl::LayerEvictionTileIterator it = |
3680 PictureLayerImpl::LayerEvictionTileIterator(layer, | 3687 PictureLayerImpl::LayerEvictionTileIterator(layer, |
3681 tree_priority); | 3688 tree_priority); |
3682 it; | 3689 it; |
3683 ++it) { | 3690 ++it) { |
3684 Tile* tile = *it; | 3691 Tile* tile = *it; |
3685 if (!last_tile) | 3692 if (!last_tile) |
3686 last_tile = tile; | 3693 last_tile = tile; |
3687 | 3694 |
3688 // The only way we will encounter an occluded tile after an unoccluded | 3695 // The only way we will encounter an occluded tile after an unoccluded |
3689 // tile is if the priorty bin decreased, the tile is required for | 3696 // tile is if the priorty bin decreased, the tile is required for |
3690 // activation, or the scale changed. | 3697 // activation, or the scale changed. |
3691 bool tile_is_occluded = | 3698 bool tile_is_occluded = tile->is_occluded(tree); |
3692 tile->is_occluded_for_tree_priority(tree_priority); | |
3693 if (tile_is_occluded) { | 3699 if (tile_is_occluded) { |
3694 occluded_tile_count++; | 3700 occluded_tile_count++; |
3695 | 3701 |
3696 bool last_tile_is_occluded = | 3702 bool last_tile_is_occluded = last_tile->is_occluded(tree); |
3697 last_tile->is_occluded_for_tree_priority(tree_priority); | |
3698 if (!last_tile_is_occluded) { | 3703 if (!last_tile_is_occluded) { |
3699 TilePriority::PriorityBin tile_priority_bin = | 3704 TilePriority::PriorityBin tile_priority_bin = |
3700 tile->priority_for_tree_priority(tree_priority).priority_bin; | 3705 tile->priority(tree).priority_bin; |
3701 TilePriority::PriorityBin last_tile_priority_bin = | 3706 TilePriority::PriorityBin last_tile_priority_bin = |
3702 last_tile->priority_for_tree_priority(tree_priority) | 3707 last_tile->priority(tree).priority_bin; |
3703 .priority_bin; | |
3704 | 3708 |
3705 EXPECT_TRUE( | 3709 EXPECT_TRUE( |
3706 (tile_priority_bin < last_tile_priority_bin) || | 3710 (tile_priority_bin < last_tile_priority_bin) || |
3707 tile->required_for_activation() || | 3711 tile->required_for_activation() || |
3708 (tile->contents_scale() != last_tile->contents_scale())); | 3712 (tile->contents_scale() != last_tile->contents_scale())); |
3709 } | 3713 } |
3710 } | 3714 } |
3711 last_tile = tile; | 3715 last_tile = tile; |
3712 } | 3716 } |
3713 EXPECT_EQ(expected_occluded_tile_count[priority_count], | 3717 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count); |
3714 occluded_tile_count); | |
3715 } | 3718 } |
3716 } | 3719 } |
3717 }; | 3720 }; |
3718 | 3721 |
3719 TEST_F(OcclusionTrackingPictureLayerImplTest, | 3722 TEST_F(OcclusionTrackingPictureLayerImplTest, |
3720 OccludedTilesSkippedDuringRasterization) { | 3723 OccludedTilesSkippedDuringRasterization) { |
3721 base::TimeTicks time_ticks; | 3724 base::TimeTicks time_ticks; |
3722 time_ticks += base::TimeDelta::FromMilliseconds(1); | 3725 time_ticks += base::TimeDelta::FromMilliseconds(1); |
3723 host_impl_.SetCurrentBeginFrameArgs( | 3726 host_impl_.SetCurrentBeginFrameArgs( |
3724 CreateBeginFrameArgsForTesting(time_ticks)); | 3727 CreateBeginFrameArgsForTesting(time_ticks)); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4178 host_impl_.SetViewportSize(viewport_size); | 4181 host_impl_.SetViewportSize(viewport_size); |
4179 host_impl_.active_tree()->UpdateDrawProperties(); | 4182 host_impl_.active_tree()->UpdateDrawProperties(); |
4180 host_impl_.pending_tree()->UpdateDrawProperties(); | 4183 host_impl_.pending_tree()->UpdateDrawProperties(); |
4181 | 4184 |
4182 // The expected number of occluded tiles on each of the 5 tilings for each of | 4185 // The expected number of occluded tiles on each of the 5 tilings for each of |
4183 // the 3 tree priorities. | 4186 // the 3 tree priorities. |
4184 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; | 4187 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; |
4185 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; | 4188 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; |
4186 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; | 4189 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; |
4187 | 4190 |
4188 // The total expected number of occluded tiles on all tilings for each of the | 4191 size_t total_expected_occluded_count_on_trees[] = {43u, 43u}; |
4189 // 3 tree priorities. | |
4190 size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u}; | |
4191 | |
4192 ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES); | |
4193 | 4192 |
4194 // Verify number of occluded tiles on the pending layer for each tiling. | 4193 // Verify number of occluded tiles on the pending layer for each tiling. |
4195 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 4194 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
4196 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 4195 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
4197 tiling->CreateAllTilesForTesting(); | 4196 tiling->CreateAllTilesForTesting(); |
4198 tiling->UpdateAllTilePrioritiesForTesting(); | 4197 tiling->UpdateAllTilePrioritiesForTesting(); |
4199 | 4198 |
4200 size_t occluded_tile_count_on_pending = 0u; | 4199 size_t occluded_tile_count_on_pending = 0u; |
4201 size_t occluded_tile_count_on_active = 0u; | 4200 size_t occluded_tile_count_on_active = 0u; |
4202 size_t occluded_tile_count_on_both = 0u; | 4201 size_t occluded_tile_count_on_both = 0u; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4265 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 4264 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
4266 tilings.begin(); | 4265 tilings.begin(); |
4267 tiling_iterator != tilings.end(); | 4266 tiling_iterator != tilings.end(); |
4268 ++tiling_iterator) { | 4267 ++tiling_iterator) { |
4269 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 4268 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
4270 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | 4269 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
4271 } | 4270 } |
4272 | 4271 |
4273 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 4272 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
4274 | 4273 |
4275 VerifyEvictionConsidersOcclusion(pending_layer_, | 4274 VerifyEvictionConsidersOcclusion( |
4276 total_expected_occluded_tile_count); | 4275 pending_layer_, |
4277 VerifyEvictionConsidersOcclusion(active_layer_, | 4276 PENDING_TREE, |
4278 total_expected_occluded_tile_count); | 4277 total_expected_occluded_count_on_trees[PENDING_TREE]); |
4278 VerifyEvictionConsidersOcclusion( | |
4279 active_layer_, | |
4280 ACTIVE_TREE, | |
4281 total_expected_occluded_count_on_trees[ACTIVE_TREE]); | |
4279 } | 4282 } |
4280 | 4283 |
4281 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { | 4284 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { |
4282 gfx::Size tile_size(102, 102); | 4285 gfx::Size tile_size(102, 102); |
4283 gfx::Size layer_bounds(1000, 1000); | 4286 gfx::Size layer_bounds(1000, 1000); |
4284 | 4287 |
4285 scoped_refptr<FakePicturePileImpl> pile = | 4288 scoped_refptr<FakePicturePileImpl> pile = |
4286 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 4289 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
4287 SetupPendingTree(pile); | 4290 SetupPendingTree(pile); |
4288 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); | 4291 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4510 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4513 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4511 EXPECT_EQ(result.width(), 448); | 4514 EXPECT_EQ(result.width(), 448); |
4512 EXPECT_EQ(result.height(), 448); | 4515 EXPECT_EQ(result.height(), 448); |
4513 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4516 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4514 EXPECT_EQ(result.width(), 512); | 4517 EXPECT_EQ(result.width(), 512); |
4515 EXPECT_EQ(result.height(), 500 + 2); | 4518 EXPECT_EQ(result.height(), 500 + 2); |
4516 } | 4519 } |
4517 | 4520 |
4518 } // namespace | 4521 } // namespace |
4519 } // namespace cc | 4522 } // namespace cc |
OLD | NEW |