add makeShader() to SkBitmap, and deprecate SkShader version

Bug: skia:8937
Change-Id: I42f011e04937a751222bd8ecc6c69b45cf9626a2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206681
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-04-08 13:20:23 -04:00 committed by Skia Commit-Bot
parent 7a2ff3c9a8
commit 50acf8f04b
64 changed files with 115 additions and 127 deletions

View File

@ -113,7 +113,7 @@ protected:
int w = 40;
int h = 40;
makebm(&fBmp, w, h);
fBmShader = SkShader::MakeBitmapShader(fBmp, SkTileMode::kRepeat, SkTileMode::kRepeat);
fBmShader = fBmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
int offset = 2;
int count = 0;
for (int j = 0; j < NY; ++j) {

View File

@ -141,7 +141,7 @@ protected:
SkPaint p2; // for drawVertices path
p2.setColor(0xFF000000);
p2.setFilterQuality(kLow_SkFilterQuality);
p2.setShader(SkShader::MakeBitmapShader(fAtlas, SkTileMode::kClamp, SkTileMode::kClamp));
p2.setShader(fAtlas.makeShader());
for (int i = 0; i < loops; ++i, ++fNumSaved) {
if (0 == i % kNumBeforeClear) {

View File

@ -295,8 +295,7 @@ protected:
srcBM.allocN32Pixels(10, 1);
srcBM.eraseColor(0xFF00FF00);
paint.setShader(SkShader::MakeBitmapShader(srcBM,
SkTileMode::kClamp, SkTileMode::kClamp));
paint.setShader(srcBM.makeShader());
}
for (int loop = 0; loop < loops; loop++) {
for (size_t i = 0; i < sizes; i++) {

View File

@ -59,9 +59,7 @@ protected:
draw_into_bitmap(fBitmap);
fPaint.setShader(SkShader::MakeBitmapShader(fBitmap,
SkTileMode::kRepeat,
SkTileMode::kRepeat));
fPaint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
}

View File

@ -51,7 +51,7 @@ public:
create_gradient(&bm);
fPaint.setShader(SkShader::MakeBitmapShader(bm, xTile, yTile));
fPaint.setShader(bm.makeShader(xTile, yTile));
fName.printf("constXTile_");

View File

@ -14,8 +14,7 @@ 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(SkShader::MakeBitmapShader(source, SkTileMode::kClamp,
SkTileMode::kClamp, nullptr));
paint.setShader(source.makeShader());
canvas->scale(15, 15);
for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) {
canvas->drawPatch(cubics, colors, texCoords, blend, paint);

View File

@ -13,7 +13,7 @@ void draw(SkCanvas* canvas) {
/* { 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(SkShader::MakeBitmapShader(source, SkTileMode::kClamp, SkTileMode::kClamp));
paint.setShader(source.makeShader());
canvas->scale(30, 30);
canvas->drawPatch(cubics, nullptr, texCoords, paint);
}

View File

@ -9,7 +9,7 @@ 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(SkShader::MakeBitmapShader(bitmap, SkTileMode::kMirror, SkTileMode::kMirror));
paint.setShader(bitmap.makeShader(SkTileMode::kMirror, SkTileMode::kMirror));
for (SkColor c : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
paint.setColor(c); // all components in color affect shader
canvas->drawCircle(50, 50, 50, paint);

View File

@ -225,7 +225,7 @@ static sk_sp<SkShader> make_fuzz_shader(Fuzz* fuzz, int depth) {
if (useMatrix) {
FuzzNiceMatrix(fuzz, &matrix);
}
return SkShader::MakeBitmapShader(bitmap, tmX, tmY, useMatrix ? &matrix : nullptr);
return bitmap.makeShader(tmX, tmY, useMatrix ? &matrix : nullptr);
case 5:
shader1 = make_fuzz_shader(fuzz, depth - 1); // limit recursion.
FuzzNiceMatrix(fuzz, &matrix);

View File

@ -111,7 +111,7 @@ static sk_sp<SkShader> make_bg_shader() {
0xCF, 0xCE);
const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(6), SkIntToScalar(6));
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
}
DEF_SIMPLE_GM(aarectmodes, canvas, 640, 480) {

View File

@ -9,7 +9,6 @@
#include "SkCanvas.h"
#include "SkShader.h"
/** This GM draws with invalid paints. It should draw nothing other than the background. */
class BadPaintGM : public skiagm::GM {
public:
@ -32,13 +31,11 @@ protected:
// Empty bitmap.
fPaints.push_back().setColor(SK_ColorGREEN);
fPaints.back().setShader(SkShader::MakeBitmapShader(emptyBmp, SkTileMode::kClamp,
SkTileMode::kClamp));
fPaints.back().setShader(emptyBmp.makeShader());
// Non-invertible local matrix.
fPaints.push_back().setColor(SK_ColorGREEN);
fPaints.back().setShader(SkShader::MakeBitmapShader(blueBmp, SkTileMode::kClamp,
SkTileMode::kClamp, &badMatrix));
fPaints.back().setShader(blueBmp.makeShader(&badMatrix));
}
void onDraw(SkCanvas* canvas) override {

View File

@ -54,7 +54,7 @@ DEF_SIMPLE_GM_BG(bigmatrix, canvas, 50, 50, ToolUtils::color_to_565(0xFF66AA99))
SkMatrix s;
s.reset();
s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
paint.setShader(SkShader::MakeBitmapShader(bmp, SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
paint.setShader(bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
paint.setAntiAlias(false);
paint.setFilterQuality(kLow_SkFilterQuality);
rect.setLTRB(pt.fX - small, pt.fY - small, pt.fX + small, pt.fY + small);

View File

@ -67,8 +67,7 @@ protected:
}
canvas->save();
paint.setShader(SkShader::MakeBitmapShader(fBitmap, SkTileMode::kClamp,
SkTileMode::kClamp, &s));
paint.setShader(fBitmap.makeShader(&s));
// draw the shader with a bitmap mask
canvas->drawBitmap(fMask, 0, 0, &paint);
@ -90,8 +89,7 @@ protected:
canvas->translate(0, 25);
paint.setShader(SkShader::MakeBitmapShader(fMask, SkTileMode::kRepeat,
SkTileMode::kRepeat, &s));
paint.setShader(fMask.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s));
paint.setColor(SK_ColorRED);
// draw the mask using the shader and a color
@ -129,7 +127,7 @@ DEF_SIMPLE_GM(hugebitmapshader, canvas, 100, 100) {
}
bitmap.setPixels(pixels);
paint.setShader(SkShader::MakeBitmapShader(bitmap, SkTileMode::kMirror, SkTileMode::kMirror));
paint.setShader(bitmap.makeShader(SkTileMode::kMirror, SkTileMode::kMirror));
paint.setColor(SK_ColorRED);
paint.setAntiAlias(true);
canvas->drawCircle(50, 50, 50, paint);

View File

@ -74,7 +74,7 @@ private:
for (size_t q = 0; q < SK_ARRAY_COUNT(kQualities); ++q) {
constexpr SkTileMode kTM = SkTileMode::kRepeat;
bmpPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTM, kTM, &lm));
bmpPaint.setShader(fBmp.makeShader(kTM, kTM, &lm));
bmpPaint.setFilterQuality(kQualities[q].fQuality);
canvas->drawRect(rect, bmpPaint);
canvas->drawString(kQualities[q].fName, 20, 40, font, textPaint);

View File

@ -84,7 +84,7 @@ protected:
s.setScale(8, 8);
s.postTranslate(SLIDE_SIZE / 2, SLIDE_SIZE / 2);
SkPaint paint;
paint.setShader(SkShader::MakeBitmapShader(bmp, fMode, fMode, &s));
paint.setShader(bmp.makeShader(fMode, fMode, &s));
if (fHQ) {
paint.setFilterQuality(kHigh_SkFilterQuality);

View File

@ -108,7 +108,7 @@ protected:
const SkScalar h = SkIntToScalar(H);
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
auto s = SkShader::MakeBitmapShader(fBG, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
SkFont labelFont(ToolUtils::create_portable_typeface());

View File

@ -161,10 +161,9 @@ protected:
draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
SkMatrix s;
s.reset();
fColorBitmapShader = SkShader::MakeBitmapShader(fColorBitmap, SkTileMode::kRepeat,
SkTileMode::kRepeat, &s);
fAlpha8BitmapShader = SkShader::MakeBitmapShader(fAlpha8Bitmap, SkTileMode::kRepeat,
SkTileMode::kRepeat, &s);
fColorBitmapShader = fColorBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s);
fAlpha8BitmapShader = fAlpha8Bitmap.makeShader(SkTileMode::kRepeat,
SkTileMode::kRepeat, &s);
fLinearGradientShader = make_linear_gradient_shader(squareLength);
}

View File

@ -104,7 +104,7 @@ DEF_SIMPLE_GM(gamma, canvas, 850, 200) {
canvas->save();
// Black/white dither, pixel perfect. This is ground truth.
p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt));
p.setShader(ditherBmp.makeShader(rpt, rpt));
p.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality);
nextRect("Dither", "Reference");
@ -113,19 +113,19 @@ DEF_SIMPLE_GM(gamma, canvas, 850, 200) {
// the raster pipeline into *not* snapping to nearest.
SkMatrix offsetMatrix = SkMatrix::Concat(
SkMatrix::MakeScale(-1.0f), SkMatrix::MakeTrans(0.5f, 0.0f));
p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &offsetMatrix));
p.setShader(ditherBmp.makeShader(rpt, rpt, &offsetMatrix));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("Dither", "Bilerp");
// Black/white dither, scaled down by 2x. Tests minification.
SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f);
p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix));
p.setShader(ditherBmp.makeShader(rpt, rpt, &scaleMatrix));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("Dither", "Scale");
// 25%/75% dither, scaled down by 2x. Tests ALL aspects of minification. Specifically, are
// sRGB sources decoded to linear before computing mipmaps?
p.setShader(SkShader::MakeBitmapShader(mipmapBmp, rpt, rpt, &scaleMatrix));
p.setShader(mipmapBmp.makeShader(rpt, rpt, &scaleMatrix));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("MipMaps", nullptr);
@ -188,12 +188,12 @@ DEF_SIMPLE_GM(gamma, canvas, 850, 200) {
nextBitmap(srgbGreyBmp, "sRGB BMP");
// Bitmap wrapped in a shader (linear):
p.setShader(SkShader::MakeBitmapShader(linearGreyBmp, rpt, rpt));
p.setShader(linearGreyBmp.makeShader(rpt, rpt));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("Lnr BMP", "Shader");
// Bitmap wrapped in a shader (sRGB):
p.setShader(SkShader::MakeBitmapShader(srgbGreyBmp, rpt, rpt));
p.setShader(srgbGreyBmp.makeShader(rpt, rpt));
p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality);
nextRect("sRGB BMP", "Shader");

