Chromium Code Reviews| Index: cc/layers/picture_layer_impl.cc |
| diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc |
| index 39d1a65f60d65b05b19a6f9bf7be9ea0bbed3a6f..023c0918c570a5dee41b49a14a837d44c4dfbc5f 100644 |
| --- a/cc/layers/picture_layer_impl.cc |
| +++ b/cc/layers/picture_layer_impl.cc |
| @@ -887,12 +887,12 @@ void PictureLayerImpl::SetUseTransformedRasterization(bool use) { |
| NoteLayerPropertyChanged(); |
| } |
| -PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
| +PictureLayerTiling* PictureLayerImpl::AddTiling(const ScaleTranslate2d& contents_transform) { |
| DCHECK(CanHaveTilings()); |
| - DCHECK_GE(contents_scale, MinimumContentsScale()); |
| - DCHECK_LE(contents_scale, MaximumContentsScale()); |
| + DCHECK_GE(contents_transform.scale(), MinimumContentsScale()); |
| + DCHECK_LE(contents_transform.scale(), MaximumContentsScale()); |
| DCHECK(raster_source_->HasRecordings()); |
| - return tilings_->AddTiling(ScaleTranslate2d(contents_scale, gfx::Vector2dF()), raster_source_); |
| + return tilings_->AddTiling(contents_transform, raster_source_); |
| } |
| void PictureLayerImpl::RemoveAllTilings() { |
| @@ -908,9 +908,14 @@ void PictureLayerImpl::AddTilingsForRasterScale() { |
| PictureLayerTiling* high_res = |
| tilings_->FindTilingWithScaleKey(raster_contents_scale_); |
| + gfx::Vector2dF raster_translation = CalculateRasterTranslation(raster_contents_scale_); |
| + if (high_res && high_res->raster_transform().translation() != raster_translation) { |
|
enne (OOO)
2017/01/03 22:54:00
This logic about changing the raster translation b
|
| + tilings_->Remove(high_res); |
| + high_res = nullptr; |
| + } |
| if (!high_res) { |
| // We always need a high res tiling, so create one if it doesn't exist. |
| - high_res = AddTiling(raster_contents_scale_); |
| + high_res = AddTiling(ScaleTranslate2d(raster_contents_scale_, raster_translation)); |
| } else if (high_res->may_contain_low_resolution_tiles()) { |
| // If the tiling we find here was LOW_RESOLUTION previously, it may not be |
| // fully rastered, so destroy the old tiles. |
| @@ -1007,7 +1012,7 @@ void PictureLayerImpl::AddLowResolutionTilingIfNeeded() { |
| bool is_animating = draw_properties().screen_space_transform_is_animating; |
| if (!is_pinching && !is_animating) { |
| if (!low_res) |
| - low_res = AddTiling(low_res_raster_contents_scale_); |
| + low_res = AddTiling(ScaleTranslate2d(low_res_raster_contents_scale_, gfx::Vector2dF())); |
| low_res->set_resolution(LOW_RESOLUTION); |
| } |
| } |
| @@ -1173,6 +1178,34 @@ void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
| SanityCheckTilingState(); |
| } |
| +gfx::Vector2dF PictureLayerImpl::CalculateRasterTranslation( |
| + float raster_scale) { |
| + if (!use_transformed_rasterization_) |
| + return gfx::Vector2dF(); |
| + |
| + DCHECK(!draw_properties().screen_space_transform_is_animating); |
| + gfx::Transform draw_transform = DrawTransform(); |
| + DCHECK(draw_transform.IsScaleOrTranslation()); |
| + |
| + // It is only useful to align the content space to the target space if their |
| + // relative pixel ratio is some small rational number. Currently we only |
| + // align if the relative pixel ratio is 1:1. |
| + // Good match if the maximum alignment error on a layer of size 10000px |
| + // does not exceed 0.001px. |
| + static constexpr float kErrorThreshold = 0.0000001f; |
| + if (std::abs(draw_transform.matrix().getFloat(0, 0) - raster_scale) > |
| + kErrorThreshold || |
| + std::abs(draw_transform.matrix().getFloat(1, 1) - raster_scale) > |
| + kErrorThreshold) |
| + return gfx::Vector2dF(); |
| + |
| + // Extract the fractional part of layer origin in the target space. |
| + float origin_x = draw_transform.matrix().getFloat(0, 3); |
| + float origin_y = draw_transform.matrix().getFloat(1, 3); |
| + return gfx::Vector2dF(origin_x - floorf(origin_x), |
| + origin_y - floorf(origin_y)); |
| +} |
| + |
| float PictureLayerImpl::MinimumContentsScale() const { |
| float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |