diff --git a/bench/AlternatingColorPatternBench.cpp b/bench/AlternatingColorPatternBench.cpp index 639f1f6684..b2735cf030 100644 --- a/bench/AlternatingColorPatternBench.cpp +++ b/bench/AlternatingColorPatternBench.cpp @@ -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) { diff --git a/bench/GameBench.cpp b/bench/GameBench.cpp index ef1595f364..4096e0dd84 100644 --- a/bench/GameBench.cpp +++ b/bench/GameBench.cpp @@ -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) { diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp index 4dcb3b74f9..0c30dc049e 100644 --- a/bench/RectBench.cpp +++ b/bench/RectBench.cpp @@ -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++) { diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp index ccea88d27b..adec4f44b9 100644 --- a/bench/RepeatTileBench.cpp +++ b/bench/RepeatTileBench.cpp @@ -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)); } diff --git a/bench/TileBench.cpp b/bench/TileBench.cpp index 0ce19aeaa6..067958795d 100644 --- a/bench/TileBench.cpp +++ b/bench/TileBench.cpp @@ -51,7 +51,7 @@ public: create_gradient(&bm); - fPaint.setShader(SkShader::MakeBitmapShader(bm, xTile, yTile)); + fPaint.setShader(bm.makeShader(xTile, yTile)); fName.printf("constXTile_"); diff --git a/docs/examples/Canvas_drawPatch.cpp b/docs/examples/Canvas_drawPatch.cpp index b888fd4c6a..83c3a81623 100644 --- a/docs/examples/Canvas_drawPatch.cpp +++ b/docs/examples/Canvas_drawPatch.cpp @@ -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); diff --git a/docs/examples/Canvas_drawPatch_2_b.cpp b/docs/examples/Canvas_drawPatch_2_b.cpp index 5863303e5f..bb8175ab56 100644 --- a/docs/examples/Canvas_drawPatch_2_b.cpp +++ b/docs/examples/Canvas_drawPatch_2_b.cpp @@ -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); } diff --git a/docs/examples/Shader_Methods_b.cpp b/docs/examples/Shader_Methods_b.cpp index 98885aaeb4..f04ed31936 100644 --- a/docs/examples/Shader_Methods_b.cpp +++ b/docs/examples/Shader_Methods_b.cpp @@ -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); diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index c88fddf011..891e0de09e 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -225,7 +225,7 @@ static sk_sp 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); diff --git a/gm/aarectmodes.cpp b/gm/aarectmodes.cpp index dbb6afb7a1..9a39d04360 100644 --- a/gm/aarectmodes.cpp +++ b/gm/aarectmodes.cpp @@ -111,7 +111,7 @@ static sk_sp 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) { diff --git a/gm/badpaint.cpp b/gm/badpaint.cpp index a1010b430a..c0e531708b 100644 --- a/gm/badpaint.cpp +++ b/gm/badpaint.cpp @@ -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 { diff --git a/gm/bigmatrix.cpp b/gm/bigmatrix.cpp index fc2ea950ff..e54e04ba84 100644 --- a/gm/bigmatrix.cpp +++ b/gm/bigmatrix.cpp @@ -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); diff --git a/gm/bitmapshader.cpp b/gm/bitmapshader.cpp index 98c864b93b..7143160a04 100644 --- a/gm/bitmapshader.cpp +++ b/gm/bitmapshader.cpp @@ -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); diff --git a/gm/bmpfilterqualityrepeat.cpp b/gm/bmpfilterqualityrepeat.cpp index 071b319a0a..611420cc81 100644 --- a/gm/bmpfilterqualityrepeat.cpp +++ b/gm/bmpfilterqualityrepeat.cpp @@ -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); diff --git a/gm/clippedbitmapshaders.cpp b/gm/clippedbitmapshaders.cpp index 583abb7c10..88499b1c73 100644 --- a/gm/clippedbitmapshaders.cpp +++ b/gm/clippedbitmapshaders.cpp @@ -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); diff --git a/gm/coloremoji_blendmodes.cpp b/gm/coloremoji_blendmodes.cpp index b3f3f13a57..dccf55a45c 100644 --- a/gm/coloremoji_blendmodes.cpp +++ b/gm/coloremoji_blendmodes.cpp @@ -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()); diff --git a/gm/composeshader.cpp b/gm/composeshader.cpp index 53003d0ce1..3ab3828428 100644 --- a/gm/composeshader.cpp +++ b/gm/composeshader.cpp @@ -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); } diff --git a/gm/gamma.cpp b/gm/gamma.cpp index 534f518812..9cdd870e3a 100644 --- a/gm/gamma.cpp +++ b/gm/gamma.cpp @@ -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"); diff --git a/gm/giantbitmap.cpp b/gm/giantbitmap.cpp index 03a6b5db5f..17b6063ce5 100644 --- a/gm/giantbitmap.cpp +++ b/gm/giantbitmap.cpp @@ -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)); diff --git a/gm/gm.cpp b/gm/gm.cpp index 59983a1ae8..1831aaab5f 100644 --- a/gm/gm.cpp +++ b/gm/gm.cpp @@ -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); } diff --git a/gm/hairmodes.cpp b/gm/hairmodes.cpp index 8d946be988..9793e9318d 100644 --- a/gm/hairmodes.cpp +++ b/gm/hairmodes.cpp @@ -63,7 +63,7 @@ static sk_sp 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 { diff --git a/gm/lightingshader.cpp b/gm/lightingshader.cpp index 586ed8f549..a9c438355c 100644 --- a/gm/lightingshader.cpp +++ b/gm/lightingshader.cpp @@ -96,10 +96,8 @@ protected: const SkMatrix& ctm = canvas->getTotalMatrix(); SkPaint paint; - sk_sp diffuseShader = SkShader::MakeBitmapShader(fDiffuse, - SkTileMode::kClamp, SkTileMode::kClamp, &matrix); - sk_sp normalMap = SkShader::MakeBitmapShader(fNormalMaps[mapType], - SkTileMode::kClamp, SkTileMode::kClamp, &matrix); + sk_sp diffuseShader = fDiffuse.makeShader(&matrix); + sk_sp normalMap = fNormalMaps[mapType].makeShader(&matrix); sk_sp normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap), ctm); paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource), diff --git a/gm/lightingshader2.cpp b/gm/lightingshader2.cpp index faf56f0837..883fbbf6a6 100644 --- a/gm/lightingshader2.cpp +++ b/gm/lightingshader2.cpp @@ -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); } diff --git a/gm/modecolorfilters.cpp b/gm/modecolorfilters.cpp index 8467ee4810..6a14fecf8f 100644 --- a/gm/modecolorfilters.cpp +++ b/gm/modecolorfilters.cpp @@ -49,7 +49,7 @@ static sk_sp 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 { diff --git a/gm/p3.cpp b/gm/p3.cpp index 8266de27bd..297a870afd 100644 --- a/gm/p3.cpp +++ b/gm/p3.cpp @@ -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", diff --git a/gm/perspshaders.cpp b/gm/perspshaders.cpp index 25c3345ffe..aaecad82a7 100644 --- a/gm/perspshaders.cpp +++ b/gm/perspshaders.cpp @@ -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) } diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp index 0bdbca100e..bfadac184d 100644 --- a/gm/pictureshader.cpp +++ b/gm/pictureshader.cpp @@ -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 diff --git a/gm/samplerstress.cpp b/gm/samplerstress.cpp index 22404b9ffb..3653bfdb57 100644 --- a/gm/samplerstress.cpp +++ b/gm/samplerstress.cpp @@ -72,7 +72,7 @@ protected: createTexture(); - fShader = SkShader::MakeBitmapShader(fTexture, SkTileMode::kRepeat, SkTileMode::kRepeat); + fShader = fTexture.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat); } void createMaskFilter() { diff --git a/gm/shadertext3.cpp b/gm/shadertext3.cpp index eeab37e56a..1e54adc9f0 100644 --- a/gm/shadertext3.cpp +++ b/gm/shadertext3.cpp @@ -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); diff --git a/gm/shadows.cpp b/gm/shadows.cpp index 1688f831d9..4cd1076346 100644 --- a/gm/shadows.cpp +++ b/gm/shadows.cpp @@ -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); diff --git a/gm/skbug_257.cpp b/gm/skbug_257.cpp index f74ec629d1..296babf969 100644 --- a/gm/skbug_257.cpp +++ b/gm/skbug_257.cpp @@ -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, diff --git a/gm/strokedlines.cpp b/gm/strokedlines.cpp index 2eac0f248b..13862bc025 100644 --- a/gm/strokedlines.cpp +++ b/gm/strokedlines.cpp @@ -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); } { diff --git a/gm/subsetshader.cpp b/gm/subsetshader.cpp index 5b4908389f..aa27c79073 100644 --- a/gm/subsetshader.cpp +++ b/gm/subsetshader.cpp @@ -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; } diff --git a/gm/tiledscaledbitmap.cpp b/gm/tiledscaledbitmap.cpp index 85508051d9..4bf827f245 100644 --- a/gm/tiledscaledbitmap.cpp +++ b/gm/tiledscaledbitmap.cpp @@ -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); } diff --git a/gm/tilemodes.cpp b/gm/tilemodes.cpp index 73d8cac11c..e9af37b002 100644 --- a/gm/tilemodes.cpp +++ b/gm/tilemodes.cpp @@ -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 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 make_grad(SkTileMode tx, SkTileMode ty) { diff --git a/gm/tilemodes_scaled.cpp b/gm/tilemodes_scaled.cpp index 0a5aec0c7b..21d475471c 100644 --- a/gm/tilemodes_scaled.cpp +++ b/gm/tilemodes_scaled.cpp @@ -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 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 make_grad(SkTileMode tx, SkTileMode ty) { diff --git a/gm/tinybitmap.cpp b/gm/tinybitmap.cpp index 75e5e75114..0d99f9ec21 100644 --- a/gm/tinybitmap.cpp +++ b/gm/tinybitmap.cpp @@ -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); } diff --git a/gm/transparency.cpp b/gm/transparency.cpp index 8a275726b8..645dfb96bf 100644 --- a/gm/transparency.cpp +++ b/gm/transparency.cpp @@ -42,7 +42,7 @@ static sk_sp 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 diff --git a/gm/xfermodes.cpp b/gm/xfermodes.cpp index 542e9d39fc..df58a842b0 100644 --- a/gm/xfermodes.cpp +++ b/gm/xfermodes.cpp @@ -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); diff --git a/gm/xfermodes2.cpp b/gm/xfermodes2.cpp index 0088436539..df6127c8a2 100644 --- a/gm/xfermodes2.cpp +++ b/gm/xfermodes2.cpp @@ -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(dstBmp.getPixels()); @@ -120,7 +120,7 @@ private: pixels[kSize * y + x] = colColor; } } - fDst = SkShader::MakeBitmapShader(dstBmp, SkTileMode::kClamp, SkTileMode::kClamp); + fDst = dstBmp.makeShader(); } enum { diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp index c7bbe44286..45eb5683d7 100644 --- a/gm/xfermodes3.cpp +++ b/gm/xfermodes3.cpp @@ -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 { diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 096409a01b..76f255d67a 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -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 makeShader(SkTileMode tmx, SkTileMode tmy, + const SkMatrix* localMatrix = nullptr) const; + // defaults to Clamp in x, and y + sk_sp makeShader(const SkMatrix* localMatrix = nullptr) const; + /** Asserts if internal values are illegal or inconsistent. Only available if SK_DEBUG is defined at compile time. */ diff --git a/include/core/SkShader.h b/include/core/SkShader.h index dc8d08bb87..b5ca2da75e 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -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 MakeMixer(sk_sp dst, sk_sp src, sk_sp); - /** 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 MakeBitmapShader(const SkBitmap& src, SkTileMode tmx, SkTileMode tmy, const SkMatrix* localMatrix = nullptr); +#endif #ifdef SK_SUPPORT_LEGACY_TILEMODE_ENUM static sk_sp MakeBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy, const SkMatrix* localMatrix = nullptr) { diff --git a/samplecode/SampleAARectModes.cpp b/samplecode/SampleAARectModes.cpp index 3b9bb7698c..c8767120e9 100644 --- a/samplecode/SampleAARectModes.cpp +++ b/samplecode/SampleAARectModes.cpp @@ -65,7 +65,7 @@ static sk_sp 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 { diff --git a/samplecode/SampleAARects.cpp b/samplecode/SampleAARects.cpp index d909af3363..d556482d6d 100644 --- a/samplecode/SampleAARects.cpp +++ b/samplecode/SampleAARects.cpp @@ -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); diff --git a/samplecode/SampleCamera.cpp b/samplecode/SampleCamera.cpp index e3aca05dbf..3b3b98ccbf 100644 --- a/samplecode/SampleCamera.cpp +++ b/samplecode/SampleCamera.cpp @@ -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; } diff --git a/samplecode/SampleHairModes.cpp b/samplecode/SampleHairModes.cpp index 3885bf2223..781d212f70 100644 --- a/samplecode/SampleHairModes.cpp +++ b/samplecode/SampleHairModes.cpp @@ -64,7 +64,7 @@ static sk_sp 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 { diff --git a/samplecode/SampleLighting.cpp b/samplecode/SampleLighting.cpp index a3dc621329..154b7c391d 100644 --- a/samplecode/SampleLighting.cpp +++ b/samplecode/SampleLighting.cpp @@ -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 normalMap = SkShader::MakeBitmapShader(normalBitmap, - SkTileMode::kClamp, - SkTileMode::kClamp); + sk_sp normalMap = normalBitmap.makeShader(); fNormalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap), SkMatrix::I()); } } diff --git a/samplecode/SampleLitAtlas.cpp b/samplecode/SampleLitAtlas.cpp index a9e57626f4..b2d7f977ac 100644 --- a/samplecode/SampleLitAtlas.cpp +++ b/samplecode/SampleLitAtlas.cpp @@ -132,12 +132,10 @@ protected: SkMatrix m; m.setRSXform(xforms[i]); - sk_sp normalMap = SkShader::MakeBitmapShader(fAtlas, SkTileMode::kClamp, - SkTileMode::kClamp, &normalMat); + sk_sp normalMap = fAtlas.makeShader(&normalMat); sk_sp normalSource = SkNormalSource::MakeFromNormalMap( std::move(normalMap), m); - sk_sp diffuseShader = SkShader::MakeBitmapShader(fAtlas, - SkTileMode::kClamp, SkTileMode::kClamp, &diffMat); + sk_sp diffuseShader = fAtlas.makeShader(&diffMat); paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource), fLights)); diff --git a/samplecode/SamplePatch.cpp b/samplecode/SamplePatch.cpp index b7f5f365b2..9bd9dbdfa8 100644 --- a/samplecode/SamplePatch.cpp +++ b/samplecode/SamplePatch.cpp @@ -33,7 +33,7 @@ static sk_sp 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 make_shader1(const SkIPoint& size) { diff --git a/samplecode/SampleRepeatTile.cpp b/samplecode/SampleRepeatTile.cpp index f2d51deb8a..dfde1cf364 100644 --- a/samplecode/SampleRepeatTile.cpp +++ b/samplecode/SampleRepeatTile.cpp @@ -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 { diff --git a/samplecode/SampleShaders.cpp b/samplecode/SampleShaders.cpp index 65dbe07bfa..8bc080772f 100644 --- a/samplecode/SampleShaders.cpp +++ b/samplecode/SampleShaders.cpp @@ -29,7 +29,7 @@ static sk_sp 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); } diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp index a69beadab4..2ede187fe4 100644 --- a/samplecode/SampleSlides.cpp +++ b/samplecode/SampleSlides.cpp @@ -246,7 +246,7 @@ static sk_sp 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 make_shader1(const SkIPoint& size) { diff --git a/samplecode/SampleTiling.cpp b/samplecode/SampleTiling.cpp index 169c5b763c..3c219a2203 100644 --- a/samplecode/SampleTiling.cpp +++ b/samplecode/SampleTiling.cpp @@ -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); } diff --git a/samplecode/SampleVertices.cpp b/samplecode/SampleVertices.cpp index 0435f3e436..a6c5ab3bdf 100644 --- a/samplecode/SampleVertices.cpp +++ b/samplecode/SampleVertices.cpp @@ -34,7 +34,7 @@ static sk_sp 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 make_shader1(const SkIPoint& size) { diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp index e5a0d894d3..079ba3c8ac 100644 --- a/samplecode/SampleXfermodesBlur.cpp +++ b/samplecode/SampleXfermodesBlur.cpp @@ -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); diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index ed284ce9ec..8c21959384 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -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 { diff --git a/src/shaders/SkShader.cpp b/src/shaders/SkShader.cpp index f5f7a9727d..22321f43f1 100644 --- a/src/shaders/SkShader.cpp +++ b/src/shaders/SkShader.cpp @@ -142,6 +142,7 @@ sk_sp SkShader::MakeEmptyShader() { return sk_make_sp() sk_sp SkShader::MakeColorShader(SkColor color) { return sk_make_sp(color); } +#ifdef SK_SUPPORT_LEGACY_BITMAPSHADER_FACTORY sk_sp SkShader::MakeBitmapShader(const SkBitmap& src, SkTileMode tmx, SkTileMode tmy, const SkMatrix* localMatrix) { if (localMatrix && !localMatrix->invert(nullptr)) { @@ -149,6 +150,18 @@ sk_sp SkShader::MakeBitmapShader(const SkBitmap& src, SkTileMode tmx, } return SkMakeBitmapShader(src, tmx, tmy, localMatrix, kIfMutable_SkCopyPixelsMode); } +#endif + +sk_sp 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 SkBitmap::makeShader(const SkMatrix* lm) const { + return this->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, lm); +} #ifdef SK_SUPPORT_LEGACY_TILEMODE_ENUM sk_sp SkShader::MakePictureShader(sk_sp src, TileMode tmx, TileMode tmy, diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 3046c4d9c9..8bd0092c33 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -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); diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp index 0fca8ff83c..6d3c1befcf 100644 --- a/tests/DrawBitmapRectTest.cpp +++ b/tests/DrawBitmapRectTest.cpp @@ -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); diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 47a9550398..ddfe07327a 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -603,12 +603,10 @@ DEF_TEST(Serialization, reporter) { normals.allocN32Pixels(kTexSize, kTexSize); ToolUtils::create_frustum_normal_map(&normals, SkIRect::MakeWH(kTexSize, kTexSize)); - sk_sp normalMap = SkShader::MakeBitmapShader(normals, SkTileMode::kClamp, - SkTileMode::kClamp, &matrix); + sk_sp normalMap = normals.makeShader(&matrix); sk_sp normalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap), ctm); - sk_sp diffuseShader = SkShader::MakeBitmapShader(diffuse, - SkTileMode::kClamp, SkTileMode::kClamp, &matrix); + sk_sp diffuseShader = diffuse.makeShader(&matrix); sk_sp lightingShader = SkLightingShader::Make(diffuseShader, normalSource, diff --git a/tests/ShaderOpacityTest.cpp b/tests/ShaderOpacityTest.cpp index dd25429b00..53f3146fd2 100644 --- a/tests/ShaderOpacityTest.cpp +++ b/tests/ShaderOpacityTest.cpp @@ -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()); } diff --git a/tests/ShaderTest.cpp b/tests/ShaderTest.cpp index 395fcdc104..5305f6f063 100644 --- a/tests/ShaderTest.cpp +++ b/tests/ShaderTest.cpp @@ -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); diff --git a/tools/ToolUtils.cpp b/tools/ToolUtils.cpp index e9e8451b0c..6bc0b09e0b 100644 --- a/tools/ToolUtils.cpp +++ b/tools/ToolUtils.cpp @@ -83,7 +83,7 @@ sk_sp 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) {