View File

@ -107,7 +107,7 @@ protected:
SkScalar scale = 11*SK_Scalar1/12;
m.setScale(scale, scale);
}
paint.setShader(SkShader::MakeBitmapShader(getBitmap(), fMode, fMode, &m));
paint.setShader(getBitmap().makeShader(fMode, fMode, &m));
paint.setFilterQuality(fDoFilter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
canvas->translate(SkIntToScalar(50), SkIntToScalar(50));

View File

@ -45,8 +45,7 @@ static void draw_gpu_only_message(SkCanvas* canvas) {
SkMatrix localM;
localM.setRotate(35.f);
localM.postTranslate(10.f, 0.f);
paint.setShader(SkShader::MakeBitmapShader(
bmp, SkTileMode::kMirror, SkTileMode::kMirror, &localM));
paint.setShader(bmp.makeShader(SkTileMode::kMirror, SkTileMode::kMirror, &localM));
paint.setFilterQuality(kMedium_SkFilterQuality);
canvas->drawPaint(paint);
}

View File

@ -63,7 +63,7 @@ static sk_sp<SkShader> make_bg_shader() {
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
}
namespace skiagm {

View File

@ -96,10 +96,8 @@ protected:
const SkMatrix& ctm = canvas->getTotalMatrix();
SkPaint paint;
sk_sp<SkShader> diffuseShader = SkShader::MakeBitmapShader(fDiffuse,
SkTileMode::kClamp, SkTileMode::kClamp, &matrix);
sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(fNormalMaps[mapType],
SkTileMode::kClamp, SkTileMode::kClamp, &matrix);
sk_sp<SkShader> diffuseShader = fDiffuse.makeShader(&matrix);
sk_sp<SkShader> normalMap = fNormalMaps[mapType].makeShader(&matrix);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap),
ctm);
paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource),

View File

@ -79,8 +79,7 @@ protected:
SkBitmap opaqueDiffuseMap = ToolUtils::create_checkerboard_bitmap(
kTexSize, kTexSize, SK_ColorBLACK, 0xFF808080, 8);
fOpaqueDiffuse = SkShader::MakeBitmapShader(opaqueDiffuseMap, SkTileMode::kClamp,
SkTileMode::kClamp, &matrix);
fOpaqueDiffuse = opaqueDiffuseMap.makeShader(&matrix);
SkBitmap translucentDiffuseMap =
ToolUtils::create_checkerboard_bitmap(kTexSize,
@ -88,13 +87,10 @@ protected:
SkColorSetARGB(0x55, 0x00, 0x00, 0x00),
SkColorSetARGB(0x55, 0x80, 0x80, 0x80),
8);
fTranslucentDiffuse = SkShader::MakeBitmapShader(translucentDiffuseMap,
SkTileMode::kClamp,
SkTileMode::kClamp, &matrix);
fTranslucentDiffuse = translucentDiffuseMap.makeShader(&matrix);
SkBitmap normalMap = make_frustum_normalmap(kTexSize);
fNormalMapShader = SkShader::MakeBitmapShader(normalMap, SkTileMode::kClamp,
SkTileMode::kClamp, &matrix);
fNormalMapShader = normalMap.makeShader(&matrix);
}

