Use sampling for bitmap shaders

Change-Id: Ifa656ffc83a1adb5670cff1e2ce77f2edb1d6b03
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343776
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-12-12 14:31:25 -05:00 committed by Skia Commit-Bot
parent b41bd15a4b
commit 057fcbec5d
8 changed files with 31 additions and 29 deletions

View File

@ -29,7 +29,6 @@ static void create_gradient(SkBitmap* bm) {
class ConstXTileBench : public Benchmark {
SkPaint fPaint;
SkString fName;
bool fDoFilter;
bool fDoTrans;
bool fDoScale;
static const int kWidth = 1;
@ -38,11 +37,10 @@ class ConstXTileBench : public Benchmark {
public:
ConstXTileBench(SkTileMode xTile,
SkTileMode yTile,
bool doFilter,
SkFilterMode fm,
bool doTrans,
bool doScale)
: fDoFilter(doFilter)
, fDoTrans(doTrans)
: fDoTrans(doTrans)
, fDoScale(doScale) {
SkBitmap bm;
@ -51,7 +49,7 @@ public:
create_gradient(&bm);
fPaint.setShader(bm.makeShader(xTile, yTile));
fPaint.setShader(bm.makeShader(xTile, yTile, SkSamplingOptions(fm, SkMipmapMode::kNone)));
fName.printf("constXTile_");
@ -59,7 +57,7 @@ public:
fName.append(gTileModeStr[(unsigned)xTile]);
fName.append(gTileModeStr[(unsigned)yTile]);
if (doFilter) {
if (fm != SkFilterMode::kNearest) {
fName.append("_filter");
}
@ -80,8 +78,6 @@ protected:
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint(fPaint);
this->setupPaint(&paint);
paint.setFilterQuality(fDoFilter ? kLow_SkFilterQuality
: kNone_SkFilterQuality);
if (fDoTrans) {
paint.setColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF));
}
@ -114,18 +110,21 @@ private:
// Scaled benches are trending towards free. Seems like caching.
// TODO(mtklein, reed): fix and reenable
constexpr SkFilterMode gNN = SkFilterMode::kNearest;
constexpr SkFilterMode gLI = SkFilterMode::kLinear;
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, false, false, true))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, false, false, false))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, gNN, false, false))
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, false, false, true))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, true, false, false))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, gLI, false, false))
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, true, false, true))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, true, false, false))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, gLI, false, false))
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, false, true, true))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, false, true, false))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, gNN, true, false))
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, false, true, true))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, true, true, false))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, gLI, true, false))
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, true, true, true))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, true, true, false))
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, gLI, true, false))

View File

@ -182,7 +182,8 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
SkAssertResult(pm.erase({1,0,0,1}, p3.get()));
SkPaint paint;
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions()));
canvas->drawRect({10,10,70,70}, paint);
compare_pixel("drawBitmapAsShader P3 red, from SkPixmap::erase",
@ -347,8 +348,8 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
SkPaint as_shader;
as_shader.setColor4f({1,0,0,1}, p3.get());
as_shader.setFilterQuality(kLow_SkFilterQuality);
as_shader.setShader(bm.makeShader());
as_shader.setShader(bm.makeShader(SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kNone)));
canvas->drawBitmap(bm, 10,10, &as_bitmap);
compare_pixel("A8 sprite bitmap P3 red",

View File

@ -84,7 +84,8 @@ protected:
createTexture();
fShader = fTexture.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
fShader = fTexture.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions());
}
void createMaskFilter() {

View File

@ -116,8 +116,10 @@ protected:
SkPaint fillPaint;
fillPaint.setAntiAlias(true);
fillPaint.setFilterQuality(kLow_SkFilterQuality);
fillPaint.setShader(fBmp.makeShader(kTileModes[tm0], kTileModes[tm1], &localM));
fillPaint.setShader(fBmp.makeShader(kTileModes[tm0], kTileModes[tm1],
SkSamplingOptions(SkFilterMode::kLinear,
SkMipmapMode::kNone),
localM));
constexpr char kText[] = "B";
canvas->drawString(kText, 0, 0, font, fillPaint);

View File

@ -60,13 +60,13 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setFilterQuality(kHigh_SkFilterQuality);
SkMatrix mat;
mat.setScale(121.f/360.f, 93.f/288.f);
mat.postTranslate(-72, -72);
paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &mat));
paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions({1.0f/3, 1.0f/3}), mat));
canvas->drawRect({ 8, 8, 1008, 608 }, paint);
}

View File

@ -47,10 +47,9 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
canvas.drawPaint(paint);
}
static void setup(SkPaint* paint, const SkBitmap& bm, bool filter,
static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterMode fm,
SkTileMode tmx, SkTileMode tmy) {
paint->setShader(bm.makeShader(tmx, tmy));
paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
paint->setShader(bm.makeShader(tmx, tmy, SkSamplingOptions(fm, SkMipmapMode::kNone)));
}
constexpr SkColorType gColorTypes[] = {
@ -100,7 +99,7 @@ protected:
const char* gConfigNames[] = { "8888", "565", "4444" };
constexpr bool gFilters[] = { false, true };
constexpr SkFilterMode gFilters[] = { SkFilterMode::kNearest, SkFilterMode::kLinear };
static const char* gFilterNames[] = { "point", "bilinear" };
constexpr SkTileMode gModes[] = {
@ -171,7 +170,7 @@ constexpr int gHeight = 32;
static sk_sp<SkShader> make_bm(SkTileMode tx, SkTileMode ty) {
SkBitmap bm;
makebm(&bm, kN32_SkColorType, gWidth, gHeight);
return bm.makeShader(tx, ty);
return bm.makeShader(tx, ty, SkSamplingOptions());
}
static sk_sp<SkShader> make_grad(SkTileMode tx, SkTileMode ty) {

View File

@ -167,7 +167,7 @@ constexpr int gHeight = 32;
static sk_sp<SkShader> make_bm(SkTileMode tx, SkTileMode ty) {
SkBitmap bm;
makebm(&bm, kN32_SkColorType, gWidth, gHeight);
return bm.makeShader(tx, ty);
return bm.makeShader(tx, ty, SkSamplingOptions());
}
static sk_sp<SkShader> make_grad(SkTileMode tx, SkTileMode ty) {

View File

@ -53,7 +53,7 @@ static sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int si
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions());
}
// http://crrev.com/834303005