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

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

Issue 822713002: Update from https://crrev.com/309415 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years 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
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 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 mask->SetContentBounds(layer_bounds); 1182 mask->SetContentBounds(layer_bounds);
1183 mask->SetDrawsContent(true); 1183 mask->SetDrawsContent(true);
1184 1184
1185 SetupDrawPropertiesAndUpdateTiles(mask.get(), contents_scale, device_scale, 1185 SetupDrawPropertiesAndUpdateTiles(mask.get(), contents_scale, device_scale,
1186 page_scale, maximum_animation_scale, 1186 page_scale, maximum_animation_scale,
1187 animating_transform); 1187 animating_transform);
1188 EXPECT_EQ(mask->HighResTiling()->contents_scale(), contents_scale); 1188 EXPECT_EQ(mask->HighResTiling()->contents_scale(), contents_scale);
1189 EXPECT_EQ(mask->num_tilings(), 1u); 1189 EXPECT_EQ(mask->num_tilings(), 1u);
1190 } 1190 }
1191 1191
1192 TEST_F(PictureLayerImplTest, HugeMasksDontGetTiles) { 1192 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) {
1193 base::TimeTicks time_ticks; 1193 base::TimeTicks time_ticks;
1194 time_ticks += base::TimeDelta::FromMilliseconds(1); 1194 time_ticks += base::TimeDelta::FromMilliseconds(1);
1195 host_impl_.SetCurrentBeginFrameArgs( 1195 host_impl_.SetCurrentBeginFrameArgs(
1196 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1196 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1197 1197
1198 gfx::Size tile_size(100, 100); 1198 gfx::Size tile_size(100, 100);
1199 gfx::Size layer_bounds(1000, 1000); 1199 gfx::Size layer_bounds(1000, 1000);
1200 1200
1201 scoped_refptr<FakePicturePileImpl> valid_pile = 1201 scoped_refptr<FakePicturePileImpl> valid_pile =
1202 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1202 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
(...skipping 26 matching lines...) Expand all
1229 FakePictureLayerImpl* active_mask = 1229 FakePictureLayerImpl* active_mask =
1230 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer()); 1230 static_cast<FakePictureLayerImpl*>(active_layer_->mask_layer());
1231 1231
1232 // Mask layers have a tiling with a single tile in it. 1232 // Mask layers have a tiling with a single tile in it.
1233 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1233 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1234 // The mask resource exists. 1234 // The mask resource exists.
1235 ResourceProvider::ResourceId mask_resource_id; 1235 ResourceProvider::ResourceId mask_resource_id;
1236 gfx::Size mask_texture_size; 1236 gfx::Size mask_texture_size;
1237 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1237 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1238 EXPECT_NE(0u, mask_resource_id); 1238 EXPECT_NE(0u, mask_resource_id);
1239 EXPECT_EQ(mask_texture_size, active_mask->bounds()); 1239 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1240 1240
1241 // Drop resources and recreate them, still the same. 1241 // Drop resources and recreate them, still the same.
1242 pending_mask->ReleaseResources(); 1242 pending_mask->ReleaseResources();
1243 active_mask->ReleaseResources(); 1243 active_mask->ReleaseResources();
1244 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false); 1244 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1245 active_mask->HighResTiling()->CreateAllTilesForTesting(); 1245 active_mask->HighResTiling()->CreateAllTilesForTesting();
1246 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1246 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1247 EXPECT_NE(0u, mask_resource_id); 1247 EXPECT_NE(0u, mask_resource_id);
1248 EXPECT_EQ(mask_texture_size, active_layer_->bounds()); 1248 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1249
1250 // Drop resources and recreate them, still the same.
1251 pending_mask->ReleaseResources();
1252 active_mask->ReleaseResources();
1253 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1254 active_mask->HighResTiling()->CreateAllTilesForTesting();
1255 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1256 EXPECT_NE(0u, mask_resource_id);
1257 EXPECT_EQ(mask_texture_size, active_mask->bounds());
1258 1249
1259 // Resize larger than the max texture size. 1250 // Resize larger than the max texture size.
1260 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size; 1251 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1261 gfx::Size huge_bounds(max_texture_size + 1, 10); 1252 gfx::Size huge_bounds(max_texture_size + 1, 10);
1262 scoped_refptr<FakePicturePileImpl> huge_pile = 1253 scoped_refptr<FakePicturePileImpl> huge_pile =
1263 FakePicturePileImpl::CreateFilledPile(tile_size, huge_bounds); 1254 FakePicturePileImpl::CreateFilledPile(tile_size, huge_bounds);
1264 1255
1265 SetupPendingTree(huge_pile); 1256 SetupPendingTree(huge_pile);
1266 pending_mask->SetBounds(huge_bounds); 1257 pending_mask->SetBounds(huge_bounds);
1267 pending_mask->SetContentBounds(huge_bounds); 1258 pending_mask->SetContentBounds(huge_bounds);
1268 pending_mask->SetRasterSourceOnPending(huge_pile, Region()); 1259 pending_mask->SetRasterSourceOnPending(huge_pile, Region());
1269 1260
1270 time_ticks += base::TimeDelta::FromMilliseconds(1); 1261 time_ticks += base::TimeDelta::FromMilliseconds(1);
1271 host_impl_.SetCurrentBeginFrameArgs( 1262 host_impl_.SetCurrentBeginFrameArgs(
1272 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1263 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1273 host_impl_.pending_tree()->UpdateDrawProperties(); 1264 host_impl_.pending_tree()->UpdateDrawProperties();
1274 1265
1275 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale()); 1266 // The mask tiling gets scaled down.
1267 EXPECT_LT(pending_mask->HighResTiling()->contents_scale(), 1.f);
1276 EXPECT_EQ(1u, pending_mask->num_tilings()); 1268 EXPECT_EQ(1u, pending_mask->num_tilings());
1277 1269
1278 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( 1270 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1279 pending_mask->HighResTiling()->AllTilesForTesting()); 1271 pending_mask->HighResTiling()->AllTilesForTesting());
1280 1272
1281 ActivateTree(); 1273 ActivateTree();
1282 1274
1283 // Mask layers have a tiling, but there should be no tiles in it. 1275 // Mask layers have a tiling with a single tile in it.
1284 EXPECT_EQ(0u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1276 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1285 // The mask resource is empty. 1277 // The mask resource exists.
1286 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1278 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1287 EXPECT_EQ(0u, mask_resource_id); 1279 EXPECT_NE(0u, mask_resource_id);
1280 gfx::Size expected_size = active_mask->bounds();
1281 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
1282 EXPECT_EQ(expected_size, mask_texture_size);
1288 1283
1289 // Drop resources and recreate them, still the same. 1284 // Drop resources and recreate them, still the same.
1290 pending_mask->ReleaseResources(); 1285 pending_mask->ReleaseResources();
1291 active_mask->ReleaseResources(); 1286 active_mask->ReleaseResources();
1292 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false); 1287 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, false);
1293 active_mask->HighResTiling()->CreateAllTilesForTesting(); 1288 active_mask->HighResTiling()->CreateAllTilesForTesting();
1294 EXPECT_EQ(0u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1289 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1295 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1290 EXPECT_NE(0u, mask_resource_id);
1296 EXPECT_EQ(0u, mask_resource_id); 1291 EXPECT_EQ(expected_size, mask_texture_size);
1297 1292
1298 // Do another activate, the same holds. 1293 // Do another activate, the same holds.
1299 SetupPendingTree(huge_pile); 1294 SetupPendingTree(huge_pile);
1300 ActivateTree(); 1295 ActivateTree();
1301 EXPECT_EQ(0u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1296 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1302 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1297 active_layer_->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
1298 EXPECT_EQ(expected_size, mask_texture_size);
1303 EXPECT_EQ(0u, mask_resource_id); 1299 EXPECT_EQ(0u, mask_resource_id);
1300
1301 // Resize even larger, so that the scale would be smaller than the minimum
1302 // contents scale. Then the layer should no longer have any tiling.
1303 float min_contents_scale = host_impl_.settings().minimum_contents_scale;
1304 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10);
1305 scoped_refptr<FakePicturePileImpl> extra_huge_pile =
1306 FakePicturePileImpl::CreateFilledPile(tile_size, extra_huge_bounds);
1307
1308 SetupPendingTree(extra_huge_pile);
1309 pending_mask->SetBounds(extra_huge_bounds);
1310 pending_mask->SetContentBounds(extra_huge_bounds);
1311 pending_mask->SetRasterSourceOnPending(extra_huge_pile, Region());
1312
1313 EXPECT_FALSE(pending_mask->CanHaveTilings());
1314
1315 time_ticks += base::TimeDelta::FromMilliseconds(1);
1316 host_impl_.SetCurrentBeginFrameArgs(
1317 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1318 host_impl_.pending_tree()->UpdateDrawProperties();
1319
1320 EXPECT_EQ(0u, pending_mask->num_tilings());
1304 } 1321 }
1305 1322
1306 TEST_F(PictureLayerImplTest, ScaledMaskLayer) { 1323 TEST_F(PictureLayerImplTest, ScaledMaskLayer) {
1307 base::TimeTicks time_ticks; 1324 base::TimeTicks time_ticks;
1308 time_ticks += base::TimeDelta::FromMilliseconds(1); 1325 time_ticks += base::TimeDelta::FromMilliseconds(1);
1309 host_impl_.SetCurrentBeginFrameArgs( 1326 host_impl_.SetCurrentBeginFrameArgs(
1310 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 1327 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
1311 1328
1312 gfx::Size tile_size(100, 100); 1329 gfx::Size tile_size(100, 100);
1313 gfx::Size layer_bounds(1000, 1000); 1330 gfx::Size layer_bounds(1000, 1000);
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 int num_outside = 0; 1684 int num_outside = 0;
1668 for (PictureLayerTiling::CoverageIterator iter( 1685 for (PictureLayerTiling::CoverageIterator iter(
1669 pending_layer_->HighResTiling(), 1.f, gfx::Rect(layer_bounds)); 1686 pending_layer_->HighResTiling(), 1.f, gfx::Rect(layer_bounds));
1670 iter; ++iter) { 1687 iter; ++iter) {
1671 if (!*iter) 1688 if (!*iter)
1672 continue; 1689 continue;
1673 Tile* tile = *iter; 1690 Tile* tile = *iter;
1674 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) { 1691 if (viewport_for_tile_priority.Intersects(iter.geometry_rect())) {
1675 num_inside++; 1692 num_inside++;
1676 // Mark everything in viewport for tile priority as ready to draw. 1693 // Mark everything in viewport for tile priority as ready to draw.
1677 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); 1694 TileDrawInfo& draw_info = tile->draw_info();
1678 draw_info.SetSolidColorForTesting(SK_ColorRED); 1695 draw_info.SetSolidColorForTesting(SK_ColorRED);
1679 } else { 1696 } else {
1680 num_outside++; 1697 num_outside++;
1681 EXPECT_FALSE(tile->required_for_activation()); 1698 EXPECT_FALSE(tile->required_for_activation());
1682 } 1699 }
1683 } 1700 }
1684 1701
1685 EXPECT_GT(num_inside, 0); 1702 EXPECT_GT(num_inside, 0);
1686 EXPECT_GT(num_outside, 0); 1703 EXPECT_GT(num_outside, 0);
1687 1704
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 pending_layer_->draw_properties().visible_content_rect = 2829 pending_layer_->draw_properties().visible_content_rect =
2813 gfx::Rect(0, 0, 500, 500); 2830 gfx::Rect(0, 0, 500, 500);
2814 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); 2831 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw);
2815 2832
2816 std::vector<Tile*> high_res_tiles = 2833 std::vector<Tile*> high_res_tiles =
2817 pending_layer_->HighResTiling()->AllTilesForTesting(); 2834 pending_layer_->HighResTiling()->AllTilesForTesting();
2818 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin(); 2835 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin();
2819 tile_it != high_res_tiles.end(); 2836 tile_it != high_res_tiles.end();
2820 ++tile_it) { 2837 ++tile_it) {
2821 Tile* tile = *tile_it; 2838 Tile* tile = *tile_it;
2822 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); 2839 TileDrawInfo& draw_info = tile->draw_info();
2823 draw_info.SetSolidColorForTesting(SK_ColorRED); 2840 draw_info.SetSolidColorForTesting(SK_ColorRED);
2824 } 2841 }
2825 2842
2826 non_ideal_tile_count = 0; 2843 non_ideal_tile_count = 0;
2827 low_res_tile_count = 0; 2844 low_res_tile_count = 0;
2828 high_res_tile_count = 0; 2845 high_res_tile_count = 0;
2829 queue = pending_layer_->CreateRasterQueue(true); 2846 queue = pending_layer_->CreateRasterQueue(true);
2830 while (!queue->IsEmpty()) { 2847 while (!queue->IsEmpty()) {
2831 Tile* tile = queue->Top(); 2848 Tile* tile = queue->Top();
2832 TilePriority priority = tile->priority(PENDING_TREE); 2849 TilePriority priority = tile->priority(PENDING_TREE);
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 EXPECT_EQ( 3616 EXPECT_EQ(
3600 gfx::Size(2500u, 5000u).ToString(), 3617 gfx::Size(2500u, 5000u).ToString(),
3601 render_pass->shared_quad_state_list.front()->content_bounds.ToString()); 3618 render_pass->shared_quad_state_list.front()->content_bounds.ToString());
3602 // The visible_content_rect should be scaled by the 3619 // The visible_content_rect should be scaled by the
3603 // MaximumTilingContentsScale on the layer. 3620 // MaximumTilingContentsScale on the layer.
3604 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(), 3621 EXPECT_EQ(gfx::Rect(0u, 0u, 2500u, 5000u).ToString(),
3605 render_pass->shared_quad_state_list.front() 3622 render_pass->shared_quad_state_list.front()
3606 ->visible_content_rect.ToString()); 3623 ->visible_content_rect.ToString());
3607 } 3624 }
3608 3625
3609 TEST_F(PictureLayerImplTest, UpdateTilesForMasksWithNoVisibleContent) {
3610 gfx::Size tile_size(400, 400);
3611 gfx::Size bounds(100000, 100);
3612
3613 host_impl_.CreatePendingTree();
3614
3615 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.pending_tree(), 1);
3616
3617 scoped_refptr<FakePicturePileImpl> pending_pile =
3618 FakePicturePileImpl::CreateFilledPile(tile_size, bounds);
3619 scoped_ptr<FakePictureLayerImpl> layer_with_mask =
3620 FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 2,
3621 pending_pile);
3622 layer_with_mask->SetBounds(bounds);
3623 layer_with_mask->SetContentBounds(bounds);
3624
3625 scoped_refptr<FakePicturePileImpl> mask_pile =
3626 FakePicturePileImpl::CreateFilledPile(tile_size, bounds);
3627 scoped_ptr<FakePictureLayerImpl> mask =
3628 FakePictureLayerImpl::CreateMaskWithRasterSource(
3629 host_impl_.pending_tree(), 3, mask_pile);
3630 mask->SetBounds(bounds);
3631 mask->SetContentBounds(bounds);
3632 mask->SetDrawsContent(true);
3633 layer_with_mask->SetMaskLayer(mask.Pass());
3634
3635 FakePictureLayerImpl* pending_mask =
3636 static_cast<FakePictureLayerImpl*>(layer_with_mask->mask_layer());
3637
3638 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask =
3639 FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 4,
3640 pending_pile);
3641 child_of_layer_with_mask->SetBounds(bounds);
3642 child_of_layer_with_mask->SetContentBounds(bounds);
3643 child_of_layer_with_mask->SetDrawsContent(true);
3644 layer_with_mask->AddChild(child_of_layer_with_mask.Pass());
3645 root->AddChild(layer_with_mask.Pass());
3646
3647 host_impl_.pending_tree()->SetRootLayer(root.Pass());
3648
3649 EXPECT_EQ(0u, pending_mask->num_tilings());
3650 host_impl_.pending_tree()->UpdateDrawProperties();
3651 EXPECT_NE(0u, pending_mask->num_tilings());
3652 }
3653
3654 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest { 3626 class PictureLayerImplTestWithDelegatingRenderer : public PictureLayerImplTest {
3655 public: 3627 public:
3656 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {} 3628 PictureLayerImplTestWithDelegatingRenderer() : PictureLayerImplTest() {}
3657 3629
3658 void InitializeRenderer() override { 3630 void InitializeRenderer() override {
3659 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d()); 3631 host_impl_.InitializeRenderer(FakeOutputSurface::CreateDelegating3d());
3660 } 3632 }
3661 }; 3633 };
3662 3634
3663 TEST_F(PictureLayerImplTestWithDelegatingRenderer, 3635 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
4758 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4730 result = layer->CalculateTileSize(gfx::Size(447, 400));
4759 EXPECT_EQ(result.width(), 448); 4731 EXPECT_EQ(result.width(), 448);
4760 EXPECT_EQ(result.height(), 448); 4732 EXPECT_EQ(result.height(), 448);
4761 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4733 result = layer->CalculateTileSize(gfx::Size(500, 499));
4762 EXPECT_EQ(result.width(), 512); 4734 EXPECT_EQ(result.width(), 512);
4763 EXPECT_EQ(result.height(), 500 + 2); 4735 EXPECT_EQ(result.height(), 500 + 2);
4764 } 4736 }
4765 4737
4766 } // namespace 4738 } // namespace
4767 } // namespace cc 4739 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698