Add flag to hide non-sampling imageshader factories

Bug: skia:11056
Change-Id: Ic79876106c003f6061cbb50ad2f4a4bf4f446231
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341681
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-12-08 13:16:56 -05:00 committed by Skia Commit-Bot
parent fb2c2d2d59
commit 99c944647f
21 changed files with 61 additions and 35 deletions

View File

@ -21,7 +21,8 @@ static sk_sp<SkShader> make_bitmap_shader() {
auto surface = SkSurface::MakeRasterN32Premul(100, 100);
surface->getCanvas()->drawCircle(50, 50, 50, p);
return surface->makeImageSnapshot()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
return surface->makeImageSnapshot()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions());
}
static sk_sp<SkShader> make_picture_shader() {

View File

@ -54,7 +54,7 @@ class VertBench : public Benchmark {
void onDelayedSetup() override {
auto img = GetResourceAsImage("images/mandrill_256.png");
if (img) {
fShader = img->makeShader();
fShader = img->makeShader(SkSamplingOptions());
}
}

View File

@ -200,7 +200,7 @@ static sk_sp<SkShader> make_fuzz_shader(Fuzz* fuzz, int depth) {
if (useMatrix) {
FuzzNiceMatrix(fuzz, &matrix);
}
return img->makeShader(tmX, tmY, useMatrix ? &matrix : nullptr);
return img->makeShader(tmX, tmY, SkSamplingOptions(), useMatrix ? &matrix : nullptr);
case 4:
bitmap = make_fuzz_bitmap(fuzz);
fuzz->nextEnum(&tmX, SkTileMode::kLastTileMode);

View File

@ -81,6 +81,6 @@ DEF_SIMPLE_GM(alpha_image_alpha_tint, canvas, 152, 80) {
canvas->drawImage(image.get(), 0, 0, &paint);
canvas->translate(72, 0);
paint.setShader(image->makeShader());
paint.setShader(image->makeShader(SkSamplingOptions()));
canvas->drawRect({ 0, 0, 64, 64 }, paint);
}

View File

@ -47,10 +47,10 @@ DEF_SIMPLE_GM(bug6783, canvas, 500, 500) {
SkMatrix m = SkMatrix::Translate(25, 214) * SkMatrix::Scale(2, 2);
m.preSkew(0.5f, 0.5f);
// The bug was present at all filter levels, but you might not notice it at kNone.
p.setFilterQuality(kLow_SkFilterQuality);
// The bug was present at all filter levels, but you might not notice it at nearest.
SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
// It's only important to repeat or mirror in x to show off the bug.
p.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kClamp, &m));
p.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kClamp, sampling, m));
canvas->drawPaint(p);
}

View File

