Use preTranslate when applying offset to matrix (#21648)

This commit is contained in:
Matej Knopp 2020-10-29 23:03:02 +01:00 committed by GitHub
parent caf32d5b28
commit ed0f477c5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -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.

View File

@ -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<OpacityLayer>(0.5, SkPoint::Make(10, 10));
auto mock_layer1 = std::make_shared<MockLayer>(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);

View File

@ -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