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 <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-01-22 21:44:57 -05:00 committed by Skia Commit-Bot
parent 8a42b09c16
commit 9702fc6f38
12 changed files with 38 additions and 25 deletions

View File

@ -413,7 +413,7 @@ static sk_sp<SkSpecialImage> 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<SkSpecialImage> 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

View File

@ -85,9 +85,14 @@ sk_sp<SkSpecialImage> 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;

View File

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

View File

@ -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<SkSpecialImage> MakeFromImage(GrRecordingContext*,
const SkIRect& subset,

View File

@ -242,7 +242,7 @@ sk_sp<SkSpecialImage> 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);

View File

@ -134,7 +134,7 @@ sk_sp<SkSpecialImage> SkColorFilterImageFilterImpl::onFilterImage(const Context&
input->draw(canvas,
SkIntToScalar(inputOffset.fX - bounds.fLeft),
SkIntToScalar(inputOffset.fY - bounds.fTop),
&paint);
SkSamplingOptions(), &paint);
}
offset->fX = bounds.fLeft;

View File

@ -138,10 +138,10 @@ sk_sp<SkSpecialImage> 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;

View File

@ -116,8 +116,7 @@ sk_sp<SkSpecialImage> 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();

View File

@ -120,7 +120,7 @@ sk_sp<SkSpecialImage> 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;

View File

@ -143,7 +143,7 @@ sk_sp<SkSpecialImage> SkTileImageFilterImpl::onFilterImage(const Context& ctx,
input->draw(canvas,
SkIntToScalar(inputOffset.x()), SkIntToScalar(inputOffset.y()),
&paint);
SkSamplingOptions(), &paint);
subset = surf->makeImageSnapshot();
}

View File

@ -159,7 +159,7 @@ sk_sp<SkSpecialImage> 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);

View File

@ -93,7 +93,7 @@ static void test_image(const sk_sp<SkSpecialImage>& 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);