@ -211,7 +211,7 @@ DEF_GM(return new ComplexClipGM(true, true, true);)
DEF_SIMPLE_GM(clip_shader, canvas, 840, 650) {
auto img = GetResourceAsImage("images/yellow_rose.png");
auto sh = img->makeShader();
auto sh = img->makeShader(SkSamplingOptions());
SkRect r = SkRect::MakeIWH(img->width(), img->height());
SkPaint p;
@ -238,7 +238,8 @@ DEF_SIMPLE_GM(clip_shader, canvas, 840, 650) {
canvas->clipShader(sh, SkClipOp::kIntersect);
canvas->save();
SkMatrix lm = SkMatrix::Scale(1.0f/5, 1.0f/5);
canvas->clipShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &lm));
canvas->clipShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions(), lm));
canvas->drawImage(img, 0, 0, nullptr);
canvas->restore();
@ -247,7 +248,7 @@ DEF_SIMPLE_GM(clip_shader, canvas, 840, 650) {
DEF_SIMPLE_GM(clip_shader_layer, canvas, 430, 320) {
auto img = GetResourceAsImage("images/yellow_rose.png");
auto sh = img->makeShader();
auto sh = img->makeShader(SkSamplingOptions());
SkRect r = SkRect::MakeIWH(img->width(), img->height());

View File

@ -17,6 +17,7 @@ flutter_defines = [
# Staging
"SK_SUPPORT_LEGACY_ADJUSTHQHEURISTIC",
"SK_SUPPORT_LEGACY_ONDRAWIMAGERECT",
"SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY",
# Fast low-precision software rendering isn't a priority for Flutter.
"SK_DISABLE_LEGACY_SHADERCONTEXT",

View File

@ -8,6 +8,10 @@
#ifndef SkImage_DEFINED
#define SkImage_DEFINED
#ifndef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
#define SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
#endif
#include "include/core/SkFilterQuality.h"
#include "include/core/SkImageEncoder.h"
#include "include/core/SkImageInfo.h"
@ -657,8 +661,21 @@ public:
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions&,
const SkMatrix* localMatrix = nullptr) const;
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions& sampling,
const SkMatrix& lm) const {
return this->makeShader(tmx, tmy, sampling, &lm);
}
sk_sp<SkShader> makeShader(const SkSamplingOptions& sampling, const SkMatrix& lm) const {
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, &lm);
}
sk_sp<SkShader> makeShader(const SkSamplingOptions& sampling,
const SkMatrix* lm = nullptr) const {
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, sampling, lm);
}
using CubicResampler = SkCubicResampler;
#ifdef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
/** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
SkTileMode rules to fill drawn area outside SkImage. localMatrix permits
transforming SkImage before SkCanvas matrix is applied.
@ -677,13 +694,6 @@ public:
return this->makeShader(tmx, tmy, &localMatrix);
}
#ifdef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix* localMatrix,
SkFilterQuality fq) const {
return this->makeShader(tmx, tmy, SkSamplingOptions(fq), localMatrix);
}
#endif
/** Creates SkShader from SkImage. SkShader dimensions are taken from SkImage. SkShader uses
SkShader::kClamp_TileMode to fill drawn area outside SkImage. localMatrix permits
transforming SkImage before SkCanvas matrix is applied.
@ -697,6 +707,14 @@ public:
sk_sp<SkShader> makeShader(const SkMatrix& localMatrix) const {
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, &localMatrix);
}
#endif
#ifdef SK_SUPPORT_LEGACY_SCALEPIXELS_PARAM
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix* localMatrix,
SkFilterQuality fq) const {
return this->makeShader(tmx, tmy, SkSamplingOptions(fq), localMatrix);
}
#endif
/** Copies SkImage pixel address, row bytes, and SkImageInfo to pixmap, if address
is available, and returns true. If pixel address is not available, return

View File

@ -363,9 +363,9 @@ public:
void onOnceBeforeDraw() override {
fRR = SkRRect::MakeRectXY({20, 20, 380, 380}, 50, 50);
auto img = GetResourceAsImage("images/brickwork-texture.jpg");
fImgShader = img->makeShader(SkMatrix::Scale(2, 2));
fImgShader = img->makeShader(SkSamplingOptions(), SkMatrix::Scale(2, 2));
img = GetResourceAsImage("images/brickwork_normal-map.jpg");
fBmpShader = img->makeShader(SkMatrix::Scale(2, 2));
fBmpShader = img->makeShader(SkSamplingOptions(), SkMatrix::Scale(2, 2));
const char code[] = R"(
uniform shader color_map;

View File

@ -498,7 +498,7 @@ class HalfPlaneView3 : public SampleCameraView {
void onOnceBeforeDraw() override {
fPath = make_path();
fShader = GetResourceAsImage("images/mandrill_128.png")
->makeShader(SkMatrix::Scale(3, 3));
->makeShader(SkSamplingOptions(), SkMatrix::Scale(3, 3));
}
bool onChar(SkUnichar uni) override {
@ -571,7 +571,7 @@ class HalfPlaneCoons : public SampleCameraView {
fPatch[10] = { 0, 200 };
fPatch[11] = { 0, 100 };
fShader = GetResourceAsImage("images/mandrill_256.png")->makeShader();
fShader = GetResourceAsImage("images/mandrill_256.png")->makeShader(SkSamplingOptions());
}
void onDrawContent(SkCanvas* canvas) override {

View File

@ -28,7 +28,7 @@ static sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info)
static sk_sp<SkShader> make_shader(const SkRect& bounds) {
sk_sp<SkImage> image(GetResourceAsImage("images/mandrill_128.png"));
return image ? image->makeShader() : nullptr;
return image ? image->makeShader(SkSamplingOptions()) : nullptr;
}
#define N 128

View File

@ -212,16 +212,15 @@ class CubicResamplerDemo : public Sample {
SkMatrix lm = SkMatrix::Translate(r.x(), r.y())
* SkMatrix::Scale(10, 10);
paint.setShader(fImage->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, &lm));
paint.setShader(fImage->makeShader(SkSamplingOptions(), lm));
canvas->drawRect(r, paint);
r.offset(r.width() + 10, 0);
lm.postTranslate(r.width() + 10, 0);
paint.setShader(fImage->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
SkSamplingOptions{ SkFilterMode::kLinear,
paint.setShader(fImage->makeShader(SkSamplingOptions{ SkFilterMode::kLinear,
SkMipmapMode::kNone },
&lm));
lm));
canvas->drawRect(r, paint);
r.offset(r.width() + 10, 0);

View File

@ -241,7 +241,7 @@ void SkBaseDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[],
}
}
SkPaint p(paint);
p.setShader(atlas->makeShader());
p.setShader(atlas->makeShader(SkSamplingOptions()));
this->drawVertices(builder.detach().get(), mode, p);
}

View File

@ -48,7 +48,7 @@ static void load_color(SkRasterPipeline_UniformColorCtx* ctx, const float rgba[]
void SkDraw::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect textures[],
const SkColor colors[], int count, SkBlendMode bmode, const SkPaint& paint) {
sk_sp<SkShader> atlasShader = atlas->makeShader();
sk_sp<SkShader> atlasShader = atlas->makeShader(SkSamplingOptions(paint.getFilterQuality()));
if (!atlasShader) {
return;
}

View File

@ -163,7 +163,8 @@ sk_sp<SkSpecialImage> SkTileImageFilterImpl::onFilterImage(const Context& ctx,
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc);
paint.setShader(subset->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
paint.setShader(subset->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions()));
canvas->translate(-dstRect.fLeft, -dstRect.fTop);
canvas->drawRect(dstRect, paint);
offset->fX = dstIRect.fLeft;

View File

@ -950,6 +950,7 @@ void SkGpuDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) {
///////////////////////////////////////////////////////////////////////////////
// TODO: pass samplingoptions explicitly
void SkGpuDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[],
const SkRect texRect[], const SkColor colors[], int count,
SkBlendMode mode, const SkPaint& paint) {
@ -957,7 +958,7 @@ void SkGpuDevice::drawAtlas(const SkImage* atlas, const SkRSXform xform[],
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawAtlas", fContext.get());
// Convert atlas to an image shader.
sk_sp<SkShader> shader = atlas->makeShader();
sk_sp<SkShader> shader = atlas->makeShader(SkSamplingOptions(paint.getFilterQuality()));
if (!shader) {
return;
}

View File

@ -136,12 +136,14 @@ SkColorSpace* SkImage::colorSpace() const { return fInfo.colorSpace(); }
sk_sp<SkColorSpace> SkImage::refColorSpace() const { return fInfo.refColorSpace(); }
#ifdef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
sk_sp<SkShader> SkImage::makeShader(SkTileMode tmx, SkTileMode tmy,
const SkMatrix* localMatrix) const {
const SkSamplingOptions* inherit_from_paint = nullptr;
return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tmx, tmy, inherit_from_paint,
localMatrix);
}
#endif
sk_sp<SkShader> SkImage::makeShader(SkTileMode tmx, SkTileMode tmy,
const SkSamplingOptions& sampling,

View File

@ -1513,7 +1513,7 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
canvas.concat(ctm);
if (paint->getMaskFilter()) {
SkPaint tmpPaint;
tmpPaint.setShader(mask->makeShader(&transform));
tmpPaint.setShader(mask->makeShader(SkSamplingOptions(), transform));
tmpPaint.setMaskFilter(sk_ref_sp(paint->getMaskFilter()));
canvas.drawRect(dst, tmpPaint);
} else {
@ -1541,7 +1541,8 @@ void SkPDFDevice::internalDrawImageRect(SkKeyedImage imageSubset,
return;
}
if (paint->getMaskFilter()) {
paint.writable()->setShader(imageSubset.image()->makeShader(&transform));
paint.writable()->setShader(imageSubset.image()->makeShader(SkSamplingOptions(),
transform));
SkPath path = SkPath::Rect(dst); // handles non-integral clipping.
this->internalDrawPath(this->cs(), this->localToDevice(), path, *paint, true);
return;

View File

@ -37,5 +37,5 @@ DEF_TEST(FlattenableFactoryToName, r) {
bm.allocN32Pixels(8, 8);
bm.eraseColor(SK_ColorCYAN);
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
test_flattenable(r, image->makeShader().get(), "SkImage::newShader()");
test_flattenable(r, image->makeShader(SkSamplingOptions()).get(), "SkImage::newShader()");
}

View File

@ -22,7 +22,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(MatrixColorFilter_TransparentBlack, reporter,
auto imgSurf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
SkImageInfo::MakeN32(5, 5, kPremul_SkAlphaType));
imgSurf->getCanvas()->drawColor(0x0000000);
auto shader = imgSurf->makeImageSnapshot()->makeShader(SkTileMode::kClamp, SkTileMode::kClamp);
auto shader = imgSurf->makeImageSnapshot()->makeShader(SkSamplingOptions());
SkColorMatrix m;
m.setScale(0, 0, 0, 127.f);
SkPaint p;

View File

@ -24,7 +24,8 @@ void draw(SkCanvas* canvas) {
matrix.setScale(0.75f, 0.75f);
matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s.
SkPaint paint;
paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &matrix));
paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
SkSamplingOptions(), matrix));
canvas->drawPaint(paint);
SkDebugf("This is text output: %d", 2);