View File

@ -49,7 +49,7 @@ static sk_sp<SkShader> make_bg_shader(int checkSize) {
SkIntToScalar(checkSize), SkIntToScalar(checkSize));
canvas.drawRect(rect1, paint);
canvas.drawRect(rect0, paint);
return SkShader::MakeBitmapShader(bmp, SkTileMode::kRepeat, SkTileMode::kRepeat);
return bmp.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
}
class ModeColorFilterGM : public GM {

View File

@ -179,7 +179,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
SkAssertResult(pm.erase({1,0,0,1} /*in p3*/));
SkPaint paint;
paint.setShader(SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat));
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
canvas->drawRect({10,10,70,70}, paint);
compare_pixel("drawBitmapAsShader P3 red, from SkPixmap::erase",
@ -345,8 +345,7 @@ DEF_SIMPLE_GM(p3, canvas, 450, 1300) {
SkPaint as_shader;
as_shader.setColor4f({1,0,0,1}, p3.get());
as_shader.setFilterQuality(kLow_SkFilterQuality);
as_shader.setShader(SkShader::MakeBitmapShader(bm, SkTileMode::kClamp
, SkTileMode::kClamp));
as_shader.setShader(bm.makeShader());
canvas->drawBitmap(bm, 10,10, &as_bitmap);
compare_pixel("A8 sprite bitmap P3 red",

View File

@ -43,7 +43,7 @@ protected:
fBitmap = ToolUtils::create_checkerboard_bitmap(
kCellSize, kCellSize, SK_ColorBLUE, SK_ColorYELLOW, kCellSize / 10);
fBitmapShader = SkShader::MakeBitmapShader(fBitmap, SkTileMode::kClamp, SkTileMode::kClamp);
fBitmapShader = fBitmap.makeShader();
SkPoint pts1[] = {
{ 0, 0 },
{ SkIntToScalar(kCellSize), SkIntToScalar(kCellSize) }

View File

@ -162,7 +162,7 @@ private:
canvas->translate(fSceneSize * 1.1f, 0);
auto bitmapShader = SkShader::MakeBitmapShader(fBitmap,
auto bitmapShader = fBitmap.makeShader(
kTileConfigs[tileMode].tmx,
kTileConfigs[tileMode].tmy,
fUseLocalMatrixWrapper

View File

@ -72,7 +72,7 @@ protected:
createTexture();
fShader = SkShader::MakeBitmapShader(fTexture, SkTileMode::kRepeat, SkTileMode::kRepeat);
fShader = fTexture.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
}
void createMaskFilter() {

View File

@ -100,8 +100,7 @@ protected:
SkPaint fillPaint;
fillPaint.setAntiAlias(true);
fillPaint.setFilterQuality(kLow_SkFilterQuality);
fillPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTileModes[tm0],
kTileModes[tm1], &localM));
fillPaint.setShader(fBmp.makeShader(kTileModes[tm0], kTileModes[tm1], &localM));
constexpr char kText[] = "B";
canvas->drawString(kText, 0, 0, font, fillPaint);

View File

@ -108,9 +108,7 @@ protected:
canvas->drawBitmap(fBitmap, 10, 10, &paint);
canvas->translate(0, 40);
paint.setShader(SkShader::MakeBitmapShader(
fBitmap, SkTileMode::kRepeat,
SkTileMode::kRepeat));
paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
// see bug.skia.org/562 (shows bug as reported)
paint.setStyle(SkPaint::kFill_Style);

View File

@ -23,8 +23,7 @@ static void rotated_checkerboard_shader(SkPaint* paint,
SkMatrix matrix;
matrix.setScale(0.75f, 0.75f);
matrix.preRotate(30.0f);
paint->setShader(
SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat, &matrix));
paint->setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &matrix));
}
static void exercise_draw_pos_text(SkCanvas* canvas,

View File

@ -153,10 +153,7 @@ protected:
m.preScale(3.0f, 3.0f);
SkPaint p;
p.setShader(SkShader::MakeBitmapShader(bm,
SkTileMode::kRepeat,
SkTileMode::kRepeat,
&m));
p.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m));
fPaints.push_back(p);
}
{

View File

@ -31,9 +31,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(SkShader::MakeBitmapShader(leftBitmap, tm, tm, &matrix));
paint.setShader(leftBitmap.makeShader(tm, tm, &matrix));
canvas->drawRect(SkRect::MakeWH(256.0f, 128.0f), paint);
paint.setShader(SkShader::MakeBitmapShader(rightBitmap, tm, tm, &matrix));
paint.setShader(rightBitmap.makeShader(tm, tm, &matrix));
canvas->drawRect(SkRect::MakeXYWH(0, 128.0f, 256.0f, 128.0f), paint);
return skiagm::DrawResult::kOk;
}

