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

Commit b230278

Browse files
authored
Fix null filter NOP case in DlLocalMatrixImageFilter (#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.
1 parent e25e977 commit b230278

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

display_list/effects/dl_image_filter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@ class DlLocalMatrixImageFilter final : public DlImageFilter {
700700
SkRect* map_local_bounds(const SkRect& input_bounds,
701701
SkRect& output_bounds) const override {
702702
if (!image_filter_) {
703-
return nullptr;
703+
output_bounds = input_bounds;
704+
return &output_bounds;
704705
}
705706
return image_filter_->map_local_bounds(input_bounds, output_bounds);
706707
}
@@ -709,7 +710,8 @@ class DlLocalMatrixImageFilter final : public DlImageFilter {
709710
const SkMatrix& ctm,
710711
SkIRect& output_bounds) const override {
711712
if (!image_filter_) {
712-
return nullptr;
713+
output_bounds = input_bounds;
714+
return &output_bounds;
713715
}
714716
return image_filter_->map_device_bounds(
715717
input_bounds, SkMatrix::Concat(ctm, matrix_), output_bounds);
@@ -719,7 +721,8 @@ class DlLocalMatrixImageFilter final : public DlImageFilter {
719721
const SkMatrix& ctm,
720722
SkIRect& input_bounds) const override {
721723
if (!image_filter_) {
722-
return nullptr;
724+
input_bounds = output_bounds;
725+
return &input_bounds;
723726
}
724727
return image_filter_->get_input_device_bounds(
725728
output_bounds, SkMatrix::Concat(ctm, matrix_), input_bounds);

display_list/effects/dl_image_filter_unittests.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,36 @@ TEST(DisplayListImageFilter, LocalImageFilterBounds) {
734734
std::vector<SkMatrix> bounds_matrices{SkMatrix::Translate(5.0, 10.0),
735735
SkMatrix::Scale(2.0, 2.0)};
736736

737+
for (unsigned j = 0; j < matrices.size(); j++) {
738+
DlLocalMatrixImageFilter filter(matrices[j], nullptr);
739+
{
740+
const auto input_bounds = SkRect::MakeLTRB(20, 20, 80, 80);
741+
SkRect output_bounds;
742+
EXPECT_EQ(filter.map_local_bounds(input_bounds, output_bounds),
743+
&output_bounds);
744+
EXPECT_EQ(input_bounds, output_bounds);
745+
}
746+
for (unsigned k = 0; k < bounds_matrices.size(); k++) {
747+
auto& bounds_matrix = bounds_matrices[k];
748+
{
749+
const auto input_bounds = SkIRect::MakeLTRB(20, 20, 80, 80);
750+
SkIRect output_bounds;
751+
EXPECT_EQ(filter.map_device_bounds(input_bounds, bounds_matrix,
752+
output_bounds),
753+
&output_bounds);
754+
EXPECT_EQ(input_bounds, output_bounds);
755+
}
756+
{
757+
const auto output_bounds = SkIRect::MakeLTRB(20, 20, 80, 80);
758+
SkIRect input_bounds;
759+
EXPECT_EQ(filter.get_input_device_bounds(output_bounds, bounds_matrix,
760+
input_bounds),
761+
&input_bounds);
762+
EXPECT_EQ(input_bounds, output_bounds);
763+
}
764+
}
765+
}
766+
737767
for (unsigned i = 0; i < sk_filters.size(); i++) {
738768
for (unsigned j = 0; j < matrices.size(); j++) {
739769
for (unsigned k = 0; k < bounds_matrices.size(); k++) {

0 commit comments

Comments
 (0)