Skip to content

Commit

Permalink
Stop using SkFilterQuality
Browse files Browse the repository at this point in the history
Change-Id: Ief80d125eacb5922b95ab16ebc8d6b483469ada7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/429097
Reviewed-by: Mike Reed <[email protected]>
Commit-Queue: Mike Reed <[email protected]>
  • Loading branch information
reed-at-google committed Jul 17, 2021
1 parent fb0440e commit 2bdf6ed
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 45 deletions.
23 changes: 11 additions & 12 deletions gm/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkEncodedImageFormat.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageEncoder.h"
Expand Down Expand Up @@ -42,6 +41,13 @@

class GrSurfaceDrawContext;

const SkSamplingOptions gSamplings[] = {
SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions(SkCubicResampler::Mitchell()),
};

static void drawContents(SkSurface* surface, SkColor fillC) {
SkSize size = SkSize::Make(SkIntToScalar(surface->width()),
SkIntToScalar(surface->height()));
Expand Down Expand Up @@ -199,14 +205,11 @@ static void show_scaled_pixels(SkCanvas* canvas, SkImage* image) {
const SkImage::CachingHint chints[] = {
SkImage::kAllow_CachingHint, SkImage::kDisallow_CachingHint,
};
const SkFilterQuality qualities[] = {
kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality, kHigh_SkFilterQuality,
};

for (auto ch : chints) {
canvas->save();
for (auto q : qualities) {
if (image->scalePixels(storage, SkSamplingOptions(q), ch)) {
for (auto s : gSamplings) {
if (image->scalePixels(storage, s, ch)) {
draw_pixmap(canvas, storage);
}
canvas->translate(70, 0);
Expand Down Expand Up @@ -404,12 +407,8 @@ DEF_SIMPLE_GM(scalepixels_unpremul, canvas, 1080, 280) {
SkAutoPixmapStorage pm2;
pm2.alloc(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType));

const SkFilterQuality qualities[] = {
kNone_SkFilterQuality, kLow_SkFilterQuality, kMedium_SkFilterQuality, kHigh_SkFilterQuality
};

for (auto fq : qualities) {
pm.scalePixels(pm2, SkSamplingOptions(fq));
for (auto s : gSamplings) {
pm.scalePixels(pm2, s);
slam_ff(pm2);
draw_pixmap(canvas, pm2, 10, 10);
canvas->translate(pm2.width() + 10.0f, 0);
Expand Down
1 change: 0 additions & 1 deletion gm/mipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
Expand Down
1 change: 0 additions & 1 deletion gm/ninepatchstretch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
Expand Down
1 change: 0 additions & 1 deletion gm/perspimages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
Expand Down
1 change: 0 additions & 1 deletion gm/perspshaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
Expand Down
1 change: 0 additions & 1 deletion gm/pictureimagefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
Expand Down
1 change: 0 additions & 1 deletion gm/postercircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImage.h"
Expand Down
14 changes: 10 additions & 4 deletions gm/rectangletexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
Expand Down Expand Up @@ -204,8 +203,15 @@ class RectangleTexture : public GM {
canvas->translate(kOutset, kOutset);
auto dstRect = SkRect::Make(fSmallImg->dimensions()).makeOutset(kOutset, kOutset);

for (int fq = kNone_SkFilterQuality; fq <= kLast_SkFilterQuality; ++fq) {
if (fq == kMedium_SkFilterQuality) {
const SkSamplingOptions gSamplings[] = {
SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions(SkCubicResampler::Mitchell()),
};

for (const auto& sampling : gSamplings) {
if (!sampling.useCubic && sampling.mipmap != SkMipmapMode::kNone) {
// Medium is the same as Low for upscaling.
continue;
}
Expand All @@ -219,7 +225,7 @@ class RectangleTexture : public GM {
SkPaint paint;
paint.setShader(fSmallImg->makeShader(static_cast<SkTileMode>(tx),
static_cast<SkTileMode>(ty),
SkSamplingOptions((SkFilterQuality)fq),
sampling,
lm));
canvas->drawRect(dstRect, paint);
canvas->translate(dstRect.width() + kPad, 0);
Expand Down
1 change: 0 additions & 1 deletion gm/resizeimagefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkMatrix.h"
Expand Down
1 change: 0 additions & 1 deletion gm/shadertext3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkMatrix.h"
Expand Down
1 change: 0 additions & 1 deletion gm/skbug_8664.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
Expand Down
1 change: 0 additions & 1 deletion gm/tiledscaledbitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkShader.h"
Expand Down
7 changes: 3 additions & 4 deletions gm/tilemodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
Expand Down Expand Up @@ -274,15 +273,15 @@ DEF_SIMPLE_GM(tilemode_decal, canvas, 720, 1100) {
std::function<void(SkPaint*, SkTileMode, SkTileMode)> shader_procs[] = {
[img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
// Test no filtering with decal mode
paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(kNone_SkFilterQuality)));
paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkFilterMode::kNearest)));
},
[img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
// Test bilerp approximation for decal mode (or clamp to border HW)
paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(kLow_SkFilterQuality)));
paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkFilterMode::kLinear)));
},
[img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
// Test bicubic filter with decal mode
paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(kHigh_SkFilterQuality)));
paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkCubicResampler::Mitchell())));
},
[img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
Expand Down
21 changes: 11 additions & 10 deletions gm/tilemodes_scaled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
Expand All @@ -27,6 +26,13 @@
#include "include/utils/SkTextUtils.h"
#include "tools/ToolUtils.h"

const SkSamplingOptions gSamplings[] = {
SkSamplingOptions(SkFilterMode::kNearest),
SkSamplingOptions(SkFilterMode::kLinear),
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear),
SkSamplingOptions(SkCubicResampler::Mitchell()),
};

