From ed0f477c5ac1dca8cee4e802a3841c270717c3c9 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Thu, 29 Oct 2020 23:03:02 +0100 Subject: [PATCH] Use preTranslate when applying offset to matrix (#21648) --- flow/layers/opacity_layer.cc | 2 +- flow/layers/opacity_layer_unittests.cc | 17 +++++++++++++++++ flow/layers/picture_layer.cc | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/flow/layers/opacity_layer.cc b/flow/layers/opacity_layer.cc index 9e8001d6e3..b8922bff18 100644 --- a/flow/layers/opacity_layer.cc +++ b/flow/layers/opacity_layer.cc @@ -17,7 +17,7 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { FML_DCHECK(!GetChildContainer()->layers().empty()); // We can't be a leaf. SkMatrix child_matrix = matrix; - child_matrix.postTranslate(offset_.fX, offset_.fY); + child_matrix.preTranslate(offset_.fX, offset_.fY); // Similar to what's done in TransformLayer::Preroll, we have to apply the // reverse transformation to the cull rect to properly cull child layers. diff --git a/flow/layers/opacity_layer_unittests.cc b/flow/layers/opacity_layer_unittests.cc index 1ca9ddb2c4..b8238cc8da 100644 --- a/flow/layers/opacity_layer_unittests.cc +++ b/flow/layers/opacity_layer_unittests.cc @@ -54,6 +54,23 @@ TEST_F(OpacityLayerTest, PaintBeforePreollDies) { } #endif +TEST_F(OpacityLayerTest, TranslateChildren) { + SkPath child_path1; + child_path1.addRect(10.0f, 10.0f, 20.0f, 20.f); + SkPaint child_paint1(SkColors::kGray); + auto layer = std::make_shared(0.5, SkPoint::Make(10, 10)); + auto mock_layer1 = std::make_shared(child_path1, child_paint1); + layer->Add(mock_layer1); + + auto initial_transform = SkMatrix::Scale(2.0, 2.0); + layer->Preroll(preroll_context(), initial_transform); + + SkRect layer_bounds = mock_layer1->paint_bounds(); + mock_layer1->parent_matrix().mapRect(&layer_bounds); + + EXPECT_EQ(layer_bounds, SkRect::MakeXYWH(40, 40, 20, 20)); +} + TEST_F(OpacityLayerTest, ChildIsCached) { const SkAlpha alpha_half = 255 / 2; auto initial_transform = SkMatrix::Translate(50.0, 25.5); diff --git a/flow/layers/picture_layer.cc b/flow/layers/picture_layer.cc index d5d6a34b57..6df2c9e34b 100644 --- a/flow/layers/picture_layer.cc +++ b/flow/layers/picture_layer.cc @@ -30,7 +30,7 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { TRACE_EVENT0("flutter", "PictureLayer::RasterCache (Preroll)"); SkMatrix ctm = matrix; - ctm.postTranslate(offset_.x(), offset_.y()); + ctm.preTranslate(offset_.x(), offset_.y()); #ifndef SUPPORT_FRACTIONAL_TRANSLATION ctm = RasterCache::GetIntegralTransCTM(ctm); #endif -- GitLab