Switch AlphaThresholdFilter over to new onFilterImage interface
This CL also alters the raster path in two ways:
it now respects the sRGB/linear distinction of its input
it now respects the clip
TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1879643003
Review URL: https://codereview.chromium.org/1879643003
diff --git a/gm/imagealphathreshold.cpp b/gm/imagealphathreshold.cpp
index fdd93bd..2b65202 100644
--- a/gm/imagealphathreshold.cpp
+++ b/gm/imagealphathreshold.cpp
@@ -27,7 +27,7 @@
canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rectPaint);
}
-SkPaint create_filter_paint() {
+SkPaint create_filter_paint(SkImageFilter::CropRect* cropRect = nullptr) {
SkIRect rects[2];
rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
@@ -35,7 +35,7 @@
region.setRects(rects, 2);
SkPaint paint;
- paint.setImageFilter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
+ paint.setImageFilter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr, cropRect));
return paint;
}
@@ -45,13 +45,17 @@
class ImageAlphaThresholdGM : public GM {
public:
- ImageAlphaThresholdGM() {
+ ImageAlphaThresholdGM(bool useCropRect) : fUseCropRect(true) {
this->setBGColor(0xFFFFFFFF);
}
protected:
SkString onShortName() override {
+ if (fUseCropRect) {
+ return SkString("imagealphathreshold_crop");
+ }
+
return SkString("imagealphathreshold");
}
@@ -67,7 +71,10 @@
canvas->concat(matrix);
- SkPaint paint = create_filter_paint();
+ SkRect r = SkRect::MakeLTRB(100, 100, WIDTH - 100, HEIGHT - 100);
+ SkImageFilter::CropRect cropRect(r);
+
+ SkPaint paint = create_filter_paint(fUseCropRect ? &cropRect : nullptr);
canvas->saveLayer(nullptr, &paint);
draw_rects(canvas);
@@ -75,9 +82,12 @@
}
private:
+ bool fUseCropRect;
+
typedef GM INHERITED;
};
+
class ImageAlphaThresholdSurfaceGM : public GM {
public:
ImageAlphaThresholdSurfaceGM() {
@@ -113,7 +123,8 @@
//////////////////////////////////////////////////////////////////////////////
-DEF_GM(return new ImageAlphaThresholdGM();)
+DEF_GM(return new ImageAlphaThresholdGM(true);)
+DEF_GM(return new ImageAlphaThresholdGM(false);)
DEF_GM(return new ImageAlphaThresholdSurfaceGM();)
}