Add customization for kMedium

Change-Id: If08d7d71be59179b22bbf27dacca5942f1832a11
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347637
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-12-26 21:48:57 -05:00
parent caca7bfff9
commit 9a27566e0c
3 changed files with 21 additions and 10 deletions

View File

@ -9,6 +9,7 @@
#define SkImageSampling_DEFINED
#include "include/core/SkFilterQuality.h"
#include <new>
enum class SkFilterMode {
kNearest, // single sample point (nearest neighbor)
@ -65,7 +66,11 @@ struct SK_API SkSamplingOptions {
: useCubic(true)
, cubic(c) {}
explicit SkSamplingOptions(SkFilterQuality);
enum MediumBehavior {
kMedium_asMipmapNearest, // historic cpu behavior
kMedium_asMipmapLinear, // historic gpu behavior
};
explicit SkSamplingOptions(SkFilterQuality, MediumBehavior = kMedium_asMipmapNearest);
bool operator==(const SkSamplingOptions& other) const {
return useCubic == other.useCubic

View File

@ -2251,8 +2251,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);
static SkSamplingOptions paint_to_sampling(const SkPaint* paint, GrRecordingContext* ctx) {
SkSamplingOptions::MediumBehavior mb = ctx ? SkSamplingOptions::kMedium_asMipmapLinear
: SkSamplingOptions::kMedium_asMipmapNearest;
return SkSamplingOptions(paint ? paint->getFilterQuality() : kNone_SkFilterQuality, mb);
}
void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) {
@ -2263,8 +2265,7 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
return;
}
// TODO: this should be passed in directly by the client
const SkSamplingOptions sampling(paint ? paint->getFilterQuality() : kNone_SkFilterQuality);
const SkSamplingOptions sampling = paint_to_sampling(&realPaint, this->recordingContext());
if (realPaint.getImageFilter() &&
this->canDrawBitmapAsSprite(x, y, image->width(), image->height(), sampling, realPaint) &&
@ -2294,7 +2295,8 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
}
AutoLayerForImageFilter layer(this, realPaint, &bounds);
this->topDevice()->drawImageRect(image, nullptr, bounds, paint_to_sampling(&layer.paint()),
this->topDevice()->drawImageRect(image, nullptr, bounds,
paint_to_sampling(&layer.paint(), this->recordingContext()),
layer.paint(), kStrict_SrcRectConstraint);
}
@ -2309,7 +2311,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, paint_to_sampling(&layer.paint()),
this->topDevice()->drawImageRect(image, src, dst, paint_to_sampling(&layer.paint(),
this->recordingContext()),
layer.paint(), constraint);
}
@ -2350,7 +2353,8 @@ void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
AutoLayerForImageFilter layer(this, realPaint, &dst);
this->topDevice()->drawImageLattice(image, lattice, dst,
paint_to_sampling(&layer.paint()).filter,
paint_to_sampling(&layer.paint(),
this->recordingContext()).filter,
layer.paint());
}

View File

@ -641,13 +641,15 @@ sk_sp<SkImage> SkMipmapBuilder::attachTo(const SkImage* src) {
return src->withMipmaps(fMM);
}
SkSamplingOptions::SkSamplingOptions(SkFilterQuality fq) {
SkSamplingOptions::SkSamplingOptions(SkFilterQuality fq, MediumBehavior behavior) {
switch (fq) {
case SkFilterQuality::kHigh_SkFilterQuality:
*this = SkSamplingOptions(SkCubicResampler{1/3.0f, 1/3.0f});
break;
case SkFilterQuality::kMedium_SkFilterQuality:
*this = SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest);
*this = SkSamplingOptions(SkFilterMode::kLinear,
behavior == kMedium_asMipmapNearest ? SkMipmapMode::kNearest
: SkMipmapMode::kLinear);
break;
case SkFilterQuality::kLow_SkFilterQuality:
*this = SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNone);