Use explicit samplingoptions
Promoting pictureshader to linear by default
Change-Id: Icd4102c3eee47558ecec845d0581ddbded981ef8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341979
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/gm/colorfilterimagefilter.cpp b/gm/colorfilterimagefilter.cpp
index 9373388..cf1b1a6 100644
--- a/gm/colorfilterimagefilter.cpp
+++ b/gm/colorfilterimagefilter.cpp
@@ -81,7 +81,7 @@
if (!image) {
return nullptr;
}
- return image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
+ return image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions());
}
static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) {
@@ -234,8 +234,7 @@
}
template <typename Maker> void do_mixershader(SkCanvas* canvas, Maker&& maker) {
- auto shaderA = GetResourceAsImage("images/mandrill_128.png")->makeShader(SkTileMode::kClamp,
- SkTileMode::kClamp);
+ auto shaderA = GetResourceAsImage("images/mandrill_128.png")->makeShader(SkSamplingOptions());
const SkColor colors[] = { SK_ColorGREEN, 0 };
auto shaderB = SkGradientShader::MakeRadial({60, 60}, 55, colors, nullptr, 2,
SkTileMode::kClamp,
diff --git a/gm/colorfilters.cpp b/gm/colorfilters.cpp
index 0c547a1..a4a57ad 100644
--- a/gm/colorfilters.cpp
+++ b/gm/colorfilters.cpp
@@ -95,7 +95,7 @@
mandrill->height()),
SkRect::MakeWH(kWheelSize, kWheelSize),
SkMatrix::kFill_ScaleToFit);
- fShaders.push_back(mandrill->makeShader(&lm));
+ fShaders.push_back(mandrill->makeShader(SkSamplingOptions(), &lm));
static constexpr SkColor gGrads[][4] = {
{ 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffff0000 },
diff --git a/gm/complexclip.cpp b/gm/complexclip.cpp
index b285ffa..e2da27c 100644
--- a/gm/complexclip.cpp
+++ b/gm/complexclip.cpp
@@ -394,7 +394,7 @@
gradLM ? &persp : nullptr);
bool imageLM = config.fLM == kImageWithLocalMat || config.fLM == kBothWithLocalMat;
auto imgShader = img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
- imageLM ? perspScale : scale);
+ SkSamplingOptions(), imageLM ? perspScale : scale);
// Perspective before any clipShader
if (config.fConcat == kConcatBeforeClips) {
@@ -449,7 +449,8 @@
SkRect rect = SkRect::MakeWH(256, 256);
SkMatrix local = SkMatrix::MakeRectToRect(SkRect::MakeWH(image->width(), image->height()),
SkRect::MakeWH(64, 64), SkMatrix::kFill_ScaleToFit);
- auto shader = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &local);
+ auto shader = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
+ SkSamplingOptions(), &local);
SkPaint paint;
paint.setColor(SK_ColorRED);
diff --git a/gm/composeshader.cpp b/gm/composeshader.cpp
index a383c8e..d3bbfc3 100644
--- a/gm/composeshader.cpp
+++ b/gm/composeshader.cpp
@@ -274,7 +274,9 @@
sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
sk_sp<SkImage> skMaskImage = SkImage::MakeFromBitmap(skMask);
paint.setShader(
- SkShaders::Blend(SkBlendMode::kSrcIn, skMaskImage->makeShader(), skSrc->makeShader()));
+ SkShaders::Blend(SkBlendMode::kSrcIn,
+ skMaskImage->makeShader(SkSamplingOptions()),
+ skSrc->makeShader(SkSamplingOptions())));
canvas->drawRect(r, paint);
}
diff --git a/gm/croppedrects.cpp b/gm/croppedrects.cpp
index 5e9f0bd..428677f 100644
--- a/gm/croppedrects.cpp
+++ b/gm/croppedrects.cpp
@@ -56,7 +56,7 @@
srcCanvas->drawRect(kSrcImageClip.makeInset(kStrokeWidth / 2, kStrokeWidth / 2), stroke);
fSrcImage = srcSurface->makeImageSnapshot();
- fSrcImageShader = fSrcImage->makeShader();
+ fSrcImageShader = fSrcImage->makeShader(SkSamplingOptions());
}
void onDraw(SkCanvas* canvas) override {
@@ -67,7 +67,6 @@
SkAutoCanvasRestore acr(canvas, true);
SkPaint paint;
paint.setShader(fSrcImageShader);
- paint.setFilterQuality(kNone_SkFilterQuality);
canvas->clipRect(kSrcImageClip);
canvas->drawPaint(paint);
}
@@ -76,7 +75,6 @@
// GrRenderTargetContext::fillRectToRect.
SkAutoCanvasRestore acr(canvas, true);
SkPaint paint;
- paint.setFilterQuality(kNone_SkFilterQuality);
SkRect drawRect = SkRect::MakeXYWH(350, 100, 100, 300);
canvas->clipRect(drawRect);
canvas->drawImageRect(fSrcImage.get(),
@@ -96,7 +94,6 @@
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2 * kSrcImageClip.height());
paint.setShader(fSrcImageShader);
- paint.setFilterQuality(kNone_SkFilterQuality);
canvas->translate(23, 301);
canvas->scale(300 / kSrcImageClip.width(), 100 / kSrcImageClip.height());
canvas->translate(-kSrcImageClip.left(), -kSrcImageClip.top());
diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp
index 51b192a..06ab3d6 100644
--- a/gm/drawatlas.cpp
+++ b/gm/drawatlas.cpp
@@ -342,10 +342,9 @@
canvas->save();
for (const sk_sp<SkColorFilter>& cf : filters) {
paint.setColorFilter(cf);
- canvas->drawAtlas(image, &xform, &tex, &color, 1,
- mode, &tex, &paint);
+ canvas->drawAtlas(image, &xform, &tex, &color, 1, mode, &tex, &paint);
canvas->translate(128, 0);
- paint.setShader(image->makeShader());
+ paint.setShader(image->makeShader(SkSamplingOptions()));
canvas->drawVertices(verts, mode, paint);
paint.setShader(nullptr);
canvas->translate(145, 0);
diff --git a/gm/filterbug.cpp b/gm/filterbug.cpp
index a89dfb1..3c4e9cc 100644
--- a/gm/filterbug.cpp
+++ b/gm/filterbug.cpp
@@ -59,17 +59,17 @@
}
void onDraw(SkCanvas* canvas) override {
- static const SkFilterQuality kFilterQuality = SkFilterQuality::kHigh_SkFilterQuality;
+ static const SkSamplingOptions kSampling({1.0f/3, 1.0f/3});
static const bool kDoAA = true;
{
SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f);
SkPaint p1;
p1.setAntiAlias(kDoAA);
- p1.setFilterQuality(kFilterQuality);
SkMatrix localMat;
localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f);
- p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &localMat));
+ p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
+ kSampling, &localMat));
canvas->drawRect(r1, p1);
}
@@ -80,7 +80,6 @@
SkPaint p2;
p2.setColor(SK_ColorWHITE);
p2.setAntiAlias(kDoAA);
- p2.setFilterQuality(kFilterQuality);
canvas->drawRect(r2, p2);
}
@@ -90,10 +89,10 @@
SkPaint p3;
p3.setAntiAlias(kDoAA);
- p3.setFilterQuality(kFilterQuality);
SkMatrix localMat;
localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f);
- p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &localMat));
+ p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
+ kSampling, &localMat));
canvas->drawRect(r3, p3);
}
diff --git a/gm/image_shader.cpp b/gm/image_shader.cpp
index 9489ff1..d15a1a4 100644
--- a/gm/image_shader.cpp
+++ b/gm/image_shader.cpp
@@ -130,7 +130,7 @@
const SkTileMode tile = SkTileMode::kRepeat;
const SkMatrix localM = SkMatrix::Translate(-50, -50);
SkPaint paint;
- paint.setShader(image->makeShader(tile, tile, &localM));
+ paint.setShader(image->makeShader(tile, tile, SkSamplingOptions(), &localM));
paint.setAntiAlias(true);
canvas->drawCircle(50, 50, 50, paint);
}
diff --git a/gm/localmatriximageshader.cpp b/gm/localmatriximageshader.cpp
index da838e2..72751c5 100644
--- a/gm/localmatriximageshader.cpp
+++ b/gm/localmatriximageshader.cpp
@@ -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/SkImageInfo.h"
#include "include/core/SkMatrix.h"
@@ -37,7 +36,7 @@
SkMatrix translate = SkMatrix::Translate(100.0f, 0.0f);
SkMatrix rotate;
rotate.setRotate(45.0f);
- sk_sp<SkShader> redImageShader = redImage->makeShader(&translate);
+ sk_sp<SkShader> redImageShader = redImage->makeShader(SkSamplingOptions(), &translate);
sk_sp<SkShader> redLocalMatrixShader = redImageShader->makeWithLocalMatrix(rotate);
// Rotate about the origin will happen first.
@@ -46,7 +45,7 @@
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
sk_sp<SkImage> blueImage = make_image(canvas, SK_ColorBLUE);
- sk_sp<SkShader> blueImageShader = blueImage->makeShader(&rotate);
+ sk_sp<SkShader> blueImageShader = blueImage->makeShader(SkSamplingOptions(), &rotate);
sk_sp<SkShader> blueLocalMatrixShader = blueImageShader->makeWithLocalMatrix(translate);
// Translate will happen first.
@@ -59,10 +58,10 @@
SkTileMode mode[2];
SkMatrix matrix;
SkImage* image = redLocalMatrixShader->isAImage(&matrix, mode);
- paint.setShader(image->makeShader(mode[0], mode[1], &matrix));
+ paint.setShader(image->makeShader(mode[0], mode[1], SkSamplingOptions(), &matrix));
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
image = blueLocalMatrixShader->isAImage(&matrix, mode);
- paint.setShader(image->makeShader(mode[0], mode[1], &matrix));
+ paint.setShader(image->makeShader(mode[0], mode[1], SkSamplingOptions(), &matrix));
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
}
@@ -71,9 +70,8 @@
// comes from a local matrix shader.
auto image = GetResourceAsImage("images/mandrill_256.png");
SkPaint p;
- p.setFilterQuality(kHigh_SkFilterQuality);
SkMatrix m = SkMatrix::Scale(2, 2);
- p.setShader(image->makeShader()->makeWithLocalMatrix(m));
+ p.setShader(image->makeShader(SkSamplingOptions({1.0f/3, 1.0f/3}))->makeWithLocalMatrix(m));
canvas->drawRect(SkRect::MakeXYWH(0, 0, 256, 256), p);
}
diff --git a/gm/localmatrixshader.cpp b/gm/localmatrixshader.cpp
index c3f8496..d6695d5 100644
--- a/gm/localmatrixshader.cpp
+++ b/gm/localmatrixshader.cpp
@@ -51,19 +51,19 @@
static const FactoryT gFactories[] = {
// SkLocalMatrixShader(SkImageShader(inner), outer)
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
- return img->makeShader(&inner)->makeWithLocalMatrix(outer);
+ return img->makeShader(SkSamplingOptions(), inner)->makeWithLocalMatrix(outer);
},
// SkLocalMatrixShader(SkLocalMatrixShader(SkImageShader(I), inner), outer)
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
- return img->makeShader()->makeWithLocalMatrix(inner)->makeWithLocalMatrix(outer);
+ return img->makeShader(SkSamplingOptions())->makeWithLocalMatrix(inner)->makeWithLocalMatrix(outer);
},
// SkLocalMatrixShader(SkComposeShader(SkImageShader(inner)), outer)
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
return SkShaders::Blend(SkBlendMode::kSrcOver,
SkShaders::Color(SK_ColorTRANSPARENT),
- img->makeShader(&inner))
+ img->makeShader(SkSamplingOptions(), inner))
->makeWithLocalMatrix(outer);
},
@@ -71,7 +71,7 @@
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
return SkShaders::Blend(SkBlendMode::kSrcOver,
SkShaders::Color(SK_ColorTRANSPARENT),
- img->makeShader()->makeWithLocalMatrix(inner))
+ img->makeShader(SkSamplingOptions())->makeWithLocalMatrix(inner))
->makeWithLocalMatrix(outer);
},
};
@@ -156,21 +156,24 @@
canvas->save();
// 4 variants that all attempt to apply sample at persp * scale w/ an image shader
// 1. scale provided to SkImage::makeShader(...) but drawn with persp
- auto s1 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &scale);
+ auto s1 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
+ SkSamplingOptions(), &scale);
draw(s1, true);
// 2. persp provided to SkImage::makeShader, then wrapped in scale makeWithLocalMatrix
// These pre-concat, so it ends up as persp * scale.
- auto s2 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &persp)
+ auto s2 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
+ SkSamplingOptions(), &persp)
->makeWithLocalMatrix(scale);
draw(s2, false);
// 3. Providing pre-computed persp*scale to SkImage::makeShader()
- auto s3 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &perspScale);
+ auto s3 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
+ SkSamplingOptions(), &perspScale);
draw(s3, false);
// 4. Providing pre-computed persp*scale to makeWithLocalMatrix
- auto s4 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat)
+ auto s4 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions())
->makeWithLocalMatrix(perspScale);
draw(s4, false);
canvas->restore();
diff --git a/gm/patch.cpp b/gm/patch.cpp
index 78a3071..b5f430a 100644
--- a/gm/patch.cpp
+++ b/gm/patch.cpp
@@ -110,7 +110,7 @@
if (img) {
SkScalar w = img->width();
SkScalar h = img->height();
- shader = img->makeShader(localMatrix);
+ shader = img->makeShader(SkSamplingOptions(), localMatrix);
texStorage[0].set(0, 0);
texStorage[1].set(w, 0);
texStorage[2].set(w, h);
diff --git a/gm/perspshaders.cpp b/gm/perspshaders.cpp
index 956fd72..cd57c36 100644
--- a/gm/perspshaders.cpp
+++ b/gm/perspshaders.cpp
@@ -209,7 +209,7 @@
DEF_SIMPLE_GM(perspective_clip, canvas, 800, 800) {
SkPath path = make_path();
auto shader = GetResourceAsImage("images/mandrill_128.png")
- ->makeShader(SkMatrix::Scale(3, 3));
+ ->makeShader(SkSamplingOptions(), SkMatrix::Scale(3, 3));
SkPaint paint;
paint.setColor({0.75, 0.75, 0.75, 1});
diff --git a/gm/tilemodes_alpha.cpp b/gm/tilemodes_alpha.cpp
index 08a63d0..6297c25 100644
--- a/gm/tilemodes_alpha.cpp
+++ b/gm/tilemodes_alpha.cpp
@@ -29,7 +29,7 @@
SkRect rect = SkRect::MakeXYWH(128 * x + 1, 128 * y + 1, 126, 126);
SkMatrix matrix = SkMatrix::Translate(rect.x(), rect.y());
SkPaint paint(SkColor4f{0, 0, 0, 0.5f});
- paint.setShader(image->makeShader(kModes[x], kModes[y], &matrix));
+ paint.setShader(image->makeShader(kModes[x], kModes[y], SkSamplingOptions(), &matrix));
canvas->drawRect(rect, paint);
}
}
diff --git a/src/shaders/SkPictureShader.cpp b/src/shaders/SkPictureShader.cpp
index 95415aa..9761f3a 100644
--- a/src/shaders/SkPictureShader.cpp
+++ b/src/shaders/SkPictureShader.cpp
@@ -244,7 +244,8 @@
return nullptr;
}
- tileShader = tileImage->makeShader(fTmx, fTmy);
+ tileShader = tileImage->makeShader(fTmx, fTmy, SkSamplingOptions(SkFilterMode::kLinear,
+ SkMipmapMode::kNone));
SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get()));
fAddedToCache.store(true);
diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp
index da52da3..6d262d2 100644
--- a/tests/ImageNewShaderTest.cpp
+++ b/tests/ImageNewShaderTest.cpp
@@ -41,8 +41,7 @@
sk_sp<SkImage> sourceImage(sourceSurface->makeImageSnapshot());
sk_sp<SkShader> sourceShader = sourceImage->makeShader(
- SkTileMode::kRepeat,
- SkTileMode::kRepeat);
+ SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions());
SkPaint paint;
paint.setShader(sourceShader);
@@ -69,7 +68,7 @@
sk_sp<SkShader> sourceShaderTranslated = sourceImage->makeShader(
SkTileMode::kRepeat,
SkTileMode::kRepeat,
- &matrix);
+ SkSamplingOptions(), &matrix);
destinationCanvas->clear(SK_ColorTRANSPARENT);
diff --git a/tests/PromiseImageTest.cpp b/tests/PromiseImageTest.cpp
index fe15753..c472b35 100644
--- a/tests/PromiseImageTest.cpp
+++ b/tests/PromiseImageTest.cpp
@@ -393,7 +393,7 @@
SkPaint paint;
paint.setColorFilter(SkColorFilters::LinearToSRGBGamma());
canvas->drawImage(refImg, 0, 0, &paint);
- auto shader = refImg->makeShader(SkTileMode::kClamp, SkTileMode::kClamp);
+ auto shader = refImg->makeShader(SkSamplingOptions());
REPORTER_ASSERT(reporter, shader);
paint.setShader(std::move(shader));
canvas->drawRect(SkRect::MakeWH(1,1), paint);