diff options
author | reed <reed@google.com> | 2016-03-08 18:50:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-08 18:50:00 -0800 |
commit | 8a21c9fe7f5fef9e87115defef27bd7218419f28 (patch) | |
tree | 1dd8b9eda9eae99b33bc88b97bd5f0a7a0769dc3 /src | |
parent | 042f859c19f71ca9feacddd1cb058ff59eed8963 (diff) |
use Make instead of Create to return a shared shader
Partially updated call sites. Undefine the flag in SkSHader.h to convert the remaining sites.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1772463002
Review URL: https://codereview.chromium.org/1772463002
Diffstat (limited to 'src')
26 files changed, 191 insertions, 205 deletions
diff --git a/src/animator/SkDrawGradient.cpp b/src/animator/SkDrawGradient.cpp index 4aecbc3936..2fa4502f6b 100644 --- a/src/animator/SkDrawGradient.cpp +++ b/src/animator/SkDrawGradient.cpp @@ -126,14 +126,12 @@ void SkDrawLinearGradient::dump(SkAnimateMaker* maker) { #endif SkShader* SkDrawLinearGradient::getShader() { - if (addPrelude() == 0 || points.count() != 4) + if (addPrelude() == 0 || points.count() != 4) { return nullptr; - SkShader* shader = SkGradientShader::CreateLinear((SkPoint*)points.begin(), + } + return SkGradientShader::MakeLinear((SkPoint*)points.begin(), fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode, - 0, getMatrix()); - SkAutoTDelete<SkShader> autoDel(shader); - (void)autoDel.detach(); - return shader; + 0, getMatrix()).release(); } @@ -161,12 +159,10 @@ void SkDrawRadialGradient::dump(SkAnimateMaker* maker) { #endif SkShader* SkDrawRadialGradient::getShader() { - if (addPrelude() == 0) + if (addPrelude() == 0) { return nullptr; - SkShader* shader = SkGradientShader::CreateRadial(center, + } + return SkGradientShader::MakeRadial(center, radius, fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode, - 0, getMatrix()); - SkAutoTDelete<SkShader> autoDel(shader); - (void)autoDel.detach(); - return shader; + 0, getMatrix()).release(); } diff --git a/src/animator/SkDrawShader.cpp b/src/animator/SkDrawShader.cpp index 9e3becc48b..2868b9f4ef 100644 --- a/src/animator/SkDrawShader.cpp +++ b/src/animator/SkDrawShader.cpp @@ -71,8 +71,8 @@ SkShader* SkDrawBitmapShader::getShader() { // // oops, bitmapshader no longer takes filterBitmap, but deduces it at // draw-time from the paint - return SkShader::CreateBitmapShader(image->fBitmap, + return SkShader::MakeBitmapShader(image->fBitmap, (SkShader::TileMode) tileMode, (SkShader::TileMode) tileMode, - getMatrix()); + getMatrix()).release(); } diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp index 6618881bc1..f7fa30f28a 100644 --- a/src/c/sk_surface.cpp +++ b/src/c/sk_surface.cpp @@ -551,10 +551,10 @@ sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2], } else { matrix.setIdentity(); } - SkShader* s = SkGradientShader::CreateLinear(reinterpret_cast<const SkPoint*>(pts), - reinterpret_cast<const SkColor*>(colors), - colorPos, colorCount, mode, 0, &matrix); - return (sk_shader_t*)s; + return (sk_shader_t*)SkGradientShader::MakeLinear(reinterpret_cast<const SkPoint*>(pts), + reinterpret_cast<const SkColor*>(colors), + colorPos, colorCount, + mode, 0, &matrix).release(); } static const SkPoint& to_skpoint(const sk_point_t& p) { @@ -579,12 +579,10 @@ sk_shader_t* sk_shader_new_radial_gradient(const sk_point_t* ccenter, matrix.setIdentity(); } SkPoint center = to_skpoint(*ccenter); - SkShader* s = SkGradientShader::CreateRadial( - center, (SkScalar)radius, - reinterpret_cast<const SkColor*>(colors), - reinterpret_cast<const SkScalar*>(colorPos), - colorCount, mode, 0, &matrix); - return (sk_shader_t*)s; + return (sk_shader_t*)SkGradientShader::MakeRadial(center, (SkScalar)radius, + reinterpret_cast<const SkColor*>(colors), + reinterpret_cast<const SkScalar*>(colorPos), + colorCount, mode, 0, &matrix).release(); } sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* ccenter, @@ -598,13 +596,11 @@ sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* ccenter, } else { matrix.setIdentity(); } - SkShader* s = SkGradientShader::CreateSweep( - (SkScalar)(ccenter->x), - (SkScalar)(ccenter->y), - reinterpret_cast<const SkColor*>(colors), - reinterpret_cast<const SkScalar*>(colorPos), - colorCount, 0, &matrix); - return (sk_shader_t*)s; + return (sk_shader_t*)SkGradientShader::MakeSweep((SkScalar)(ccenter->x), + (SkScalar)(ccenter->y), + reinterpret_cast<const SkColor*>(colors), + reinterpret_cast<const SkScalar*>(colorPos), + colorCount, 0, &matrix).release(); } sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start, @@ -628,13 +624,11 @@ sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start, } SkPoint skstart = to_skpoint(*start); SkPoint skend = to_skpoint(*end); - SkShader* s = SkGradientShader::CreateTwoPointConical( - skstart, (SkScalar)startRadius, - skend, (SkScalar)endRadius, - reinterpret_cast<const SkColor*>(colors), - reinterpret_cast<const SkScalar*>(colorPos), - colorCount, mode, 0, &matrix); - return (sk_shader_t*)s; + return (sk_shader_t*)SkGradientShader::MakeTwoPointConical(skstart, (SkScalar)startRadius, + skend, (SkScalar)endRadius, + reinterpret_cast<const SkColor*>(colors), + reinterpret_cast<const SkScalar*>(colorPos), + colorCount, mode, 0, &matrix).release(); } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index d5dfcc1733..fc0e63e9ae 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -314,17 +314,15 @@ void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, } // construct a shader, so we can call drawRect with the dst - SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, - SkShader::kClamp_TileMode, - SkShader::kClamp_TileMode, - &matrix); - if (nullptr == s) { + auto s = SkShader::MakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode, &matrix); + if (!s) { return; } SkPaint paintWithShader(paint); paintWithShader.setStyle(SkPaint::kFill_Style); - paintWithShader.setShader(s)->unref(); + paintWithShader.setShader(std::move(s)); // Call ourself, in case the subclass wanted to share this setup code // but handle the drawRect code themselves. diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index f26194280c..4813e01d54 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -289,7 +289,7 @@ SkFlattenable* SkBitmapProcShader::CreateProc(SkReadBuffer& buffer) { bm.setImmutable(); TileMode mx = (TileMode)buffer.readUInt(); TileMode my = (TileMode)buffer.readUInt(); - return SkShader::CreateBitmapShader(bm, mx, my, &lm); + return SkShader::MakeBitmapShader(bm, mx, my, &lm).release(); } void SkBitmapProcShader::flatten(SkWriteBuffer& buffer) const { @@ -352,9 +352,9 @@ static bool bitmap_is_too_big(const SkBitmap& bm) { return bm.width() > kMaxSize || bm.height() > kMaxSize; } -SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, - SkShader::TileMode tmy, const SkMatrix* localMatrix, - SkTBlitterAllocator* allocator) { +sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, + SkShader::TileMode tmy, const SkMatrix* localMatrix, + SkTBlitterAllocator* allocator) { SkShader* shader; SkColor color; if (src.isNull() || bitmap_is_too_big(src)) { @@ -376,7 +376,7 @@ SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, localMatrix); } } - return shader; + return sk_sp<SkShader>(shader); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h index dc4d832ca3..185a95de66 100644 --- a/src/core/SkBitmapProcShader.h +++ b/src/core/SkBitmapProcShader.h @@ -59,7 +59,7 @@ typedef SkSmallAllocator<3, 2100> SkTBlitterAllocator; // If alloc is non-nullptr, it will be used to allocate the returned SkShader, and MUST outlive // the SkShader. -SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode, - const SkMatrix* localMatrix, SkTBlitterAllocator* alloc); +sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode, + const SkMatrix* localMatrix, SkTBlitterAllocator* alloc); #endif diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index bb5cfb72e3..9fcab9c982 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -584,13 +584,7 @@ SkBlitter* SkBlitterClipper::apply(SkBlitter* blitter, const SkRegion* clip, class Sk3DShader : public SkShader { public: - Sk3DShader(SkShader* proxy) : fProxy(proxy) { - SkSafeRef(proxy); - } - - virtual ~Sk3DShader() { - SkSafeUnref(fProxy); - } + Sk3DShader(sk_sp<SkShader> proxy) : fProxy(std::move(proxy)) {} size_t onContextSize(const ContextRec& rec) const override { size_t size = sizeof(Sk3DShaderContext); @@ -727,18 +721,17 @@ public: protected: void flatten(SkWriteBuffer& buffer) const override { - buffer.writeFlattenable(fProxy); + buffer.writeFlattenable(fProxy.get()); } private: - SkShader* fProxy; + sk_sp<SkShader> fProxy; typedef SkShader INHERITED; }; SkFlattenable* Sk3DShader::CreateProc(SkReadBuffer& buffer) { - SkAutoTUnref<SkShader> shader(buffer.readShader()); - return new Sk3DShader(shader); + return new Sk3DShader(buffer.readShader()); } class Sk3DBlitter : public SkBlitter { @@ -822,7 +815,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, if (origPaint.getMaskFilter() != nullptr && origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { - shader3D = new Sk3DShader(shader); + shader3D = new Sk3DShader(sk_sp<SkShader>(SkSafeRef(shader))); // we know we haven't initialized lazyPaint yet, so just do it paint.writable()->setShader(shader3D)->unref(); shader = shader3D; diff --git a/src/core/SkColorFilterShader.cpp b/src/core/SkColorFilterShader.cpp index c7cf76b53e..f5a3b9c9e1 100644 --- a/src/core/SkColorFilterShader.cpp +++ b/src/core/SkColorFilterShader.cpp @@ -24,12 +24,12 @@ SkColorFilterShader::SkColorFilterShader(SkShader* shader, SkColorFilter* filter } SkFlattenable* SkColorFilterShader::CreateProc(SkReadBuffer& buffer) { - SkAutoTUnref<SkShader> shader(buffer.readShader()); + auto shader = buffer.readShader(); SkAutoTUnref<SkColorFilter> filter(buffer.readColorFilter()); - if (!shader.get() || !filter.get()) { + if (!shader || !filter.get()) { return nullptr; } - return new SkColorFilterShader(shader, filter); + return new SkColorFilterShader(shader.get(), filter); } void SkColorFilterShader::flatten(SkWriteBuffer& buffer) const { diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp index b6ba3729d1..4d3e4e57ba 100644 --- a/src/core/SkComposeShader.cpp +++ b/src/core/SkComposeShader.cpp @@ -16,9 +16,10 @@ /////////////////////////////////////////////////////////////////////////////// -SkComposeShader::SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode) { - fShaderA = sA; sA->ref(); - fShaderB = sB; sB->ref(); +SkComposeShader::SkComposeShader(sk_sp<SkShader> sA, sk_sp<SkShader> sB, SkXfermode* mode) + : fShaderA(std::move(sA)) + , fShaderB(std::move(sB)) +{ // mode may be null fMode = mode; SkSafeRef(mode); @@ -26,8 +27,6 @@ SkComposeShader::SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode) { SkComposeShader::~SkComposeShader() { SkSafeUnref(fMode); - fShaderB->unref(); - fShaderA->unref(); } size_t SkComposeShader::onContextSize(const ContextRec& rec) const { @@ -54,18 +53,18 @@ private: #define SkAutoAlphaRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoAlphaRestore) SkFlattenable* SkComposeShader::CreateProc(SkReadBuffer& buffer) { - SkAutoTUnref<SkShader> shaderA(buffer.readShader()); - SkAutoTUnref<SkShader> shaderB(buffer.readShader()); + sk_sp<SkShader> shaderA(buffer.readShader()); + sk_sp<SkShader> shaderB(buffer.readShader()); SkAutoTUnref<SkXfermode> mode(buffer.readXfermode()); - if (!shaderA.get() || !shaderB.get()) { + if (!shaderA || !shaderB) { return nullptr; } - return new SkComposeShader(shaderA, shaderB, mode); + return new SkComposeShader(std::move(shaderA), std::move(shaderB), mode); } void SkComposeShader::flatten(SkWriteBuffer& buffer) const { - buffer.writeFlattenable(fShaderA); - buffer.writeFlattenable(fShaderB); + buffer.writeFlattenable(fShaderA.get()); + buffer.writeFlattenable(fShaderB.get()); buffer.writeFlattenable(fMode); } @@ -119,8 +118,8 @@ SkComposeShader::ComposeShaderContext::~ComposeShaderContext() { bool SkComposeShader::asACompose(ComposeRec* rec) const { if (rec) { - rec->fShaderA = fShaderA; - rec->fShaderB = fShaderB; + rec->fShaderA = fShaderA.get(); + rec->fShaderB = fShaderB.get(); rec->fMode = fMode; } return true; @@ -255,14 +254,16 @@ void SkComposeShader::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////////////////////////// -SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode* xfer) { +sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src, + SkXfermode* xfer) { if (!dst || !src) { return nullptr; } - return new SkComposeShader(dst, src, xfer); + return sk_make_sp<SkComposeShader>(std::move(dst), std::move(src), xfer); } -SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode::Mode mode) { +sk_sp<SkShader> SkShader::MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader> src, + SkXfermode::Mode mode) { SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); - return CreateComposeShader(dst, src, xfer); + return MakeComposeShader(std::move(dst), std::move(src), xfer); } diff --git a/src/core/SkComposeShader.h b/src/core/SkComposeShader.h index 9220a0de97..ee6e36a222 100644 --- a/src/core/SkComposeShader.h +++ b/src/core/SkComposeShader.h @@ -31,7 +31,7 @@ public: @param mode The xfermode that combines the colors from the two shaders. If mode is null, then SRC_OVER is assumed. */ - SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL); + SkComposeShader(sk_sp<SkShader> sA, sk_sp<SkShader> sB, SkXfermode* mode = NULL); virtual ~SkComposeShader(); #if SK_SUPPORT_GPU @@ -63,8 +63,8 @@ public: }; #ifdef SK_DEBUG - SkShader* getShaderA() { return fShaderA; } - SkShader* getShaderB() { return fShaderB; } + SkShader* getShaderA() { return fShaderA.get(); } + SkShader* getShaderB() { return fShaderB.get(); } #endif bool asACompose(ComposeRec* rec) const override; @@ -79,9 +79,9 @@ protected: Context* onCreateContext(const ContextRec&, void*) const override; private: - SkShader* fShaderA; - SkShader* fShaderB; - SkXfermode* fMode; + sk_sp<SkShader> fShaderA; + sk_sp<SkShader> fShaderB; + SkXfermode* fMode; typedef SkShader INHERITED; }; diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index c479221369..409b652e93 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -81,10 +81,10 @@ public: SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, const SkMatrix* localMatrix = nullptr) : fPaint(paint) /* makes a copy of the paint */ { - fPaint.setShader(SkCreateBitmapShader(src, SkShader::kClamp_TileMode, - SkShader::kClamp_TileMode, - localMatrix, &fAllocator)); + fPaint.setShader(SkMakeBitmapShader(src, SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode, localMatrix, &fAllocator)); // we deliberately left the shader with an owner-count of 2 + fPaint.getShader()->ref(); SkASSERT(2 == fPaint.getShader()->getRefCnt()); } @@ -1880,7 +1880,7 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, Thus for texture drawing, we need both texture[] and a shader. */ - SkTriColorShader triShader; // must be above declaration of p + auto triShader = sk_make_sp<SkTriColorShader>(); SkPaint p(paint); SkShader* shader = p.getShader(); @@ -1894,11 +1894,12 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, } // setup the custom shader (if needed) - SkAutoTUnref<SkComposeShader> composeShader; + sk_sp<SkShader> composeShader; if (colors) { if (nullptr == textures) { // just colors (no texture) - shader = p.setShader(&triShader); + p.setShader(triShader); + shader = p.getShader(); } else { // colors * texture SkASSERT(shader); @@ -1907,7 +1908,7 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, xmode = SkXfermode::Create(SkXfermode::kModulate_Mode); releaseMode = true; } - composeShader.reset(new SkComposeShader(&triShader, shader, xmode)); + composeShader = sk_make_sp<SkComposeShader>(triShader, sk_ref_sp(shader), xmode); p.setShader(composeShader); if (releaseMode) { xmode->unref(); @@ -1940,14 +1941,14 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, } } if (colors) { - triShader.bindSetupData(&verticesSetup); + triShader->bindSetupData(&verticesSetup); } SkPoint tmp[] = { devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] }; SkScan::FillTriangle(tmp, *fRC, blitter.get()); - triShader.bindSetupData(NULL); + triShader->bindSetupData(NULL); } } else { // no colors[] and no texture, stroke hairlines with paint's color. diff --git a/src/core/SkLocalMatrixShader.cpp b/src/core/SkLocalMatrixShader.cpp index 336f1c49cf..42b378d61a 100644 --- a/src/core/SkLocalMatrixShader.cpp +++ b/src/core/SkLocalMatrixShader.cpp @@ -10,7 +10,7 @@ SkFlattenable* SkLocalMatrixShader::CreateProc(SkReadBuffer& buffer) { SkMatrix lm; buffer.readMatrix(&lm); - SkAutoTUnref<SkShader> baseShader(buffer.readShader()); + auto baseShader(buffer.readShader()); if (!baseShader) { return nullptr; } diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 3d768074ca..678b1a1102 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1929,7 +1929,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { if (flatFlags & kHasEffects_FlatFlag) { SkSafeUnref(this->setPathEffect(buffer.readPathEffect())); - SkSafeUnref(this->setShader(buffer.readShader())); + this->setShader(buffer.readShader()); SkSafeUnref(this->setXfermode(buffer.readXfermode())); SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter())); SkSafeUnref(this->setColorFilter(buffer.readColorFilter())); diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 3919471b1b..a6644aacba 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -93,21 +93,21 @@ struct BitmapShaderRec : public SkResourceCache::Rec { } // namespace -SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMode tmy, +SkPictureShader::SkPictureShader(sk_sp<const SkPicture> picture, TileMode tmx, TileMode tmy, const SkMatrix* localMatrix, const SkRect* tile) : INHERITED(localMatrix) - , fPicture(SkRef(picture)) - , fTile(tile ? *tile : picture->cullRect()) + , fPicture(std::move(picture)) + , fTile(tile ? *tile : fPicture->cullRect()) , fTmx(tmx) , fTmy(tmy) { } -SkShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx, TileMode tmy, - const SkMatrix* localMatrix, const SkRect* tile) { +sk_sp<SkShader> SkPictureShader::Make(sk_sp<const SkPicture> picture, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix, const SkRect* tile) { if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) { - return SkShader::CreateEmptyShader(); + return SkShader::MakeEmptyShader(); } - return new SkPictureShader(picture, tmx, tmy, localMatrix, tile); + return sk_sp<SkShader>(new SkPictureShader(std::move(picture), tmx, tmy, localMatrix, tile)); } SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { @@ -118,7 +118,7 @@ SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { SkRect tile; buffer.readRect(&tile); - SkAutoTUnref<SkPicture> picture; + sk_sp<SkPicture> picture; if (buffer.isCrossProcess() && SkPicture::PictureIOSecurityPrecautionsEnabled()) { if (buffer.isVersionLT(SkReadBuffer::kPictureShaderHasPictureBool_Version)) { @@ -136,7 +136,7 @@ SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { picture.reset(SkPicture::CreateFromBuffer(buffer)); } } - return SkPictureShader::Create(picture, mx, my, &lm, &tile); + return SkPictureShader::Make(picture, mx, my, &lm, &tile).release(); } void SkPictureShader::flatten(SkWriteBuffer& buffer) const { @@ -155,8 +155,8 @@ void SkPictureShader::flatten(SkWriteBuffer& buffer) const { } } -SkShader* SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkMatrix* localM, - const int maxTextureSize) const { +sk_sp<SkShader> SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkMatrix* localM, + const int maxTextureSize) const { SkASSERT(fPicture && !fPicture->cullRect().isEmpty()); SkMatrix m; @@ -203,14 +203,14 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkM const SkISize tileSize = scaledSize.toCeil(); #endif if (tileSize.isEmpty()) { - return SkShader::CreateEmptyShader(); + return SkShader::MakeEmptyShader(); } // The actual scale, compensating for rounding & clamping. const SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fTile.width(), SkIntToScalar(tileSize.height()) / fTile.height()); - SkAutoTUnref<SkShader> tileShader; + sk_sp<SkShader> tileShader; BitmapShaderKey key(fPicture->uniqueID(), fTile, fTmx, @@ -224,7 +224,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkM SkMatrix::kFill_ScaleToFit); SkAutoTUnref<SkImage> tileImage( - SkImage::NewFromPicture(fPicture, tileSize, &tileMatrix, nullptr)); + SkImage::NewFromPicture(fPicture.get(), tileSize, &tileMatrix, nullptr)); if (!tileImage) { return nullptr; } @@ -238,7 +238,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkM tileInfo.getSafeSize(tileInfo.minRowBytes()))); } - return tileShader.detach(); + return tileShader; } size_t SkPictureShader::onContextSize(const ContextRec&) const { @@ -246,8 +246,8 @@ size_t SkPictureShader::onContextSize(const ContextRec&) const { } SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const { - SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec.fLocalMatrix)); - if (nullptr == bitmapShader.get()) { + sk_sp<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec.fLocalMatrix)); + if (!bitmapShader) { return nullptr; } return PictureShaderContext::Create(storage, *this, rec, bitmapShader); @@ -256,8 +256,10 @@ SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* ///////////////////////////////////////////////////////////////////////////////////////// SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, - const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader) { - PictureShaderContext* ctx = new (storage) PictureShaderContext(shader, rec, bitmapShader); + const SkPictureShader& shader, const ContextRec& rec, + sk_sp<SkShader> bitmapShader) { + PictureShaderContext* ctx = new (storage) PictureShaderContext(shader, rec, + std::move(bitmapShader)); if (nullptr == ctx->fBitmapShaderContext) { ctx->~PictureShaderContext(); ctx = nullptr; @@ -266,12 +268,12 @@ SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, } SkPictureShader::PictureShaderContext::PictureShaderContext( - const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader) + const SkPictureShader& shader, const ContextRec& rec, sk_sp<SkShader> bitmapShader) : INHERITED(shader, rec) - , fBitmapShader(SkRef(bitmapShader)) + , fBitmapShader(std::move(bitmapShader)) { - fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize(rec)); - fBitmapShaderContext = bitmapShader->createContext(rec, fBitmapShaderContextStorage); + fBitmapShaderContextStorage = sk_malloc_throw(fBitmapShader->contextSize(rec)); + fBitmapShaderContext = fBitmapShader->createContext(rec, fBitmapShaderContextStorage); //if fBitmapShaderContext is null, we are invalid } @@ -325,7 +327,7 @@ const GrFragmentProcessor* SkPictureShader::asFragmentProcessor( if (context) { maxTextureSize = context->caps()->maxTextureSize(); } - SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix, maxTextureSize)); + sk_sp<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix, maxTextureSize)); if (!bitmapShader) { return nullptr; } diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h index 8cccd251d5..eb9c38b95b 100644 --- a/src/core/SkPictureShader.h +++ b/src/core/SkPictureShader.h @@ -22,8 +22,8 @@ class SkPicture; */ class SkPictureShader : public SkShader { public: - static SkShader* Create(const SkPicture*, TileMode, TileMode, const SkMatrix*, - const SkRect*); + static sk_sp<SkShader> Make(sk_sp<const SkPicture>, TileMode, TileMode, const SkMatrix*, + const SkRect*); SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader) @@ -42,18 +42,19 @@ protected: Context* onCreateContext(const ContextRec&, void* storage) const override; private: - SkPictureShader(const SkPicture*, TileMode, TileMode, const SkMatrix*, const SkRect*); + SkPictureShader(sk_sp<const SkPicture>, TileMode, TileMode, const SkMatrix*, const SkRect*); - SkShader* refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix, const int maxTextureSize = 0) const; + sk_sp<SkShader> refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix, + const int maxTextureSize = 0) const; - SkAutoTUnref<const SkPicture> fPicture; - SkRect fTile; - TileMode fTmx, fTmy; + sk_sp<const SkPicture> fPicture; + SkRect fTile; + TileMode fTmx, fTmy; class PictureShaderContext : public SkShader::Context { public: static Context* Create(void* storage, const SkPictureShader&, const ContextRec&, - SkShader* bitmapShader); + sk_sp<SkShader> bitmapShader); virtual ~PictureShaderContext(); @@ -63,11 +64,12 @@ private: void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; private: - PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader* bitmapShader); + PictureShaderContext(const SkPictureShader&, const ContextRec&, + sk_sp<SkShader> bitmapShader); - SkAutoTUnref<SkShader> fBitmapShader; - SkShader::Context* fBitmapShaderContext; - void* fBitmapShaderContextStorage; + sk_sp<SkShader> fBitmapShader; + SkShader::Context* fBitmapShaderContext; + void* fBitmapShaderContextStorage; typedef SkShader::Context INHERITED; }; diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index b9b30944ff..5db9f4644d 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -136,7 +136,7 @@ public: SkMaskFilter* readMaskFilter() { return this->readFlattenable<SkMaskFilter>(); } SkPathEffect* readPathEffect() { return this->readFlattenable<SkPathEffect>(); } SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer>(); } - SkShader* readShader() { return this->readFlattenable<SkShader>(); } + sk_sp<SkShader> readShader() { return sk_sp<SkShader>(this->readFlattenable<SkShader>()); } SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); } /** diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 75f527bff3..7b322fb627 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -229,18 +229,18 @@ SkShader* SkShader::refAsALocalMatrixShader(SkMatrix*) const { return nullptr; } -SkShader* SkShader::CreateEmptyShader() { return new SkEmptyShader; } +sk_sp<SkShader> SkShader::MakeEmptyShader() { return sk_make_sp<SkEmptyShader>(); } -SkShader* SkShader::CreateColorShader(SkColor color) { return new SkColorShader(color); } +sk_sp<SkShader> SkShader::MakeColorShader(SkColor color) { return sk_make_sp<SkColorShader>(color); } -SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy, - const SkMatrix* localMatrix) { - return SkCreateBitmapShader(src, tmx, tmy, localMatrix, nullptr); +sk_sp<SkShader> SkShader::MakeBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix) { + return SkMakeBitmapShader(src, tmx, tmy, localMatrix, nullptr); } -SkShader* SkShader::CreatePictureShader(const SkPicture* src, TileMode tmx, TileMode tmy, - const SkMatrix* localMatrix, const SkRect* tile) { - return SkPictureShader::Create(src, tmx, tmy, localMatrix, tile); +sk_sp<SkShader> SkShader::MakePictureShader(sk_sp<const SkPicture> src, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix, const SkRect* tile) { + return SkPictureShader::Make(std::move(src), tmx, tmy, localMatrix, tile); } #ifndef SK_IGNORE_TO_STRING @@ -362,7 +362,7 @@ void SkColorShader::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////// SkFlattenable* SkEmptyShader::CreateProc(SkReadBuffer&) { - return SkShader::CreateEmptyShader(); + return SkShader::MakeEmptyShader().release(); } #ifndef SK_IGNORE_TO_STRING @@ -376,3 +376,18 @@ void SkEmptyShader::toString(SkString* str) const { str->append(")"); } #endif + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR +SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode::Mode mode) { + return MakeComposeShader(sk_ref_sp(dst), sk_ref_sp(src), mode).release(); +} +SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode* xfer) { + return MakeComposeShader(sk_ref_sp(dst), sk_ref_sp(src), xfer).release(); +} +SkShader* SkShader::CreatePictureShader(const SkPicture* src, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix, const SkRect* tile) { + return MakePictureShader(sk_ref_sp(src), tmx, tmy, localMatrix, tile).release(); +} +#endif diff --git a/src/effects/SkTileImageFilter.cpp b/src/effects/SkTileImageFilter.cpp index 66cad47ad0..dff8e9bbfc 100644 --- a/src/effects/SkTileImageFilter.cpp +++ b/src/effects/SkTileImageFilter.cpp @@ -96,10 +96,8 @@ bool SkTileImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& sr SkCanvas canvas(device); SkPaint paint; paint.setXfermodeMode(SkXfermode::kSrc_Mode); - - SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset, - SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode)); - paint.setShader(shader); + paint.setShader(SkShader::MakeBitmapShader(subset, SkShader::kRepeat_TileMode, + SkShader::kRepeat_TileMode)); canvas.translate(-dstRect.fLeft, -dstRect.fTop); canvas.drawRect(dstRect, paint); *dst = device->accessBitmap(false); diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 985d45966b..9fe6c91a01 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -786,7 +786,7 @@ static void desc_init(SkGradientShaderBase::Descriptor* desc, desc->fLocalMatrix = localMatrix; } -SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2], +sk_sp<SkShader> SkGradientShader::MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int colorCount, SkShader::TileMode mode, @@ -802,10 +802,10 @@ SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2], SkGradientShaderBase::Descriptor desc; desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix); - return new SkLinearGradient(pts, desc); + return sk_make_sp<SkLinearGradient>(pts, desc); } -SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius, +sk_sp<SkShader> SkGradientShader::MakeRadial(const SkPoint& center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int colorCount, SkShader::TileMode mode, @@ -821,10 +821,10 @@ SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius, SkGradientShaderBase::Descriptor desc; desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix); - return new SkRadialGradient(center, radius, desc); + return sk_make_sp<SkRadialGradient>(center, radius, desc); } -SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, +sk_sp<SkShader> SkGradientShader::MakeTwoPointConical(const SkPoint& start, SkScalar startRadius, const SkPoint& end, SkScalar endRadius, @@ -842,7 +842,7 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, } if (startRadius == endRadius) { if (start == end || startRadius == 0) { - return SkShader::CreateEmptyShader(); + return SkShader::MakeEmptyShader(); } } @@ -854,8 +854,8 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, if (!flipGradient) { desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix); - return new SkTwoPointConicalGradient(start, startRadius, end, endRadius, flipGradient, - desc); + return sk_make_sp<SkTwoPointConicalGradient>(start, startRadius, end, endRadius, + flipGradient, desc); } else { SkAutoSTArray<8, SkColor> colorsNew(colorCount); SkAutoSTArray<8, SkScalar> posNew(colorCount); @@ -872,12 +872,12 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, desc_init(&desc, colorsNew.get(), nullptr, colorCount, mode, flags, localMatrix); } - return new SkTwoPointConicalGradient(end, endRadius, start, startRadius, flipGradient, - desc); + return sk_make_sp<SkTwoPointConicalGradient>(end, endRadius, start, startRadius, + flipGradient, desc); } } -SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy, +sk_sp<SkShader> SkGradientShader::MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int colorCount, @@ -890,7 +890,7 @@ SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy, SkGradientShaderBase::Descriptor desc; desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags, localMatrix); - return new SkSweepGradient(cx, cy, desc); + return sk_make_sp<SkSweepGradient>(cx, cy, desc); } SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader) diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 15d461960d..8ad120991d 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -78,8 +78,8 @@ SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) { SkPoint pts[2]; pts[0] = buffer.readPoint(); pts[1] = buffer.readPoint(); - return SkGradientShader::CreateLinear(pts, desc.fColors, desc.fPos, desc.fCount, - desc.fTileMode, desc.fGradFlags, desc.fLocalMatrix); + return SkGradientShader::MakeLinear(pts, desc.fColors, desc.fPos, desc.fCount, desc.fTileMode, + desc.fGradFlags, desc.fLocalMatrix).release(); } void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { @@ -430,9 +430,7 @@ const GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d) SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeLinear(points, colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index d175f238cd..1560cd2f39 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -68,8 +68,9 @@ SkFlattenable* SkRadialGradient::CreateProc(SkReadBuffer& buffer) { } const SkPoint center = buffer.readPoint(); const SkScalar radius = buffer.readScalar(); - return SkGradientShader::CreateRadial(center, radius, desc.fColors, desc.fPos, desc.fCount, - desc.fTileMode, desc.fGradFlags, desc.fLocalMatrix); + return SkGradientShader::MakeRadial(center, radius, desc.fColors, desc.fPos, desc.fCount, + desc.fTileMode, desc.fGradFlags, + desc.fLocalMatrix).release(); } void SkRadialGradient::flatten(SkWriteBuffer& buffer) const { @@ -313,9 +314,7 @@ const GrFragmentProcessor* GrRadialGradient::TestCreate(GrProcessorTestData* d) SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 1bdf40e115..3021e4bc08 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -36,8 +36,8 @@ SkFlattenable* SkSweepGradient::CreateProc(SkReadBuffer& buffer) { return nullptr; } const SkPoint center = buffer.readPoint(); - return SkGradientShader::CreateSweep(center.x(), center.y(), desc.fColors, desc.fPos, - desc.fCount, desc.fGradFlags, desc.fLocalMatrix); + return SkGradientShader::MakeSweep(center.x(), center.y(), desc.fColors, desc.fPos, + desc.fCount, desc.fGradFlags, desc.fLocalMatrix).release(); } void SkSweepGradient::flatten(SkWriteBuffer& buffer) const { @@ -190,8 +190,8 @@ const GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) { SkScalar* stops = stopsArray; SkShader::TileMode tmIgnored; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY, - colors, stops, colorCount)); + sk_sp<SkShader> shader(SkGradientShader::MakeSweep(center.fX, center.fY, colors, stops, + colorCount)); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index 43d6f1f7c9..d9fc39c3bc 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -338,9 +338,9 @@ SkFlattenable* SkTwoPointConicalGradient::CreateProc(SkReadBuffer& buffer) { } } - return SkGradientShader::CreateTwoPointConical(c1, r1, c2, r2, desc.fColors, desc.fPos, - desc.fCount, desc.fTileMode, desc.fGradFlags, - desc.fLocalMatrix); + return SkGradientShader::MakeTwoPointConical(c1, r1, c2, r2, desc.fColors, desc.fPos, + desc.fCount, desc.fTileMode, desc.fGradFlags, + desc.fLocalMatrix).release(); } void SkTwoPointConicalGradient::flatten(SkWriteBuffer& buffer) const { diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp index 5b0855ab7c..539436928c 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp @@ -207,10 +207,8 @@ const GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData* SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center1, radius1, - center2, radius2, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2, + colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); @@ -484,10 +482,8 @@ const GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorT SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center1, radius1, - center2, radius2, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2, + colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); @@ -692,10 +688,8 @@ const GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTe SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center1, radius1, - center2, radius2, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2, + colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); @@ -940,10 +934,8 @@ const GrFragmentProcessor* CircleInside2PtConicalEffect::TestCreate(GrProcessorT SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center1, radius1, - center2, radius2, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2, + colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); @@ -1173,10 +1165,8 @@ const GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessor SkScalar* stops = stopsArray; SkShader::TileMode tm; int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); - SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center1, radius1, - center2, radius2, - colors, stops, colorCount, - tm)); + auto shader = SkGradientShader::MakeTwoPointConical(center1, radius1, center2, radius2, + colors, stops, colorCount, tm); const GrFragmentProcessor* fp = shader->asFragmentProcessor( d->fContext,GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); GrAlwaysAssert(fp); diff --git a/src/utils/SkMeshUtils.cpp b/src/utils/SkMeshUtils.cpp index cf4e5099b3..5d3eefc54f 100644 --- a/src/utils/SkMeshUtils.cpp +++ b/src/utils/SkMeshUtils.cpp @@ -92,9 +92,9 @@ void SkMeshUtils::Draw(SkCanvas* canvas, const SkBitmap& bitmap, if (idx.init(bitmap.width(), bitmap.height(), rows, cols)) { SkPaint p(paint); - p.setShader(SkShader::CreateBitmapShader(bitmap, + p.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_TileMode, - SkShader::kClamp_TileMode))->unref(); + SkShader::kClamp_TileMode)); canvas->drawVertices(SkCanvas::kTriangles_VertexMode, rows * cols, verts, idx.tex(), colors, nullptr, idx.indices(), idx.indexCount(), p); diff --git a/src/utils/SkNinePatch.cpp b/src/utils/SkNinePatch.cpp index 5ee488e44b..aeb65b1e28 100644 --- a/src/utils/SkNinePatch.cpp +++ b/src/utils/SkNinePatch.cpp @@ -236,14 +236,13 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds, fillRow(verts, texs, bounds.fBottom, SkIntToScalar(bitmap.height()), bounds, xDivs, numXDivs, stretchX, bitmap.width()); - SkShader* shader = SkShader::CreateBitmapShader(bitmap, - SkShader::kClamp_TileMode, - SkShader::kClamp_TileMode); SkPaint p; if (paint) { p = *paint; } - p.setShader(shader)->unref(); + p.setShader(SkShader::MakeBitmapShader(bitmap, + SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode)); canvas->drawVertices(SkCanvas::kTriangles_VertexMode, vCount, mesh.fVerts, mesh.fTexs, mesh.fColors, nullptr, mesh.fIndices, indexCount, p); |