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

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

Issue 2099903002: Make tile size a function of the device scale factor. Base URL: https://chromium.googlesource.com/chromium/src.git@layouttests-display
Patch Set: tilesize: . Created 4 years, 5 months 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 LayerTreeSettings CreateSettings() override { 283 LayerTreeSettings CreateSettings() override {
284 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings(); 284 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings();
285 settings.create_low_res_tiling = false; 285 settings.create_low_res_tiling = false;
286 return settings; 286 return settings;
287 } 287 }
288 }; 288 };
289 289
290 TEST_F(PictureLayerImplTest, TileGridAlignment) { 290 TEST_F(PictureLayerImplTest, TileGridAlignment) {
291 // Layer to span 4 raster tiles in x and in y 291 // Layer to span 4 raster tiles in x and in y
292 LayerTreeSettings settings; 292 LayerTreeSettings settings;
293 gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2, 293 gfx::Size layer_size(256 * 7 / 2, 256 * 7 / 2);
294 settings.default_tile_size.height() * 7 / 2);
295 294
296 scoped_refptr<FakeRasterSource> pending_raster_source = 295 scoped_refptr<FakeRasterSource> pending_raster_source =
297 FakeRasterSource::CreateFilled(layer_size); 296 FakeRasterSource::CreateFilled(layer_size);
298 297
299 // Create an active recording source, but make sure it's not solid. 298 // Create an active recording source, but make sure it's not solid.
300 std::unique_ptr<FakeRecordingSource> active_recording_source = 299 std::unique_ptr<FakeRecordingSource> active_recording_source =
301 FakeRecordingSource::CreateFilledRecordingSource(layer_size); 300 FakeRecordingSource::CreateFilledRecordingSource(layer_size);
302 active_recording_source->SetLayerBounds(layer_size); 301 active_recording_source->SetLayerBounds(layer_size);
303 active_recording_source->add_draw_rect(gfx::Rect(layer_size)); 302 active_recording_source->add_draw_rect(gfx::Rect(layer_size));
304 active_recording_source->add_draw_rect( 303 active_recording_source->add_draw_rect(
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings()); 1072 ASSERT_EQ(2u, active_layer()->tilings()->num_tilings());
1074 EXPECT_FLOAT_EQ(1.2f, 1073 EXPECT_FLOAT_EQ(1.2f,
1075 active_layer()->tilings()->tiling_at(0)->contents_scale()); 1074 active_layer()->tilings()->tiling_at(0)->contents_scale());
1076 EXPECT_FLOAT_EQ(1.2 * low_res_factor, 1075 EXPECT_FLOAT_EQ(1.2 * low_res_factor,
1077 active_layer()->tilings()->tiling_at(1)->contents_scale()); 1076 active_layer()->tilings()->tiling_at(1)->contents_scale());
1078 } 1077 }
1079 1078
1080 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) { 1079 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1081 // Make sure this layer covers multiple tiles, since otherwise low 1080 // Make sure this layer covers multiple tiles, since otherwise low
1082 // res won't get created because it is too small. 1081 // res won't get created because it is too small.
1083 gfx::Size tile_size(host_impl()->settings().default_tile_size); 1082 gfx::Size tile_size(256, 256);
1084 // Avoid max untiled layer size heuristics via fixed tile size. 1083 // Avoid max untiled layer size heuristics via fixed tile size.
1085 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1); 1084 gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1);
1086 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); 1085 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
1087 1086
1088 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 1087 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor;
1089 float contents_scale = 1.f; 1088 float contents_scale = 1.f;
1090 float device_scale = 1.f; 1089 float device_scale = 1.f;
1091 float page_scale = 1.f; 1090 float page_scale = 1.f;
1092 float maximum_animation_scale = 1.f; 1091 float maximum_animation_scale = 1.f;
1093 float starting_animation_scale = 0.f; 1092 float starting_animation_scale = 0.f;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 maximum_animation_scale, 1136 maximum_animation_scale,
1138 starting_animation_scale, animating_transform); 1137 starting_animation_scale, animating_transform);
1139 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f); 1138 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 2.f);
1140 EXPECT_EQ(active_layer()->LowResTiling()->contents_scale(), 1139 EXPECT_EQ(active_layer()->LowResTiling()->contents_scale(),
1141 2.f * low_res_factor); 1140 2.f * low_res_factor);
1142 EXPECT_EQ(4u, active_layer()->num_tilings()); 1141 EXPECT_EQ(4u, active_layer()->num_tilings());
1143 EXPECT_EQ(1u, pending_layer()->num_tilings()); 1142 EXPECT_EQ(1u, pending_layer()->num_tilings());
1144 } 1143 }
1145 1144
1146 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { 1145 TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
1147 gfx::Size layer_bounds(host_impl()->settings().default_tile_size); 1146 gfx::Size tile_size(256, 256);
1147 gfx::Size layer_bounds(tile_size);
1148 1148
1149 scoped_refptr<FakeRasterSource> pending_raster_source = 1149 scoped_refptr<FakeRasterSource> pending_raster_source =
1150 FakeRasterSource::CreateFilled(layer_bounds); 1150 FakeRasterSource::CreateFilled(layer_bounds);
1151 scoped_refptr<FakeRasterSource> active_raster_source = 1151 scoped_refptr<FakeRasterSource> active_raster_source =
1152 FakeRasterSource::CreateFilled(layer_bounds); 1152 FakeRasterSource::CreateFilled(layer_bounds);
1153 1153
1154 SetupTrees(pending_raster_source, active_raster_source); 1154 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
1155 tile_size, Region());
1155 1156
1156 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 1157 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor;
1157 float device_scale = 1.f; 1158 float device_scale = 1.f;
1158 float page_scale = 1.f; 1159 float page_scale = 1.f;
1159 float maximum_animation_scale = 1.f; 1160 float maximum_animation_scale = 1.f;
1160 float starting_animation_scale = 0.f; 1161 float starting_animation_scale = 0.f;
1161 bool animating_transform = false; 1162 bool animating_transform = false;
1162 1163
1163 // Contents exactly fit on one tile at scale 1, no low res. 1164 // Contents exactly fit on one tile at scale 1, no low res.
1164 float contents_scale = 1.f; 1165 float contents_scale = 1.f;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 1.f, // ideal contents scale 1419 1.f, // ideal contents scale
1419 1.f, // device scale 1420 1.f, // device scale
1420 1.f, // page scale 1421 1.f, // page scale
1421 1.f, // maximum animation scale 1422 1.f, // maximum animation scale
1422 0.f, // starting animation_scale 1423 0.f, // starting animation_scale
1423 false); 1424 false);
1424 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 1425 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
1425 } 1426 }
1426 1427
1427 TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) { 1428 TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
1428 gfx::Size layer_bounds(5000, 5000); 1429 gfx::Size layer_bounds(500, 500);
1429 1430
1430 scoped_refptr<FakeRasterSource> pending_raster_source = 1431 scoped_refptr<FakeRasterSource> pending_raster_source =
1431 FakeRasterSource::CreateFilled(layer_bounds); 1432 FakeRasterSource::CreateFilled(layer_bounds);
1432 1433
1433 SetupPendingTree(pending_raster_source); 1434 SetupPendingTree(pending_raster_source);
1434 EXPECT_GE(pending_layer()->tilings()->num_tilings(), 1u); 1435 EXPECT_GE(pending_layer()->tilings()->num_tilings(), 1u);
1435 1436
1436 pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1437 pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1437 1438
1438 // The default value. 1439 int small_size = 4;
1439 EXPECT_EQ(gfx::Size(256, 256).ToString(),
1440 host_impl()->settings().default_tile_size.ToString());
1441 1440
1442 Tile* tile = 1441 Tile* tile =
1443 pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1442 pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1444 EXPECT_EQ(gfx::Size(256, 256).ToString(), 1443 EXPECT_GT(tile->content_rect().width(), small_size);
1445 tile->content_rect().size().ToString()); 1444 EXPECT_GT(tile->content_rect().height(), small_size);
1446 1445
1447 ResetTilingsAndRasterScales(); 1446 ResetTilingsAndRasterScales();
1448 1447
1449 // Change the max texture size on the output surface context. 1448 // Change the max texture size on the output surface context.
1450 std::unique_ptr<TestWebGraphicsContext3D> context = 1449 std::unique_ptr<TestWebGraphicsContext3D> context =
1451 TestWebGraphicsContext3D::Create(); 1450 TestWebGraphicsContext3D::Create();
1452 context->set_max_texture_size(140); 1451 context->set_max_texture_size(small_size);
1453 ResetOutputSurface(FakeOutputSurface::Create3d(std::move(context))); 1452 ResetOutputSurface(FakeOutputSurface::Create3d(std::move(context)));
1454 1453
1455 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.f, 1.f, 1.f, 1.f, 0.f, 1454 SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.f, 1.f, 1.f, 1.f, 0.f,
1456 false); 1455 false);
1457 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); 1456 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings());
1458 1457
1459 pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1458 pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1460 1459
1461 // Verify the tiles are not larger than the context's max texture size. 1460 // Verify the tiles are not larger than the context's max texture size.
1462 tile = pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0]; 1461 tile = pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0];
1463 EXPECT_GE(140, tile->content_rect().width()); 1462 EXPECT_EQ(small_size, tile->content_rect().width());
1464 EXPECT_GE(140, tile->content_rect().height()); 1463 EXPECT_EQ(small_size, tile->content_rect().height());
1465 } 1464 }
1466 1465
1467 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) { 1466 TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
1468 gfx::Size layer_bounds(500, 500); 1467 gfx::Size layer_bounds(500, 500);
1468 // The layer is smaller enough to be untiled.
1469 EXPECT_LE(layer_bounds.width(), PictureLayerImpl::kMaxUntiledContentSize);
1470 EXPECT_LE(layer_bounds.height(), PictureLayerImpl::kMaxUntiledContentSize);
1471
1469 SetupDefaultTrees(layer_bounds); 1472 SetupDefaultTrees(layer_bounds);
1470 EXPECT_GE(active_layer()->tilings()->num_tilings(), 1u); 1473 EXPECT_GE(active_layer()->tilings()->num_tilings(), 1u);
1471 1474
1472 active_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting(); 1475 active_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting();
1473 1476
1474 // The default value. The layer is smaller than this.
1475 EXPECT_EQ(gfx::Size(512, 512).ToString(),
1476 host_impl()->settings().max_untiled_layer_size.ToString());
1477
1478 // There should be a single tile since the layer is small. 1477 // There should be a single tile since the layer is small.
1479 PictureLayerTiling* high_res_tiling = active_layer()->tilings()->tiling_at(0); 1478 PictureLayerTiling* high_res_tiling = active_layer()->tilings()->tiling_at(0);
1480 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size()); 1479 EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
1481 1480
1482 ResetTilingsAndRasterScales(); 1481 ResetTilingsAndRasterScales();
1483 1482
1484 // Change the max texture size on the output surface context. 1483 // Change the max texture size on the output surface context.
1485 std::unique_ptr<TestWebGraphicsContext3D> context = 1484 std::unique_ptr<TestWebGraphicsContext3D> context =
1486 TestWebGraphicsContext3D::Create(); 1485 TestWebGraphicsContext3D::Create();
1487 context->set_max_texture_size(140); 1486 context->set_max_texture_size(140);
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 // Since the MinContentsScale is 1, the 0.5 tiling should have been replaced 2382 // Since the MinContentsScale is 1, the 0.5 tiling should have been replaced
2384 // by a 1.0 tiling during the UDP in SetupPendingTree. 2383 // by a 1.0 tiling during the UDP in SetupPendingTree.
2385 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2384 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
2386 PictureLayerTiling* tiling = 2385 PictureLayerTiling* tiling =
2387 pending_layer()->tilings()->FindTilingWithScale(1.0f); 2386 pending_layer()->tilings()->FindTilingWithScale(1.0f);
2388 ASSERT_TRUE(tiling); 2387 ASSERT_TRUE(tiling);
2389 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution()); 2388 EXPECT_EQ(HIGH_RESOLUTION, tiling->resolution());
2390 } 2389 }
2391 2390
2392 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) { 2391 TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
2393 gfx::Size default_tile_size(host_impl()->settings().default_tile_size); 2392 gfx::Size tile_size(256, 256);
2394 gfx::Size layer_bounds(default_tile_size.width() * 4, 2393 gfx::Size layer_bounds(tile_size.width() * 4, tile_size.height() * 4);
2395 default_tile_size.height() * 4);
2396 2394
2397 host_impl()->SetHasGpuRasterizationTrigger(false); 2395 host_impl()->SetHasGpuRasterizationTrigger(false);
2398 2396
2399 SetupDefaultTrees(layer_bounds); 2397 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2400 EXPECT_FALSE(host_impl()->use_gpu_rasterization()); 2398 EXPECT_FALSE(host_impl()->use_gpu_rasterization());
2401 // Should have only a high-res tiling. 2399 // Should have only a high-res tiling.
2402 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2400 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
2403 ActivateTree(); 2401 ActivateTree();
2404 // Should add a high and a low res for active tree. 2402 // Should add a high and a low res for active tree.
2405 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings()); 2403 EXPECT_EQ(2u, active_layer()->tilings()->num_tilings());
2406 } 2404 }
2407 2405
2408 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { 2406 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
2409 gfx::Size default_tile_size(host_impl()->settings().default_tile_size); 2407 gfx::Size tile_size(256, 256);
2410 gfx::Size layer_bounds(default_tile_size.width() * 4, 2408 gfx::Size layer_bounds(tile_size.width() * 4, tile_size.height() * 4);
2411 default_tile_size.height() * 4);
2412 2409
2413 host_impl()->SetHasGpuRasterizationTrigger(true); 2410 host_impl()->SetHasGpuRasterizationTrigger(true);
2414 host_impl()->SetContentIsSuitableForGpuRasterization(true); 2411 host_impl()->SetContentIsSuitableForGpuRasterization(true);
2415 2412
2416 SetupDefaultTrees(layer_bounds); 2413 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
2417 EXPECT_TRUE(host_impl()->use_gpu_rasterization()); 2414 EXPECT_TRUE(host_impl()->use_gpu_rasterization());
2418 // Should only have the high-res tiling. 2415 // Should only have the high-res tiling.
2419 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 2416 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
2420 ActivateTree(); 2417 ActivateTree();
2421 // Should only have the high-res tiling. 2418 // Should only have the high-res tiling.
2422 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings()); 2419 EXPECT_EQ(1u, active_layer()->tilings()->num_tilings());
2423 } 2420 }
2424 2421
2425 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) { 2422 TEST_F(PictureLayerImplTest, RequiredTilesWithGpuRasterization) {
2426 host_impl()->SetHasGpuRasterizationTrigger(true); 2423 host_impl()->SetHasGpuRasterizationTrigger(true);
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
3151 size_t partially_occluded_count = 0; 3148 size_t partially_occluded_count = 0;
3152 LayerTestCommon::VerifyQuadsAreOccluded( 3149 LayerTestCommon::VerifyQuadsAreOccluded(
3153 impl.quad_list(), occluded, &partially_occluded_count); 3150 impl.quad_list(), occluded, &partially_occluded_count);
3154 // The layer outputs one quad, which is partially occluded. 3151 // The layer outputs one quad, which is partially occluded.
3155 EXPECT_EQ(100u - 10u, impl.quad_list().size()); 3152 EXPECT_EQ(100u - 10u, impl.quad_list().size());
3156 EXPECT_EQ(10u + 10u, partially_occluded_count); 3153 EXPECT_EQ(10u + 10u, partially_occluded_count);
3157 } 3154 }
3158 } 3155 }
3159 3156
3160 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) { 3157 TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
3161 gfx::Size tile_size(host_impl()->settings().default_tile_size); 3158 gfx::Size tile_size(256, 256);
3162 SetupDefaultTrees(tile_size); 3159 gfx::Size layer_bounds(tile_size);
3160 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
3163 3161
3164 ResetTilingsAndRasterScales(); 3162 ResetTilingsAndRasterScales();
3165 3163
3166 float contents_scale = 2.f; 3164 float contents_scale = 2.f;
3167 float device_scale = 1.f; 3165 float device_scale = 1.f;
3168 float page_scale = 1.f; 3166 float page_scale = 1.f;
3169 float maximum_animation_scale = 1.f; 3167 float maximum_animation_scale = 1.f;
3170 float starting_animation_scale = 0.f; 3168 float starting_animation_scale = 0.f;
3171 bool animating_transform = false; 3169 bool animating_transform = false;
3172 3170
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
3643 std::unique_ptr<OutputSurface> CreateOutputSurface() override { 3641 std::unique_ptr<OutputSurface> CreateOutputSurface() override {
3644 return FakeOutputSurface::CreateDelegating3d(); 3642 return FakeOutputSurface::CreateDelegating3d();
3645 } 3643 }
3646 }; 3644 };
3647 3645
3648 TEST_F(PictureLayerImplTestWithDelegatingRenderer, 3646 TEST_F(PictureLayerImplTestWithDelegatingRenderer,
3649 DelegatingRendererWithTileOOM) { 3647 DelegatingRendererWithTileOOM) {
3650 // This test is added for crbug.com/402321, where quad should be produced when 3648 // This test is added for crbug.com/402321, where quad should be produced when
3651 // raster on demand is not allowed and tile is OOM. 3649 // raster on demand is not allowed and tile is OOM.
3652 gfx::Size layer_bounds(1000, 1000); 3650 gfx::Size layer_bounds(1000, 1000);
3651 gfx::Size tile_size(256, 256);
3653 3652
3654 // Create tiles. 3653 // Create tiles.
3655 scoped_refptr<FakeRasterSource> pending_raster_source = 3654 scoped_refptr<FakeRasterSource> pending_raster_source =
3656 FakeRasterSource::CreateFilled(layer_bounds); 3655 FakeRasterSource::CreateFilled(layer_bounds);
3657 SetupPendingTree(pending_raster_source); 3656 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
3658 pending_layer()->SetBounds(layer_bounds); 3657 pending_layer()->SetBounds(layer_bounds);
3659 ActivateTree(); 3658 ActivateTree();
3660 bool update_lcd_text = false; 3659 bool update_lcd_text = false;
3661 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text); 3660 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text);
3662 std::vector<Tile*> tiles = 3661 std::vector<Tile*> tiles =
3663 active_layer()->HighResTiling()->AllTilesForTesting(); 3662 active_layer()->HighResTiling()->AllTilesForTesting();
3664 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles); 3663 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
3665 3664
3666 // Force tiles after max_tiles to be OOM. TileManager uses 3665 // Force tiles after max_tiles to be OOM. TileManager uses
3667 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot 3666 // GlobalStateThatImpactsTilesPriority from LayerTreeHostImpl, and we cannot
3668 // directly set state to host_impl_, so we set policy that would change the 3667 // directly set state to host_impl_, so we set policy that would change the
3669 // state. We also need to update tree priority separately. 3668 // state. We also need to update tree priority separately.
3670 GlobalStateThatImpactsTilePriority state; 3669 GlobalStateThatImpactsTilePriority state;
3671 size_t max_tiles = 1; 3670 size_t max_tiles = 1;
3672 gfx::Size tile_size(host_impl()->settings().default_tile_size);
3673 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height(); 3671 size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height();
3674 size_t resource_limit = max_tiles; 3672 size_t resource_limit = max_tiles;
3675 ManagedMemoryPolicy policy(memory_limit, 3673 ManagedMemoryPolicy policy(memory_limit,
3676 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 3674 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
3677 resource_limit); 3675 resource_limit);
3678 host_impl()->SetMemoryPolicy(policy); 3676 host_impl()->SetMemoryPolicy(policy);
3679 host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); 3677 host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
3680 host_impl()->PrepareTiles(); 3678 host_impl()->PrepareTiles();
3681 3679
3682 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 3680 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
4654 tiles = pending_layer()->HighResTiling()->AllTilesForTesting(); 4652 tiles = pending_layer()->HighResTiling()->AllTilesForTesting();
4655 prioritized_tiles = pending_layer() 4653 prioritized_tiles = pending_layer()
4656 ->HighResTiling() 4654 ->HighResTiling()
4657 ->UpdateAndGetAllPrioritizedTilesForTesting(); 4655 ->UpdateAndGetAllPrioritizedTilesForTesting();
4658 for (Tile* tile : tiles) 4656 for (Tile* tile : tiles)
4659 EXPECT_EQ(pending_layer()->raster_source(), 4657 EXPECT_EQ(pending_layer()->raster_source(),
4660 prioritized_tiles[tile].raster_source()); 4658 prioritized_tiles[tile].raster_source());
4661 } 4659 }
4662 4660
4663 TEST_F(PictureLayerImplTest, TilingAllTilesDone) { 4661 TEST_F(PictureLayerImplTest, TilingAllTilesDone) {
4664 gfx::Size tile_size = host_impl()->settings().default_tile_size; 4662 gfx::Size tile_size(256, 256);
4665 size_t tile_mem = 4 * tile_size.width() * tile_size.height(); 4663 size_t tile_mem = 4 * tile_size.width() * tile_size.height();
4666 gfx::Size layer_bounds(1000, 1000); 4664 gfx::Size layer_bounds(1000, 1000);
4667 4665
4668 // Create tiles. 4666 // Create tiles.
4669 scoped_refptr<FakeRasterSource> pending_raster_source = 4667 scoped_refptr<FakeRasterSource> pending_raster_source =
4670 FakeRasterSource::CreateFilled(layer_bounds); 4668 FakeRasterSource::CreateFilled(layer_bounds);
4671 SetupPendingTree(pending_raster_source); 4669 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4672 pending_layer()->SetBounds(layer_bounds); 4670 pending_layer()->SetBounds(layer_bounds);
4673 ActivateTree(); 4671 ActivateTree();
4674 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 4672 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(
4675 active_layer()->HighResTiling()->AllTilesForTesting()); 4673 active_layer()->HighResTiling()->AllTilesForTesting());
4676 host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); 4674 host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
4677 4675
4678 EXPECT_FALSE(active_layer()->HighResTiling()->all_tiles_done()); 4676 EXPECT_FALSE(active_layer()->HighResTiling()->all_tiles_done());
4679 4677
4680 { 4678 {
4681 // Set a memory policy that will fit all tiles. 4679 // Set a memory policy that will fit all tiles.
(...skipping 15 matching lines...) Expand all
4697 ManagedMemoryPolicy policy(memory_limit, 4695 ManagedMemoryPolicy policy(memory_limit,
4698 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 4696 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
4699 max_tiles); 4697 max_tiles);
4700 host_impl()->SetMemoryPolicy(policy); 4698 host_impl()->SetMemoryPolicy(policy);
4701 host_impl()->PrepareTiles(); 4699 host_impl()->PrepareTiles();
4702 4700
4703 EXPECT_FALSE(active_layer()->HighResTiling()->all_tiles_done()); 4701 EXPECT_FALSE(active_layer()->HighResTiling()->all_tiles_done());
4704 } 4702 }
4705 } 4703 }
4706 4704
4707 class TileSizeTest : public PictureLayerImplTest { 4705 TEST_F(PictureLayerImplTest, TileSizes) {
4708 public: 4706 host_impl()->CreatePendingTree();
4709 LayerTreeSettings CreateSettings() override {
4710 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings();
4711 settings.default_tile_size = gfx::Size(100, 100);
4712 settings.max_untiled_layer_size = gfx::Size(200, 200);
4713 return settings;
4714 }
4715 };
4716 4707
4717 TEST_F(TileSizeTest, TileSizes) { 4708 // Software raster uses 256 sized tiles for low dpi.
4718 host_impl()->CreatePendingTree(); 4709 int default_tile_size = 256;
4719 4710
4720 LayerTreeImpl* pending_tree = host_impl()->pending_tree(); 4711 LayerTreeImpl* pending_tree = host_impl()->pending_tree();
4721 std::unique_ptr<FakePictureLayerImpl> layer = 4712 std::unique_ptr<FakePictureLayerImpl> layer =
4722 FakePictureLayerImpl::Create(pending_tree, layer_id()); 4713 FakePictureLayerImpl::Create(pending_tree, layer_id());
4723 4714
4724 host_impl()->SetViewportSize(gfx::Size(1000, 1000)); 4715 host_impl()->SetViewportSize(gfx::Size(1000, 1000));
4725 gfx::Size result; 4716 gfx::Size result;
4726 4717
4727 host_impl()->SetContentIsSuitableForGpuRasterization(true); 4718 host_impl()->SetContentIsSuitableForGpuRasterization(true);
4728 host_impl()->SetHasGpuRasterizationTrigger(false); 4719 host_impl()->SetHasGpuRasterizationTrigger(false);
4729 EXPECT_EQ(host_impl()->gpu_rasterization_status(), 4720 EXPECT_EQ(host_impl()->gpu_rasterization_status(),
4730 GpuRasterizationStatus::OFF_VIEWPORT); 4721 GpuRasterizationStatus::OFF_VIEWPORT);
4731 4722
4732 // Default tile-size for large layers. 4723 // Default tile-size for large layers.
4733 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); 4724 result = layer->CalculateTileSize(
4734 EXPECT_EQ(result.width(), 100); 4725 gfx::Size(default_tile_size * 100, default_tile_size * 100));
4735 EXPECT_EQ(result.height(), 100); 4726 EXPECT_EQ(default_tile_size, result.width());
4736 // Don't tile and round-up, when under max_untiled_layer_size. 4727 EXPECT_EQ(default_tile_size, result.height());
4737 result = layer->CalculateTileSize(gfx::Size(42, 42)); 4728 // Don't tile and round-up, when under kMaxUntiledContentSize.
4738 EXPECT_EQ(result.width(), 64); 4729 int small = PictureLayerImpl::kMaxUntiledContentSize / 2;
4739 EXPECT_EQ(result.height(), 64); 4730 result = layer->CalculateTileSize(gfx::Size(small - 64 + 1, small - 64 + 1));
4740 result = layer->CalculateTileSize(gfx::Size(191, 191)); 4731 EXPECT_EQ(small, result.width());
4741 EXPECT_EQ(result.width(), 192); 4732 EXPECT_EQ(small, result.height());
4742 EXPECT_EQ(result.height(), 192); 4733 small = PictureLayerImpl::kMaxUntiledContentSize - 64;
4743 result = layer->CalculateTileSize(gfx::Size(199, 199)); 4734 result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
4744 EXPECT_EQ(result.width(), 200); 4735 EXPECT_EQ(small, result.width());
4745 EXPECT_EQ(result.height(), 200); 4736 EXPECT_EQ(small, result.height());
4737
4738 // If the DSF is 2, then tiles change to be larger.
4739 pending_tree->SetDeviceScaleFactor(2.f);
4740 default_tile_size = 512;
4741
4742 result = layer->CalculateTileSize(
4743 gfx::Size(default_tile_size * 100, default_tile_size * 100));
4744 EXPECT_EQ(default_tile_size, result.width());
4745 EXPECT_EQ(default_tile_size, result.height());
4746 // TODO(crbug.com/622885): This limit should scale with the DSF.
4747 small = PictureLayerImpl::kMaxUntiledContentSize - 64;
4748 result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
4749 EXPECT_EQ(small, result.width());
4750 EXPECT_EQ(small, result.height());
4751
4752 // If the DSF is larger than 2, then tiles are the same as at 2.
4753 pending_tree->SetDeviceScaleFactor(10.f);
4754 default_tile_size = 512;
4755
4756 result = layer->CalculateTileSize(
4757 gfx::Size(default_tile_size * 100, default_tile_size * 100));
4758 EXPECT_EQ(default_tile_size, result.width());
4759 EXPECT_EQ(default_tile_size, result.height());
4760 // TODO(crbug.com/622885): This limit should scale with the DSF.
4761 small = PictureLayerImpl::kMaxUntiledContentSize - 64;
4762 result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
4763 EXPECT_EQ(small, result.width());
4764 EXPECT_EQ(small, result.height());
4746 4765
4747 // Gpu-rasterization uses 25% viewport-height tiles. 4766 // Gpu-rasterization uses 25% viewport-height tiles.
4748 // The +2's below are for border texels. 4767 // The +2's below are for border texels.
4749 host_impl()->SetHasGpuRasterizationTrigger(true); 4768 host_impl()->SetHasGpuRasterizationTrigger(true);
4750 EXPECT_EQ(host_impl()->gpu_rasterization_status(), 4769 EXPECT_EQ(host_impl()->gpu_rasterization_status(),
4751 GpuRasterizationStatus::ON); 4770 GpuRasterizationStatus::ON);
4752 host_impl()->SetViewportSize(gfx::Size(2000, 2000)); 4771 host_impl()->SetViewportSize(gfx::Size(2000, 2000));
4753 4772
4754 layer->set_gpu_raster_max_texture_size(host_impl()->device_viewport_size()); 4773 layer->set_gpu_raster_max_texture_size(host_impl()->device_viewport_size());
4755 result = layer->CalculateTileSize(gfx::Size(10000, 10000)); 4774 result = layer->CalculateTileSize(gfx::Size(10000, 10000));
(...skipping 13 matching lines...) Expand all
4769 // Largest layer is 50% of viewport width (rounded up), and 4788 // Largest layer is 50% of viewport width (rounded up), and
4770 // 50% of viewport in height. 4789 // 50% of viewport in height.
4771 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4790 result = layer->CalculateTileSize(gfx::Size(447, 400));
4772 EXPECT_EQ(result.width(), 448); 4791 EXPECT_EQ(result.width(), 448);
4773 EXPECT_EQ(result.height(), 448); 4792 EXPECT_EQ(result.height(), 448);
4774 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4793 result = layer->CalculateTileSize(gfx::Size(500, 499));
4775 EXPECT_EQ(result.width(), 512); 4794 EXPECT_EQ(result.width(), 512);
4776 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned. 4795 EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned.
4777 } 4796 }
4778 4797
4798 class ViewportForTileSizeTest : public PictureLayerImplTest {
4799 public:
4800 LayerTreeSettings CreateSettings() override {
4801 LayerTreeSettings settings = PictureLayerImplTest::CreateSettings();
4802 settings.use_viewport_for_tile_size = true;
4803 return settings;
4804 }
4805 };
4806
4807 TEST_F(ViewportForTileSizeTest, TileSizesFromViewport) {
4808 host_impl()->CreatePendingTree();
4809
4810 LayerTreeImpl* pending_tree = host_impl()->pending_tree();
4811 std::unique_ptr<FakePictureLayerImpl> layer =
4812 FakePictureLayerImpl::Create(pending_tree, layer_id());
4813
4814 int viewport_size = 1000;
4815 // A portrait mode viewport size.
4816 host_impl()->SetViewportSize(gfx::Size(viewport_size, 2 * viewport_size));
4817 gfx::Size result;
4818
4819 int expected_tile_size = MathUtil::UncheckedRoundUp(viewport_size / 3, 32);
vmpstr 2016/06/29 01:40:23 I'd prefer if we moved 3 to some common place, so
4820
4821 // The tile-size for large layers will be based on the viewport.
4822 result = layer->CalculateTileSize(
4823 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4824 EXPECT_EQ(expected_tile_size, result.width());
4825 EXPECT_EQ(expected_tile_size, result.height());
4826 // Don't tile and round-up, when under kMaxUntiledContentSize.
4827 int small = PictureLayerImpl::kMaxUntiledContentSize / 2;
4828 result = layer->CalculateTileSize(gfx::Size(small - 64 + 1, small - 64 + 1));
4829 EXPECT_EQ(small, result.width());
4830 EXPECT_EQ(small, result.height());
4831 small = PictureLayerImpl::kMaxUntiledContentSize - 64;
4832 result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
4833 EXPECT_EQ(small, result.width());
4834 EXPECT_EQ(small, result.height());
4835
4836 // In landscape mode, the tiles are the same size.
4837 host_impl()->SetViewportSize(gfx::Size(2 * viewport_size, viewport_size));
4838 result = layer->CalculateTileSize(
4839 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4840 EXPECT_EQ(expected_tile_size, result.width());
4841 EXPECT_EQ(expected_tile_size, result.height());
4842
4843 // For large viewports the tile size is capped.
4844 expected_tile_size = 512;
4845 host_impl()->SetViewportSize(gfx::Size(4 * viewport_size, 6 * viewport_size));
4846 result = layer->CalculateTileSize(
4847 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4848 EXPECT_EQ(expected_tile_size, result.width());
4849 EXPECT_EQ(expected_tile_size, result.height());
4850
4851 // And for small viewports the tile size is capped.
4852 expected_tile_size = 256;
4853 host_impl()->SetViewportSize(gfx::Size(400, 400));
4854 result = layer->CalculateTileSize(
4855 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4856 EXPECT_EQ(expected_tile_size, result.width());
4857 EXPECT_EQ(expected_tile_size, result.height());
4858 }
4859
4860 TEST_F(ViewportForTileSizeTest, TileSizesWithExternalViewport) {
4861 host_impl()->CreatePendingTree();
4862
4863 LayerTreeImpl* pending_tree = host_impl()->pending_tree();
4864 std::unique_ptr<FakePictureLayerImpl> layer =
4865 FakePictureLayerImpl::Create(pending_tree, layer_id());
4866
4867 int viewport_size = 1000;
4868 // A portrait mode viewport size.
4869 host_impl()->SetViewportSize(gfx::Size(viewport_size, 2 * viewport_size));
4870 gfx::Size result;
4871
4872 // No external viewport, so it doesn't affect things.
4873 gfx::Rect external_viewport;
4874 host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
4875
4876 int expected_tile_size = MathUtil::UncheckedRoundUp(viewport_size / 3, 32);
4877
4878 // The tile-size for large layers will be based on the viewport.
4879 result = layer->CalculateTileSize(
4880 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4881 EXPECT_EQ(expected_tile_size, result.width());
4882 EXPECT_EQ(expected_tile_size, result.height());
4883
4884 // If an external viewport is specified and it is bigger, then we ignore it.
4885 external_viewport =
4886 gfx::Rect(1000, 1000, viewport_size + 200, 2 * viewport_size);
4887 host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
4888 result = layer->CalculateTileSize(
4889 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4890 EXPECT_EQ(expected_tile_size, result.width());
4891 EXPECT_EQ(expected_tile_size, result.height());
4892
4893 // If an external viewport is specified and it is smaller, then we use that.
4894 external_viewport =
4895 gfx::Rect(1000, 1000, viewport_size - 200, 2 * viewport_size);
4896 int old_expected_tile_size = expected_tile_size;
4897 expected_tile_size =
4898 MathUtil::UncheckedRoundUp((viewport_size - 200) / 3, 32);
4899 EXPECT_NE(old_expected_tile_size, expected_tile_size);
4900 host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
4901 result = layer->CalculateTileSize(
4902 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4903 EXPECT_EQ(expected_tile_size, result.width());
4904 EXPECT_EQ(expected_tile_size, result.height());
4905
4906 // Same thing in landscape mode.
4907 external_viewport =
4908 gfx::Rect(1000, 1000, 2 * viewport_size, viewport_size - 200);
4909 host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
4910 result = layer->CalculateTileSize(
4911 gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
4912 EXPECT_EQ(expected_tile_size, result.width());
4913 EXPECT_EQ(expected_tile_size, result.height());
4914 }
4915
4779 TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) { 4916 TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) {
4780 gfx::Size layer_bounds(1300, 1900); 4917 gfx::Size layer_bounds(1300, 1900);
4781 4918
4782 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; 4919 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor;
4783 SetupDefaultTrees(layer_bounds); 4920 SetupDefaultTrees(layer_bounds);
4784 ResetTilingsAndRasterScales(); 4921 ResetTilingsAndRasterScales();
4785 4922
4786 float page_scale = 2.f; 4923 float page_scale = 2.f;
4787 SetContentsScaleOnBothLayers(page_scale, 1.0f, page_scale, 1.0f, 0.f, false); 4924 SetContentsScaleOnBothLayers(page_scale, 1.0f, page_scale, 1.0f, 0.f, false);
4788 EXPECT_BOTH_EQ(num_tilings(), 1u); 4925 EXPECT_BOTH_EQ(num_tilings(), 1u);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4939 5076
4940 ASSERT_FALSE(render_pass->quad_list.empty()); 5077 ASSERT_FALSE(render_pass->quad_list.empty());
4941 EXPECT_EQ(DrawQuad::TILED_CONTENT, render_pass->quad_list.front()->material); 5078 EXPECT_EQ(DrawQuad::TILED_CONTENT, render_pass->quad_list.front()->material);
4942 5079
4943 // Tiles are ready at correct scale, so should not set had_incomplete_tile. 5080 // Tiles are ready at correct scale, so should not set had_incomplete_tile.
4944 EXPECT_EQ(0, data.num_incomplete_tiles); 5081 EXPECT_EQ(0, data.num_incomplete_tiles);
4945 } 5082 }
4946 5083
4947 } // namespace 5084 } // namespace
4948 } // namespace cc 5085 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698