Index: cc/layers/picture_layer_impl.cc |
diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc |
index 56fcfecbfe559b8a5827426e681d925be025c026..8ca115935020d703c09bf70ed7f6f0c9ba87ea07 100644 |
--- a/cc/layers/picture_layer_impl.cc |
+++ b/cc/layers/picture_layer_impl.cc |
@@ -51,6 +51,11 @@ const int kMinHeightForGpuRasteredTile = 256; |
// of using the same tile size. |
const int kTileRoundUp = 64; |
+// When sizing tiles relative to the viewport, we keep them as a multiple of |
+// this. |
+// TODO(crbug.com/622885) But why not just use kTileMinimalAlignment. |
+const int kTileViewportAlignment = 32; |
+ |
// For performance reasons and to support compressed tile textures, tile |
// width and height should be an even multiple of 4 in size. |
const int kTileMinimalAlignment = 4; |
@@ -715,15 +720,15 @@ gfx::Size PictureLayerImpl::CalculateTileSize( |
return content_bounds; |
} |
- int default_tile_width = 0; |
- int default_tile_height = 0; |
+ int tile_width = 0; |
+ int tile_height = 0; |
if (layer_tree_impl()->use_gpu_rasterization()) { |
// For GPU rasterization, we pick an ideal tile size using the viewport |
// so we don't need any settings. The current approach uses 4 tiles |
// to cover the viewport vertically. |
int viewport_width = gpu_raster_max_texture_size_.width(); |
int viewport_height = gpu_raster_max_texture_size_.height(); |
- default_tile_width = viewport_width; |
+ tile_width = viewport_width; |
// Also, increase the height proportionally as the width decreases, and |
// pad by our border texels to make the tiles exactly match the viewport. |
@@ -732,50 +737,86 @@ gfx::Size PictureLayerImpl::CalculateTileSize( |
divisor = 2; |
if (content_bounds.width() <= viewport_width / 4) |
divisor = 1; |
- default_tile_height = |
+ tile_height = |
MathUtil::UncheckedRoundUp(viewport_height, divisor) / divisor; |
// Grow default sizes to account for overlapping border texels. |
- default_tile_width += 2 * PictureLayerTiling::kBorderTexels; |
- default_tile_height += 2 * PictureLayerTiling::kBorderTexels; |
+ tile_width += 2 * PictureLayerTiling::kBorderTexels; |
+ tile_height += 2 * PictureLayerTiling::kBorderTexels; |
- default_tile_height = |
- std::max(default_tile_height, kMinHeightForGpuRasteredTile); |
+ tile_height = std::max(tile_height, kMinHeightForGpuRasteredTile); |
} else { |
- // For CPU rasterization we use tile-size settings. |
+ // For CPU rasterization we use stuff. |
+ int tile_size; |
const LayerTreeSettings& settings = layer_tree_impl()->settings(); |
- int max_untiled_content_width = settings.max_untiled_layer_size.width(); |
- int max_untiled_content_height = settings.max_untiled_layer_size.height(); |
- default_tile_width = settings.default_tile_size.width(); |
- default_tile_height = settings.default_tile_size.height(); |
- |
- // If the content width is small, increase tile size vertically. |
- // If the content height is small, increase tile size horizontally. |
- // If both are less than the untiled-size, use a single tile. |
- if (content_bounds.width() < default_tile_width) |
- default_tile_height = max_untiled_content_height; |
- if (content_bounds.height() < default_tile_height) |
- default_tile_width = max_untiled_content_width; |
- if (content_bounds.width() < max_untiled_content_width && |
- content_bounds.height() < max_untiled_content_height) { |
- default_tile_height = max_untiled_content_height; |
- default_tile_width = max_untiled_content_width; |
+ // TODO(crbug.com/622885): Supply the physical device size along with the |
+ // device scale factor to layer tree host. Use that instead of the viewport. |
+ // Then we should have use_viewport_for_tile_size always be true, and use it |
+ // for ganesh also (maybe with different |num_tiles| for it). |
+ if (settings.use_viewport_for_tile_size) { |
+ int min_tile_size = 256; |
+ int max_tile_size = 512; |
+ |
+ int display_width = layer_tree_impl()->device_viewport_size().width(); |
+ // TODO(crbug.com/622885): Make this independent of the top controls, but |
+ // large enough to not have small tiles at the bottom. |
+ int display_height = layer_tree_impl()->device_viewport_size().height(); |
+ |
+ int portrait_num_tiles = 3; |
+ int landscape_num_tiles = 5; |
+ |
+ int num_tiles = display_width < display_height ? portrait_num_tiles |
+ : landscape_num_tiles; |
+ |
+ // Tiles overlap by a border, so make the display seem that many pixels |
+ // larger. |
+ display_width += (num_tiles - 1) * PictureLayerTiling::kBorderTexels; |
+ |
+ // These are the ideal tile size to put |num_tiles| across the screen at a |
+ // time, rounded up to a multiple of kTileViewportAlignment, so the last |
+ // tile will end up usually entending past the right edge of the screen a |
+ // bit. |
+ tile_size = MathUtil::UncheckedRoundUp( |
+ (display_width + num_tiles - 1) / num_tiles, kTileViewportAlignment); |
+ tile_size = std::max(tile_size, min_tile_size); |
+ tile_size = std::min(tile_size, max_tile_size); |
+ } else { |
+ tile_size = 256; |
+ if (layer_tree_impl()->device_scale_factor() >= 2.f) |
+ tile_size = 512; |
+ } |
+ DCHECK_GT(tile_size, 0); |
+ |
+ tile_width = tile_height = tile_size; |
+ |
+ if (content_bounds.width() < kMaxUntiledContentSize && |
+ content_bounds.height() < kMaxUntiledContentSize) { |
+ // Small layers should not be tiled. |
+ tile_width = tile_height = kMaxUntiledContentSize; |
+ } else if (content_bounds.width() < tile_width) { |
+ // If the content width is small, increase tile size vertically. |
+ tile_height *= 2; |
+ } else if (content_bounds.height() < tile_height) { |
+ // If the content height is small, increase tile size horizontally. |
+ tile_width *= 2; |
} |
} |
- |
- int tile_width = default_tile_width; |
- int tile_height = default_tile_height; |
- |
- // Clamp the tile width/height to the content width/height to save space. |
- if (content_bounds.width() < default_tile_width) { |
- tile_width = std::min(tile_width, content_bounds.width()); |
- tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileRoundUp); |
- tile_width = std::min(tile_width, default_tile_width); |
+ DCHECK_GT(tile_width, 0); |
+ DCHECK_GT(tile_height, 0); |
+ |
+ // Shrink the tile width/height to be closer content width/height to save |
+ // space, if there's a smaller multiple of kTileRoundUp. |
+ if (content_bounds.width() < tile_width) { |
+ int before_tile_width = tile_width; |
+ tile_width = |
+ MathUtil::UncheckedRoundUp(content_bounds.width(), kTileRoundUp); |
+ tile_width = std::min(tile_width, before_tile_width); |
} |
- if (content_bounds.height() < default_tile_height) { |
- tile_height = std::min(tile_height, content_bounds.height()); |
- tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileRoundUp); |
- tile_height = std::min(tile_height, default_tile_height); |
+ if (content_bounds.height() < tile_height) { |
+ int before_tile_height = tile_height; |
+ tile_height = |
+ MathUtil::UncheckedRoundUp(content_bounds.height(), kTileRoundUp); |
+ tile_height = std::min(tile_height, before_tile_height); |
} |
// Ensure that tile width and height are properly aligned. |