Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ed0f477

Browse files
authored
Use preTranslate when applying offset to matrix (#21648)
1 parent caf32d5 commit ed0f477

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

flow/layers/opacity_layer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void OpacityLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
1717
FML_DCHECK(!GetChildContainer()->layers().empty()); // We can't be a leaf.
1818

1919
SkMatrix child_matrix = matrix;
20-
child_matrix.postTranslate(offset_.fX, offset_.fY);
20+
child_matrix.preTranslate(offset_.fX, offset_.fY);
2121

2222
// Similar to what's done in TransformLayer::Preroll, we have to apply the
2323
// reverse transformation to the cull rect to properly cull child layers.

flow/layers/opacity_layer_unittests.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ TEST_F(OpacityLayerTest, PaintBeforePreollDies) {
5454
}
5555
#endif
5656

57+
TEST_F(OpacityLayerTest, TranslateChildren) {
58+
SkPath child_path1;
59+
child_path1.addRect(10.0f, 10.0f, 20.0f, 20.f);
60+
SkPaint child_paint1(SkColors::kGray);
61+
auto layer = std::make_shared<OpacityLayer>(0.5, SkPoint::Make(10, 10));
62+
auto mock_layer1 = std::make_shared<MockLayer>(child_path1, child_paint1);
63+
layer->Add(mock_layer1);
64+
65+
auto initial_transform = SkMatrix::Scale(2.0, 2.0);
66+
layer->Preroll(preroll_context(), initial_transform);
67+
68+
SkRect layer_bounds = mock_layer1->paint_bounds();
69+
mock_layer1->parent_matrix().mapRect(&layer_bounds);
70+
71+
EXPECT_EQ(layer_bounds, SkRect::MakeXYWH(40, 40, 20, 20));
72+
}
73+
5774
TEST_F(OpacityLayerTest, ChildIsCached) {
5875
const SkAlpha alpha_half = 255 / 2;
5976
auto initial_transform = SkMatrix::Translate(50.0, 25.5);

flow/layers/picture_layer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
3030
TRACE_EVENT0("flutter", "PictureLayer::RasterCache (Preroll)");
3131

3232
SkMatrix ctm = matrix;
33-
ctm.postTranslate(offset_.x(), offset_.y());
33+
ctm.preTranslate(offset_.x(), offset_.y());
3434
#ifndef SUPPORT_FRACTIONAL_TRANSLATION
3535
ctm = RasterCache::GetIntegralTransCTM(ctm);
3636
#endif

0 commit comments

Comments
 (0)