Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8b5f3ac

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
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 <[email protected]> Reviewed-by: Florin Malita <[email protected]>
1 parent eca04ee commit 8b5f3ac

16 files changed

+42
-44
lines changed

gm/colorfilterimagefilter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static sk_sp<SkShader> sh_make_image() {
8181
if (!image) {
8282
return nullptr;
8383
}
84-
return image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
84+
return image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions());
8585
}
8686

8787
static void sk_gm_get_shaders(SkTDArray<SkShader*>* array) {
@@ -234,8 +234,7 @@ DEF_SIMPLE_GM(colorfiltershader, canvas, 610, 610) {
234234
}
235235

236236
template <typename Maker> void do_mixershader(SkCanvas* canvas, Maker&& maker) {
237-
auto shaderA = GetResourceAsImage("images/mandrill_128.png")->makeShader(SkTileMode::kClamp,
238-
SkTileMode::kClamp);
237+
auto shaderA = GetResourceAsImage("images/mandrill_128.png")->makeShader(SkSamplingOptions());
239238
const SkColor colors[] = { SK_ColorGREEN, 0 };
240239
auto shaderB = SkGradientShader::MakeRadial({60, 60}, 55, colors, nullptr, 2,
241240
SkTileMode::kClamp,

gm/colorfilters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class HSLColorFilterGM : public skiagm::GM {
9595
mandrill->height()),
9696
SkRect::MakeWH(kWheelSize, kWheelSize),
9797
SkMatrix::kFill_ScaleToFit);
98-
fShaders.push_back(mandrill->makeShader(&lm));
98+
fShaders.push_back(mandrill->makeShader(SkSamplingOptions(), &lm));
9999

100100
static constexpr SkColor gGrads[][4] = {
101101
{ 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffff0000 },

gm/complexclip.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ DEF_SIMPLE_GM(clip_shader_persp, canvas, 1370, 1030) {
394394
gradLM ? &persp : nullptr);
395395
bool imageLM = config.fLM == kImageWithLocalMat || config.fLM == kBothWithLocalMat;
396396
auto imgShader = img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
397-
imageLM ? perspScale : scale);
397+
SkSamplingOptions(), imageLM ? perspScale : scale);
398398

399399
// Perspective before any clipShader
400400
if (config.fConcat == kConcatBeforeClips) {
@@ -449,7 +449,8 @@ DEF_SIMPLE_GM(clip_shader_difference, canvas, 512, 512) {
449449
SkRect rect = SkRect::MakeWH(256, 256);
450450
SkMatrix local = SkMatrix::MakeRectToRect(SkRect::MakeWH(image->width(), image->height()),
451451
SkRect::MakeWH(64, 64), SkMatrix::kFill_ScaleToFit);
452-
auto shader = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &local);
452+
auto shader = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
453+
SkSamplingOptions(), &local);
453454

454455
SkPaint paint;
455456
paint.setColor(SK_ColorRED);

gm/composeshader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ DEF_SIMPLE_GM(composeshader_bitmap2, canvas, 200, 200) {
274274
sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
275275
sk_sp<SkImage> skMaskImage = SkImage::MakeFromBitmap(skMask);
276276
paint.setShader(
277-
SkShaders::Blend(SkBlendMode::kSrcIn, skMaskImage->makeShader(), skSrc->makeShader()));
277+
SkShaders::Blend(SkBlendMode::kSrcIn,
278+
skMaskImage->makeShader(SkSamplingOptions()),
279+
skSrc->makeShader(SkSamplingOptions())));
278280
canvas->drawRect(r, paint);
279281
}
280282

gm/croppedrects.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CroppedRectsGM : public GM {
5656
srcCanvas->drawRect(kSrcImageClip.makeInset(kStrokeWidth / 2, kStrokeWidth / 2), stroke);
5757

5858
fSrcImage = srcSurface->makeImageSnapshot();
59-
fSrcImageShader = fSrcImage->makeShader();
59+
fSrcImageShader = fSrcImage->makeShader(SkSamplingOptions());
6060
}
6161

