Take sampling params on device apis

This is part of the bottom-up approach, trying to eliminate
filter-quality from the inside, force us to pass in the sampling
parameters (eventually) from the client/canvas.

Change-Id: I5c17c9912333c7a481e88744569518c06ba4a945
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345576
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-12-17 21:55:04 -05:00 committed by Skia Commit-Bot
parent b9a172aaef
commit 5d3227096d
13 changed files with 46 additions and 27 deletions

View File

@ -422,9 +422,9 @@ static inline bool CanApplyDstMatrixAsCTM(const SkMatrix& m, const SkPaint& pain
return m.getType() <= SkMatrix::kTranslate_Mask;
}
void SkBitmapDevice::drawImageRect(const SkImage* image,
const SkRect* src, const SkRect& dst,
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
void SkBitmapDevice::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkSamplingOptions& sampling, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
SkASSERT(dst.isFinite());
SkASSERT(dst.isSorted());
@ -470,7 +470,7 @@ void SkBitmapDevice::drawImageRect(const SkImage* image,
if (src && !src->contains(bitmapBounds) &&
SkCanvas::kFast_SrcRectConstraint == constraint &&
paint.getFilterQuality() != kNone_SkFilterQuality) {
sampling != SkSamplingOptions()) {
// src is smaller than the bounds of the bitmap, and we are filtering, so we don't know
// how much more of the bitmap we need, so we can't use extractSubset or drawBitmap,
// but we must use a shader w/ dst bounds (which can access all of the bitmap needed).

View File

@ -91,7 +91,8 @@ protected:
void drawPath(const SkPath&, const SkPaint&, bool pathIsMutable) override;
void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint&, SkCanvas::SrcRectConstraint) override;
const SkSamplingOptions&, const SkPaint&,
SkCanvas::SrcRectConstraint) override;
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) override;

View File

@ -2245,6 +2245,10 @@ static SkPaint clean_paint_for_drawImage(const SkPaint* paint) {
return cleaned;
}
static SkSamplingOptions paint_to_sampling(const SkPaint* paint) {
return SkSamplingOptions(paint ? paint->getFilterQuality() : kNone_SkFilterQuality);
}
void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) {
SkPaint realPaint = clean_paint_for_drawImage(paint);
@ -2281,8 +2285,8 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
}
AutoLayerForImageFilter layer(this, realPaint, &bounds);
this->topDevice()->drawImageRect(image, nullptr, bounds, layer.paint(),
kStrict_SrcRectConstraint);
this->topDevice()->drawImageRect(image, nullptr, bounds, paint_to_sampling(&layer.paint()),
layer.paint(), kStrict_SrcRectConstraint);
}
void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
@ -2296,7 +2300,8 @@ void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
AutoLayerForImageFilter layer(this, realPaint, &dst, CheckForOverwrite::kYes,
image->isOpaque() ? kOpaque_ShaderOverrideOpacity
: kNotOpaque_ShaderOverrideOpacity);
this->topDevice()->drawImageRect(image, src, dst, layer.paint(), constraint);
this->topDevice()->drawImageRect(image, src, dst, paint_to_sampling(&layer.paint()),
layer.paint(), constraint);
}
void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y,
@ -2335,7 +2340,9 @@ void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
}
AutoLayerForImageFilter layer(this, realPaint, &dst);
this->topDevice()->drawImageLattice(image, lattice, dst, layer.paint());
this->topDevice()->drawImageLattice(image, lattice, dst,
paint_to_sampling(&layer.paint()).filter,
layer.paint());
}
void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,

View File

@ -163,9 +163,8 @@ void SkBaseDevice::drawPatch(const SkPoint cubics[12], const SkColor colors[4],
}
}
void SkBaseDevice::drawImageLattice(const SkImage* image,
const SkCanvas::Lattice& lattice, const SkRect& dst,
const SkPaint& paint) {
void SkBaseDevice::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& lattice,
const SkRect& dst, SkFilterMode filter, const SkPaint& paint) {
SkLatticeIter iter(lattice, dst);
SkRect srcR, dstR;
@ -186,7 +185,9 @@ void SkBaseDevice::drawImageLattice(const SkImage* image,
this->drawRect(dstR, paintCopy);
}
} else {
this->drawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
SkSamplingOptions sampling(filter, SkMipmapMode::kNone);
this->drawImageRect(image, &srcR, dstR, sampling, paint,
SkCanvas::kStrict_SrcRectConstraint);
}
}
}
@ -260,6 +261,8 @@ void SkBaseDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry images[], in
SkASSERT(paint.getStyle() == SkPaint::kFill_Style);
SkASSERT(!paint.getPathEffect());
// TODO: pass this in directly
const SkSamplingOptions sampling(paint.getFilterQuality());
SkPaint entryPaint = paint;
const SkM44 baseLocalToDevice = this->localToDevice44();
int clipIndex = 0;
@ -292,7 +295,7 @@ void SkBaseDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry images[], in
clipIndex += 4;
}
this->drawImageRect(images[i].fImage.get(), &images[i].fSrcRect, images[i].fDstRect,
entryPaint, constraint);
sampling, entryPaint, constraint);
if (needsRestore) {
this->restoreLocal(baseLocalToDevice);
}

View File

