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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/layers/picture_layer_impl_unittest.cc
diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc
index 758527a13037932aad700dc96c034cbee9390ca3..b46882aedc91322e017dbda35c1bf00b13dcb293 100644
--- a/cc/layers/picture_layer_impl_unittest.cc
+++ b/cc/layers/picture_layer_impl_unittest.cc
@@ -290,8 +290,7 @@ class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
TEST_F(PictureLayerImplTest, TileGridAlignment) {
// Layer to span 4 raster tiles in x and in y
LayerTreeSettings settings;
- gfx::Size layer_size(settings.default_tile_size.width() * 7 / 2,
- settings.default_tile_size.height() * 7 / 2);
+ gfx::Size layer_size(256 * 7 / 2, 256 * 7 / 2);
scoped_refptr<FakeRasterSource> pending_raster_source =
FakeRasterSource::CreateFilled(layer_size);
@@ -1080,7 +1079,7 @@ TEST_F(PictureLayerImplTest, CleanUpTilings) {
TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
// Make sure this layer covers multiple tiles, since otherwise low
// res won't get created because it is too small.
- gfx::Size tile_size(host_impl()->settings().default_tile_size);
+ gfx::Size tile_size(256, 256);
// Avoid max untiled layer size heuristics via fixed tile size.
gfx::Size layer_bounds(tile_size.width() + 1, tile_size.height() + 1);
SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
@@ -1144,14 +1143,16 @@ TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
}
TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) {
- gfx::Size layer_bounds(host_impl()->settings().default_tile_size);
+ gfx::Size tile_size(256, 256);
+ gfx::Size layer_bounds(tile_size);
scoped_refptr<FakeRasterSource> pending_raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
scoped_refptr<FakeRasterSource> active_raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
- SetupTrees(pending_raster_source, active_raster_source);
+ SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source,
+ tile_size, Region());
float low_res_factor = host_impl()->settings().low_res_contents_scale_factor;
float device_scale = 1.f;
@@ -1425,7 +1426,7 @@ TEST_F(PictureLayerImplTest, ReleaseResources) {
}
TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
- gfx::Size layer_bounds(5000, 5000);
+ gfx::Size layer_bounds(500, 500);
scoped_refptr<FakeRasterSource> pending_raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
@@ -1435,21 +1436,19 @@ TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
pending_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting();
- // The default value.
- EXPECT_EQ(gfx::Size(256, 256).ToString(),
- host_impl()->settings().default_tile_size.ToString());
+ int small_size = 4;
Tile* tile =
pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0];
- EXPECT_EQ(gfx::Size(256, 256).ToString(),
- tile->content_rect().size().ToString());
+ EXPECT_GT(tile->content_rect().width(), small_size);
+ EXPECT_GT(tile->content_rect().height(), small_size);
ResetTilingsAndRasterScales();
// Change the max texture size on the output surface context.
std::unique_ptr<TestWebGraphicsContext3D> context =
TestWebGraphicsContext3D::Create();
- context->set_max_texture_size(140);
+ context->set_max_texture_size(small_size);
ResetOutputSurface(FakeOutputSurface::Create3d(std::move(context)));
SetupDrawPropertiesAndUpdateTiles(pending_layer(), 1.f, 1.f, 1.f, 1.f, 0.f,
@@ -1460,21 +1459,21 @@ TEST_F(PictureLayerImplTest, ClampTilesToMaxTileSize) {
// Verify the tiles are not larger than the context's max texture size.
tile = pending_layer()->tilings()->tiling_at(0)->AllTilesForTesting()[0];
- EXPECT_GE(140, tile->content_rect().width());
- EXPECT_GE(140, tile->content_rect().height());
+ EXPECT_EQ(small_size, tile->content_rect().width());
+ EXPECT_EQ(small_size, tile->content_rect().height());
}
TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
gfx::Size layer_bounds(500, 500);
+ // The layer is smaller enough to be untiled.
+ EXPECT_LE(layer_bounds.width(), PictureLayerImpl::kMaxUntiledContentSize);
+ EXPECT_LE(layer_bounds.height(), PictureLayerImpl::kMaxUntiledContentSize);
+
SetupDefaultTrees(layer_bounds);
EXPECT_GE(active_layer()->tilings()->num_tilings(), 1u);
active_layer()->tilings()->tiling_at(0)->CreateAllTilesForTesting();
- // The default value. The layer is smaller than this.
- EXPECT_EQ(gfx::Size(512, 512).ToString(),
- host_impl()->settings().max_untiled_layer_size.ToString());
-
// There should be a single tile since the layer is small.
PictureLayerTiling* high_res_tiling = active_layer()->tilings()->tiling_at(0);
EXPECT_EQ(1u, high_res_tiling->AllTilesForTesting().size());
@@ -2390,13 +2389,12 @@ TEST_F(PictureLayerImplTest, HighResCreatedWhenBoundsShrink) {
}
TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
- gfx::Size default_tile_size(host_impl()->settings().default_tile_size);
- gfx::Size layer_bounds(default_tile_size.width() * 4,
- default_tile_size.height() * 4);
+ gfx::Size tile_size(256, 256);
+ gfx::Size layer_bounds(tile_size.width() * 4, tile_size.height() * 4);
host_impl()->SetHasGpuRasterizationTrigger(false);
- SetupDefaultTrees(layer_bounds);
+ SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
EXPECT_FALSE(host_impl()->use_gpu_rasterization());
// Should have only a high-res tiling.
EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
@@ -2406,14 +2404,13 @@ TEST_F(PictureLayerImplTest, LowResTilingWithoutGpuRasterization) {
}
TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
- gfx::Size default_tile_size(host_impl()->settings().default_tile_size);
- gfx::Size layer_bounds(default_tile_size.width() * 4,
- default_tile_size.height() * 4);
+ gfx::Size tile_size(256, 256);
+ gfx::Size layer_bounds(tile_size.width() * 4, tile_size.height() * 4);
host_impl()->SetHasGpuRasterizationTrigger(true);
host_impl()->SetContentIsSuitableForGpuRasterization(true);
- SetupDefaultTrees(layer_bounds);
+ SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
EXPECT_TRUE(host_impl()->use_gpu_rasterization());
// Should only have the high-res tiling.
EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
@@ -3158,8 +3155,9 @@ TEST_F(PictureLayerImplTest, Occlusion) {
}
TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
- gfx::Size tile_size(host_impl()->settings().default_tile_size);
- SetupDefaultTrees(tile_size);
+ gfx::Size tile_size(256, 256);
+ gfx::Size layer_bounds(tile_size);
+ SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region());
ResetTilingsAndRasterScales();
@@ -3650,11 +3648,12 @@ TEST_F(PictureLayerImplTestWithDelegatingRenderer,
// This test is added for crbug.com/402321, where quad should be produced when
// raster on demand is not allowed and tile is OOM.
gfx::Size layer_bounds(1000, 1000);
+ gfx::Size tile_size(256, 256);
// Create tiles.
scoped_refptr<FakeRasterSource> pending_raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
- SetupPendingTree(pending_raster_source);
+ SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
pending_layer()->SetBounds(layer_bounds);
ActivateTree();
bool update_lcd_text = false;
@@ -3669,7 +3668,6 @@ TEST_F(PictureLayerImplTestWithDelegatingRenderer,
// state. We also need to update tree priority separately.
GlobalStateThatImpactsTilePriority state;
size_t max_tiles = 1;
- gfx::Size tile_size(host_impl()->settings().default_tile_size);
size_t memory_limit = max_tiles * 4 * tile_size.width() * tile_size.height();
size_t resource_limit = max_tiles;
ManagedMemoryPolicy policy(memory_limit,
@@ -4661,14 +4659,14 @@ TEST_F(PictureLayerImplTest, UpdateLCDInvalidatesPendingTree) {
}
TEST_F(PictureLayerImplTest, TilingAllTilesDone) {
- gfx::Size tile_size = host_impl()->settings().default_tile_size;
+ gfx::Size tile_size(256, 256);
size_t tile_mem = 4 * tile_size.width() * tile_size.height();
gfx::Size layer_bounds(1000, 1000);
// Create tiles.
scoped_refptr<FakeRasterSource> pending_raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
- SetupPendingTree(pending_raster_source);
+ SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
pending_layer()->SetBounds(layer_bounds);
ActivateTree();
host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(
@@ -4704,19 +4702,12 @@ TEST_F(PictureLayerImplTest, TilingAllTilesDone) {
}
}
-class TileSizeTest : public PictureLayerImplTest {
- public:
- LayerTreeSettings CreateSettings() override {
- LayerTreeSettings settings = PictureLayerImplTest::CreateSettings();
- settings.default_tile_size = gfx::Size(100, 100);
- settings.max_untiled_layer_size = gfx::Size(200, 200);
- return settings;
- }
-};
-
-TEST_F(TileSizeTest, TileSizes) {
+TEST_F(PictureLayerImplTest, TileSizes) {
host_impl()->CreatePendingTree();
+ // Software raster uses 256 sized tiles for low dpi.
+ int default_tile_size = 256;
+
LayerTreeImpl* pending_tree = host_impl()->pending_tree();
std::unique_ptr<FakePictureLayerImpl> layer =
FakePictureLayerImpl::Create(pending_tree, layer_id());
@@ -4730,19 +4721,47 @@ TEST_F(TileSizeTest, TileSizes) {
GpuRasterizationStatus::OFF_VIEWPORT);
// Default tile-size for large layers.
- result = layer->CalculateTileSize(gfx::Size(10000, 10000));
- EXPECT_EQ(result.width(), 100);
- EXPECT_EQ(result.height(), 100);
- // Don't tile and round-up, when under max_untiled_layer_size.
- result = layer->CalculateTileSize(gfx::Size(42, 42));
- EXPECT_EQ(result.width(), 64);
- EXPECT_EQ(result.height(), 64);
- result = layer->CalculateTileSize(gfx::Size(191, 191));
- EXPECT_EQ(result.width(), 192);
- EXPECT_EQ(result.height(), 192);
- result = layer->CalculateTileSize(gfx::Size(199, 199));
- EXPECT_EQ(result.width(), 200);
- EXPECT_EQ(result.height(), 200);
+ result = layer->CalculateTileSize(
+ gfx::Size(default_tile_size * 100, default_tile_size * 100));
+ EXPECT_EQ(default_tile_size, result.width());
+ EXPECT_EQ(default_tile_size, result.height());
+ // Don't tile and round-up, when under kMaxUntiledContentSize.
+ int small = PictureLayerImpl::kMaxUntiledContentSize / 2;
+ result = layer->CalculateTileSize(gfx::Size(small - 64 + 1, small - 64 + 1));
+ EXPECT_EQ(small, result.width());
+ EXPECT_EQ(small, result.height());
+ small = PictureLayerImpl::kMaxUntiledContentSize - 64;
+ result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
+ EXPECT_EQ(small, result.width());
+ EXPECT_EQ(small, result.height());
+
+ // If the DSF is 2, then tiles change to be larger.
+ pending_tree->SetDeviceScaleFactor(2.f);
+ default_tile_size = 512;
+
+ result = layer->CalculateTileSize(
+ gfx::Size(default_tile_size * 100, default_tile_size * 100));
+ EXPECT_EQ(default_tile_size, result.width());
+ EXPECT_EQ(default_tile_size, result.height());
+ // TODO(crbug.com/622885): This limit should scale with the DSF.
+ small = PictureLayerImpl::kMaxUntiledContentSize - 64;
+ result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
+ EXPECT_EQ(small, result.width());
+ EXPECT_EQ(small, result.height());
+
+ // If the DSF is larger than 2, then tiles are the same as at 2.
+ pending_tree->SetDeviceScaleFactor(10.f);
+ default_tile_size = 512;
+
+ result = layer->CalculateTileSize(
+ gfx::Size(default_tile_size * 100, default_tile_size * 100));
+ EXPECT_EQ(default_tile_size, result.width());
+ EXPECT_EQ(default_tile_size, result.height());
+ // TODO(crbug.com/622885): This limit should scale with the DSF.
+ small = PictureLayerImpl::kMaxUntiledContentSize - 64;
+ result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
+ EXPECT_EQ(small, result.width());
+ EXPECT_EQ(small, result.height());
// Gpu-rasterization uses 25% viewport-height tiles.
// The +2's below are for border texels.
@@ -4776,6 +4795,124 @@ TEST_F(TileSizeTest, TileSizes) {
EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned.
}
+class ViewportForTileSizeTest : public PictureLayerImplTest {
+ public:
+ LayerTreeSettings CreateSettings() override {
+ LayerTreeSettings settings = PictureLayerImplTest::CreateSettings();
+ settings.use_viewport_for_tile_size = true;
+ return settings;
+ }
+};
+
+TEST_F(ViewportForTileSizeTest, TileSizesFromViewport) {
+ host_impl()->CreatePendingTree();
+
+ LayerTreeImpl* pending_tree = host_impl()->pending_tree();
+ std::unique_ptr<FakePictureLayerImpl> layer =
+ FakePictureLayerImpl::Create(pending_tree, layer_id());
+
+ int viewport_size = 1000;
+ // A portrait mode viewport size.
+ host_impl()->SetViewportSize(gfx::Size(viewport_size, 2 * viewport_size));
+ gfx::Size result;
+
+ 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
+
+ // The tile-size for large layers will be based on the viewport.
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+ // Don't tile and round-up, when under kMaxUntiledContentSize.
+ int small = PictureLayerImpl::kMaxUntiledContentSize / 2;
+ result = layer->CalculateTileSize(gfx::Size(small - 64 + 1, small - 64 + 1));
+ EXPECT_EQ(small, result.width());
+ EXPECT_EQ(small, result.height());
+ small = PictureLayerImpl::kMaxUntiledContentSize - 64;
+ result = layer->CalculateTileSize(gfx::Size(small - 1, small - 1));
+ EXPECT_EQ(small, result.width());
+ EXPECT_EQ(small, result.height());
+
+ // In landscape mode, the tiles are the same size.
+ host_impl()->SetViewportSize(gfx::Size(2 * viewport_size, viewport_size));
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+
+ // For large viewports the tile size is capped.
+ expected_tile_size = 512;
+ host_impl()->SetViewportSize(gfx::Size(4 * viewport_size, 6 * viewport_size));
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+
+ // And for small viewports the tile size is capped.
+ expected_tile_size = 256;
+ host_impl()->SetViewportSize(gfx::Size(400, 400));
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+}
+
+TEST_F(ViewportForTileSizeTest, TileSizesWithExternalViewport) {
+ host_impl()->CreatePendingTree();
+
+ LayerTreeImpl* pending_tree = host_impl()->pending_tree();
+ std::unique_ptr<FakePictureLayerImpl> layer =
+ FakePictureLayerImpl::Create(pending_tree, layer_id());
+
+ int viewport_size = 1000;
+ // A portrait mode viewport size.
+ host_impl()->SetViewportSize(gfx::Size(viewport_size, 2 * viewport_size));
+ gfx::Size result;
+
+ // No external viewport, so it doesn't affect things.
+ gfx::Rect external_viewport;
+ host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
+
+ int expected_tile_size = MathUtil::UncheckedRoundUp(viewport_size / 3, 32);
+
+ // The tile-size for large layers will be based on the viewport.
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+
+ // If an external viewport is specified and it is bigger, then we ignore it.
+ external_viewport =
+ gfx::Rect(1000, 1000, viewport_size + 200, 2 * viewport_size);
+ host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+
+ // If an external viewport is specified and it is smaller, then we use that.
+ external_viewport =
+ gfx::Rect(1000, 1000, viewport_size - 200, 2 * viewport_size);
+ int old_expected_tile_size = expected_tile_size;
+ expected_tile_size =
+ MathUtil::UncheckedRoundUp((viewport_size - 200) / 3, 32);
+ EXPECT_NE(old_expected_tile_size, expected_tile_size);
+ host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+
+ // Same thing in landscape mode.
+ external_viewport =
+ gfx::Rect(1000, 1000, 2 * viewport_size, viewport_size - 200);
+ host_impl()->OnDraw(gfx::Transform(), external_viewport, gfx::Rect(), false);
+ result = layer->CalculateTileSize(
+ gfx::Size(expected_tile_size * 100, expected_tile_size * 100));
+ EXPECT_EQ(expected_tile_size, result.width());
+ EXPECT_EQ(expected_tile_size, result.height());
+}
+
TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) {
gfx::Size layer_bounds(1300, 1900);

Powered by Google App Engine
This is Rietveld 408576698