Name common cubic resamplers

Useful in client code to document what we're doing as we switch away
from SkFilterQuality.

Change-Id: I05737beb99a567a46a3c3ec418b7f7da71b1ff62
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/366723
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-02-05 12:55:38 -05:00 committed by Skia Commit-Bot
parent ca21e14d77
commit f3ac2afbb6
21 changed files with 28 additions and 21 deletions

View File

@ -22,7 +22,7 @@ namespace skiagm {
// This GM exercises HighQuality anisotropic filtering. // This GM exercises HighQuality anisotropic filtering.
class AnisotropicGM : public GM { class AnisotropicGM : public GM {
public: public:
AnisotropicGM() : fSampling({1.0f/3, 1.0f/3}) { AnisotropicGM() : fSampling(SkCubicResampler::Mitchell()) {
this->setBGColor(0xFFCCCCCC); this->setBGColor(0xFFCCCCCC);
} }

View File

@ -34,8 +34,8 @@ DEF_SIMPLE_GM(bicubic, canvas, 300, 320) {
SkPaint paint; SkPaint paint;
SkImage::CubicResampler cubics[] = { SkImage::CubicResampler cubics[] = {
{ 0, 1.0f/2 }, SkCubicResampler::CatmullRom(),
{ 1.0f/3, 1.0f/3 }, SkCubicResampler::Mitchell(),
}; };
for (auto c : cubics) { for (auto c : cubics) {
paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, paint.setShader(img->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,

View File

@ -246,7 +246,7 @@ protected:
const SkSamplingOptions none(SkFilterMode::kNearest); const SkSamplingOptions none(SkFilterMode::kNearest);
const SkSamplingOptions low(SkFilterMode::kLinear); const SkSamplingOptions low(SkFilterMode::kLinear);
const SkSamplingOptions high({1.0f/3, 1.0f/3}); const SkSamplingOptions high(SkCubicResampler::Mitchell());
SkScalar maxX = 0; SkScalar maxX = 0;
for (bool antiAlias : {false, true}) { for (bool antiAlias : {false, true}) {

View File

@ -92,7 +92,7 @@ protected:
s.postTranslate(SLIDE_SIZE / 2, SLIDE_SIZE / 2); s.postTranslate(SLIDE_SIZE / 2, SLIDE_SIZE / 2);
SkPaint paint; SkPaint paint;
paint.setShader(bmp.makeShader(fMode, fMode, paint.setShader(bmp.makeShader(fMode, fMode,
fHQ ? SkSamplingOptions({1.0f/3, 1.0f/3}) fHQ ? SkSamplingOptions(SkCubicResampler::Mitchell())
: SkSamplingOptions(), : SkSamplingOptions(),
s)); s));

View File

@ -270,7 +270,7 @@ private:
int numMipLevels = SkMipmap::ComputeLevelCount(levelDimensions.width(), int numMipLevels = SkMipmap::ComputeLevelCount(levelDimensions.width(),
levelDimensions.height()) + 1; levelDimensions.height()) + 1;
SkSamplingOptions sampling({1.0f/3, 1.0f/3}); SkSamplingOptions sampling(SkCubicResampler::Mitchell());
bool isCompressed = false; bool isCompressed = false;
if (image->isTextureBacked()) { if (image->isTextureBacked()) {

View File

@ -110,7 +110,7 @@ protected:
// Create a base-layer FP for the const color processor to draw on top of. // Create a base-layer FP for the const color processor to draw on top of.
std::unique_ptr<GrFragmentProcessor> baseFP; std::unique_ptr<GrFragmentProcessor> baseFP;
if (paintType >= SK_ARRAY_COUNT(kPaintColors)) { if (paintType >= SK_ARRAY_COUNT(kPaintColors)) {
SkSamplingOptions high({1.0f/3, 1.0f/3}); SkSamplingOptions high(SkCubicResampler::Mitchell());
GrColorInfo colorInfo; GrColorInfo colorInfo;
GrFPArgs args(context, SkSimpleMatrixProvider(SkMatrix::I()), high, &colorInfo); GrFPArgs args(context, SkSimpleMatrixProvider(SkMatrix::I()), high, &colorInfo);
baseFP = as_SB(fShader)->asFragmentProcessor(args); baseFP = as_SB(fShader)->asFragmentProcessor(args);

View File

@ -59,7 +59,7 @@ protected:
} }
void onDraw(SkCanvas* canvas) override { void onDraw(SkCanvas* canvas) override {
static const SkSamplingOptions kSampling({1.0f/3, 1.0f/3}); static const SkSamplingOptions kSampling(SkCubicResampler::Mitchell());
static const bool kDoAA = true; static const bool kDoAA = true;
{ {

View File

@ -41,7 +41,7 @@ static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
draw_cell(canvas, bm, mat, 1 * dx, SkSamplingOptions(SkFilterMode::kLinear)); draw_cell(canvas, bm, mat, 1 * dx, SkSamplingOptions(SkFilterMode::kLinear));
draw_cell(canvas, bm, mat, 2 * dx, SkSamplingOptions(SkFilterMode::kLinear, draw_cell(canvas, bm, mat, 2 * dx, SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kLinear)); SkMipmapMode::kLinear));
draw_cell(canvas, bm, mat, 3 * dx, SkSamplingOptions({1.0f/3, 1.0f/3})); draw_cell(canvas, bm, mat, 3 * dx, SkSamplingOptions(SkCubicResampler::Mitchell()));
} }
class FilterIndiaBoxGM : public skiagm::GM { class FilterIndiaBoxGM : public skiagm::GM {

View File

@ -190,7 +190,7 @@ static void draw_atlas(SkCanvas* canvas, SkImage* atlas, const SkRect& r,
SkPaint paint; SkPaint paint;
paint.setImageFilter(std::move(imf)); paint.setImageFilter(std::move(imf));
paint.setAntiAlias(true); paint.setAntiAlias(true);
SkSamplingOptions sampling({1.0f/3, 1.0f/3}); SkSamplingOptions sampling(SkCubicResampler::Mitchell());
canvas->drawAtlas(atlas, &xform, &r, /*colors=*/nullptr, /*count=*/1, SkBlendMode::kSrc, canvas->drawAtlas(atlas, &xform, &r, /*colors=*/nullptr, /*count=*/1, SkBlendMode::kSrc,
sampling, /*cullRect=*/nullptr, &paint); sampling, /*cullRect=*/nullptr, &paint);
} }

View File

@ -243,7 +243,7 @@ protected:
SkSamplingOptions(SkFilterMode::kNearest), SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest),
SkSamplingOptions({1.0f/3, 1.0f/3})}) SkSamplingOptions(SkCubicResampler::Mitchell())})
{ {
canvas->save(); canvas->save();
canvas->scale(scale, scale); canvas->scale(scale, scale);

View File

@ -111,7 +111,7 @@ private:
SkSamplingOptions(SkFilterMode::kNearest), SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions({1.0f/3, 1.0f/3}), SkSamplingOptions(SkCubicResampler::Mitchell()),
}; };
const bool AAs[] = { false, true }; const bool AAs[] = { false, true };

View File

@ -71,7 +71,8 @@ DEF_SIMPLE_GM(localmatriximageshader_filtering, canvas, 256, 256) {
auto image = GetResourceAsImage("images/mandrill_256.png"); auto image = GetResourceAsImage("images/mandrill_256.png");
SkPaint p; SkPaint p;
SkMatrix m = SkMatrix::Scale(2, 2); SkMatrix m = SkMatrix::Scale(2, 2);
p.setShader(image->makeShader(SkSamplingOptions({1.0f/3, 1.0f/3}))->makeWithLocalMatrix(m)); p.setShader(image->makeShader(SkSamplingOptions(SkCubicResampler::Mitchell()))
->makeWithLocalMatrix(m));
canvas->drawRect(SkRect::MakeXYWH(0, 0, 256, 256), p); canvas->drawRect(SkRect::MakeXYWH(0, 0, 256, 256), p);
} }

View File

@ -49,7 +49,7 @@ DEF_SIMPLE_GM(mipmap, canvas, 400, 200) {
SkSamplingOptions(SkFilterMode::kNearest), SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions({1.0f/3, 1.0f/3}), SkSamplingOptions(SkCubicResampler::Mitchell()),
}; };
canvas->translate(20, 20); canvas->translate(20, 20);

View File

@ -82,7 +82,7 @@ protected:
SkSamplingOptions(SkFilterMode::kNearest), SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions({1.0f/3, 1.0f/3})}) { SkSamplingOptions(SkCubicResampler::Mitchell())}) {
for (const auto& img : fImages) { for (const auto& img : fImages) {
canvas->save(); canvas->save();
canvas->concat(m); canvas->concat(m);

View File

@ -157,7 +157,7 @@ protected:
this->drawRow(canvas, SkSamplingOptions(SkFilterMode::kLinear, this->drawRow(canvas, SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kNearest)); SkMipmapMode::kNearest));
canvas->translate(0, SkIntToScalar(kCellSize)); canvas->translate(0, SkIntToScalar(kCellSize));
this->drawRow(canvas, SkSamplingOptions({1.0f/3, 1.0f/3})); this->drawRow(canvas, SkSamplingOptions(SkCubicResampler::Mitchell()));
canvas->translate(0, SkIntToScalar(kCellSize)); canvas->translate(0, SkIntToScalar(kCellSize));
} }
private: private:

View File

@ -157,7 +157,7 @@ private:
SkSamplingOptions(SkFilterMode::kNearest), SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions({1.0f/3, 1.0f/3}), SkSamplingOptions(SkCubicResampler::Mitchell()),
}; };
constexpr SkScalar kScales[] = {1.0f, 1.2f, 0.75f}; constexpr SkScalar kScales[] = {1.0f, 1.2f, 0.75f};

View File

@ -77,7 +77,7 @@ protected:
SkSamplingOptions(), SkSamplingOptions(),
SkSamplingOptions(SkFilterMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear), SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions({1.0f/3, 1.0f/3}), SkSamplingOptions(SkCubicResampler::Mitchell()),
}; };
const SkRect srcRect = SkRect::MakeWH(96, 96); const SkRect srcRect = SkRect::MakeWH(96, 96);
const SkSize deviceSize = SkSize::Make(16, 16); const SkSize deviceSize = SkSize::Make(16, 16);