View File

@ -62,8 +62,7 @@ protected:
mat.setScale(121.f/360.f, 93.f/288.f);
mat.postTranslate(-72, -72);
paint.setShader(SkShader::MakeBitmapShader(fBitmap, SkTileMode::kRepeat,
SkTileMode::kRepeat, &mat));
paint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &mat));
canvas->drawRect({ 8, 8, 1008, 608 }, paint);
}

View File

@ -37,7 +37,7 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
static void setup(SkPaint* paint, const SkBitmap& bm, bool filter,
SkTileMode tmx, SkTileMode tmy) {
paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
paint->setShader(bm.makeShader(tmx, tmy));
paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
}
@ -159,7 +159,7 @@ constexpr int gHeight = 32;
static sk_sp<SkShader> make_bm(SkTileMode tx, SkTileMode ty) {
SkBitmap bm;
makebm(&bm, kN32_SkColorType, gWidth, gHeight);
return SkShader::MakeBitmapShader(bm, tx, ty);
return bm.makeShader(tx, ty);
}
static sk_sp<SkShader> make_grad(SkTileMode tx, SkTileMode ty) {

View File

@ -36,7 +36,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(SkShader::MakeBitmapShader(bm, tmx, tmy));
paint->setShader(bm.makeShader(tmx, tmy));
paint->setFilterQuality(filter_level);
}
@ -159,7 +159,7 @@ constexpr int gHeight = 32;
static sk_sp<SkShader> make_bm(SkTileMode tx, SkTileMode ty) {
SkBitmap bm;
makebm(&bm, kN32_SkColorType, gWidth, gHeight);
return SkShader::MakeBitmapShader(bm, tx, ty);
return bm.makeShader(tx, ty);
}
static sk_sp<SkShader> make_grad(SkTileMode tx, SkTileMode ty) {

View File

@ -37,7 +37,7 @@ protected:
SkBitmap bm = make_bitmap();
SkPaint paint;
paint.setAlphaf(0.5f);
paint.setShader(SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kMirror));
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kMirror));
canvas->drawPaint(paint);
}

View File

@ -42,7 +42,7 @@ static sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int si
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
}
// http://crrev.com/834303005

View File

@ -222,7 +222,7 @@ protected:
const SkScalar h = SkIntToScalar(H);
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
auto s = SkShader::MakeBitmapShader(fBG, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
SkPaint labelP;
labelP.setAntiAlias(true);

View File

@ -95,7 +95,7 @@ private:
SkMatrix lm;
lm.setScale(SkIntToScalar(16), SkIntToScalar(16));
fBG = SkShader::MakeBitmapShader(bg, SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
fBG = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
SkBitmap srcBmp;
srcBmp.allocN32Pixels(kSize, kSize);
@ -108,7 +108,7 @@ private:
pixels[kSize * y + x] = rowColor;
}
}
fSrc = SkShader::MakeBitmapShader(srcBmp, SkTileMode::kClamp, SkTileMode::kClamp);
fSrc = srcBmp.makeShader();
SkBitmap dstBmp;
dstBmp.allocN32Pixels(kSize, kSize);
pixels = reinterpret_cast<SkPMColor*>(dstBmp.getPixels());
@ -120,7 +120,7 @@ private:
pixels[kSize * y + x] = colColor;
}
}
fDst = SkShader::MakeBitmapShader(dstBmp, SkTileMode::kClamp, SkTileMode::kClamp);
fDst = dstBmp.makeShader();
}
enum {

View File

@ -169,7 +169,7 @@ private:
SkMatrix lm;
lm.setScale(SkIntToScalar(kCheckSize), SkIntToScalar(kCheckSize));
fBGShader = SkShader::MakeBitmapShader(bg, SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
fBGShader = bg.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &lm);
SkPaint bmpPaint;
const SkPoint kCenter = { SkIntToScalar(kSize) / 2, SkIntToScalar(kSize) / 2 };
@ -189,7 +189,7 @@ private:
7 * SkIntToScalar(kSize) / 8, 7 * SkIntToScalar(kSize) / 8};
bmpCanvas.drawRect(rect, bmpPaint);
fBmpShader = SkShader::MakeBitmapShader(bmp, SkTileMode::kClamp, SkTileMode::kClamp);
fBmpShader = bmp.makeShader();
}
enum {

View File

@ -13,12 +13,14 @@
#include "SkPixmap.h"
#include "SkPoint.h"
#include "SkRefCnt.h"
#include "SkTileMode.h"
struct SkMask;
struct SkIRect;
struct SkRect;
class SkPaint;
class SkPixelRef;
class SkShader;
class SkString;
/** \class SkBitmap
@ -1094,6 +1096,11 @@ public:
*/
bool peekPixels(SkPixmap* pixmap) const;
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy,
const SkMatrix* localMatrix = nullptr) const;
// defaults to Clamp in x, and y
sk_sp<SkShader> makeShader(const SkMatrix* localMatrix = nullptr) const;
/** Asserts if internal values are illegal or inconsistent. Only available if
SK_DEBUG is defined at compile time.
*/