6262
void onDraw(SkCanvas* canvas) override {
@@ -67,7 +67,6 @@ class CroppedRectsGM : public GM {
6767
SkAutoCanvasRestore acr(canvas, true);
6868
SkPaint paint;
6969
paint.setShader(fSrcImageShader);
70-
paint.setFilterQuality(kNone_SkFilterQuality);
7170
canvas->clipRect(kSrcImageClip);
7271
canvas->drawPaint(paint);
7372
}
@@ -76,7 +75,6 @@ class CroppedRectsGM : public GM {
7675
// GrRenderTargetContext::fillRectToRect.
7776
SkAutoCanvasRestore acr(canvas, true);
7877
SkPaint paint;
79-
paint.setFilterQuality(kNone_SkFilterQuality);
8078
SkRect drawRect = SkRect::MakeXYWH(350, 100, 100, 300);
8179
canvas->clipRect(drawRect);
8280
canvas->drawImageRect(fSrcImage.get(),
@@ -96,7 +94,6 @@ class CroppedRectsGM : public GM {
9694
paint.setStyle(SkPaint::kStroke_Style);
9795
paint.setStrokeWidth(2 * kSrcImageClip.height());
9896
paint.setShader(fSrcImageShader);
99-
paint.setFilterQuality(kNone_SkFilterQuality);
10097
canvas->translate(23, 301);
10198
canvas->scale(300 / kSrcImageClip.width(), 100 / kSrcImageClip.height());
10299
canvas->translate(-kSrcImageClip.left(), -kSrcImageClip.top());

gm/drawatlas.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,9 @@ DEF_SIMPLE_GM(compare_atlas_vertices, canvas, 560, 585) {
342342
canvas->save();
343343
for (const sk_sp<SkColorFilter>& cf : filters) {
344344
paint.setColorFilter(cf);
345-
canvas->drawAtlas(image, &xform, &tex, &color, 1,
346-
mode, &tex, &paint);
345+
canvas->drawAtlas(image, &xform, &tex, &color, 1, mode, &tex, &paint);
347346
canvas->translate(128, 0);
348-
paint.setShader(image->makeShader());
347+
paint.setShader(image->makeShader(SkSamplingOptions()));
349348
canvas->drawVertices(verts, mode, paint);
350349
paint.setShader(nullptr);
351350
canvas->translate(145, 0);

gm/filterbug.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ class FilterBugGM : public skiagm::GM {
5959
}
6060

6161
void onDraw(SkCanvas* canvas) override {
62-
static const SkFilterQuality kFilterQuality = SkFilterQuality::kHigh_SkFilterQuality;
62+
static const SkSamplingOptions kSampling({1.0f/3, 1.0f/3});
6363
static const bool kDoAA = true;
6464

6565
{
6666
SkRect r1 = SkRect::MakeXYWH(50.0f, 0.0f, 50.0f, 50.0f);
6767
SkPaint p1;
6868
p1.setAntiAlias(kDoAA);
69-
p1.setFilterQuality(kFilterQuality);
7069
SkMatrix localMat;
7170
localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 0.0f);
72-
p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &localMat));
71+
p1.setShader(fTop->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
72+
kSampling, &localMat));
7373

7474
canvas->drawRect(r1, p1);
7575
}
@@ -80,7 +80,6 @@ class FilterBugGM : public skiagm::GM {
8080
SkPaint p2;
8181
p2.setColor(SK_ColorWHITE);
8282
p2.setAntiAlias(kDoAA);
83-
p2.setFilterQuality(kFilterQuality);
8483

8584
canvas->drawRect(r2, p2);
8685
}
@@ -90,10 +89,10 @@ class FilterBugGM : public skiagm::GM {
9089

9190
SkPaint p3;
9291
p3.setAntiAlias(kDoAA);
93-
p3.setFilterQuality(kFilterQuality);
9492
SkMatrix localMat;
9593
localMat.setScaleTranslate(2.0f, 2.0f, 50.0f, 86.0f);
96-
p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &localMat));
94+
p3.setShader(fBot->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
95+
kSampling, &localMat));
9796

9897
canvas->drawRect(r3, p3);
9998
}

gm/image_shader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class ImageShaderGM : public skiagm::GM {
130130
const SkTileMode tile = SkTileMode::kRepeat;
131131
const SkMatrix localM = SkMatrix::Translate(-50, -50);
132132
SkPaint paint;
133-
paint.setShader(image->makeShader(tile, tile, &localM));
133+
paint.setShader(image->makeShader(tile, tile, SkSamplingOptions(), &localM));
134134
paint.setAntiAlias(true);
135135
canvas->drawCircle(50, 50, 50, paint);
136136
}

gm/localmatriximageshader.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "gm/gm.h"
99
#include "include/core/SkCanvas.h"
1010
#include "include/core/SkColor.h"
11-
#include "include/core/SkFilterQuality.h"
1211
#include "include/core/SkImage.h"
1312
#include "include/core/SkImageInfo.h"
1413
#include "include/core/SkMatrix.h"
@@ -37,7 +36,7 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
3736
SkMatrix translate = SkMatrix::Translate(100.0f, 0.0f);
3837
SkMatrix rotate;
3938
rotate.setRotate(45.0f);
40-
sk_sp<SkShader> redImageShader = redImage->makeShader(&translate);
39+
sk_sp<SkShader> redImageShader = redImage->makeShader(SkSamplingOptions(), &translate);
4140
sk_sp<SkShader> redLocalMatrixShader = redImageShader->makeWithLocalMatrix(rotate);
4241

4342
// Rotate about the origin will happen first.
@@ -46,7 +45,7 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
4645
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
4746

4847
sk_sp<SkImage> blueImage = make_image(canvas, SK_ColorBLUE);
49-
sk_sp<SkShader> blueImageShader = blueImage->makeShader(&rotate);
48+
sk_sp<SkShader> blueImageShader = blueImage->makeShader(SkSamplingOptions(), &rotate);
5049
sk_sp<SkShader> blueLocalMatrixShader = blueImageShader->makeWithLocalMatrix(translate);
5150

