Revert "Revert "Use explicit samplingoptions""

Undo pictureshader change from prev version

This reverts commit fde98cbddd.

Change-Id: I52fe7d2753dee91fd08ae26f38e47ecd933d0c94
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/342378
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-12-08 21:58:35 -05:00
parent fde98cbddd
commit b612b6cfa0
15 changed files with 40 additions and 43 deletions

View File

@ -81,7 +81,7 @@ static sk_sp<SkShader> sh_make_image() {
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 @@ DEF_SIMPLE_GM(colorfiltershader, canvas, 610, 610) {
}
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,

View File

@ -95,7 +95,7 @@ protected:
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 },

View File

@ -394,7 +394,7 @@ DEF_SIMPLE_GM(clip_shader_persp, canvas, 1370, 1030) {
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 @@ DEF_SIMPLE_GM(clip_shader_difference, canvas, 512, 512) {
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);

View File

@ -274,7 +274,9 @@ DEF_SIMPLE_GM(composeshader_bitmap2, canvas, 200, 200) {
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);
}

View File

@ -56,7 +56,7 @@ private:
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 @@ private:
SkAutoCanvasRestore acr(canvas, true);
SkPaint paint;
paint.setShader(fSrcImageShader);
paint.setFilterQuality(kNone_SkFilterQuality);
canvas->clipRect(kSrcImageClip);
canvas->drawPaint(paint);
}
@ -76,7 +75,6 @@ private:
// 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 @@ private:
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());

View File

@ -342,10 +342,9 @@ DEF_SIMPLE_GM(compare_atlas_vertices, canvas, 560, 585) {
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);

View File

@ -59,17 +59,17 @@ protected:
}
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 @@ protected:
SkPaint p2;
p2.setColor(SK_ColorWHITE);
p2.setAntiAlias(kDoAA);
p2.setFilterQuality(kFilterQuality);
canvas->drawRect(r2, p2);
}
@ -90,10 +89,10 @@ protected:
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);
}

View File

@ -130,7 +130,7 @@ protected:
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);
}

View File

@ -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 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
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 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
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 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
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 @@ DEF_SIMPLE_GM(localmatriximageshader_filtering, canvas, 256, 256) {
// 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);
}

View File

@ -51,19 +51,19 @@ DEF_SIMPLE_GM(localmatrixshader_nested, canvas, 450, 1200) {
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 @@ DEF_SIMPLE_GM(localmatrixshader_nested, canvas, 450, 1200) {
[](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 @@ DEF_SIMPLE_GM(localmatrixshader_persp, canvas, 542, 266) {
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();

View File

@ -110,7 +110,7 @@ static void dopatch(SkCanvas* canvas, const SkColor colors[], sk_sp<SkImage> img
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);

View File

@ -209,7 +209,7 @@ static SkPath make_path() {
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});

View File

@ -29,7 +29,7 @@ DEF_SIMPLE_GM(tilemodes_alpha, canvas, 512, 512) {
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);
}
}

View File

@ -41,8 +41,7 @@ static void run_shader_test(skiatest::Reporter* reporter, SkSurface* sourceSurfa
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 @@ static void run_shader_test(skiatest::Reporter* reporter, SkSurface* sourceSurfa
sk_sp<SkShader> sourceShaderTranslated = sourceImage->makeShader(
SkTileMode::kRepeat,
SkTileMode::kRepeat,
&matrix);
SkSamplingOptions(), &matrix);
destinationCanvas->clear(SK_ColorTRANSPARENT);

View File

@ -393,7 +393,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageNullFulfill, reporter, ctxInfo) {
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);