View File

@ -98,7 +98,8 @@ DEF_SIMPLE_GPU_GM(sample_matrix_constant, ctx, rtCtx, canvas, 1024, 256) {
SkMatrix matrix; SkMatrix matrix;
SkSimpleMatrixProvider matrixProvider(matrix); SkSimpleMatrixProvider matrixProvider(matrix);
GrColorInfo colorInfo; GrColorInfo colorInfo;
GrFPArgs args(ctx, matrixProvider, SkSamplingOptions({1.0f/3, 1.0f/3}), &colorInfo); GrFPArgs args(ctx, matrixProvider, SkSamplingOptions(SkCubicResampler::Mitchell()),
&colorInfo);
std::unique_ptr<GrFragmentProcessor> gradientFP = as_SB(shader)->asFragmentProcessor(args); std::unique_ptr<GrFragmentProcessor> gradientFP = as_SB(shader)->asFragmentProcessor(args);
draw(std::move(gradientFP), 512, 0); draw(std::move(gradientFP), 512, 0);
gradientFP = as_SB(shader)->asFragmentProcessor(args); gradientFP = as_SB(shader)->asFragmentProcessor(args);

View File

@ -96,7 +96,8 @@ DEF_SIMPLE_GPU_GM(sample_matrix_variable, ctx, rtCtx, canvas, 512, 256) {
SkMatrix matrix; SkMatrix matrix;
SkSimpleMatrixProvider matrixProvider(matrix); SkSimpleMatrixProvider matrixProvider(matrix);
GrColorInfo colorInfo; GrColorInfo colorInfo;
GrFPArgs args(ctx, matrixProvider, SkSamplingOptions({1.0f/3, 1.0f/3}), &colorInfo); GrFPArgs args(ctx, matrixProvider, SkSamplingOptions(SkCubicResampler::Mitchell()),
&colorInfo);
std::unique_ptr<GrFragmentProcessor> gradientFP = as_SB(shader)->asFragmentProcessor(args); std::unique_ptr<GrFragmentProcessor> gradientFP = as_SB(shader)->asFragmentProcessor(args);
draw(std::move(gradientFP), -128, 256, 256, 0); draw(std::move(gradientFP), -128, 256, 256, 0);
} }

View File

@ -66,7 +66,7 @@ protected:
mat.postTranslate(-72, -72); mat.postTranslate(-72, -72);
paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions({1.0f/3, 1.0f/3}), mat)); SkSamplingOptions(SkCubicResampler::Mitchell()), mat));
canvas->drawRect({ 8, 8, 1008, 608 }, paint); canvas->drawRect({ 8, 8, 1008, 608 }, paint);
} }

View File

@ -45,6 +45,10 @@ enum class SkMipmapMode {
*/ */
struct SkCubicResampler { struct SkCubicResampler {
float B, C; float B, C;
// Historic default for kHigh_SkFilterQuality
static constexpr SkCubicResampler Mitchell() { return {1/3.0f, 1/3.0f}; }
static constexpr SkCubicResampler CatmullRom() { return {0.0f, 1/2.0f}; }
}; };
struct SK_API SkSamplingOptions { struct SK_API SkSamplingOptions {