Fix crash in BackdropFilterLayer::Diff (flutter/engine#30460)
* Fix crash in BackdropFilterLayer::Diff * Pass context transform to filterBounds instead of scaling the filter
This commit is contained in:
@@ -25,15 +25,11 @@ void BackdropFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {
|
||||
context->AddLayerBounds(paint_bounds);
|
||||
|
||||
if (filter_) {
|
||||
// convert paint bounds and filter to screen coordinates
|
||||
context->GetTransform().mapRect(&paint_bounds);
|
||||
auto input_filter_bounds = paint_bounds.roundOut();
|
||||
auto filter = filter_->makeWithLocalMatrix(context->GetTransform());
|
||||
|
||||
auto filter_bounds = // in screen coordinates
|
||||
filter->filterBounds(input_filter_bounds, SkMatrix::I(),
|
||||
SkImageFilter::kReverse_MapDirection);
|
||||
|
||||
filter_->filterBounds(input_filter_bounds, context->GetTransform(),
|
||||
SkImageFilter::kReverse_MapDirection);
|
||||
context->AddReadbackRegion(filter_bounds);
|
||||
}
|
||||
|
||||
|
||||
@@ -327,5 +327,29 @@ TEST_F(BackdropLayerDiffTest, BackdropLayer) {
|
||||
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 190, 190));
|
||||
}
|
||||
|
||||
TEST_F(BackdropLayerDiffTest, BackdropLayerInvalidTransform) {
|
||||
auto filter = SkImageFilters::Blur(10, 10, SkTileMode::kClamp, nullptr);
|
||||
|
||||
{
|
||||
// tests later assume 30px readback area, fail early if that's not the case
|
||||
auto readback = filter->filterBounds(SkIRect::MakeWH(10, 10), SkMatrix::I(),
|
||||
SkImageFilter::kReverse_MapDirection);
|
||||
EXPECT_EQ(readback, SkIRect::MakeLTRB(-30, -30, 40, 40));
|
||||
}
|
||||
|
||||
MockLayerTree l1(SkISize::Make(100, 100));
|
||||
SkMatrix transform;
|
||||
transform.setPerspX(0.1);
|
||||
transform.setPerspY(0.1);
|
||||
|
||||
auto transform_layer = std::make_shared<TransformLayer>(transform);
|
||||
l1.root()->Add(transform_layer);
|
||||
transform_layer->Add(
|
||||
std::make_shared<BackdropFilterLayer>(filter, SkBlendMode::kSrcOver));
|
||||
|
||||
auto damage = DiffLayerTree(l1, MockLayerTree(SkISize::Make(100, 100)));
|
||||
EXPECT_EQ(damage.frame_damage, SkIRect::MakeWH(15, 15));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
Reference in New Issue
Block a user