View File

@ -28,6 +28,10 @@ class SkRasterPipeline;
class GrContext;
class GrFragmentProcessor;
#ifndef SK_SUPPORT_LEGACY_BITMAPSHADER_FACTORY
#define SK_SUPPORT_LEGACY_BITMAPSHADER_FACTORY
#endif
/** \class SkShader
*
* Shaders specify the source color(s) for what is being drawn. If a paint
@ -211,7 +215,9 @@ public:
static sk_sp<SkShader> MakeMixer(sk_sp<SkShader> dst, sk_sp<SkShader> src, sk_sp<SkMixer>);
/** Call this to create a new shader that will draw with the specified bitmap.
#ifdef SK_SUPPORT_LEGACY_BITMAPSHADER_FACTORY
/** DEPRECATED. call bitmap.makeShader()
* Call this to create a new shader that will draw with the specified bitmap.
*
* If the bitmap cannot be used (e.g. has no pixels, or its dimensions
* exceed implementation limits (currently at 64K - 1)) then SkEmptyShader
@ -227,6 +233,7 @@ public:
*/
static sk_sp<SkShader> MakeBitmapShader(const SkBitmap& src, SkTileMode tmx, SkTileMode tmy,
const SkMatrix* localMatrix = nullptr);
#endif
#ifdef SK_SUPPORT_LEGACY_TILEMODE_ENUM
static sk_sp<SkShader> MakeBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix = nullptr) {

View File

@ -65,7 +65,7 @@ static sk_sp<SkShader> make_bg_shader() {
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
}
class AARectsModesView : public Sample {

View File

@ -59,8 +59,7 @@ protected:
SkPaint bluePaint;
bluePaint.setARGB(0xff, 0x0, 0x0, 0xff);
SkPaint bmpPaint;
bmpPaint.setShader(SkShader::MakeBitmapShader(fBitmap, SkTileMode::kRepeat,
SkTileMode::kRepeat));
bmpPaint.setShader(fBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat));
bluePaint.setStrokeWidth(3);
bmpPaint.setStrokeWidth(3);

View File

@ -39,10 +39,7 @@ public:
SkMatrix matrix;
matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
fShaders.push_back(SkShader::MakeBitmapShader(bm,
SkTileMode::kClamp,
SkTileMode::kClamp,
&matrix));
fShaders.push_back(bm.makeShader(&matrix));
} else {
break;
}

View File

@ -64,7 +64,7 @@ static sk_sp<SkShader> make_bg_shader() {
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
}
class HairModesView : public Sample {

View File

@ -38,17 +38,14 @@ public:
fRect = SkRect::MakeIWH(diffuseBitmap.width(), diffuseBitmap.height());
fDiffuseShader = SkShader::MakeBitmapShader(diffuseBitmap,
SkTileMode::kClamp, SkTileMode::kClamp);
fDiffuseShader = diffuseBitmap.makeShader();
}
{
SkBitmap normalBitmap;
SkAssertResult(GetResourceAsBitmap("images/brickwork_normal-map.jpg", &normalBitmap));
sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(normalBitmap,
SkTileMode::kClamp,
SkTileMode::kClamp);
sk_sp<SkShader> normalMap = normalBitmap.makeShader();
fNormalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap), SkMatrix::I());
}
}

View File

