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 <michaelludwig@google.com>
Auto-Submit: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Michael Ludwig 2019-08-05 10:24:49 -04:00 committed by Skia Commit-Bot
parent 9655534306
commit bf8439d7e2
3 changed files with 24 additions and 19 deletions

View File

@ -30,7 +30,7 @@ namespace {
void make_checkerboard(SkBitmap* bitmap);
sk_sp<SkImage> 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<SkImageFilter> 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<SkImageFilter> 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);

View File

@ -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);

View File

@ -159,8 +159,11 @@ public:
* @param image The image that is output by the filter.
*/
static sk_sp<SkImageFilter> Image(sk_sp<SkImage> 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);
}
/**