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 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2815 | 2815 |
2816 class OcclusionTrackingSettings : public ImplSidePaintingSettings { | 2816 class OcclusionTrackingSettings : public ImplSidePaintingSettings { |
2817 public: | 2817 public: |
2818 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } | 2818 OcclusionTrackingSettings() { use_occlusion_for_tile_prioritization = true; } |
2819 }; | 2819 }; |
2820 | 2820 |
2821 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { | 2821 class OcclusionTrackingPictureLayerImplTest : public PictureLayerImplTest { |
2822 public: | 2822 public: |
2823 OcclusionTrackingPictureLayerImplTest() | 2823 OcclusionTrackingPictureLayerImplTest() |
2824 : PictureLayerImplTest(OcclusionTrackingSettings()) {} | 2824 : PictureLayerImplTest(OcclusionTrackingSettings()) {} |
2825 | |
2826 void VerifyEvictionConsidersOcclusion(PictureLayerImpl* layer, | |
2827 size_t expected_occluded_tile_count[]) { | |
danakj
2014/07/15 21:26:50
can this be size_t expected_occluded_tile_count[NU
jbedley
2014/07/16 16:09:31
Done.
| |
2828 for (int priority_count = 0; priority_count < 3; ++priority_count) { | |
danakj
2014/07/15 21:26:50
can this 3 be NUM_TREE_PRIORITIES (and any other h
jbedley
2014/07/16 16:09:31
Done.
| |
2829 TreePriority tree_priority = static_cast<TreePriority>(priority_count); | |
2830 size_t occluded_tile_count = 0u; | |
2831 Tile* last_tile = NULL; | |
2832 | |
2833 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
2834 PictureLayerImpl::LayerEvictionTileIterator(layer, | |
2835 tree_priority); | |
2836 it; | |
2837 ++it) { | |
2838 Tile* tile = *it; | |
2839 if (!last_tile) | |
2840 last_tile = tile; | |
2841 | |
2842 // The only way we will encounter an occluded tile after an unoccluded | |
2843 // tile is if the priorty bin decreased, the tile is required for | |
2844 // activation, or the scale changed. | |
2845 bool tile_is_occluded = | |
2846 tile->is_occluded_for_tree_priority(tree_priority); | |
2847 if (tile_is_occluded) { | |
2848 occluded_tile_count++; | |
2849 | |
2850 bool last_tile_is_occluded = | |
2851 last_tile->is_occluded_for_tree_priority(tree_priority); | |
2852 if (!last_tile_is_occluded) { | |
2853 TilePriority::PriorityBin tile_priority_bin = | |
2854 tile->priority_for_tree_priority(tree_priority).priority_bin; | |
2855 TilePriority::PriorityBin last_tile_priority_bin = | |
2856 last_tile->priority_for_tree_priority(tree_priority) | |
2857 .priority_bin; | |
2858 | |
2859 EXPECT_TRUE( | |
2860 (tile_priority_bin < last_tile_priority_bin) || | |
2861 tile->required_for_activation() || | |
2862 (tile->contents_scale() != last_tile->contents_scale())); | |
2863 } | |
2864 } | |
2865 last_tile = tile; | |
2866 } | |
2867 EXPECT_EQ(expected_occluded_tile_count[priority_count], | |
2868 occluded_tile_count); | |
2869 } | |
2870 } | |
2825 }; | 2871 }; |
2826 | 2872 |
2827 TEST_F(OcclusionTrackingPictureLayerImplTest, | 2873 TEST_F(OcclusionTrackingPictureLayerImplTest, |
2828 OccludedTilesSkippedDuringRasterization) { | 2874 OccludedTilesSkippedDuringRasterization) { |
2829 gfx::Size tile_size(102, 102); | 2875 gfx::Size tile_size(102, 102); |
2830 gfx::Size layer_bounds(1000, 1000); | 2876 gfx::Size layer_bounds(1000, 1000); |
2831 gfx::Size viewport_size(500, 500); | 2877 gfx::Size viewport_size(500, 500); |
2832 gfx::Point occluding_layer_position(310, 0); | 2878 gfx::Point occluding_layer_position(310, 0); |
2833 | 2879 |
2834 scoped_refptr<FakePicturePileImpl> pending_pile = | 2880 scoped_refptr<FakePicturePileImpl> pending_pile = |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3197 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); | 3243 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); |
3198 | 3244 |
3199 // Unshared tiles are occluded on the active tree iff they lie beneath | 3245 // Unshared tiles are occluded on the active tree iff they lie beneath |
3200 // the occluding layer. | 3246 // the occluding layer. |
3201 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), | 3247 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), |
3202 scaled_content_rect.x() >= occluding_layer_position.x()); | 3248 scaled_content_rect.x() >= occluding_layer_position.x()); |
3203 } | 3249 } |
3204 } | 3250 } |
3205 } | 3251 } |
3206 } | 3252 } |
3253 | |
3254 TEST_F(OcclusionTrackingPictureLayerImplTest, | |
3255 OccludedTilesConsideredDuringEviction) { | |
3256 gfx::Size tile_size(102, 102); | |
3257 gfx::Size layer_bounds(1000, 1000); | |
3258 gfx::Size viewport_size(500, 500); | |
3259 gfx::Point pending_occluding_layer_position(310, 0); | |
3260 gfx::Point active_occluding_layer_position(0, 310); | |
3261 gfx::Rect invalidation_rect(230, 230, 102, 102); | |
3262 | |
3263 scoped_refptr<FakePicturePileImpl> pending_pile = | |
3264 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
3265 scoped_refptr<FakePicturePileImpl> active_pile = | |
3266 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
3267 SetupTrees(pending_pile, active_pile); | |
3268 | |
3269 pending_layer_->set_fixed_tile_size(tile_size); | |
3270 active_layer_->set_fixed_tile_size(tile_size); | |
3271 | |
3272 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | |
3273 | |
3274 std::vector<PictureLayerTiling*> tilings; | |
3275 tilings.push_back(pending_layer_->AddTiling(low_res_factor)); | |
3276 tilings.push_back(pending_layer_->AddTiling(0.3f)); | |
3277 tilings.push_back(pending_layer_->AddTiling(0.7f)); | |
3278 tilings.push_back(pending_layer_->AddTiling(1.0f)); | |
3279 tilings.push_back(pending_layer_->AddTiling(2.0f)); | |
3280 | |
3281 EXPECT_EQ(5u, pending_layer_->num_tilings()); | |
3282 EXPECT_EQ(5u, active_layer_->num_tilings()); | |
3283 | |
3284 // Partially occlude the pending layer. | |
3285 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); | |
3286 LayerImpl* pending_occluding_layer = pending_layer_->children()[0]; | |
3287 pending_occluding_layer->SetBounds(layer_bounds); | |
3288 pending_occluding_layer->SetContentBounds(layer_bounds); | |
3289 pending_occluding_layer->SetDrawsContent(true); | |
3290 pending_occluding_layer->SetContentsOpaque(true); | |
3291 pending_occluding_layer->SetPosition(pending_occluding_layer_position); | |
3292 | |
3293 // Partially occlude the active layer. | |
3294 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2)); | |
3295 LayerImpl* active_occluding_layer = active_layer_->children()[0]; | |
3296 active_occluding_layer->SetBounds(layer_bounds); | |
3297 active_occluding_layer->SetContentBounds(layer_bounds); | |
3298 active_occluding_layer->SetDrawsContent(true); | |
3299 active_occluding_layer->SetContentsOpaque(true); | |
3300 active_occluding_layer->SetPosition(active_occluding_layer_position); | |
3301 | |
3302 // Partially invalidate the pending layer. Tiles inside the invalidation rect | |
3303 // are not shared between trees. | |
3304 pending_layer_->set_invalidation(invalidation_rect); | |
3305 | |
3306 host_impl_.SetViewportSize(viewport_size); | |
3307 host_impl_.active_tree()->UpdateDrawProperties(); | |
3308 host_impl_.pending_tree()->UpdateDrawProperties(); | |
3309 | |
3310 size_t expected_occluded_on_both_count[] = {9u, 1u, 1u, 1u, 1u}; | |
danakj
2014/07/15 21:26:50
Can you add a comment saying why there's 5 values
jbedley
2014/07/16 16:09:30
Done.
| |
3311 size_t expected_occluded_on_active_count[] = {30u, 5u, 4u, 2u, 2u}; | |
3312 size_t expected_occluded_on_pending_count[] = {30u, 5u, 4u, 2u, 2u}; | |
3313 size_t expected_occluded_sum[] = {13u, 43u, 43u}; | |
danakj
2014/07/15 21:26:50
And why there's 3 in this one, and what this is a
jbedley
2014/07/16 16:09:31
Done.
| |
3314 | |
3315 // Verify number of occluded tiles on the pending layer for each tiling. | |
3316 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | |
3317 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | |
3318 tiling->CreateAllTilesForTesting(); | |
3319 | |
3320 size_t occluded_on_pending_count = 0u; | |
3321 size_t occluded_on_active_count = 0u; | |
3322 size_t occluded_on_both_count = 0u; | |
3323 for (PictureLayerTiling::CoverageIterator iter( | |
3324 tiling, | |
3325 pending_layer_->contents_scale_x(), | |
3326 gfx::Rect(layer_bounds)); | |
3327 iter; | |
3328 ++iter) { | |
3329 Tile* tile = *iter; | |
3330 | |
3331 if (tile->is_occluded(PENDING_TREE)) | |
3332 occluded_on_pending_count++; | |
3333 if (tile->is_occluded(ACTIVE_TREE)) | |
3334 occluded_on_active_count++; | |
3335 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) | |
3336 occluded_on_both_count++; | |
3337 } | |
3338 EXPECT_EQ(expected_occluded_on_pending_count[i], occluded_on_pending_count); | |
danakj
2014/07/15 21:26:50
can you add "<< i" to the end of each of these EXP
jbedley
2014/07/16 16:09:31
Done.
| |
3339 EXPECT_EQ(expected_occluded_on_active_count[i], occluded_on_active_count); | |
3340 EXPECT_EQ(expected_occluded_on_both_count[i], occluded_on_both_count); | |
3341 } | |
3342 | |
3343 // Verify number of occluded tiles on the active layer for each tiling. | |
3344 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { | |
3345 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i); | |
3346 tiling->CreateAllTilesForTesting(); | |
3347 | |
3348 size_t occluded_on_pending_count = 0u; | |
3349 size_t occluded_on_active_count = 0u; | |
3350 size_t occluded_on_both_count = 0u; | |
3351 for (PictureLayerTiling::CoverageIterator iter( | |
3352 tiling, | |
3353 active_layer_->contents_scale_x(), | |
3354 gfx::Rect(layer_bounds)); | |
3355 iter; | |
3356 ++iter) { | |
3357 Tile* tile = *iter; | |
3358 | |
3359 if (tile->is_occluded(PENDING_TREE)) | |
3360 occluded_on_pending_count++; | |
3361 if (tile->is_occluded(ACTIVE_TREE)) | |
3362 occluded_on_active_count++; | |
3363 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) | |
3364 occluded_on_both_count++; | |
3365 } | |
3366 EXPECT_EQ(expected_occluded_on_pending_count[i], occluded_on_pending_count); | |
danakj
2014/07/15 21:26:50
<< i here also
jbedley
2014/07/16 16:09:31
Done.
| |
3367 EXPECT_EQ(expected_occluded_on_active_count[i], occluded_on_active_count); | |
3368 EXPECT_EQ(expected_occluded_on_both_count[i], occluded_on_both_count); | |
3369 } | |
3370 | |
3371 std::vector<Tile*> all_tiles; | |
3372 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | |
3373 tilings.begin(); | |
3374 tiling_iterator != tilings.end(); | |
3375 ++tiling_iterator) { | |
3376 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | |
3377 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | |
3378 } | |
3379 | |
3380 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | |
3381 | |
3382 VerifyEvictionConsidersOcclusion(pending_layer_, expected_occluded_sum); | |
3383 VerifyEvictionConsidersOcclusion(active_layer_, expected_occluded_sum); | |
3384 } | |
3207 } // namespace | 3385 } // namespace |
3208 } // namespace cc | 3386 } // namespace cc |
OLD | NEW |