Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 664803003: Update from chromium a8e7c94b1b79a0948d05a1fcfff53391d22ce37a (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/tiled_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 2187 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
2188 } 2188 }
2189 2189
2190 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) { 2190 TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
2191 SetupDefaultTrees(gfx::Size(10, 10)); 2191 SetupDefaultTrees(gfx::Size(10, 10));
2192 host_impl_.active_tree()->UpdateDrawProperties(); 2192 host_impl_.active_tree()->UpdateDrawProperties();
2193 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties()); 2193 EXPECT_FALSE(host_impl_.active_tree()->needs_update_draw_properties());
2194 2194
2195 SetupDrawPropertiesAndUpdateTiles( 2195 SetupDrawPropertiesAndUpdateTiles(
2196 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false); 2196 active_layer_, 0.5f, 0.5f, 0.5f, 0.5f, false);
2197 pending_layer_->tilings()->RemoveAllTilings();
2197 active_layer_->tilings()->RemoveAllTilings(); 2198 active_layer_->tilings()->RemoveAllTilings();
2198 PictureLayerTiling* tiling = active_layer_->tilings()->AddTiling(0.5f); 2199 PictureLayerTiling* tiling = active_layer_->AddTiling(0.5f);
2199 active_layer_->tilings()->AddTiling(1.5f); 2200 active_layer_->AddTiling(1.5f);
2200 active_layer_->tilings()->AddTiling(0.25f); 2201 active_layer_->AddTiling(0.25f);
2201 tiling->set_resolution(HIGH_RESOLUTION); 2202 tiling->set_resolution(HIGH_RESOLUTION);
2202 2203
2203 // Sanity checks. 2204 // Sanity checks.
2204 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 2205 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
2205 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f)); 2206 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f));
2206 2207
2208 pending_layer_->tilings()->RemoveAllTilings();
2209 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
2210
2207 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes 2211 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
2208 // 1.0f). Note that we should also ensure that the pending layer needs post 2212 // 1.0f). Note that we should also ensure that the pending layer needs post
2209 // commit initialization, since this is what would happen during commit. In 2213 // commit initialization, since this is what would happen during commit. In
2210 // other words we want the pending layer to sync from the active layer. 2214 // other words we want the pending layer to sync from the active layer.
2211 pending_layer_->SetBounds(gfx::Size(1, 1)); 2215 pending_layer_->SetBounds(gfx::Size(1, 1));
2212 pending_layer_->SetNeedsPostCommitInitialization(); 2216 pending_layer_->SetNeedsPostCommitInitialization();
2213 pending_layer_->set_twin_layer(nullptr); 2217 pending_layer_->set_twin_layer(nullptr);
2214 active_layer_->set_twin_layer(nullptr); 2218 active_layer_->set_twin_layer(nullptr);
2215 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization()); 2219 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
2216 2220
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 SetContentsScaleOnBothLayers(contents_scale, 2599 SetContentsScaleOnBothLayers(contents_scale,
2596 device_scale, 2600 device_scale,
2597 page_scale, 2601 page_scale,
2598 maximum_animation_scale, 2602 maximum_animation_scale,
2599 animating_transform); 2603 animating_transform);
2600 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); 2604 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2601 2605
2602 static_cast<FakePicturePileImpl*>(pending_layer_->pile())->set_has_text(true); 2606 static_cast<FakePicturePileImpl*>(pending_layer_->pile())->set_has_text(true);
2603 static_cast<FakePicturePileImpl*>(active_layer_->pile())->set_has_text(true); 2607 static_cast<FakePicturePileImpl*>(active_layer_->pile())->set_has_text(true);
2604 2608
2605 // Since we're GPU-rasterizing but have text, starting an animation should 2609 // When we're GPU-rasterizing, even if we have text, starting an animation
2606 // cause tiling resolution to get set to the maximum animation scale. 2610 // should cause tiling resolution to get set to the content scale, since we
2611 // render animating text at content scale using distance fields.
2607 animating_transform = true; 2612 animating_transform = true;
2608 contents_scale = 2.f; 2613 contents_scale = 2.f;
2609 maximum_animation_scale = 3.f; 2614 maximum_animation_scale = 3.f;
2610 2615
2611 SetContentsScaleOnBothLayers(contents_scale, 2616 SetContentsScaleOnBothLayers(contents_scale,
2612 device_scale, 2617 device_scale,
2613 page_scale, 2618 page_scale,
2614 maximum_animation_scale, 2619 maximum_animation_scale,
2615 animating_transform); 2620 animating_transform);
2616 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f); 2621 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
2617 2622
2618 // Further changes to scale during the animation should not cause a new 2623 // Further changes to scale during the animation should still cause a new
2619 // high-res tiling to get created. 2624 // high-res tiling to get created at content scale.
2620 contents_scale = 4.f; 2625 contents_scale = 4.f;
2621 maximum_animation_scale = 5.f; 2626 maximum_animation_scale = 5.f;
2622 2627
2623 SetContentsScaleOnBothLayers(contents_scale, 2628 SetContentsScaleOnBothLayers(contents_scale,
2624 device_scale, 2629 device_scale,
2625 page_scale, 2630 page_scale,
2626 maximum_animation_scale, 2631 maximum_animation_scale,
2627 animating_transform); 2632 animating_transform);
2628 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 3.f); 2633 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
2629 2634
2630 // Once we stop animating, a new high-res tiling should be created. 2635 // Once we stop animating, a new high-res tiling should be created.
2631 animating_transform = false; 2636 animating_transform = false;
2632 2637
2633 SetContentsScaleOnBothLayers(contents_scale, 2638 SetContentsScaleOnBothLayers(contents_scale,
2634 device_scale, 2639 device_scale,
2635 page_scale, 2640 page_scale,
2636 maximum_animation_scale, 2641 maximum_animation_scale,
2637 animating_transform); 2642 animating_transform);
2638 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); 2643 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 2702
2698 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION; 2703 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2699 low_res_tile_count += priority.resolution == LOW_RESOLUTION; 2704 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2700 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; 2705 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2701 2706
2702 unique_tiles.insert(tile); 2707 unique_tiles.insert(tile);
2703 } 2708 }
2704 2709
2705 EXPECT_TRUE(reached_prepaint); 2710 EXPECT_TRUE(reached_prepaint);
2706 EXPECT_EQ(0u, non_ideal_tile_count); 2711 EXPECT_EQ(0u, non_ideal_tile_count);
2707 EXPECT_EQ(1u, low_res_tile_count); 2712 EXPECT_EQ(0u, low_res_tile_count);
2708 EXPECT_EQ(16u, high_res_tile_count); 2713 EXPECT_EQ(16u, high_res_tile_count);
2709 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count, 2714 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count,
2710 unique_tiles.size()); 2715 unique_tiles.size());
2711 2716
2712 // No NOW tiles. 2717 // No NOW tiles.
2713 time_ticks += base::TimeDelta::FromMilliseconds(200); 2718 time_ticks += base::TimeDelta::FromMilliseconds(200);
2714 host_impl_.SetCurrentBeginFrameArgs( 2719 host_impl_.SetCurrentBeginFrameArgs(
2715 CreateBeginFrameArgsForTesting(time_ticks)); 2720 CreateBeginFrameArgsForTesting(time_ticks));
2716 2721
2717 pending_layer_->draw_properties().visible_content_rect = 2722 pending_layer_->draw_properties().visible_content_rect =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 tile_it != high_res_tiles.end(); 2759 tile_it != high_res_tiles.end();
2755 ++tile_it) { 2760 ++tile_it) {
2756 Tile* tile = *tile_it; 2761 Tile* tile = *tile_it;
2757 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); 2762 ManagedTileState::DrawInfo& draw_info = tile->draw_info();
2758 draw_info.SetSolidColorForTesting(SK_ColorRED); 2763 draw_info.SetSolidColorForTesting(SK_ColorRED);
2759 } 2764 }
2760 2765
2761 non_ideal_tile_count = 0; 2766 non_ideal_tile_count = 0;
2762 low_res_tile_count = 0; 2767 low_res_tile_count = 0;
2763 high_res_tile_count = 0; 2768 high_res_tile_count = 0;
2764 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); 2769 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, true); it;
2765 it;
2766 ++it) { 2770 ++it) {
2767 Tile* tile = *it; 2771 Tile* tile = *it;
2768 TilePriority priority = tile->priority(PENDING_TREE); 2772 TilePriority priority = tile->priority(PENDING_TREE);
2769 2773
2770 EXPECT_TRUE(tile); 2774 EXPECT_TRUE(tile);
2771 2775
2772 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION; 2776 non_ideal_tile_count += priority.resolution == NON_IDEAL_RESOLUTION;
2773 low_res_tile_count += priority.resolution == LOW_RESOLUTION; 2777 low_res_tile_count += priority.resolution == LOW_RESOLUTION;
2774 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; 2778 high_res_tile_count += priority.resolution == HIGH_RESOLUTION;
2775 } 2779 }
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
3787 // Occluded tiles should not be iterated over. 3791 // Occluded tiles should not be iterated over.
3788 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); 3792 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
3789 3793
3790 // Some tiles may not be visible (i.e. outside the viewport). The rest are 3794 // Some tiles may not be visible (i.e. outside the viewport). The rest are
3791 // visible and at least partially unoccluded, verified by the above expect. 3795 // visible and at least partially unoccluded, verified by the above expect.
3792 bool tile_is_visible = 3796 bool tile_is_visible =
3793 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); 3797 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
3794 if (tile_is_visible) 3798 if (tile_is_visible)
3795 unoccluded_tile_count++; 3799 unoccluded_tile_count++;
3796 } 3800 }
3797 EXPECT_EQ(unoccluded_tile_count, 25 + 4); 3801 EXPECT_EQ(unoccluded_tile_count, 25);
3798 3802
3799 // Partial occlusion. 3803 // Partial occlusion.
3800 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 3804 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3801 LayerImpl* layer1 = pending_layer_->children()[0]; 3805 LayerImpl* layer1 = pending_layer_->children()[0];
3802 layer1->SetBounds(layer_bounds); 3806 layer1->SetBounds(layer_bounds);
3803 layer1->SetContentBounds(layer_bounds); 3807 layer1->SetContentBounds(layer_bounds);
3804 layer1->SetDrawsContent(true); 3808 layer1->SetDrawsContent(true);
3805 layer1->SetContentsOpaque(true); 3809 layer1->SetContentsOpaque(true);
3806 layer1->SetPosition(occluding_layer_position); 3810 layer1->SetPosition(occluding_layer_position);
3807 3811
3808 time_ticks += base::TimeDelta::FromMilliseconds(200); 3812 time_ticks += base::TimeDelta::FromMilliseconds(200);
3809 host_impl_.SetCurrentBeginFrameArgs( 3813 host_impl_.SetCurrentBeginFrameArgs(
3810 CreateBeginFrameArgsForTesting(time_ticks)); 3814 CreateBeginFrameArgsForTesting(time_ticks));
3811 host_impl_.pending_tree()->UpdateDrawProperties(); 3815 host_impl_.pending_tree()->UpdateDrawProperties();
3812 3816
3813 unoccluded_tile_count = 0; 3817 unoccluded_tile_count = 0;
3814 for (PictureLayerImpl::LayerRasterTileIterator it = 3818 for (PictureLayerImpl::LayerRasterTileIterator it =
3815 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); 3819 PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false);
3816 it; 3820 it;
3817 ++it) { 3821 ++it) {
3818 Tile* tile = *it; 3822 Tile* tile = *it;
3819 3823
3820 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); 3824 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
3821 3825
3822 bool tile_is_visible = 3826 bool tile_is_visible =
3823 tile->content_rect().Intersects(pending_layer_->visible_content_rect()); 3827 tile->content_rect().Intersects(pending_layer_->visible_content_rect());
3824 if (tile_is_visible) 3828 if (tile_is_visible)
3825 unoccluded_tile_count++; 3829 unoccluded_tile_count++;
3826 } 3830 }
3827 EXPECT_EQ(20 + 2, unoccluded_tile_count); 3831 EXPECT_EQ(20, unoccluded_tile_count);
3828 3832
3829 // Full occlusion. 3833 // Full occlusion.
3830 layer1->SetPosition(gfx::Point(0, 0)); 3834 layer1->SetPosition(gfx::Point(0, 0));
3831 3835
3832 time_ticks += base::TimeDelta::FromMilliseconds(200); 3836 time_ticks += base::TimeDelta::FromMilliseconds(200);
3833 host_impl_.SetCurrentBeginFrameArgs( 3837 host_impl_.SetCurrentBeginFrameArgs(
3834 CreateBeginFrameArgsForTesting(time_ticks)); 3838 CreateBeginFrameArgsForTesting(time_ticks));
3835 host_impl_.pending_tree()->UpdateDrawProperties(); 3839 host_impl_.pending_tree()->UpdateDrawProperties();
3836 3840
3837 unoccluded_tile_count = 0; 3841 unoccluded_tile_count = 0;
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 PicturePileImpl::CreateFromOther(pile); 4487 PicturePileImpl::CreateFromOther(pile);
4484 4488
4485 SetupPendingTree(pending_pile2); 4489 SetupPendingTree(pending_pile2);
4486 ActivateTree(); 4490 ActivateTree();
4487 4491
4488 // We've switched to a solid color, so we should end up with no tilings. 4492 // We've switched to a solid color, so we should end up with no tilings.
4489 ASSERT_TRUE(active_layer_->tilings()); 4493 ASSERT_TRUE(active_layer_->tilings());
4490 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); 4494 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings());
4491 } 4495 }
4492 4496
4497 TEST_F(PictureLayerImplTest, ChangeInViewportAllowsTilingUpdates) {
4498 base::TimeTicks time_ticks;
4499 time_ticks += base::TimeDelta::FromMilliseconds(1);
4500 host_impl_.SetCurrentBeginFrameArgs(
4501 CreateBeginFrameArgsForTesting(time_ticks));
4502
4503 gfx::Size tile_size(100, 100);
4504 gfx::Size layer_bounds(400, 4000);
4505
4506 scoped_refptr<FakePicturePileImpl> pending_pile =
4507 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4508 scoped_refptr<FakePicturePileImpl> active_pile =
4509 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4510
4511 SetupTrees(pending_pile, active_pile);
4512
4513 Region invalidation;
4514 gfx::Rect viewport = gfx::Rect(0, 0, 100, 100);
4515 gfx::Transform transform;
4516
4517 host_impl_.SetRequiresHighResToDraw();
4518
4519 // Update tiles.
4520 pending_layer_->draw_properties().visible_content_rect = viewport;
4521 pending_layer_->draw_properties().screen_space_transform = transform;
4522 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
4523 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4524
4525 // Ensure we can't activate.
4526 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
4527
4528 // Now in the same frame, move the viewport (this can happen during
4529 // animation).
4530 viewport = gfx::Rect(0, 2000, 100, 100);
4531
4532 // Update tiles.
4533 pending_layer_->draw_properties().visible_content_rect = viewport;
4534 pending_layer_->draw_properties().screen_space_transform = transform;
4535 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
4536 pending_layer_->HighResTiling()->UpdateAllTilePrioritiesForTesting();
4537
4538 // Make sure all viewport tiles (viewport from the tiling) are ready to draw.
4539 std::vector<Tile*> tiles;
4540 for (PictureLayerTiling::CoverageIterator iter(
4541 pending_layer_->HighResTiling(),
4542 1.f,
4543 pending_layer_->HighResTiling()->GetCurrentVisibleRectForTesting());
4544 iter;
4545 ++iter) {
4546 if (*iter)
4547 tiles.push_back(*iter);
4548 }
4549
4550 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
4551
4552 // Ensure we can activate.
4553 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw());
4554 }
4555
4493 class TileSizeSettings : public ImplSidePaintingSettings { 4556 class TileSizeSettings : public ImplSidePaintingSettings {
4494 public: 4557 public:
4495 TileSizeSettings() { 4558 TileSizeSettings() {
4496 default_tile_size = gfx::Size(100, 100); 4559 default_tile_size = gfx::Size(100, 100);
4497 max_untiled_layer_size = gfx::Size(200, 200); 4560 max_untiled_layer_size = gfx::Size(200, 200);
4498 } 4561 }
4499 }; 4562 };
4500 4563
4501 class TileSizeTest : public PictureLayerImplTest { 4564 class TileSizeTest : public PictureLayerImplTest {
4502 public: 4565 public:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4550 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4613 result = layer->CalculateTileSize(gfx::Size(447, 400));
4551 EXPECT_EQ(result.width(), 448); 4614 EXPECT_EQ(result.width(), 448);
4552 EXPECT_EQ(result.height(), 448); 4615 EXPECT_EQ(result.height(), 448);
4553 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4616 result = layer->CalculateTileSize(gfx::Size(500, 499));
4554 EXPECT_EQ(result.width(), 512); 4617 EXPECT_EQ(result.width(), 512);
4555 EXPECT_EQ(result.height(), 500 + 2); 4618 EXPECT_EQ(result.height(), 500 + 2);
4556 } 4619 }
4557 4620
4558 } // namespace 4621 } // namespace
4559 } // namespace cc 4622 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/tiled_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698