From 9702fc6f385205e43b49cf7e09222720cc11aa8c Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Fri, 22 Jan 2021 21:44:57 -0500 Subject: [PATCH] SpecialImage draw takes sampling, not filter-quality Bug: skia:7650 Change-Id: Iebb3df29a55b049e34492cf072aad3d6c7df9c1d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358019 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- src/core/SkImageFilter.cpp | 4 ++-- src/core/SkMatrixImageFilter.cpp | 9 ++++++-- src/core/SkSpecialImage.cpp | 22 +++++++++++-------- src/core/SkSpecialImage.h | 6 ++++- .../imagefilters/SkArithmeticImageFilter.cpp | 2 +- .../imagefilters/SkColorFilterImageFilter.cpp | 2 +- .../imagefilters/SkDropShadowImageFilter.cpp | 4 ++-- .../imagefilters/SkMergeImageFilter.cpp | 3 +-- .../imagefilters/SkOffsetImageFilter.cpp | 2 +- .../imagefilters/SkTileImageFilter.cpp | 2 +- .../imagefilters/SkXfermodeImageFilter.cpp | 5 +++-- tests/SpecialImageTest.cpp | 2 +- 12 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 08da5a0347..f05081c35e 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -413,7 +413,7 @@ static sk_sp pad_image(SkSpecialImage* src, const SkImageFilter_ canvas->clear(0x0); - src->draw(canvas, offX, offY, nullptr); + src->draw(canvas, offX, offY); return surf->makeImageSnapshot(); } @@ -645,7 +645,7 @@ sk_sp SkImageFilter_Base::ImageToColorSpace(SkSpecialImage* src, SkASSERT(canvas); SkPaint p; p.setBlendMode(SkBlendMode::kSrc); - src->draw(canvas, 0, 0, &p); + src->draw(canvas, 0, 0, SkSamplingOptions(), &p); return surf->makeImageSnapshot(); } #endif diff --git a/src/core/SkMatrixImageFilter.cpp b/src/core/SkMatrixImageFilter.cpp index 9fb877851f..fe1d69ff68 100644 --- a/src/core/SkMatrixImageFilter.cpp +++ b/src/core/SkMatrixImageFilter.cpp @@ -85,9 +85,14 @@ sk_sp SkMatrixImageFilter::onFilterImage(const Context& ctx, SkPaint paint; paint.setAntiAlias(true); paint.setBlendMode(SkBlendMode::kSrc); - paint.setFilterQuality(fFilterQuality); - input->draw(canvas, srcRect.x(), srcRect.y(), &paint); + // TODO: change MatrixImageFilter to take sampling explicitly, not filter-quality + SkSamplingOptions sampling(fFilterQuality, + canvas->recordingContext() + ? SkSamplingOptions::kMedium_asMipmapLinear + : SkSamplingOptions::kMedium_asMipmapNearest); + + input->draw(canvas, srcRect.x(), srcRect.y(), sampling, &paint); offset->fX = dstBounds.fLeft; offset->fY = dstBounds.fTop; diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index f94ab71987..171234c584 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -39,7 +39,8 @@ public: } ~SkSpecialImage_Base() override { } - virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const = 0; + virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkSamplingOptions&, + const SkPaint*) const = 0; virtual bool onGetROPixels(SkBitmap*) const = 0; @@ -84,8 +85,9 @@ SkSpecialImage::SkSpecialImage(const SkIRect& subset, , fUniqueID(kNeedNewImageUniqueID_SpecialImage == uniqueID ? SkNextID::ImageID() : uniqueID) { } -void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const { - return as_SIB(this)->onDraw(canvas, x, y, paint); +void SkSpecialImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, + const SkSamplingOptions& sampling, const SkPaint* paint) const { + return as_SIB(this)->onDraw(canvas, x, y, sampling, paint); } bool SkSpecialImage::getROPixels(SkBitmap* bm) const { @@ -191,12 +193,13 @@ public: size_t getSize() const override { return fBitmap.computeByteSize(); } - void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { + void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling, + const SkPaint* paint) const override { SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height()); - canvas->drawImageRect(fBitmap.asImage(), this->subset(), dst, paint, - SkCanvas::kStrict_SrcRectConstraint); + canvas->drawImageRect(fBitmap.asImage(), SkRect::Make(this->subset()), dst, + sampling, paint, SkCanvas::kStrict_SrcRectConstraint); } bool onGetROPixels(SkBitmap* bm) const override { @@ -342,7 +345,8 @@ public: return fView.proxy()->gpuMemorySize(); } - void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { + void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling, + const SkPaint* paint) const override { SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height()); @@ -357,8 +361,8 @@ public: this->uniqueID(), fView, this->colorType(), fAlphaType, fColorSpace)); - canvas->drawImageRect(img, this->subset(), - dst, paint, SkCanvas::kStrict_SrcRectConstraint); + canvas->drawImageRect(img, SkRect::Make(this->subset()), dst, + sampling, paint, SkCanvas::kStrict_SrcRectConstraint); } GrRecordingContext* onGetContext() const override { return fContext; } diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index 1f21e90938..ba752f7dde 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -10,6 +10,7 @@ #include "include/core/SkImageInfo.h" #include "include/core/SkRefCnt.h" +#include "include/core/SkSamplingOptions.h" #include "include/core/SkSurfaceProps.h" #include "src/core/SkNextID.h" @@ -64,7 +65,10 @@ public: /** * Draw this SpecialImage into the canvas, automatically taking into account the image's subset */ - void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const; + void draw(SkCanvas*, SkScalar x, SkScalar y, const SkSamplingOptions&, const SkPaint*) const; + void draw(SkCanvas* canvas, SkScalar x, SkScalar y) const { + this->draw(canvas, x, y, SkSamplingOptions(), nullptr); + } static sk_sp MakeFromImage(GrRecordingContext*, const SkIRect& subset, diff --git a/src/effects/imagefilters/SkArithmeticImageFilter.cpp b/src/effects/imagefilters/SkArithmeticImageFilter.cpp index ab4a54642e..0669358b27 100644 --- a/src/effects/imagefilters/SkArithmeticImageFilter.cpp +++ b/src/effects/imagefilters/SkArithmeticImageFilter.cpp @@ -242,7 +242,7 @@ sk_sp ArithmeticImageFilterImpl::onFilterImage(const Context& ct SkPaint paint; paint.setBlendMode(SkBlendMode::kSrc); background->draw(canvas, SkIntToScalar(backgroundOffset.fX), - SkIntToScalar(backgroundOffset.fY), &paint); + SkIntToScalar(backgroundOffset.fY), SkSamplingOptions(), &paint); } this->drawForeground(canvas, foreground.get(), foregroundBounds); diff --git a/src/effects/imagefilters/SkColorFilterImageFilter.cpp b/src/effects/imagefilters/SkColorFilterImageFilter.cpp index f64727ccce..4c25aaf563 100644 --- a/src/effects/imagefilters/SkColorFilterImageFilter.cpp +++ b/src/effects/imagefilters/SkColorFilterImageFilter.cpp @@ -134,7 +134,7 @@ sk_sp SkColorFilterImageFilterImpl::onFilterImage(const Context& input->draw(canvas, SkIntToScalar(inputOffset.fX - bounds.fLeft), SkIntToScalar(inputOffset.fY - bounds.fTop), - &paint); + SkSamplingOptions(), &paint); } offset->fX = bounds.fLeft; diff --git a/src/effects/imagefilters/SkDropShadowImageFilter.cpp b/src/effects/imagefilters/SkDropShadowImageFilter.cpp index 0abaa14bec..2a1fa7e6dd 100644 --- a/src/effects/imagefilters/SkDropShadowImageFilter.cpp +++ b/src/effects/imagefilters/SkDropShadowImageFilter.cpp @@ -138,10 +138,10 @@ sk_sp SkDropShadowImageFilterImpl::onFilterImage(const Context& canvas->translate(SkIntToScalar(inputOffset.fX) - SkIntToScalar(bounds.fLeft), SkIntToScalar(inputOffset.fY) - SkIntToScalar(bounds.fTop)); - input->draw(canvas, offsetVec.fX, offsetVec.fY, &paint); + input->draw(canvas, offsetVec.fX, offsetVec.fY, SkSamplingOptions(), &paint); if (!fShadowOnly) { - input->draw(canvas, 0, 0, nullptr); + input->draw(canvas, 0, 0); } offset->fX = bounds.fLeft; offset->fY = bounds.fTop; diff --git a/src/effects/imagefilters/SkMergeImageFilter.cpp b/src/effects/imagefilters/SkMergeImageFilter.cpp index 114e70f2bf..94579fda45 100644 --- a/src/effects/imagefilters/SkMergeImageFilter.cpp +++ b/src/effects/imagefilters/SkMergeImageFilter.cpp @@ -116,8 +116,7 @@ sk_sp SkMergeImageFilterImpl::onFilterImage(const Context& ctx, } inputs[i]->draw(canvas, - SkIntToScalar(offsets[i].x() - x0), SkIntToScalar(offsets[i].y() - y0), - nullptr); + SkIntToScalar(offsets[i].x() - x0), SkIntToScalar(offsets[i].y() - y0)); } offset->fX = bounds.left(); diff --git a/src/effects/imagefilters/SkOffsetImageFilter.cpp b/src/effects/imagefilters/SkOffsetImageFilter.cpp index 2ddac13edb..74786fdb0d 100644 --- a/src/effects/imagefilters/SkOffsetImageFilter.cpp +++ b/src/effects/imagefilters/SkOffsetImageFilter.cpp @@ -120,7 +120,7 @@ sk_sp SkOffsetImageFilterImpl::onFilterImage(const Context& ctx, canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), SkIntToScalar(srcOffset.fY - bounds.fTop)); - input->draw(canvas, vec.fX, vec.fY, &paint); + input->draw(canvas, vec.fX, vec.fY, SkSamplingOptions(), &paint); offset->fX = bounds.fLeft; offset->fY = bounds.fTop; diff --git a/src/effects/imagefilters/SkTileImageFilter.cpp b/src/effects/imagefilters/SkTileImageFilter.cpp index a9c6f7780f..dcf4bfc3c4 100644 --- a/src/effects/imagefilters/SkTileImageFilter.cpp +++ b/src/effects/imagefilters/SkTileImageFilter.cpp @@ -143,7 +143,7 @@ sk_sp SkTileImageFilterImpl::onFilterImage(const Context& ctx, input->draw(canvas, SkIntToScalar(inputOffset.x()), SkIntToScalar(inputOffset.y()), - &paint); + SkSamplingOptions(), &paint); subset = surf->makeImageSnapshot(); } diff --git a/src/effects/imagefilters/SkXfermodeImageFilter.cpp b/src/effects/imagefilters/SkXfermodeImageFilter.cpp index 2ce8f212e6..3ec3504461 100644 --- a/src/effects/imagefilters/SkXfermodeImageFilter.cpp +++ b/src/effects/imagefilters/SkXfermodeImageFilter.cpp @@ -159,7 +159,7 @@ sk_sp SkXfermodeImageFilterImpl::onFilterImage(const Context& ct paint.setBlendMode(SkBlendMode::kSrc); background->draw(canvas, SkIntToScalar(backgroundOffset.fX), SkIntToScalar(backgroundOffset.fY), - &paint); + SkSamplingOptions(), &paint); } this->drawForeground(canvas, foreground.get(), foregroundBounds); @@ -217,7 +217,8 @@ void SkXfermodeImageFilterImpl::drawForeground(SkCanvas* canvas, SkSpecialImage* SkPaint paint; paint.setBlendMode(fMode); if (img) { - img->draw(canvas, SkIntToScalar(fgBounds.fLeft), SkIntToScalar(fgBounds.fTop), &paint); + img->draw(canvas, SkIntToScalar(fgBounds.fLeft), SkIntToScalar(fgBounds.fTop), + SkSamplingOptions(), &paint); } SkAutoCanvasRestore acr(canvas, true); diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp index 2e08a394fe..bb57ed419d 100644 --- a/tests/SpecialImageTest.cpp +++ b/tests/SpecialImageTest.cpp @@ -93,7 +93,7 @@ static void test_image(const sk_sp& img, skiatest::Reporter* rep SkCanvas* canvas = surf->getCanvas(); canvas->clear(SK_ColorBLUE); - img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad), nullptr); + img->draw(canvas, SkIntToScalar(kPad), SkIntToScalar(kPad)); SkBitmap bm; bm.allocN32Pixels(kFullSize, kFullSize, false);