static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
bm->eraseColor(SK_ColorTRANSPARENT);
Expand All @@ -43,9 +49,9 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
canvas.drawPaint(paint);
}

static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_level,
static void setup(SkPaint* paint, const SkBitmap& bm, const SkSamplingOptions& sampling,
SkTileMode tmx, SkTileMode tmy) {
paint->setShader(bm.makeShader(tmx, tmy, SkSamplingOptions(filter_level)));
paint->setShader(bm.makeShader(tmx, tmy, sampling));
}

constexpr SkColorType gColorTypes[] = {
Expand Down Expand Up @@ -96,11 +102,6 @@ class ScaledTilingGM : public skiagm::GM {

const char* gColorTypeNames[] = { "8888" , "565", "4444" };

constexpr SkFilterQuality gFilterQualitys[] =
{ kNone_SkFilterQuality,
kLow_SkFilterQuality,
kMedium_SkFilterQuality,
kHigh_SkFilterQuality };
const char* gFilterNames[] = { "None", "Low", "Medium", "High" };

constexpr SkTileMode gModes[] = {
Expand All @@ -125,7 +126,7 @@ class ScaledTilingGM : public skiagm::GM {
y = SkIntToScalar(40) / scale;

for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
for (size_t j = 0; j < SK_ARRAY_COUNT(gFilterQualitys); j++) {
for (size_t j = 0; j < SK_ARRAY_COUNT(gSamplings); j++) {
x = SkIntToScalar(10)/scale;
for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
Expand All @@ -136,7 +137,7 @@ class ScaledTilingGM : public skiagm::GM {
makebm(&fTexture[i], gColorTypes[i], size, size);
}
#endif
setup(&paint, fTexture[i], gFilterQualitys[j], gModes[kx], gModes[ky]);
setup(&paint, fTexture[i], gSamplings[j], gModes[kx], gModes[ky]);
paint.setDither(true);

canvas->save();
Expand Down
1 change: 0 additions & 1 deletion gm/wacky_yuv_formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkFontTypes.h"
Expand Down
9 changes: 5 additions & 4 deletions samplecode/SampleThinAA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,15 @@ class OffscreenShapeRenderer : public ShapeRenderer {
blit.setColorFilter(SkColorFilters::Matrix(kFilter));
}

auto sampling = scale > 1 ? SkSamplingOptions(SkFilterMode::kNearest)
: SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kLinear);

canvas->scale(scale, scale);
canvas->drawImageRect(fLastRendered.get(),
SkRect::MakeWH(kTileWidth, kTileHeight),
SkRect::MakeWH(kTileWidth, kTileHeight),
SkSamplingOptions(scale > 1.f ? kNone_SkFilterQuality
: kMedium_SkFilterQuality),
&blit,
SkCanvas::kFast_SrcRectConstraint);
sampling, &blit, SkCanvas::kFast_SrcRectConstraint);
}

private:
Expand Down

0 comments on commit 2bdf6ed

Please sign in to comment.