@ -132,12 +132,10 @@ protected:
SkMatrix m;
m.setRSXform(xforms[i]);
sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(fAtlas, SkTileMode::kClamp,
SkTileMode::kClamp, &normalMat);
sk_sp<SkShader> normalMap = fAtlas.makeShader(&normalMat);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(
std::move(normalMap), m);
sk_sp<SkShader> diffuseShader = SkShader::MakeBitmapShader(fAtlas,
SkTileMode::kClamp, SkTileMode::kClamp, &diffMat);
sk_sp<SkShader> diffuseShader = fAtlas.makeShader(&diffMat);
paint.setShader(SkLightingShader::Make(std::move(diffuseShader),
std::move(normalSource), fLights));

View File

@ -33,7 +33,7 @@ static sk_sp<SkShader> make_shader0(SkIPoint* size) {
// decode_file("/skimages/progressivejpg.jpg", &bm);
decode_file("/skimages/logo.png", &bm);
size->set(bm.width(), bm.height());
return SkShader::MakeBitmapShader(bm, SkTileMode::kClamp, SkTileMode::kClamp);
return bm.makeShader();
}
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {

View File

@ -35,7 +35,7 @@ static void make_paint(SkPaint* paint, SkTileMode tm) {
SkBitmap bm;
make_bitmap(&bm);
paint->setShader(SkShader::MakeBitmapShader(bm, tm, tm));
paint->setShader(bm.makeShader(tm, tm));
}
class RepeatTileView : public Sample {

View File

@ -29,7 +29,7 @@ static sk_sp<SkShader> make_bitmapfade(const SkBitmap& bm) {
colors[1] = SkColorSetARGB(0, 0, 0, 0);
auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
auto shaderB = SkShader::MakeBitmapShader(bm, SkTileMode::kClamp, SkTileMode::kClamp);
auto shaderB = bm.makeShader();
return SkShader::MakeComposeShader(std::move(shaderB), std::move(shaderA), SkBlendMode::kDstIn);
}

View File

@ -246,7 +246,7 @@ static sk_sp<SkShader> make_shader0(SkIPoint* size) {
decode_file("/skimages/logo.gif", &bm);
size->set(bm.width(), bm.height());
return SkShader::MakeBitmapShader(bm, SkTileMode::kClamp, SkTileMode::kClamp);
return bm.makeShader();
}
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {

View File

@ -42,7 +42,7 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
}
static void setup(SkPaint* paint, const SkBitmap& bm, bool filter, SkTileMode tmx, SkTileMode tmy) {
paint->setShader(SkShader::MakeBitmapShader(bm, tmx, tmy));
paint->setShader(bm.makeShader(tmx, tmy));
paint->setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
}

View File

@ -34,7 +34,7 @@ static sk_sp<SkShader> make_shader0(SkIPoint* size) {
pixels[0] = pixels[2] = color0;
pixels[1] = pixels[3] = color1;
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
}
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {

View File

@ -104,7 +104,7 @@ protected:
const SkScalar h = SkIntToScalar(H);
SkMatrix m;
m.setScale(SkIntToScalar(6), SkIntToScalar(6));
auto s = SkShader::MakeBitmapShader(fBG, SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
auto s = fBG.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &m);
SkFont font;
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);

View File

@ -566,8 +566,7 @@ void SkBitmapDevice::drawDevice(SkBaseDevice* device, int x, int y, const SkPain
draw.fMatrix = &SkMatrix::I();
draw.fRC = &fRCStack.rc();
SkPaint paint(origPaint);
paint.setShader(SkShader::MakeBitmapShader(src->fBitmap, SkTileMode::kClamp,
SkTileMode::kClamp, nullptr));
paint.setShader(src->fBitmap.makeShader());
draw.drawBitmap(*src->fCoverage.get(),
SkMatrix::MakeTrans(SkIntToScalar(x),SkIntToScalar(y)), nullptr, paint);
} else {

View File

@ -142,6 +142,7 @@ sk_sp<SkShader> SkShader::MakeEmptyShader() { return sk_make_sp<SkEmptyShader>()
sk_sp<SkShader> SkShader::MakeColorShader(SkColor color) { return sk_make_sp<SkColorShader>(color); }
#ifdef SK_SUPPORT_LEGACY_BITMAPSHADER_FACTORY
sk_sp<SkShader> SkShader::MakeBitmapShader(const SkBitmap& src, SkTileMode tmx, SkTileMode tmy,
const SkMatrix* localMatrix) {
if (localMatrix && !localMatrix->invert(nullptr)) {
@ -149,6 +150,18 @@ sk_sp<SkShader> SkShader::MakeBitmapShader(const SkBitmap& src, SkTileMode tmx,
}
return SkMakeBitmapShader(src, tmx, tmy, localMatrix, kIfMutable_SkCopyPixelsMode);
}
#endif
sk_sp<SkShader> SkBitmap::makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix* lm) const {
if (lm && !lm->invert(nullptr)) {
return nullptr;
}
return SkMakeBitmapShader(*this, tmx, tmy, lm, kIfMutable_SkCopyPixelsMode);
}
sk_sp<SkShader> SkBitmap::makeShader(const SkMatrix* lm) const {
return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, lm);
}
#ifdef SK_SUPPORT_LEGACY_TILEMODE_ENUM
sk_sp<SkShader> SkShader::MakePictureShader(sk_sp<SkPicture> src, TileMode tmx, TileMode tmy,

View File

@ -476,7 +476,7 @@ static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& d,
pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight));
pts[3].set(0, SkIntToScalar(d.fHeight));
SkPaint paint;
paint.setShader(SkShader::MakeBitmapShader(d.fBitmap, SkTileMode::kClamp, SkTileMode::kClamp));
paint.setShader(d.fBitmap.makeShader());
canvas->drawVertices(SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, pts, pts,
nullptr),
SkBlendMode::kModulate, paint);

View File

@ -139,8 +139,7 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
SkIntToScalar(239),
0, 0, SK_Scalar1);
SkPaint paint;
paint.setShader(SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat,
&matrix));
paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &matrix));
SkRect r = SkRect::MakeXYWH(681, 239, 695, 253);
c.drawRect(r, paint);

View File

@ -603,12 +603,10 @@ DEF_TEST(Serialization, reporter) {
normals.allocN32Pixels(kTexSize, kTexSize);
ToolUtils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexSize, kTexSize));
sk_sp<SkShader> normalMap = SkShader::MakeBitmapShader(normals, SkTileMode::kClamp,
SkTileMode::kClamp, &matrix);
sk_sp<SkShader> normalMap = normals.makeShader(&matrix);
sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap),
ctm);
sk_sp<SkShader> diffuseShader = SkShader::MakeBitmapShader(diffuse,
SkTileMode::kClamp, SkTileMode::kClamp, &matrix);
sk_sp<SkShader> diffuseShader = diffuse.makeShader(&matrix);
sk_sp<SkShader> lightingShader = SkLightingShader::Make(diffuseShader,
normalSource,

View File

@ -18,7 +18,7 @@ static void test_bitmap(skiatest::Reporter* reporter) {
bmp.setInfo(info);
// test 1: bitmap without pixel data
auto shader = SkShader::MakeBitmapShader(bmp, SkTileMode::kClamp, SkTileMode::kClamp);
auto shader = bmp.makeShader(SkTileMode::kClamp, SkTileMode::kClamp);
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, !shader->isOpaque());
@ -26,19 +26,19 @@ static void test_bitmap(skiatest::Reporter* reporter) {
bmp.allocPixels(info);
// test 2: not opaque by default
shader = SkShader::MakeBitmapShader(bmp, SkTileMode::kClamp, SkTileMode::kClamp);
shader = bmp.makeShader();
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, !shader->isOpaque());
// test 3: explicitly opaque
bmp.setAlphaType(kOpaque_SkAlphaType);
shader = SkShader::MakeBitmapShader(bmp, SkTileMode::kClamp, SkTileMode::kClamp);
shader = bmp.makeShader();
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, shader->isOpaque());
// test 4: explicitly not opaque
bmp.setAlphaType(kPremul_SkAlphaType);
shader = SkShader::MakeBitmapShader(bmp, SkTileMode::kClamp, SkTileMode::kClamp);
shader = bmp.makeShader();
REPORTER_ASSERT(reporter, shader);
REPORTER_ASSERT(reporter, !shader->isOpaque());
}

View File

@ -45,7 +45,7 @@ DEF_TEST(Shader_isAImage, reporter) {
const SkTileMode tmx = SkTileMode::kRepeat;
const SkTileMode tmy = SkTileMode::kMirror;
auto shader0 = SkShader::MakeBitmapShader(bm, tmx, tmy, &localM);
auto shader0 = bm.makeShader(tmx, tmy, &localM);
auto shader1 = SkImage::MakeFromBitmap(bm)->makeShader(tmx, tmy, &localM);
check_isaimage(reporter, shader0.get(), W, H, tmx, tmy, localM);

View File

@ -83,7 +83,7 @@ sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
return SkShader::MakeBitmapShader(bm, SkTileMode::kRepeat, SkTileMode::kRepeat);
return bm.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat);
}
SkBitmap create_checkerboard_bitmap(int w, int h, SkColor c1, SkColor c2, int checkSize) {