Index: cc/layers/picture_layer_impl.cc |
diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc |
index 12fe4e679d06f0b50e5137284e2b2273f5e59f9c..eb4e3b6df5a8b8c1d12a4097ff19ef7e7015b5f3 100644 |
--- a/cc/layers/picture_layer_impl.cc |
+++ b/cc/layers/picture_layer_impl.cc |
@@ -830,12 +830,15 @@ void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { |
NoteLayerPropertyChanged(); |
} |
-PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
+PictureLayerTiling* PictureLayerImpl::AddTiling( |
+ float contents_scale, |
+ const gfx::Vector2dF& contents_translation) { |
DCHECK(CanHaveTilings()); |
DCHECK_GE(contents_scale, MinimumContentsScale()); |
DCHECK_LE(contents_scale, MaximumContentsScale()); |
DCHECK(raster_source_->HasRecordings()); |
- return tilings_->AddTiling(contents_scale, raster_source_); |
+ return tilings_->AddTiling(contents_scale, contents_translation, |
+ raster_source_); |
} |
void PictureLayerImpl::RemoveAllTilings() { |
@@ -851,9 +854,25 @@ void PictureLayerImpl::AddTilingsForRasterScale() { |
PictureLayerTiling* high_res = |
tilings_->FindTilingWithScale(raster_contents_scale_); |
+ |
+ if (high_res) { |
+ gfx::Vector2dF translation_error = |
+ high_res->contents_translation() - raster_contents_translation_; |
+ float error_x = std::abs(translation_error.x()); |
+ float error_y = std::abs(translation_error.y()); |
+ // Handle wrap over. |
+ error_x = error_x > 0.5f ? 1.f - error_x : error_x; |
+ error_y = error_y > 0.5f ? 1.f - error_y : error_y; |
+ static constexpr float kErrorThreshold = 0.001; |
enne (OOO)
2016/07/26 00:22:16
Where does this number come from? Should you just
trchen
2016/08/03 06:06:06
I'm worrying about tiny errors due to FP precision
trchen
2016/08/03 22:41:19
Note: This code path is removed in patch set 2, as
|
+ if (error_x > kErrorThreshold || error_y > kErrorThreshold) { |
+ tilings_->Remove(high_res); |
enne (OOO)
2016/07/26 00:22:16
It'd be nice if RecalculateRasterTranslation did a
trchen
2016/08/03 06:06:06
Not necessary. The low-res tiling is not pixel-exa
|
+ 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(raster_contents_scale_, raster_contents_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. |
@@ -955,11 +974,35 @@ 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(low_res_raster_contents_scale_, gfx::Vector2dF()); |
low_res->set_resolution(LOW_RESOLUTION); |
} |
} |
+void PictureLayerImpl::RecalculateRasterTranslation() { |
+ raster_contents_translation_ = gfx::Vector2dF(); |
+ if (draw_properties().screen_space_transform_is_animating) |
enne (OOO)
2016/07/26 00:22:16
This is my biggest worry in the patch. I get that
danakj
2016/07/27 22:52:17
Here's use counters that enne is referring to for
trchen
2016/08/03 06:06:06
I chatted with chris and also thought through a nu
|
+ return; |
+ |
+ gfx::Transform screen_space_transform = ScreenSpaceTransform(); |
+ if (!screen_space_transform.IsScaleOrTranslation()) |
enne (OOO)
2016/07/26 00:22:16
Should this just be "is translation?"
enne (OOO)
2016/07/26 00:22:16
Should this just be "is translation?"
trchen
2016/08/03 06:06:06
Many bug reports are due to layers with odd pixel
|
+ return; |
+ |
+ // 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(screen_space_transform.matrix().getFloat(0, 0) - |
+ raster_contents_scale_) > kErrorThreshold || |
+ std::abs(screen_space_transform.matrix().getFloat(1, 1) - |
+ raster_contents_scale_) > kErrorThreshold) |
+ return; |
+ |
+ float origin_x = screen_space_transform.matrix().getFloat(0, 3); |
+ float origin_y = screen_space_transform.matrix().getFloat(1, 3); |
+ raster_contents_translation_ = |
+ gfx::Vector2dF(origin_x - floorf(origin_x), origin_y - floorf(origin_y)); |
+} |
+ |
void PictureLayerImpl::RecalculateRasterScales() { |
if (is_directly_composited_image_) { |
if (!raster_source_scale_) |
@@ -1072,6 +1115,8 @@ void PictureLayerImpl::RecalculateRasterScales() { |
DCHECK_GE(raster_contents_scale_, MinimumContentsScale()); |
DCHECK_LE(raster_contents_scale_, MaximumContentsScale()); |
+ RecalculateRasterTranslation(); |
+ |
// If this layer would create zero or one tiles at this content scale, |
// don't create a low res tiling. |
gfx::Size raster_bounds = |