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 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2969 pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES); | 2969 pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES); |
2970 EXPECT_TRUE(queue->IsEmpty()); | 2970 EXPECT_TRUE(queue->IsEmpty()); |
2971 | 2971 |
2972 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 2972 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
2973 | 2973 |
2974 std::set<Tile*> unique_tiles; | 2974 std::set<Tile*> unique_tiles; |
2975 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; | 2975 float expected_scales[] = {2.0f, 0.3f, 0.7f, low_res_factor, 1.0f}; |
2976 size_t scale_index = 0; | 2976 size_t scale_index = 0; |
2977 bool reached_visible = false; | 2977 bool reached_visible = false; |
2978 Tile* last_tile = nullptr; | 2978 Tile* last_tile = nullptr; |
2979 int distance_decreasing = 0; | |
2980 int distance_increasing = 0; | |
2979 queue = pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES); | 2981 queue = pending_layer_->CreateEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES); |
2980 while (!queue->IsEmpty()) { | 2982 while (!queue->IsEmpty()) { |
2981 Tile* tile = queue->Top(); | 2983 Tile* tile = queue->Top(); |
2982 if (!last_tile) | 2984 if (!last_tile) |
2983 last_tile = tile; | 2985 last_tile = tile; |
2984 | 2986 |
2985 EXPECT_TRUE(tile); | 2987 EXPECT_TRUE(tile); |
2986 | 2988 |
2987 TilePriority priority = tile->priority(PENDING_TREE); | 2989 TilePriority priority = tile->priority(PENDING_TREE); |
2988 | 2990 |
2989 if (priority.priority_bin == TilePriority::NOW) { | 2991 if (priority.priority_bin == TilePriority::NOW) { |
2990 reached_visible = true; | 2992 reached_visible = true; |
2991 last_tile = tile; | 2993 last_tile = tile; |
2992 break; | 2994 break; |
2993 } | 2995 } |
2994 | 2996 |
2995 EXPECT_FALSE(tile->required_for_activation()); | 2997 EXPECT_FALSE(tile->required_for_activation()); |
2996 | 2998 |
2997 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > | 2999 while (std::abs(tile->contents_scale() - expected_scales[scale_index]) > |
2998 std::numeric_limits<float>::epsilon()) { | 3000 std::numeric_limits<float>::epsilon()) { |
2999 ++scale_index; | 3001 ++scale_index; |
3000 ASSERT_LT(scale_index, arraysize(expected_scales)); | 3002 ASSERT_LT(scale_index, arraysize(expected_scales)); |
3001 } | 3003 } |
3002 | 3004 |
3003 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); | 3005 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); |
3004 unique_tiles.insert(tile); | 3006 unique_tiles.insert(tile); |
3005 | 3007 |
3006 // If the tile is the same rough bin as last tile (same activation, bin, and | |
3007 // scale), then distance should be decreasing. | |
3008 if (tile->required_for_activation() == | 3008 if (tile->required_for_activation() == |
3009 last_tile->required_for_activation() && | 3009 last_tile->required_for_activation() && |
3010 priority.priority_bin == | 3010 priority.priority_bin == |
3011 last_tile->priority(PENDING_TREE).priority_bin && | 3011 last_tile->priority(PENDING_TREE).priority_bin && |
3012 std::abs(tile->contents_scale() - last_tile->contents_scale()) < | 3012 std::abs(tile->contents_scale() - last_tile->contents_scale()) < |
3013 std::numeric_limits<float>::epsilon()) { | 3013 std::numeric_limits<float>::epsilon()) { |
3014 EXPECT_LE(priority.distance_to_visible, | 3014 if (priority.distance_to_visible <= |
3015 last_tile->priority(PENDING_TREE).distance_to_visible); | 3015 last_tile->priority(PENDING_TREE).distance_to_visible) |
3016 ++distance_decreasing; | |
3017 else | |
3018 ++distance_increasing; | |
3016 } | 3019 } |
3017 | 3020 |
3018 last_tile = tile; | 3021 last_tile = tile; |
3019 queue->Pop(); | 3022 queue->Pop(); |
3020 } | 3023 } |
3021 | 3024 |
3025 EXPECT_EQ(7, distance_increasing); | |
3026 EXPECT_EQ(55, distance_decreasing); | |
3027 | |
3022 EXPECT_TRUE(reached_visible); | 3028 EXPECT_TRUE(reached_visible); |
3023 EXPECT_EQ(65u, unique_tiles.size()); | 3029 EXPECT_EQ(65u, unique_tiles.size()); |
3024 | 3030 |
3025 scale_index = 0; | 3031 scale_index = 0; |
3026 bool reached_required = false; | 3032 bool reached_required = false; |
3027 while (!queue->IsEmpty()) { | 3033 while (!queue->IsEmpty()) { |
3028 Tile* tile = queue->Top(); | 3034 Tile* tile = queue->Top(); |
3029 EXPECT_TRUE(tile); | 3035 EXPECT_TRUE(tile); |
3030 | 3036 |
3031 TilePriority priority = tile->priority(PENDING_TREE); | 3037 TilePriority priority = tile->priority(PENDING_TREE); |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3821 class OcclusionTrackingSettings : public LowResTilingsSettings { | 3827 class OcclusionTrackingSettings : public LowResTilingsSettings { |
3822 public: | 3828 public: |
3823 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } | 3829 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } |
3824 }; | 3830 }; |
3825 | 3831 |
3826 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { | 3832 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
3827 public: | 3833 public: |
3828 OcclusionTrackingPictureLayerImplTest() | 3834 OcclusionTrackingPictureLayerImplTest() |
3829 : PictureLayerImplTest(OcclusionTrackingSettings()) {} | 3835 : PictureLayerImplTest(OcclusionTrackingSettings()) {} |
3830 | 3836 |
3831 void VerifyEvictionConsidersOcclusion( | 3837 void VerifyEvictionConsidersOcclusion(FakePictureLayerImpl* layer, |
3832 PictureLayerImpl* layer, | 3838 FakePictureLayerImpl* twin_layer, |
3833 size_t expected_occluded_tile_count[NUM_TREE_PRIORITIES]) { | 3839 WhichTree tree, |
3840 size_t expected_occluded_tile_count) { | |
3841 twin_layer->set_has_valid_tile_priorities(false); | |
3834 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; | 3842 for (int priority_count = 0; priority_count < NUM_TREE_PRIORITIES; |
3835 ++priority_count) { | 3843 ++priority_count) { |
3836 TreePriority tree_priority = static_cast<TreePriority>(priority_count); | 3844 TreePriority tree_priority = static_cast<TreePriority>(priority_count); |
3837 size_t occluded_tile_count = 0u; | 3845 size_t occluded_tile_count = 0u; |
3838 Tile* last_tile = nullptr; | 3846 Tile* last_tile = nullptr; |
3847 std::set<Tile*> shared_tiles; | |
3839 | 3848 |
3840 scoped_ptr<TilingSetEvictionQueue> queue = | 3849 scoped_ptr<TilingSetEvictionQueue> queue = |
3841 layer->CreateEvictionQueue(tree_priority); | 3850 layer->CreateEvictionQueue(tree_priority); |
3842 while (!queue->IsEmpty()) { | 3851 while (!queue->IsEmpty()) { |
3843 Tile* tile = queue->Top(); | 3852 Tile* tile = queue->Top(); |
3844 if (!last_tile) | 3853 if (!last_tile) |
3845 last_tile = tile; | 3854 last_tile = tile; |
3855 if (tile->is_shared()) | |
3856 EXPECT_TRUE(shared_tiles.insert(tile).second); | |
3846 | 3857 |
3847 // The only way we will encounter an occluded tile after an unoccluded | 3858 // The only way we will encounter an occluded tile after an unoccluded |
3848 // tile is if the priorty bin decreased, the tile is required for | 3859 // tile is if the priorty bin decreased, the tile is required for |
3849 // activation, or the scale changed. | 3860 // activation, or the scale changed. |
3850 bool tile_is_occluded = | 3861 bool tile_is_occluded = tile->is_occluded(tree); |
3851 tile->is_occluded_for_tree_priority(tree_priority); | |
3852 if (tile_is_occluded) { | 3862 if (tile_is_occluded) { |
3853 occluded_tile_count++; | 3863 occluded_tile_count++; |
3854 | 3864 |
3855 bool last_tile_is_occluded = | 3865 bool last_tile_is_occluded = last_tile->is_occluded(tree); |
3856 last_tile->is_occluded_for_tree_priority(tree_priority); | |
3857 if (!last_tile_is_occluded) { | 3866 if (!last_tile_is_occluded) { |
3858 TilePriority::PriorityBin tile_priority_bin = | 3867 TilePriority::PriorityBin tile_priority_bin = |
3859 tile->priority_for_tree_priority(tree_priority).priority_bin; | 3868 tile->priority(tree).priority_bin; |
3860 TilePriority::PriorityBin last_tile_priority_bin = | 3869 TilePriority::PriorityBin last_tile_priority_bin = |
3861 last_tile->priority_for_tree_priority(tree_priority) | 3870 last_tile->priority(tree).priority_bin; |
3862 .priority_bin; | |
3863 | 3871 |
3864 EXPECT_TRUE( | 3872 EXPECT_TRUE( |
3865 (tile_priority_bin < last_tile_priority_bin) || | 3873 (tile_priority_bin < last_tile_priority_bin) || |
3866 tile->required_for_activation() || | 3874 tile->required_for_activation() || |
3867 (tile->contents_scale() != last_tile->contents_scale())); | 3875 (tile->contents_scale() != last_tile->contents_scale())); |
3868 } | 3876 } |
3869 } | 3877 } |
3870 last_tile = tile; | 3878 last_tile = tile; |
3871 queue->Pop(); | 3879 queue->Pop(); |
3872 } | 3880 } |
3873 EXPECT_EQ(expected_occluded_tile_count[priority_count], | 3881 queue = twin_layer->CreateEvictionQueue(tree_priority); |
3874 occluded_tile_count); | 3882 while (!queue->IsEmpty()) { |
3883 Tile* tile = queue->Top(); | |
3884 if (tile->is_shared()) { | |
3885 EXPECT_TRUE(shared_tiles.insert(tile).second); | |
3886 if (tile->is_occluded(tree)) | |
vmpstr
2014/12/09 02:10:58
This should happen outside of the if (is shared) b
USE eero AT chromium.org
2014/12/09 18:44:14
No, it should not.
The purpose of this second whil
vmpstr
2014/12/10 18:01:15
I think that makes sense, thanks for the explanati
USE eero AT chromium.org
2014/12/11 15:21:59
Done.
| |
3887 ++occluded_tile_count; | |
3888 } | |
3889 queue->Pop(); | |
3890 } | |
3891 EXPECT_EQ(expected_occluded_tile_count, occluded_tile_count); | |
3875 } | 3892 } |
3893 twin_layer->set_has_valid_tile_priorities(true); | |
3876 } | 3894 } |
3877 }; | 3895 }; |
3878 | 3896 |
3879 TEST_F(OcclusionTrackingPictureLayerImplTest, | 3897 TEST_F(OcclusionTrackingPictureLayerImplTest, |
3880 OccludedTilesSkippedDuringRasterization) { | 3898 OccludedTilesSkippedDuringRasterization) { |
3881 base::TimeTicks time_ticks; | 3899 base::TimeTicks time_ticks; |
3882 time_ticks += base::TimeDelta::FromMilliseconds(1); | 3900 time_ticks += base::TimeDelta::FromMilliseconds(1); |
3883 host_impl_.SetCurrentBeginFrameArgs( | 3901 host_impl_.SetCurrentBeginFrameArgs( |
3884 CreateBeginFrameArgsForTesting(time_ticks)); | 3902 CreateBeginFrameArgsForTesting(time_ticks)); |
3885 | 3903 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4338 host_impl_.SetViewportSize(viewport_size); | 4356 host_impl_.SetViewportSize(viewport_size); |
4339 host_impl_.active_tree()->UpdateDrawProperties(); | 4357 host_impl_.active_tree()->UpdateDrawProperties(); |
4340 host_impl_.pending_tree()->UpdateDrawProperties(); | 4358 host_impl_.pending_tree()->UpdateDrawProperties(); |
4341 | 4359 |
4342 // The expected number of occluded tiles on each of the 5 tilings for each of | 4360 // The expected number of occluded tiles on each of the 5 tilings for each of |
4343 // the 3 tree priorities. | 4361 // the 3 tree priorities. |
4344 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; | 4362 size_t expected_occluded_tile_count_on_both[] = {9u, 1u, 1u, 1u, 1u}; |
4345 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; | 4363 size_t expected_occluded_tile_count_on_active[] = {30u, 5u, 4u, 2u, 2u}; |
4346 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; | 4364 size_t expected_occluded_tile_count_on_pending[] = {30u, 5u, 4u, 2u, 2u}; |
4347 | 4365 |
4348 // The total expected number of occluded tiles on all tilings for each of the | 4366 size_t total_expected_occluded_tile_count_on_trees[] = {43u, 43u}; |
4349 // 3 tree priorities. | |
4350 size_t total_expected_occluded_tile_count[] = {13u, 43u, 43u}; | |
4351 | |
4352 ASSERT_EQ(arraysize(total_expected_occluded_tile_count), NUM_TREE_PRIORITIES); | |
4353 | 4367 |
4354 // Verify number of occluded tiles on the pending layer for each tiling. | 4368 // Verify number of occluded tiles on the pending layer for each tiling. |
4355 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 4369 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
4356 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 4370 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
4357 tiling->CreateAllTilesForTesting(); | 4371 tiling->CreateAllTilesForTesting(); |
4358 tiling->UpdateAllTilePrioritiesForTesting(); | 4372 tiling->UpdateAllTilePrioritiesForTesting(); |
4359 | 4373 |
4360 size_t occluded_tile_count_on_pending = 0u; | 4374 size_t occluded_tile_count_on_pending = 0u; |
4361 size_t occluded_tile_count_on_active = 0u; | 4375 size_t occluded_tile_count_on_active = 0u; |
4362 size_t occluded_tile_count_on_both = 0u; | 4376 size_t occluded_tile_count_on_both = 0u; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4425 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 4439 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
4426 tilings.begin(); | 4440 tilings.begin(); |
4427 tiling_iterator != tilings.end(); | 4441 tiling_iterator != tilings.end(); |
4428 ++tiling_iterator) { | 4442 ++tiling_iterator) { |
4429 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 4443 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
4430 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | 4444 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
4431 } | 4445 } |
4432 | 4446 |
4433 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 4447 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
4434 | 4448 |
4435 VerifyEvictionConsidersOcclusion(pending_layer_, | 4449 VerifyEvictionConsidersOcclusion( |
4436 total_expected_occluded_tile_count); | 4450 pending_layer_, active_layer_, PENDING_TREE, |
4437 VerifyEvictionConsidersOcclusion(active_layer_, | 4451 total_expected_occluded_tile_count_on_trees[PENDING_TREE]); |
4438 total_expected_occluded_tile_count); | 4452 VerifyEvictionConsidersOcclusion( |
4453 active_layer_, pending_layer_, ACTIVE_TREE, | |
4454 total_expected_occluded_tile_count_on_trees[ACTIVE_TREE]); | |
4439 } | 4455 } |
4440 | 4456 |
4441 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { | 4457 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { |
4442 gfx::Size tile_size(102, 102); | 4458 gfx::Size tile_size(102, 102); |
4443 gfx::Size layer_bounds(1000, 1000); | 4459 gfx::Size layer_bounds(1000, 1000); |
4444 | 4460 |
4445 scoped_refptr<FakePicturePileImpl> pile = | 4461 scoped_refptr<FakePicturePileImpl> pile = |
4446 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 4462 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
4447 SetupPendingTree(pile); | 4463 SetupPendingTree(pile); |
4448 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); | 4464 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4735 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4751 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4736 EXPECT_EQ(result.width(), 448); | 4752 EXPECT_EQ(result.width(), 448); |
4737 EXPECT_EQ(result.height(), 448); | 4753 EXPECT_EQ(result.height(), 448); |
4738 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4754 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4739 EXPECT_EQ(result.width(), 512); | 4755 EXPECT_EQ(result.width(), 512); |
4740 EXPECT_EQ(result.height(), 500 + 2); | 4756 EXPECT_EQ(result.height(), 500 + 2); |
4741 } | 4757 } |
4742 | 4758 |
4743 } // namespace | 4759 } // namespace |
4744 } // namespace cc | 4760 } // namespace cc |
OLD | NEW |