@ -265,9 +265,10 @@ protected:
bool pathIsMutable = false) = 0;
virtual void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint&, SkCanvas::SrcRectConstraint) = 0;
const SkSamplingOptions&, const SkPaint&,
SkCanvas::SrcRectConstraint) = 0;
virtual void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
const SkRect& dst, const SkPaint&);
const SkRect& dst, SkFilterMode, const SkPaint&);
virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) = 0;
virtual void drawShadow(const SkPath&, const SkDrawShadowRec&);
@ -519,7 +520,8 @@ protected:
void drawPaint(const SkPaint& paint) override {}
void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override {}
void drawImageRect(const SkImage*, const SkRect*, const SkRect&,
const SkPaint&, SkCanvas::SrcRectConstraint) override {}
const SkSamplingOptions&, const SkPaint&,
SkCanvas::SrcRectConstraint) override {}
void drawRect(const SkRect&, const SkPaint&) override {}
void drawOval(const SkRect&, const SkPaint&) override {}
void drawRRect(const SkRRect&, const SkPaint&) override {}

View File

@ -792,11 +792,12 @@ void SkGpuDevice::drawDevice(SkBaseDevice* device, const SkPaint& paint) {
}
void SkGpuDevice::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
const SkSamplingOptions& sampling, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
ASSERT_SINGLE_OWNER
GrQuadAAFlags aaFlags = paint.isAntiAlias() ? GrQuadAAFlags::kAll : GrQuadAAFlags::kNone;
this->drawImageQuad(image, src, &dst, nullptr, GrAA(paint.isAntiAlias()), aaFlags, nullptr,
paint, constraint);
/*sampling*/paint, constraint);
}
// When drawing nine-patches or n-patches, cap the filter quality at kLinear.
@ -839,7 +840,7 @@ void SkGpuDevice::drawProducerLattice(GrTextureProducer* producer,
void SkGpuDevice::drawImageLattice(const SkImage* image,
const SkCanvas::Lattice& lattice, const SkRect& dst,
const SkPaint& paint) {
SkFilterMode filter, const SkPaint& paint) {
ASSERT_SINGLE_OWNER
uint32_t pinnedUniqueID;
auto iter = std::make_unique<SkLatticeIter>(lattice, dst);

View File

@ -110,9 +110,10 @@ public:
const SkColor[], int count, SkBlendMode, const SkPaint&) override;
void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint&, SkCanvas::SrcRectConstraint) override;
const SkSamplingOptions&, const SkPaint&,
SkCanvas::SrcRectConstraint) override;
void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
const SkRect& dst, const SkPaint&) override;
const SkRect& dst, SkFilterMode, const SkPaint&) override;
void drawDrawable(SkDrawable*, const SkMatrix*, SkCanvas* canvas) override;

View File

@ -630,6 +630,7 @@ void SkPDFDevice::internalDrawPath(const SkClipStack& clipStack,
void SkPDFDevice::drawImageRect(const SkImage* image,
const SkRect* src,
const SkRect& dst,
const SkSamplingOptions&, // ignored
const SkPaint& paint,
SkCanvas::SrcRectConstraint) {
SkASSERT(image);

View File

@ -81,6 +81,7 @@ public:
void drawImageRect(const SkImage*,
const SkRect* src,
const SkRect& dst,
const SkSamplingOptions&,
const SkPaint&,
SkCanvas::SrcRectConstraint) override;
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;

View File

@ -950,7 +950,8 @@ void SkSVGDevice::drawBitmapCommon(const MxCp& mc, const SkBitmap& bm, const SkP
}
void SkSVGDevice::drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) {
const SkSamplingOptions& sampling, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
SkBitmap bm;
// TODO: support gpu images
if (!as_IB(image)->getROPixels(nullptr, &bm)) {

View File

@ -25,7 +25,8 @@ protected:
void drawPoints(SkCanvas::PointMode mode, size_t count,
const SkPoint[], const SkPaint& paint) override;
void drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) override;
const SkSamplingOptions&, const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) override;
void drawRect(const SkRect& r, const SkPaint& paint) override;
void drawOval(const SkRect& oval, const SkPaint& paint) override;
void drawRRect(const SkRRect& rr, const SkPaint& paint) override;

View File

@ -2003,6 +2003,7 @@ void SkXPSDevice::drawOval( const SkRect& o, const SkPaint& p) {
void SkXPSDevice::drawImageRect(const SkImage* image,
const SkRect* src,
const SkRect& dst,
const SkSamplingOptions& sampling,
const SkPaint& paint,
SkCanvas::SrcRectConstraint constraint) {
// TODO: support gpu images
@ -2026,8 +2027,7 @@ void SkXPSDevice::drawImageRect(const SkImage* image,
auto bitmapShader = SkMakeBitmapShaderForPaint(paint, bitmap,
SkTileMode::kClamp, SkTileMode::kClamp,
SkSamplingOptions(paint.getFilterQuality()),
&matrix, kNever_SkCopyPixelsMode);
sampling, &matrix, kNever_SkCopyPixelsMode);
SkASSERT(bitmapShader);
if (!bitmapShader) { return; }
SkPaint paintWithShader(paint);

View File

@ -90,7 +90,7 @@ protected:
bool pathIsMutable = false) override;
void drawImageRect(const SkImage*,
const SkRect* srcOrNull, const SkRect& dst,
const SkPaint& paint,
const SkSamplingOptions&, const SkPaint& paint,
SkCanvas::SrcRectConstraint) override;
void drawGlyphRunList(const SkGlyphRunList& glyphRunList) override;
void drawVertices(const SkVertices*, SkBlendMode, const SkPaint&) override;