Image filters: fix crop rect application in SkXfermodeImageFilter.
The crop rect was being incorrectly applied in SkXfermodeImageFilter:
the background and foreground bounds were having the crop rect applied
individually to them, and then unioned. The correct approach is to take
the union of their bounds, and apply the crop rect to that. (A similar
bug in SkMergeImageFilter was fixed a while back.)
This is important when applying a compositing mode
which affects pixels outside the foreground bounds
(e.g., SrcIn, SrcOut).
NOTE: this will change the results of the xfermodeimagefilter GM (new
test case).
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1842033005
Review URL: https://codereview.chromium.org/1842033005
diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp
index 90e2dd0..5603c78 100644
--- a/gm/xfermodeimagefilter.cpp
+++ b/gm/xfermodeimagefilter.cpp
@@ -183,6 +183,18 @@
x = 0;
y += fBitmap.height() + MARGIN;
}
+ // Test small fg, large bg with SrcIn with a crop that forces it to full size.
+ // This tests that SkXfermodeImageFilter correctly applies the compositing mode to
+ // the region outside the foreground.
+ mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode);
+ SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80));
+ paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropped, &cropRectFull));
+ DrawClippedPaint(canvas, clipRect, paint, x, y);
+ x += fBitmap.width() + MARGIN;
+ if (x + fBitmap.width() > WIDTH) {
+ x = 0;
+ y += fBitmap.height() + MARGIN;
+ }
}
private: