From 242e59c98f60a7a26416f80a87a0cb3e878f0c79 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Tue, 12 Mar 2024 14:37:58 -0700 Subject: [PATCH] Fix null filter NOP case in DlLocalMatrixImageFilter (flutter/engine#51340) The `DlLocalMatrixImageFilter` was returning null from the bounds methods when it had no filter to apply which violates the method contracts. It should have been setting the result rect to the argument rect and returning a valid pointer to meet the method contract. --- .../display_list/effects/dl_image_filter.h | 9 ++++-- .../effects/dl_image_filter_unittests.cc | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/display_list/effects/dl_image_filter.h b/engine/src/flutter/display_list/effects/dl_image_filter.h index 802f619b4c..9cd0126a0c 100644 --- a/engine/src/flutter/display_list/effects/dl_image_filter.h +++ b/engine/src/flutter/display_list/effects/dl_image_filter.h @@ -700,7 +700,8 @@ class DlLocalMatrixImageFilter final : public DlImageFilter { SkRect* map_local_bounds(const SkRect& input_bounds, SkRect& output_bounds) const override { if (!image_filter_) { - return nullptr; + output_bounds = input_bounds; + return &output_bounds; } return image_filter_->map_local_bounds(input_bounds, output_bounds); } @@ -709,7 +710,8 @@ class DlLocalMatrixImageFilter final : public DlImageFilter { const SkMatrix& ctm, SkIRect& output_bounds) const override { if (!image_filter_) { - return nullptr; + output_bounds = input_bounds; + return &output_bounds; } return image_filter_->map_device_bounds( input_bounds, SkMatrix::Concat(ctm, matrix_), output_bounds); @@ -719,7 +721,8 @@ class DlLocalMatrixImageFilter final : public DlImageFilter { const SkMatrix& ctm, SkIRect& input_bounds) const override { if (!image_filter_) { - return nullptr; + input_bounds = output_bounds; + return &input_bounds; } return image_filter_->get_input_device_bounds( output_bounds, SkMatrix::Concat(ctm, matrix_), input_bounds); diff --git a/engine/src/flutter/display_list/effects/dl_image_filter_unittests.cc b/engine/src/flutter/display_list/effects/dl_image_filter_unittests.cc index 20aa47fc2f..70925455aa 100644 --- a/engine/src/flutter/display_list/effects/dl_image_filter_unittests.cc +++ b/engine/src/flutter/display_list/effects/dl_image_filter_unittests.cc @@ -734,6 +734,36 @@ TEST(DisplayListImageFilter, LocalImageFilterBounds) { std::vector bounds_matrices{SkMatrix::Translate(5.0, 10.0), SkMatrix::Scale(2.0, 2.0)}; + for (unsigned j = 0; j < matrices.size(); j++) { + DlLocalMatrixImageFilter filter(matrices[j], nullptr); + { + const auto input_bounds = SkRect::MakeLTRB(20, 20, 80, 80); + SkRect output_bounds; + EXPECT_EQ(filter.map_local_bounds(input_bounds, output_bounds), + &output_bounds); + EXPECT_EQ(input_bounds, output_bounds); + } + for (unsigned k = 0; k < bounds_matrices.size(); k++) { + auto& bounds_matrix = bounds_matrices[k]; + { + const auto input_bounds = SkIRect::MakeLTRB(20, 20, 80, 80); + SkIRect output_bounds; + EXPECT_EQ(filter.map_device_bounds(input_bounds, bounds_matrix, + output_bounds), + &output_bounds); + EXPECT_EQ(input_bounds, output_bounds); + } + { + const auto output_bounds = SkIRect::MakeLTRB(20, 20, 80, 80); + SkIRect input_bounds; + EXPECT_EQ(filter.get_input_device_bounds(output_bounds, bounds_matrix, + input_bounds), + &input_bounds); + EXPECT_EQ(input_bounds, output_bounds); + } + } + } + for (unsigned i = 0; i < sk_filters.size(); i++) { for (unsigned j = 0; j < matrices.size(); j++) { for (unsigned k = 0; k < bounds_matrices.size(); k++) {