| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 260 |
| 261 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 261 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
| 262 host_impl_.pending_tree()->LayerById(id_)); | 262 host_impl_.pending_tree()->LayerById(id_)); |
| 263 | 263 |
| 264 // Add tilings/tiles for the layer. | 264 // Add tilings/tiles for the layer. |
| 265 bool update_lcd_text = false; | 265 bool update_lcd_text = false; |
| 266 RebuildPropertyTreesOnPendingTree(); | 266 RebuildPropertyTreesOnPendingTree(); |
| 267 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); | 267 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void SetupDrawPropertiesAndUpdateTiles( | 270 void SetupDrawProperties(FakePictureLayerImpl* layer, |
| 271 FakePictureLayerImpl* layer, | 271 float ideal_contents_scale, |
| 272 float ideal_contents_scale, | 272 float device_scale_factor, |
| 273 float device_scale_factor, | 273 float page_scale_factor, |
| 274 float page_scale_factor, | 274 float maximum_animation_contents_scale, |
| 275 float maximum_animation_contents_scale, | 275 float starting_animation_contents_scale, |
| 276 float starting_animation_contents_scale, | 276 bool animating_transform_to_screen) { |
| 277 bool animating_transform_to_screen) { | |
| 278 layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); | 277 layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 279 host_impl_.active_tree()->SetPageScaleOnActiveTree(page_scale_factor); | 278 host_impl_.active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 280 | 279 |
| 281 gfx::Transform scale_transform; | 280 gfx::Transform scale_transform; |
| 282 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale); | 281 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale); |
| 283 layer->draw_properties().target_space_transform = scale_transform; | 282 layer->draw_properties().target_space_transform = scale_transform; |
| 284 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale); | 283 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale); |
| 285 layer->draw_properties().maximum_animation_contents_scale = | 284 layer->draw_properties().maximum_animation_contents_scale = |
| 286 maximum_animation_contents_scale; | 285 maximum_animation_contents_scale; |
| 287 layer->draw_properties().starting_animation_contents_scale = | 286 layer->draw_properties().starting_animation_contents_scale = |
| 288 starting_animation_contents_scale; | 287 starting_animation_contents_scale; |
| 289 layer->draw_properties().screen_space_transform_is_animating = | 288 layer->draw_properties().screen_space_transform_is_animating = |
| 290 animating_transform_to_screen; | 289 animating_transform_to_screen; |
| 290 } |
| 291 |
| 292 void SetupDrawPropertiesAndUpdateTiles( |
| 293 FakePictureLayerImpl* layer, |
| 294 float ideal_contents_scale, |
| 295 float device_scale_factor, |
| 296 float page_scale_factor, |
| 297 float maximum_animation_contents_scale, |
| 298 float starting_animation_contents_scale, |
| 299 bool animating_transform_to_screen) { |
| 300 SetupDrawProperties(layer, ideal_contents_scale, device_scale_factor, |
| 301 page_scale_factor, maximum_animation_contents_scale, |
| 302 starting_animation_contents_scale, |
| 303 animating_transform_to_screen); |
| 291 bool resourceless_software_draw = false; | 304 bool resourceless_software_draw = false; |
| 292 layer->UpdateTiles(resourceless_software_draw); | 305 layer->UpdateTiles(resourceless_software_draw); |
| 293 } | 306 } |
| 307 |
| 294 static void VerifyAllPrioritizedTilesExistAndHaveRasterSource( | 308 static void VerifyAllPrioritizedTilesExistAndHaveRasterSource( |
| 295 const PictureLayerTiling* tiling, | 309 const PictureLayerTiling* tiling, |
| 296 DisplayListRasterSource* raster_source) { | 310 DisplayListRasterSource* raster_source) { |
| 297 auto prioritized_tiles = | 311 auto prioritized_tiles = |
| 298 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | 312 tiling->UpdateAndGetAllPrioritizedTilesForTesting(); |
| 299 for (PictureLayerTiling::CoverageIterator iter( | 313 for (PictureLayerTiling::CoverageIterator iter( |
| 300 tiling, | 314 tiling, |
| 301 tiling->contents_scale(), | 315 tiling->contents_scale(), |
| 302 gfx::Rect(tiling->tiling_size())); | 316 gfx::Rect(tiling->tiling_size())); |
| 303 iter; | 317 iter; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 tilings = active_layer_->tilings(); | 553 tilings = active_layer_->tilings(); |
| 540 for (size_t i = 0; i < tilings->num_tilings(); i++) { | 554 for (size_t i = 0; i < tilings->num_tilings(); i++) { |
| 541 PictureLayerTiling* tiling = tilings->tiling_at(i); | 555 PictureLayerTiling* tiling = tilings->tiling_at(i); |
| 542 EXPECT_EQ( | 556 EXPECT_EQ( |
| 543 tiling->GetCurrentVisibleRectForTesting(), | 557 tiling->GetCurrentVisibleRectForTesting(), |
| 544 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, | 558 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, |
| 545 tiling->contents_scale())); | 559 tiling->contents_scale())); |
| 546 } | 560 } |
| 547 } | 561 } |
| 548 | 562 |
| 549 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | 563 TEST_F(PictureLayerImplTest, SkipUpdateTilesInResourcelessDraw) { |
| 550 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | |
| 551 gfx::Size layer_bounds(400, 400); | 564 gfx::Size layer_bounds(400, 400); |
| 552 SetupDefaultTrees(layer_bounds); | 565 SetupDefaultTrees(layer_bounds); |
| 553 | 566 |
| 554 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, | 567 float ideal_contents_scale = 1.f; |
| 555 false); | 568 SetupDrawProperties(active_layer_, ideal_contents_scale, 1.f, 1.f, 1.f, 0.f, |
| 569 false); |
| 556 | 570 |
| 557 // UpdateTiles with valid viewport. Should update tile viewport. | |
| 558 // Note viewport is considered invalid if and only if in resourceless | |
| 559 // software draw. | |
| 560 bool resourceless_software_draw = false; | 571 bool resourceless_software_draw = false; |
| 561 gfx::Rect viewport = gfx::Rect(layer_bounds); | |
| 562 gfx::Transform draw_transform; | |
| 563 gfx::Transform tile_priority_transform; | |
| 564 host_impl_.SetExternalTilePriorityConstraints(viewport, | |
| 565 tile_priority_transform); | |
| 566 active_layer_->draw_properties().visible_layer_rect = viewport; | |
| 567 active_layer_->draw_properties().screen_space_transform = draw_transform; | |
| 568 active_layer_->UpdateTiles(resourceless_software_draw); | 572 active_layer_->UpdateTiles(resourceless_software_draw); |
| 573 EXPECT_EQ(ideal_contents_scale, active_layer_->ideal_contents_scale()); |
| 569 | 574 |
| 570 gfx::Rect visible_rect_for_tile_priority = | 575 float new_ideal_contents_scale = 2.f; |
| 571 active_layer_->visible_rect_for_tile_priority(); | 576 resourceless_software_draw = true; |
| 572 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | 577 SetupDrawProperties(active_layer_, new_ideal_contents_scale, 1.f, 1.f, 1.f, |
| 573 gfx::Transform screen_space_transform_for_tile_priority = | 578 0.f, false); |
| 574 active_layer_->draw_properties().screen_space_transform; | 579 EXPECT_FALSE(active_layer_->UpdateTiles(resourceless_software_draw)); |
| 580 EXPECT_EQ(ideal_contents_scale, active_layer_->ideal_contents_scale()); |
| 575 | 581 |
| 576 // Expand viewport and set it as invalid for prioritizing tiles. | |
| 577 // Should update viewport and transform, but not update visible rect. | |
| 578 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); | |
| 579 resourceless_software_draw = true; | |
| 580 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | |
| 581 tile_priority_transform.Translate(1.f, 0.f); | |
| 582 draw_transform.Translate(0.f, 1.f); | |
| 583 active_layer_->draw_properties().visible_layer_rect = viewport; | |
| 584 active_layer_->draw_properties().screen_space_transform = draw_transform; | |
| 585 host_impl_.SetExternalTilePriorityConstraints(viewport, | |
| 586 tile_priority_transform); | |
| 587 active_layer_->UpdateTiles(resourceless_software_draw); | |
| 588 | |
| 589 // Transform for tile priority is not updated. | |
| 590 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 591 screen_space_transform_for_tile_priority, | |
| 592 active_layer_->screen_space_transform_for_tile_priority()); | |
| 593 // Visible rect for tile priority retains old value. | |
| 594 EXPECT_EQ(visible_rect_for_tile_priority, | |
| 595 active_layer_->visible_rect_for_tile_priority()); | |
| 596 ASSERT_GT(active_layer_->picture_layer_tiling_set()->num_tilings(), 0u); | |
| 597 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority_in_content_space(), | |
| 598 active_layer_->picture_layer_tiling_set() | |
| 599 ->tiling_at(0) | |
| 600 ->GetCurrentVisibleRectForTesting()); | |
| 601 | |
| 602 // Keep expanded viewport but mark it valid. Should update tile viewport. | |
| 603 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); | |
| 604 resourceless_software_draw = false; | 582 resourceless_software_draw = false; |
| 605 host_impl_.SetExternalTilePriorityConstraints(viewport, | 583 EXPECT_TRUE(active_layer_->UpdateTiles(resourceless_software_draw)); |
| 606 tile_priority_transform); | 584 EXPECT_EQ(new_ideal_contents_scale, active_layer_->ideal_contents_scale()); |
| 607 active_layer_->UpdateTiles(resourceless_software_draw); | |
| 608 | |
| 609 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 610 draw_transform, | |
| 611 active_layer_->screen_space_transform_for_tile_priority()); | |
| 612 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); | |
| 613 | |
| 614 gfx::RectF visible_rect_in_content_space(viewport); | |
| 615 gfx::Transform inverse_draw_transform; | |
| 616 gfx::Transform inverse_tile_priority_transform; | |
| 617 EXPECT_TRUE(draw_transform.GetInverse(&inverse_draw_transform)); | |
| 618 EXPECT_TRUE( | |
| 619 tile_priority_transform.GetInverse(&inverse_tile_priority_transform)); | |
| 620 visible_rect_in_content_space = MathUtil::ProjectClippedRect( | |
| 621 inverse_tile_priority_transform, visible_rect_in_content_space); | |
| 622 visible_rect_in_content_space = MathUtil::ProjectClippedRect( | |
| 623 inverse_draw_transform, visible_rect_in_content_space); | |
| 624 | |
| 625 ASSERT_GT(active_layer_->picture_layer_tiling_set()->num_tilings(), 0u); | |
| 626 EXPECT_EQ(gfx::ToEnclosingRect(visible_rect_in_content_space), | |
| 627 active_layer_->picture_layer_tiling_set() | |
| 628 ->tiling_at(0) | |
| 629 ->GetCurrentVisibleRectForTesting()); | |
| 630 } | 585 } |
| 631 | 586 |
| 632 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { | 587 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { |
| 633 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | 588 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); |
| 634 gfx::Size layer_bounds(400, 400); | 589 gfx::Size layer_bounds(400, 400); |
| 635 SetupDefaultTrees(layer_bounds); | 590 SetupDefaultTrees(layer_bounds); |
| 636 | 591 |
| 637 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, | 592 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, |
| 638 false); | 593 false); |
| 639 | 594 |
| (...skipping 3022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3662 // need content in order to activate. | 3617 // need content in order to activate. |
| 3663 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting(); | 3618 pending_layer_->HighResTiling()->UpdateAllRequiredStateForTesting(); |
| 3664 if (host_impl_.settings().create_low_res_tiling) | 3619 if (host_impl_.settings().create_low_res_tiling) |
| 3665 pending_layer_->LowResTiling()->UpdateAllRequiredStateForTesting(); | 3620 pending_layer_->LowResTiling()->UpdateAllRequiredStateForTesting(); |
| 3666 | 3621 |
| 3667 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 3622 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
| 3668 if (host_impl_.settings().create_low_res_tiling) | 3623 if (host_impl_.settings().create_low_res_tiling) |
| 3669 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 3624 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
| 3670 } | 3625 } |
| 3671 | 3626 |
| 3672 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | |
| 3673 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | |
| 3674 gfx::Size layer_bounds(400, 400); | |
| 3675 SetupDefaultTrees(layer_bounds); | |
| 3676 | |
| 3677 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, 0.f, | |
| 3678 false); | |
| 3679 | |
| 3680 // UpdateTiles with valid viewport. Should update tile viewport. | |
| 3681 // Note viewport is considered invalid if and only if in resourceless | |
| 3682 // software draw. | |
| 3683 bool resourceless_software_draw = false; | |
| 3684 gfx::Rect viewport = gfx::Rect(layer_bounds); | |
| 3685 gfx::Transform transform; | |
| 3686 host_impl_.SetExternalTilePriorityConstraints(viewport, transform); | |
| 3687 active_layer_->draw_properties().visible_layer_rect = viewport; | |
| 3688 active_layer_->draw_properties().screen_space_transform = transform; | |
| 3689 active_layer_->UpdateTiles(resourceless_software_draw); | |
| 3690 | |
| 3691 gfx::Rect visible_rect_for_tile_priority = | |
| 3692 active_layer_->visible_rect_for_tile_priority(); | |
| 3693 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | |
| 3694 gfx::Transform screen_space_transform_for_tile_priority = | |
| 3695 active_layer_->draw_properties().screen_space_transform; | |
| 3696 | |
| 3697 // Expand viewport and set it as invalid for prioritizing tiles. | |
| 3698 // Should update viewport and transform, but not update visible rect. | |
| 3699 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); | |
| 3700 resourceless_software_draw = true; | |
| 3701 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | |
| 3702 transform.Translate(1.f, 1.f); | |
| 3703 active_layer_->draw_properties().visible_layer_rect = viewport; | |
| 3704 active_layer_->draw_properties().screen_space_transform = transform; | |
| 3705 host_impl_.SetExternalTilePriorityConstraints(viewport, transform); | |
| 3706 active_layer_->UpdateTiles(resourceless_software_draw); | |
| 3707 | |
| 3708 // Transform for tile priority is updated. | |
| 3709 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 3710 transform, active_layer_->draw_properties().screen_space_transform); | |
| 3711 // Visible rect for tile priority retains old value. | |
| 3712 EXPECT_EQ(visible_rect_for_tile_priority, | |
| 3713 active_layer_->visible_rect_for_tile_priority()); | |
| 3714 | |
| 3715 // Keep expanded viewport but mark it valid. Should update tile viewport. | |
| 3716 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); | |
| 3717 resourceless_software_draw = false; | |
| 3718 host_impl_.SetExternalTilePriorityConstraints(viewport, transform); | |
| 3719 active_layer_->UpdateTiles(resourceless_software_draw); | |
| 3720 | |
| 3721 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 3722 transform, active_layer_->draw_properties().screen_space_transform); | |
| 3723 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); | |
| 3724 } | |
| 3725 | |
| 3726 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { | 3627 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { |
| 3727 gfx::Size layer_bounds(1300, 1900); | 3628 gfx::Size layer_bounds(1300, 1900); |
| 3728 std::vector<PictureLayerTiling*> used_tilings; | 3629 std::vector<PictureLayerTiling*> used_tilings; |
| 3729 SetupDefaultTrees(layer_bounds); | 3630 SetupDefaultTrees(layer_bounds); |
| 3730 | 3631 |
| 3731 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; | 3632 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; |
| 3732 EXPECT_LT(low_res_factor, 1.f); | 3633 EXPECT_LT(low_res_factor, 1.f); |
| 3733 | 3634 |
| 3734 float device_scale = 1.7f; | 3635 float device_scale = 1.7f; |
| 3735 float page_scale = 3.2f; | 3636 float page_scale = 3.2f; |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5116 // New low res tiling. | 5017 // New low res tiling. |
| 5117 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles()); | 5018 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles()); |
| 5118 | 5019 |
| 5119 // This tiling will be high res now, it won't contain low res content since it | 5020 // This tiling will be high res now, it won't contain low res content since it |
| 5120 // was all destroyed. | 5021 // was all destroyed. |
| 5121 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles()); | 5022 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles()); |
| 5122 } | 5023 } |
| 5123 | 5024 |
| 5124 } // namespace | 5025 } // namespace |
| 5125 } // namespace cc | 5026 } // namespace cc |
| OLD | NEW |