Chromium Code Reviews| 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 3186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3197 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); | 3197 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); |
| 3198 | 3198 |
| 3199 // Unshared tiles are occluded on the active tree iff they lie beneath | 3199 // Unshared tiles are occluded on the active tree iff they lie beneath |
| 3200 // the occluding layer. | 3200 // the occluding layer. |
| 3201 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), | 3201 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), |
| 3202 scaled_content_rect.x() >= occluding_layer_position.x()); | 3202 scaled_content_rect.x() >= occluding_layer_position.x()); |
| 3203 } | 3203 } |
| 3204 } | 3204 } |
| 3205 } | 3205 } |
| 3206 } | 3206 } |
| 3207 | |
| 3208 TEST_F(OcclusionTrackingPictureLayerImplTest, | |
| 3209 OccludedTilesConsideredDuringEviction) { | |
| 3210 gfx::Size tile_size(102, 102); | |
| 3211 gfx::Size layer_bounds(1000, 1000); | |
| 3212 gfx::Size viewport_size(500, 500); | |
| 3213 gfx::Point pending_occluding_layer_position(310, 0); | |
| 3214 gfx::Point active_occluding_layer_position(0, 310); | |
| 3215 gfx::Rect invalidation_rect(230, 230, 102, 102); | |
| 3216 | |
| 3217 scoped_refptr<FakePicturePileImpl> pending_pile = | |
| 3218 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
| 3219 scoped_refptr<FakePicturePileImpl> active_pile = | |
| 3220 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
| 3221 SetupTrees(pending_pile, active_pile); | |
| 3222 | |
| 3223 pending_layer_->set_fixed_tile_size(tile_size); | |
| 3224 active_layer_->set_fixed_tile_size(tile_size); | |
| 3225 | |
| 3226 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | |
| 3227 | |
| 3228 std::vector<PictureLayerTiling*> tilings; | |
| 3229 tilings.push_back(pending_layer_->AddTiling(low_res_factor)); | |
| 3230 tilings.push_back(pending_layer_->AddTiling(0.3f)); | |
| 3231 tilings.push_back(pending_layer_->AddTiling(0.7f)); | |
| 3232 tilings.push_back(pending_layer_->AddTiling(1.0f)); | |
| 3233 tilings.push_back(pending_layer_->AddTiling(2.0f)); | |
| 3234 | |
| 3235 EXPECT_EQ(5u, pending_layer_->num_tilings()); | |
| 3236 EXPECT_EQ(5u, active_layer_->num_tilings()); | |
| 3237 | |
| 3238 // Partially occlude the pending layer. | |
| 3239 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); | |
| 3240 LayerImpl* pending_occluding_layer = pending_layer_->children()[0]; | |
| 3241 pending_occluding_layer->SetBounds(layer_bounds); | |
| 3242 pending_occluding_layer->SetContentBounds(layer_bounds); | |
| 3243 pending_occluding_layer->SetDrawsContent(true); | |
| 3244 pending_occluding_layer->SetContentsOpaque(true); | |
| 3245 pending_occluding_layer->SetPosition(pending_occluding_layer_position); | |
| 3246 | |
| 3247 // Partially occlude the active layer. | |
| 3248 active_layer_->AddChild(LayerImpl::Create(host_impl_.active_tree(), 2)); | |
| 3249 LayerImpl* active_occluding_layer = active_layer_->children()[0]; | |
| 3250 active_occluding_layer->SetBounds(layer_bounds); | |
| 3251 active_occluding_layer->SetContentBounds(layer_bounds); | |
| 3252 active_occluding_layer->SetDrawsContent(true); | |
| 3253 active_occluding_layer->SetContentsOpaque(true); | |
| 3254 active_occluding_layer->SetPosition(active_occluding_layer_position); | |
| 3255 | |
| 3256 // Partially invalidate the pending layer. Tiles inside the invalidation rect | |
| 3257 // are not shared between trees. | |
| 3258 pending_layer_->set_invalidation(invalidation_rect); | |
| 3259 | |
| 3260 host_impl_.SetViewportSize(viewport_size); | |
| 3261 host_impl_.active_tree()->UpdateDrawProperties(); | |
| 3262 host_impl_.pending_tree()->UpdateDrawProperties(); | |
| 3263 | |
| 3264 size_t expected_occluded_on_pending_count[] = {30u, 5u, 4u, 2u, 2u}; | |
| 3265 size_t expected_occluded_on_active_count[] = {30u, 5u, 4u, 2u, 2u}; | |
| 3266 size_t expected_occluded_on_both_count[] = {9u, 1u, 1u, 1u, 1u}; | |
| 3267 size_t expected_occluded_on_pending_sum = 43u; | |
| 3268 size_t expected_occluded_on_active_sum = 43u; | |
| 3269 size_t expected_occluded_on_both_sum = 13u; | |
| 3270 | |
| 3271 // Verify number of occluded tiles on the pending layer for each tiling. | |
| 3272 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | |
| 3273 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | |
| 3274 tiling->CreateAllTilesForTesting(); | |
| 3275 | |
| 3276 size_t occluded_on_pending_count = 0u; | |
| 3277 size_t occluded_on_active_count = 0u; | |
| 3278 size_t occluded_on_both_count = 0u; | |
| 3279 for (PictureLayerTiling::CoverageIterator iter( | |
| 3280 tiling, | |
| 3281 pending_layer_->contents_scale_x(), | |
| 3282 gfx::Rect(layer_bounds)); | |
| 3283 iter; | |
| 3284 ++iter) { | |
| 3285 Tile* tile = *iter; | |
| 3286 | |
| 3287 if (tile->is_occluded(PENDING_TREE)) | |
| 3288 occluded_on_pending_count++; | |
| 3289 if (tile->is_occluded(ACTIVE_TREE)) | |
| 3290 occluded_on_active_count++; | |
| 3291 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) | |
| 3292 occluded_on_both_count++; | |
| 3293 } | |
| 3294 EXPECT_EQ(expected_occluded_on_pending_count[i], occluded_on_pending_count); | |
| 3295 EXPECT_EQ(expected_occluded_on_active_count[i], occluded_on_active_count); | |
| 3296 EXPECT_EQ(expected_occluded_on_both_count[i], occluded_on_both_count); | |
| 3297 } | |
| 3298 | |
| 3299 // Verify number of occluded tiles on the active layer for each tiling. | |
| 3300 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { | |
| 3301 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i); | |
| 3302 tiling->CreateAllTilesForTesting(); | |
| 3303 | |
| 3304 size_t occluded_on_pending_count = 0u; | |
| 3305 size_t occluded_on_active_count = 0u; | |
| 3306 size_t occluded_on_both_count = 0u; | |
| 3307 for (PictureLayerTiling::CoverageIterator iter( | |
| 3308 tiling, | |
| 3309 active_layer_->contents_scale_x(), | |
| 3310 gfx::Rect(layer_bounds)); | |
| 3311 iter; | |
| 3312 ++iter) { | |
| 3313 Tile* tile = *iter; | |
| 3314 | |
| 3315 if (tile->is_occluded(PENDING_TREE)) | |
| 3316 occluded_on_pending_count++; | |
| 3317 if (tile->is_occluded(ACTIVE_TREE)) | |
| 3318 occluded_on_active_count++; | |
| 3319 if (tile->is_occluded(PENDING_TREE) && tile->is_occluded(ACTIVE_TREE)) | |
| 3320 occluded_on_both_count++; | |
| 3321 } | |
| 3322 EXPECT_EQ(expected_occluded_on_pending_count[i], occluded_on_pending_count); | |
| 3323 EXPECT_EQ(expected_occluded_on_active_count[i], occluded_on_active_count); | |
| 3324 EXPECT_EQ(expected_occluded_on_both_count[i], occluded_on_both_count); | |
| 3325 } | |
| 3326 | |
| 3327 std::vector<Tile*> all_tiles; | |
| 3328 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | |
| 3329 tilings.begin(); | |
| 3330 tiling_iterator != tilings.end(); | |
| 3331 ++tiling_iterator) { | |
| 3332 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | |
| 3333 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | |
| 3334 } | |
| 3335 | |
| 3336 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | |
| 3337 | |
| 3338 // Iterate over the pending layer considering occlusion on the pending tree. | |
| 3339 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; | |
| 3340 size_t occluded_tile_count = 0u; | |
| 3341 Tile* last_tile = NULL; | |
| 3342 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
| 3343 PictureLayerImpl::LayerEvictionTileIterator(pending_layer_, | |
| 3344 tree_priority); | |
| 3345 it; | |
| 3346 ++it) { | |
| 3347 Tile* tile = *it; | |
| 3348 if (!last_tile) | |
| 3349 last_tile = tile; | |
| 3350 | |
| 3351 // Since occlusion is considered after priority bin, requirement for | |
| 3352 // activation, and resolution, the only way we will encounter an occluded | |
| 3353 // tile after an unoccluded tile is if at least one of those three | |
| 3354 // properties differs between the two tiles. | |
| 3355 if (tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3356 occluded_tile_count++; | |
| 3357 if (!last_tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3358 EXPECT_TRUE( | |
| 3359 (tile->priority_for_tree_priority(tree_priority).priority_bin != | |
|
vmpstr
2014/07/11 00:44:31
Can you get the priority first, then check the bin
jbedley
2014/07/11 18:00:30
How does it look now?
| |
| 3360 last_tile->priority_for_tree_priority(tree_priority) | |
| 3361 .priority_bin) || | |
| 3362 (tile->required_for_activation() != | |
|
vmpstr
2014/07/11 00:44:31
Why is activation a part of this condition? That i
jbedley
2014/07/11 18:00:30
Tiles that are occluded on the pending tree cannot
vmpstr
2014/07/11 18:13:36
Ah, I forgot that we have occlusion for both trees
| |
| 3363 last_tile->required_for_activation()) || | |
| 3364 (tile->contents_scale() != last_tile->contents_scale())); | |
|
vmpstr
2014/07/11 00:44:32
I would pull this check up and just bypass the who
jbedley
2014/07/11 18:00:30
Sorry, could you explain what you mean by this?
vmpstr
2014/07/11 18:13:36
I just meant something like
if (one_scale != othe
| |
| 3365 } | |
| 3366 } | |
| 3367 | |
| 3368 last_tile = tile; | |
| 3369 } | |
| 3370 EXPECT_EQ(expected_occluded_on_pending_sum, occluded_tile_count); | |
| 3371 | |
| 3372 // Iterate over the active layer considering occlusion on the pending tree. | |
| 3373 occluded_tile_count = 0u; | |
| 3374 last_tile = NULL; | |
| 3375 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
| 3376 PictureLayerImpl::LayerEvictionTileIterator(active_layer_, | |
| 3377 tree_priority); | |
| 3378 it; | |
| 3379 ++it) { | |
| 3380 Tile* tile = *it; | |
| 3381 if (!last_tile) | |
| 3382 last_tile = tile; | |
| 3383 | |
| 3384 if (tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3385 occluded_tile_count++; | |
| 3386 if (!last_tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3387 EXPECT_TRUE( | |
| 3388 (tile->priority_for_tree_priority(tree_priority).priority_bin != | |
| 3389 last_tile->priority_for_tree_priority(tree_priority) | |
| 3390 .priority_bin) || | |
| 3391 (tile->required_for_activation() != | |
| 3392 last_tile->required_for_activation()) || | |
| 3393 (tile->contents_scale() != last_tile->contents_scale())); | |
| 3394 } | |
| 3395 } | |
| 3396 | |
| 3397 last_tile = tile; | |
| 3398 } | |
| 3399 EXPECT_EQ(expected_occluded_on_pending_sum, occluded_tile_count); | |
| 3400 | |
| 3401 // Iterate over the pending layer considering occlusion on the active tree. | |
| 3402 tree_priority = SMOOTHNESS_TAKES_PRIORITY; | |
|
vmpstr
2014/07/11 00:44:32
Can you compress the test a bit by making a loop:
jbedley
2014/07/11 18:00:30
Done.
| |
| 3403 occluded_tile_count = 0u; | |
| 3404 last_tile = NULL; | |
| 3405 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
| 3406 PictureLayerImpl::LayerEvictionTileIterator(pending_layer_, | |
| 3407 tree_priority); | |
| 3408 it; | |
| 3409 ++it) { | |
| 3410 Tile* tile = *it; | |
| 3411 if (!last_tile) | |
| 3412 last_tile = tile; | |
| 3413 | |
| 3414 if (tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3415 occluded_tile_count++; | |
| 3416 if (!last_tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3417 EXPECT_TRUE( | |
| 3418 (tile->priority_for_tree_priority(tree_priority).priority_bin != | |
| 3419 last_tile->priority_for_tree_priority(tree_priority) | |
| 3420 .priority_bin) || | |
| 3421 (tile->required_for_activation() != | |
| 3422 last_tile->required_for_activation()) || | |
| 3423 (tile->contents_scale() != last_tile->contents_scale())); | |
| 3424 } | |
| 3425 } | |
| 3426 | |
| 3427 last_tile = tile; | |
| 3428 } | |
| 3429 EXPECT_EQ(expected_occluded_on_active_sum, occluded_tile_count); | |
| 3430 | |
| 3431 // Iterate over the active layer considering occlusion on the active tree. | |
| 3432 occluded_tile_count = 0u; | |
| 3433 last_tile = NULL; | |
| 3434 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
| 3435 PictureLayerImpl::LayerEvictionTileIterator(active_layer_, | |
| 3436 tree_priority); | |
| 3437 it; | |
| 3438 ++it) { | |
| 3439 Tile* tile = *it; | |
| 3440 if (!last_tile) | |
| 3441 last_tile = tile; | |
| 3442 | |
| 3443 if (tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3444 occluded_tile_count++; | |
| 3445 if (!last_tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3446 EXPECT_TRUE( | |
| 3447 (tile->priority_for_tree_priority(tree_priority).priority_bin != | |
| 3448 last_tile->priority_for_tree_priority(tree_priority) | |
| 3449 .priority_bin) || | |
| 3450 (tile->required_for_activation() != | |
| 3451 last_tile->required_for_activation()) || | |
| 3452 (tile->contents_scale() != last_tile->contents_scale())); | |
| 3453 } | |
| 3454 } | |
| 3455 | |
| 3456 last_tile = tile; | |
| 3457 } | |
| 3458 EXPECT_EQ(expected_occluded_on_active_sum, occluded_tile_count); | |
| 3459 | |
| 3460 // Iterate over the pending layer considering occlusion on both trees. | |
| 3461 tree_priority = SAME_PRIORITY_FOR_BOTH_TREES; | |
| 3462 occluded_tile_count = 0u; | |
| 3463 last_tile = NULL; | |
| 3464 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
| 3465 PictureLayerImpl::LayerEvictionTileIterator(pending_layer_, | |
| 3466 tree_priority); | |
| 3467 it; | |
| 3468 ++it) { | |
| 3469 Tile* tile = *it; | |
| 3470 if (!last_tile) | |
| 3471 last_tile = tile; | |
| 3472 | |
| 3473 if (tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3474 occluded_tile_count++; | |
| 3475 if (!last_tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3476 EXPECT_TRUE( | |
| 3477 (tile->priority_for_tree_priority(tree_priority).priority_bin != | |
| 3478 last_tile->priority_for_tree_priority(tree_priority) | |
| 3479 .priority_bin) || | |
| 3480 (tile->required_for_activation() != | |
| 3481 last_tile->required_for_activation()) || | |
| 3482 (tile->contents_scale() != last_tile->contents_scale())); | |
| 3483 } | |
| 3484 } | |
| 3485 | |
| 3486 last_tile = tile; | |
| 3487 } | |
| 3488 EXPECT_EQ(expected_occluded_on_both_sum, occluded_tile_count); | |
| 3489 | |
| 3490 // Iterate over the active layer considering occlusion on both trees. | |
| 3491 occluded_tile_count = 0u; | |
| 3492 last_tile = NULL; | |
| 3493 for (PictureLayerImpl::LayerEvictionTileIterator it = | |
| 3494 PictureLayerImpl::LayerEvictionTileIterator(active_layer_, | |
| 3495 tree_priority); | |
| 3496 it; | |
| 3497 ++it) { | |
| 3498 Tile* tile = *it; | |
| 3499 if (!last_tile) | |
| 3500 last_tile = tile; | |
| 3501 | |
| 3502 if (tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3503 occluded_tile_count++; | |
| 3504 if (!last_tile->is_occluded_for_tree_priority(tree_priority)) { | |
| 3505 EXPECT_TRUE( | |
| 3506 (tile->priority_for_tree_priority(tree_priority).priority_bin != | |
| 3507 last_tile->priority_for_tree_priority(tree_priority) | |
| 3508 .priority_bin) || | |
| 3509 (tile->required_for_activation() != | |
| 3510 last_tile->required_for_activation()) || | |
| 3511 (tile->contents_scale() != last_tile->contents_scale())); | |
| 3512 } | |
| 3513 } | |
| 3514 | |
| 3515 last_tile = tile; | |
| 3516 } | |
| 3517 EXPECT_EQ(expected_occluded_on_both_sum, occluded_tile_count); | |
| 3518 } | |
| 3207 } // namespace | 3519 } // namespace |
| 3208 } // namespace cc | 3520 } // namespace cc |
| OLD | NEW |