From bf8439d7e2d20229b5177acdef0d2bcde4bf29c6 Mon Sep 17 00:00:00 2001 From: Michael Ludwig Date: Mon, 5 Aug 2019 10:24:49 -0400 Subject: [PATCH] Fix GMs broken during API porting Bugs: morphology GM: Had swapped Erode and Dilate imagefilterscropexpand GM: Was applying the filter to the wrong rectangle imagefilterstransformed, filterfastbounds, et al GMs: The new SkImageFilters::Image() factory had defaulted to using kNone for quality, since it appeared to keep a 1-to-1 scale. However, it actually draws the image from srcRect into the dstRect, mapped by the CTM, so if there's a scaling factor in the CTM the filter no longer is 1-to-1 and kNone leads to weird scaling artifacts. So switched back to the original kHigh default. Change-Id: I30ee455008720048fb27eaed1c2c42915d222c97 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/232396 Commit-Queue: Michael Ludwig Auto-Submit: Michael Ludwig Reviewed-by: Robert Phillips --- gm/imagefilterscropexpand.cpp | 36 +++++++++++++++++--------------- gm/morphology.cpp | 2 +- include/effects/SkImageFilters.h | 5 ++++- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index b6e7faebb5..763ab577d7 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -30,7 +30,7 @@ namespace { void make_checkerboard(SkBitmap* bitmap); sk_sp make_gradient_circle(int width, int height); -void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, +void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkIRect& rect, sk_sp filter); }; @@ -68,36 +68,35 @@ DEF_SIMPLE_GM(imagefilterscropexpand, canvas, 730, 650) { canvas->translate(MARGIN, MARGIN); for (int outset = -15; outset <= 20; outset += 5) { canvas->save(); - SkRect rect = SkRect::Make(cropRect); SkIRect bigRect = cropRect; bigRect.outset(outset, outset); - draw(canvas, checkerboard, rect, SkImageFilters::ColorFilter( - cfAlphaTrans, noopCropped, &bigRect)); + draw(canvas, checkerboard, bigRect, + SkImageFilters::ColorFilter(cfAlphaTrans, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, SkImageFilters::Blur( - 0.3f, 0.3f, noopCropped, &bigRect)); + draw(canvas, checkerboard, bigRect, + SkImageFilters::Blur(0.3f, 0.3f, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, SkImageFilters::Blur( - 8.0f, 8.0f, noopCropped, &bigRect)); + draw(canvas, checkerboard, bigRect, + SkImageFilters::Blur(8.0f, 8.0f, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, SkImageFilters::Dilate( - 2, 2, noopCropped, &bigRect)); + draw(canvas, checkerboard, bigRect, + SkImageFilters::Dilate(2, 2, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, SkImageFilters::Erode( - 2, 2, noopCropped, &bigRect)); + draw(canvas, checkerboard, bigRect, + SkImageFilters::Erode(2, 2, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, + draw(canvas, checkerboard, bigRect, SkImageFilters::DropShadow(10, 10, 3, 3, SK_ColorBLUE, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, + draw(canvas, checkerboard, bigRect, SkImageFilters::DisplacementMap(SkColorChannel::kR, SkColorChannel::kR, 12, gradientCircleSource, noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, + draw(canvas, checkerboard, bigRect, SkImageFilters::Offset(SkIntToScalar(-8), SkIntToScalar(16), noopCropped, &bigRect)); - draw(canvas, checkerboard, rect, + draw(canvas, checkerboard, bigRect, SkImageFilters::PointLitDiffuse(pointLocation, SK_ColorWHITE, surfaceScale, kd, noopCropped, &bigRect)); @@ -146,8 +145,11 @@ namespace { return surface->makeImageSnapshot(); } - void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, + void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkIRect& layerRect, sk_sp filter) { + // Convert SkIRect to SkRect since that's what saveLayer and drawRect need + SkRect rect = SkRect::Make(layerRect); + SkPaint paint; paint.setImageFilter(std::move(filter)); canvas->saveLayer(&rect, &paint); diff --git a/gm/morphology.cpp b/gm/morphology.cpp index eb937b69d5..d23fca573f 100644 --- a/gm/morphology.cpp +++ b/gm/morphology.cpp @@ -82,7 +82,7 @@ protected: paint.setImageFilter(SkImageFilters::Erode( samples[i].fRadiusX, samples[i].fRadiusY, nullptr, cr)); } else { - paint.setImageFilter(SkImageFilters::Erode( + paint.setImageFilter(SkImageFilters::Dilate( samples[i].fRadiusX, samples[i].fRadiusY, nullptr, cr)); } this->drawClippedBitmap(canvas, paint, i * 140, j * 140); diff --git a/include/effects/SkImageFilters.h b/include/effects/SkImageFilters.h index 066c876ead..5dd6c2bd43 100644 --- a/include/effects/SkImageFilters.h +++ b/include/effects/SkImageFilters.h @@ -159,8 +159,11 @@ public: * @param image The image that is output by the filter. */ static sk_sp Image(sk_sp image) { + // Defaults to kHigh_SkFilterQuality because the dstRect of the image filter will be mapped + // by the layer matrix set during filtering. If that has a scale factor, then the image + // will not be drawn at a 1-to-1 pixel scale, even that is what this appears to create here. SkRect r = image ? SkRect::MakeWH(image->width(), image->height()) : SkRect::MakeEmpty(); - return Image(std::move(image), r, r, kNone_SkFilterQuality); + return Image(std::move(image), r, r, kHigh_SkFilterQuality); } /**