Use samplingoptions for bitmap shader
Change-Id: I64c67ddcac29b68cdd0d25e4af4153358939b0ee Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343736 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
82abeceef9
commit
b41bd15a4b
@ -6,7 +6,6 @@ REG_FIDDLE(Canvas_drawPatch, 256, 256, false, 5) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
// SkBitmap source = cmbkygk;
|
||||
SkPaint paint;
|
||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||
paint.setAntiAlias(true);
|
||||
SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
|
||||
/* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 },
|
||||
@ -14,7 +13,8 @@ void draw(SkCanvas* canvas) {
|
||||
/* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ };
|
||||
SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff };
|
||||
SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} };
|
||||
paint.setShader(source.makeShader());
|
||||
paint.setShader(source.makeShader(SkSamplingOptions(SkFilterMode::kLinear,
|
||||
SkMipmapMode::kNone)));
|
||||
canvas->scale(15, 15);
|
||||
for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) {
|
||||
canvas->drawPatch(cubics, colors, texCoords, blend, paint);
|
||||
|
@ -6,14 +6,14 @@ REG_FIDDLE(Canvas_drawPatch_2_b, 256, 256, false, 6) {
|
||||
void draw(SkCanvas* canvas) {
|
||||
// SkBitmap source = checkerboard;
|
||||
SkPaint paint;
|
||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||
paint.setAntiAlias(true);
|
||||
SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
|
||||
/* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 },
|
||||
/* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 },
|
||||
/* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ };
|
||||
SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } };
|
||||
paint.setShader(source.makeShader());
|
||||
paint.setShader(source.makeShader(SkSamplingOptions(SkFilterMode::kLinear,
|
||||
SkMipmapMode::kNone)));
|
||||
canvas->scale(30, 30);
|
||||
canvas->drawPatch(cubics, nullptr, texCoords, paint);
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ void draw(SkCanvas* canvas) {
|
||||
bitmap.setInfo(SkImageInfo::MakeA8(5, 1), 5); // bitmap only contains alpha
|
||||
uint8_t pixels[5] = { 0x22, 0x55, 0x88, 0xBB, 0xFF };
|
||||
bitmap.setPixels(pixels);
|
||||
paint.setShader(bitmap.makeShader(SkTileMode::kMirror, SkTileMode::kMirror));
|
||||
paint.setShader(bitmap.makeShader(SkTileMode::kMirror, SkTileMode::kMirror,
|
||||
SkSamplingOptions()));
|
||||
for (SkColor c : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
||||
paint.setColor(c); // all components in color affect shader
|
||||
canvas->drawCircle(50, 50, 50, paint);
|
||||
|
@ -75,7 +75,7 @@ protected:
|
||||
}
|
||||
|
||||
canvas->save();
|
||||
paint.setShader(fBitmap.makeShader(&s));
|
||||
paint.setShader(fBitmap.makeShader(SkSamplingOptions(), s));
|
||||
|
||||
// draw the shader with a bitmap mask
|
||||
canvas->drawBitmap(fMask, 0, 0, &paint);
|
||||
@ -97,7 +97,8 @@ protected:
|
||||
|
||||
canvas->translate(0, 25);
|
||||
|
||||
paint.setShader(fMask.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
|
||||
paint.setShader(fMask.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), s));
|
||||
paint.setColor(SK_ColorRED);
|
||||
|
||||
// draw the mask using the shader and a color
|
||||
@ -135,7 +136,8 @@ DEF_SIMPLE_GM(hugebitmapshader, canvas, 100, 100) {
|
||||
}
|
||||
bitmap.setPixels(pixels);
|
||||
|
||||
paint.setShader(bitmap.makeShader(SkTileMode::kMirror, SkTileMode::kMirror));
|
||||
paint.setShader(bitmap.makeShader(SkTileMode::kMirror, SkTileMode::kMirror,
|
||||
SkSamplingOptions()));
|
||||
paint.setColor(SK_ColorRED);
|
||||
paint.setAntiAlias(true);
|
||||
canvas->drawCircle(50, 50, 50, paint);
|
||||
|
@ -174,9 +174,10 @@ protected:
|
||||
draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
|
||||
SkMatrix s;
|
||||
s.reset();
|
||||
fColorBitmapShader = fColorBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s);
|
||||
fAlpha8BitmapShader = fAlpha8Bitmap.makeShader(SkTileMode::kRepeat,
|
||||
SkTileMode::kRepeat, &s);
|
||||
fColorBitmapShader = fColorBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), s);
|
||||
fAlpha8BitmapShader = fAlpha8Bitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), s);
|
||||
fLinearGradientShader = make_linear_gradient_shader(squareLength);
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ DEF_SIMPLE_GM(sksl_sample_chaining, canvas, 380, 306) {
|
||||
auto nextRow = [&] { canvas->restore(); canvas->translate(0, 64 + 10); canvas->save(); };
|
||||
|
||||
auto draw = [&](std::initializer_list<EffectType> effectTypes) {
|
||||
auto shader = bmp.makeShader();
|
||||
auto shader = bmp.makeShader(SkSamplingOptions());
|
||||
|
||||
for (EffectType effectType : effectTypes) {
|
||||
SkRuntimeShaderBuilder builder(effects[effectType]);
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkBlendMode.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkFilterQuality.h"
|
||||
#include "include/core/SkFont.h"
|
||||
#include "include/core/SkFontTypes.h"
|
||||
#include "include/core/SkMatrix.h"
|
||||
@ -59,8 +58,10 @@ static void draw_gpu_only_message(SkCanvas* canvas) {
|
||||
SkMatrix localM;
|
||||
localM.setRotate(35.f);
|
||||
localM.postTranslate(10.f, 0.f);
|
||||
paint.setShader(bmp.makeShader(SkTileMode::kMirror, SkTileMode::kMirror, &localM));
|
||||
paint.setFilterQuality(kMedium_SkFilterQuality);
|
||||
paint.setShader(bmp.makeShader(SkTileMode::kMirror, SkTileMode::kMirror,
|
||||
SkSamplingOptions(SkFilterMode::kLinear,
|
||||
SkMipmapMode::kNearest),
|
||||
localM));
|
||||
canvas->drawPaint(paint);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,8 @@ static void rotated_checkerboard_shader(SkPaint* paint,
|
||||
SkMatrix matrix;
|
||||
matrix.setScale(0.75f, 0.75f);
|
||||
matrix.preRotate(30.0f);
|
||||
paint->setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &matrix));
|
||||
paint->setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), matrix));
|
||||
}
|
||||
|
||||
static void exercise_draw_pos_text(SkCanvas* canvas,
|
||||
|
@ -169,7 +169,8 @@ protected:
|
||||
m.preScale(3.0f, 3.0f);
|
||||
|
||||
SkPaint p;
|
||||
p.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m));
|
||||
p.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), m));
|
||||
fPaints.push_back(p);
|
||||
}
|
||||
{
|
||||
|
@ -38,9 +38,9 @@ DEF_SIMPLE_GM_CAN_FAIL(bitmap_subset_shader, canvas, errorMsg, 256, 256) {
|
||||
matrix.preRotate(30.0f);
|
||||
SkTileMode tm = SkTileMode::kRepeat;
|
||||
SkPaint paint;
|
||||
paint.setShader(leftBitmap.makeShader(tm, tm, &matrix));
|
||||
paint.setShader(leftBitmap.makeShader(tm, tm, SkSamplingOptions(), matrix));
|
||||
canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
|
||||
paint.setShader(rightBitmap.makeShader(tm, tm, &matrix));
|
||||
paint.setShader(rightBitmap.makeShader(tm, tm, SkSamplingOptions(), matrix));
|
||||
canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
|
||||
return skiagm::DrawResult::kOk;
|
||||
}
|
||||
|
@ -45,8 +45,7 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
||||
|
||||
static void setup(SkPaint* paint, const SkBitmap& bm, SkFilterQuality filter_level,
|
||||
SkTileMode tmx, SkTileMode tmy) {
|
||||
paint->setShader(bm.makeShader(tmx, tmy));
|
||||
paint->setFilterQuality(filter_level);
|
||||
paint->setShader(bm.makeShader(tmx, tmy, SkSamplingOptions(filter_level)));
|
||||
}
|
||||
|
||||
constexpr SkColorType gColorTypes[] = {
|
||||
|
@ -29,7 +29,8 @@ class TinyBitmapGM : public skiagm::GM {
|
||||
*bm.getAddr32(0, 0) = SkPackARGB32(0x80, 0x80, 0, 0);
|
||||
SkPaint paint;
|
||||
paint.setAlphaf(0.5f);
|
||||
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kMirror));
|
||||
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kMirror,
|
||||
SkSamplingOptions()));
|
||||
canvas->drawPaint(paint);
|
||||
}
|
||||
};
|
||||
|
@ -236,7 +236,8 @@ protected:
|
||||
const SkScalar h = SkIntToScalar(H);
|
||||
SkMatrix m;
|
||||
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
|
||||
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
|
||||
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), m);
|
||||
|
||||
SkPaint labelP;
|
||||
labelP.setAntiAlias(true);
|
||||
|
@ -110,7 +110,7 @@ private:
|
||||
|
||||
SkMatrix lm;
|
||||
lm.setScale(SkIntToScalar(16), SkIntToScalar(16));
|
||||
fBG = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
|
||||
fBG = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions(), lm);
|
||||
|
||||
SkBitmap srcBmp;
|
||||
srcBmp.allocN32Pixels(kSize, kSize);
|
||||
@ -123,7 +123,7 @@ private:
|
||||
pixels[kSize * y + x] = rowColor;
|
||||
}
|
||||
}
|
||||
fSrc = srcBmp.makeShader();
|
||||
fSrc = srcBmp.makeShader(SkSamplingOptions());
|
||||
SkBitmap dstBmp;
|
||||
dstBmp.allocN32Pixels(kSize, kSize);
|
||||
pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels());
|
||||
@ -135,7 +135,7 @@ private:
|
||||
pixels[kSize * y + x] = colColor;
|
||||
}
|
||||
}
|
||||
fDst = dstBmp.makeShader();
|
||||
fDst = dstBmp.makeShader(SkSamplingOptions());
|
||||
}
|
||||
|
||||
enum {
|
||||
|
@ -186,7 +186,8 @@ private:
|
||||
|
||||
SkMatrix lm;
|
||||
lm.setScale(SkIntToScalar(kCheckSize), SkIntToScalar(kCheckSize));
|
||||
fBGShader = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
|
||||
fBGShader = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(), lm);
|
||||
|
||||
SkPaint bmpPaint;
|
||||
const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar(kSize) / 2 };
|
||||
@ -206,7 +207,7 @@ private:
|
||||
7 * SkIntToScalar(kSize) / 8, 7 * SkIntToScalar(kSize) / 8};
|
||||
bmpCanvas.drawRect(rect, bmpPaint);
|
||||
|
||||
fBmpShader = bmp.makeShader();
|
||||
fBmpShader = bmp.makeShader(SkSamplingOptions());
|
||||
}
|
||||
|
||||
enum {
|
||||
|
@ -34,7 +34,8 @@ static sk_sp<SkShader> make_shader0(SkIPoint* size) {
|
||||
SkBitmap bm;
|
||||
decode_file(GetResourceAsData("images/dog.jpg"), &bm);
|
||||
*size = SkIPoint{bm.width(), bm.height()};
|
||||
return bm.makeShader();
|
||||
return bm.makeShader(SkSamplingOptions(SkFilterMode::kLinear,
|
||||
SkMipmapMode::kNone));
|
||||
}
|
||||
|
||||
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
|
||||
@ -241,7 +242,6 @@ struct PatchView : public Sample {
|
||||
|
||||
SkPaint paint;
|
||||
paint.setDither(true);
|
||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||
|
||||
canvas->translate(DX, DY);
|
||||
|
||||
|
@ -245,7 +245,8 @@ static sk_sp<SkShader> make_shader0(SkIPoint* size) {
|
||||
|
||||
decode_file("/skimages/logo.gif", &bm);
|
||||
size->set(bm.width(), bm.height());
|
||||
return bm.makeShader();
|
||||
return bm.makeShader(SkSamplingOptions(SkFilterMode::kLinear,
|
||||
SkMipmapMode::kNone));
|
||||
}
|
||||
|
||||
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
|
||||
@ -362,7 +363,6 @@ static void mesh_slide(SkCanvas* canvas) {
|
||||
|
||||
SkPaint paint;
|
||||
paint.setDither(true);
|
||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
|
||||
auto verts = SkVertices::MakeCopy(fRecs[i].fMode, fRecs[i].fCount,
|
||||
|
@ -34,7 +34,8 @@ static sk_sp<SkShader> make_shader0(SkIPoint* size) {
|
||||
pixels[0] = pixels[2] = color0;
|
||||
pixels[1] = pixels[3] = color1;
|
||||
|
||||
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
|
||||
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
|
||||
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNone));
|
||||
}
|
||||
|
||||
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
|
||||
@ -73,7 +74,6 @@ protected:
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
paint.setDither(true);
|
||||
paint.setFilterQuality(kLow_SkFilterQuality);
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
|
||||
auto verts = SkVertices::MakeCopy(fRecs[i].fMode, fRecs[i].fCount,
|
||||
|
@ -98,7 +98,7 @@ protected:
|
||||
const SkScalar h = SkIntToScalar(H);
|
||||
SkMatrix m;
|
||||
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
|
||||
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
|
||||
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, SkSamplingOptions(), m);
|
||||
|
||||
SkFont font;
|
||||
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
||||
|
@ -579,7 +579,7 @@ void SkBitmapDevice::drawDevice(SkBaseDevice* device, const SkPaint& paint) {
|
||||
draw.fRC = &fRCStack.rc();
|
||||
|
||||
SkPaint deviceAsShader = paint;
|
||||
deviceAsShader.setShader(src->fBitmap.makeShader());
|
||||
deviceAsShader.setShader(src->fBitmap.makeShader(SkSamplingOptions()));
|
||||
draw.drawBitmap(*src->fCoverage, SkMatrix::I(), nullptr, deviceAsShader);
|
||||
} else {
|
||||
this->INHERITED::drawDevice(device, paint);
|
||||
|
@ -148,6 +148,7 @@ sk_sp<SkShader> SkBitmap::makeShader(SkTileMode tmx, SkTileMode tmy,
|
||||
tmx, tmy, &sampling, lm);
|
||||
}
|
||||
|
||||
//#ifdef SK_SUPPORT_LEGACY_IMPLICIT_FILTERQUALITY
|
||||
sk_sp<SkShader> SkBitmap::makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix* lm) const {
|
||||
if (lm && !lm->invert(nullptr)) {
|
||||
return nullptr;
|
||||
@ -155,6 +156,7 @@ sk_sp<SkShader> SkBitmap::makeShader(SkTileMode tmx, SkTileMode tmy, const SkMat
|
||||
return SkImageShader::Make(SkMakeImageFromRasterBitmap(*this, kIfMutable_SkCopyPixelsMode),
|
||||
tmx, tmy, nullptr, lm);
|
||||
}
|
||||
//#endif
|
||||
|
||||
bool SkShaderBase::appendStages(const SkStageRec& rec) const {
|
||||
return this->onAppendStages(rec);
|
||||
|
@ -193,7 +193,7 @@ static sk_sp<SkShader> make_RGBW_shader() {
|
||||
bmp.pixmap().erase(SK_ColorGREEN, topLeft.makeOffset(1, 0));
|
||||
bmp.pixmap().erase(SK_ColorBLUE, topLeft.makeOffset(0, 1));
|
||||
bmp.pixmap().erase(SK_ColorWHITE, topLeft.makeOffset(1, 1));
|
||||
return bmp.makeShader();
|
||||
return bmp.makeShader(SkSamplingOptions());
|
||||
}
|
||||
|
||||
static void test_RuntimeEffect_Shaders(skiatest::Reporter* r, GrRecordingContext* rContext) {
|
||||
|
Loading…
Reference in New Issue
Block a user