5251
// Translate will happen first.
@@ -59,10 +58,10 @@ DEF_SIMPLE_GM(localmatriximageshader, canvas, 250, 250) {
5958
SkTileMode mode[2];
6059
SkMatrix matrix;
6160
SkImage* image = redLocalMatrixShader->isAImage(&matrix, mode);
62-
paint.setShader(image->makeShader(mode[0], mode[1], &matrix));
61+
paint.setShader(image->makeShader(mode[0], mode[1], SkSamplingOptions(), &matrix));
6362
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
6463
image = blueLocalMatrixShader->isAImage(&matrix, mode);
65-
paint.setShader(image->makeShader(mode[0], mode[1], &matrix));
64+
paint.setShader(image->makeShader(mode[0], mode[1], SkSamplingOptions(), &matrix));
6665
canvas->drawIRect(SkIRect::MakeWH(250, 250), paint);
6766
}
6867

@@ -71,9 +70,8 @@ DEF_SIMPLE_GM(localmatriximageshader_filtering, canvas, 256, 256) {
7170
// comes from a local matrix shader.
7271
auto image = GetResourceAsImage("images/mandrill_256.png");
7372
SkPaint p;
74-
p.setFilterQuality(kHigh_SkFilterQuality);
7573
SkMatrix m = SkMatrix::Scale(2, 2);
76-
p.setShader(image->makeShader()->makeWithLocalMatrix(m));
74+
p.setShader(image->makeShader(SkSamplingOptions({1.0f/3, 1.0f/3}))->makeWithLocalMatrix(m));
7775

7876
canvas->drawRect(SkRect::MakeXYWH(0, 0, 256, 256), p);
7977
}

gm/localmatrixshader.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ DEF_SIMPLE_GM(localmatrixshader_nested, canvas, 450, 1200) {
5151
static const FactoryT gFactories[] = {
5252
// SkLocalMatrixShader(SkImageShader(inner), outer)
5353
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
54-
return img->makeShader(&inner)->makeWithLocalMatrix(outer);
54+
return img->makeShader(SkSamplingOptions(), inner)->makeWithLocalMatrix(outer);
5555
},
5656

5757
// SkLocalMatrixShader(SkLocalMatrixShader(SkImageShader(I), inner), outer)
5858
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
59-
return img->makeShader()->makeWithLocalMatrix(inner)->makeWithLocalMatrix(outer);
59+
return img->makeShader(SkSamplingOptions())->makeWithLocalMatrix(inner)->makeWithLocalMatrix(outer);
6060
},
6161

6262
// SkLocalMatrixShader(SkComposeShader(SkImageShader(inner)), outer)
6363
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
6464
return SkShaders::Blend(SkBlendMode::kSrcOver,
6565
SkShaders::Color(SK_ColorTRANSPARENT),
66-
img->makeShader(&inner))
66+
img->makeShader(SkSamplingOptions(), inner))
6767
->makeWithLocalMatrix(outer);
6868
},
6969

7070
// SkLocalMatrixShader(SkComposeShader(SkLocalMatrixShader(SkImageShader(I), inner)), outer)
7171
[](const sk_sp<SkImage>& img, const SkMatrix& inner, const SkMatrix& outer) {
7272
return SkShaders::Blend(SkBlendMode::kSrcOver,
7373
SkShaders::Color(SK_ColorTRANSPARENT),
74-
img->makeShader()->makeWithLocalMatrix(inner))
74+
img->makeShader(SkSamplingOptions())->makeWithLocalMatrix(inner))
7575
->makeWithLocalMatrix(outer);
7676
},
7777
};
@@ -156,21 +156,24 @@ DEF_SIMPLE_GM(localmatrixshader_persp, canvas, 542, 266) {
156156
canvas->save();
157157
// 4 variants that all attempt to apply sample at persp * scale w/ an image shader
158158
// 1. scale provided to SkImage::makeShader(...) but drawn with persp
159-
auto s1 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &scale);
159+
auto s1 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
160+
SkSamplingOptions(), &scale);
160161
draw(s1, true);
161162

162163
// 2. persp provided to SkImage::makeShader, then wrapped in scale makeWithLocalMatrix
163164
// These pre-concat, so it ends up as persp * scale.
164-
auto s2 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &persp)
165+
auto s2 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
166+
SkSamplingOptions(), &persp)
165167
->makeWithLocalMatrix(scale);
166168
draw(s2, false);
167169

168170
// 3. Providing pre-computed persp*scale to SkImage::makeShader()
169-
auto s3 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &perspScale);
171+
auto s3 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
172+
SkSamplingOptions(), &perspScale);
170173
draw(s3, false);
171174

172175
// 4. Providing pre-computed persp*scale to makeWithLocalMatrix
173-
auto s4 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat)
176+
auto s4 = image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions())
174177
->makeWithLocalMatrix(perspScale);
175178
draw(s4, false);
176179
canvas->restore();

0 commit comments

Comments
 (0)