From 46c725df771d792ce1acb8585f732439d1ad0c33 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Mon, 11 Mar 2024 15:38:16 -0700 Subject: [PATCH 1/2] Fix null filter NOP case in DlLocalMatrixImageFilter --- display_list/effects/dl_image_filter.h | 9 ++++--- .../effects/dl_image_filter_unittests.cc | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/display_list/effects/dl_image_filter.h b/display_list/effects/dl_image_filter.h index 802f619b4c5af..9cd0126a0cabb 100644 --- a/display_list/effects/dl_image_filter.h +++ b/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/display_list/effects/dl_image_filter_unittests.cc b/display_list/effects/dl_image_filter_unittests.cc index 20aa47fc2fd10..c362ade49ae84 100644 --- a/display_list/effects/dl_image_filter_unittests.cc +++ b/display_list/effects/dl_image_filter_unittests.cc @@ -734,6 +734,33 @@ 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); + } + 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); + } + { + 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); + } + } + } + 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++) { From eec4c734782ea41ce24788d36135cd2e72e066e9 Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Mon, 11 Mar 2024 15:45:01 -0700 Subject: [PATCH 2/2] another test on NOP results --- display_list/effects/dl_image_filter_unittests.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/display_list/effects/dl_image_filter_unittests.cc b/display_list/effects/dl_image_filter_unittests.cc index c362ade49ae84..70925455aa999 100644 --- a/display_list/effects/dl_image_filter_unittests.cc +++ b/display_list/effects/dl_image_filter_unittests.cc @@ -741,6 +741,7 @@ TEST(DisplayListImageFilter, LocalImageFilterBounds) { 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]; @@ -750,6 +751,7 @@ TEST(DisplayListImageFilter, LocalImageFilterBounds) { 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); @@ -757,6 +759,7 @@ TEST(DisplayListImageFilter, LocalImageFilterBounds) { EXPECT_EQ(filter.get_input_device_bounds(output_bounds, bounds_matrix, input_bounds), &input_bounds); + EXPECT_EQ(input_bounds, output_bounds); } } }