diff options
author | reed <reed@google.com> | 2016-03-25 09:08:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-25 09:08:00 -0700 |
commit | fe63045f075165b1be5d3e7fc5c710021d85f53b (patch) | |
tree | c60f764504ba1d622613a432c88e43f7f65c0fec /src/core | |
parent | cce49271124ff75c880dc0dfed1489f02c82890b (diff) |
move setshader to sk_sp, re-using SK_SUPPORT_LEGACY_CREATESHADER_PTR
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1829303002
Review URL: https://codereview.chromium.org/1829303002
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBlitter.cpp | 15 | ||||
-rw-r--r-- | src/core/SkLightingShader.cpp | 12 | ||||
-rw-r--r-- | src/core/SkLightingShader.h | 8 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 2 |
4 files changed, 19 insertions, 18 deletions
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index 15562168e9..d8e81d59b8 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -809,16 +809,16 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, SkShader* shader = origPaint.getShader(); SkColorFilter* cf = origPaint.getColorFilter(); SkXfermode* mode = origPaint.getXfermode(); - Sk3DShader* shader3D = nullptr; + sk_sp<Sk3DShader> shader3D; SkTCopyOnFirstWrite<SkPaint> paint(origPaint); if (origPaint.getMaskFilter() != nullptr && origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { - shader3D = new Sk3DShader(sk_sp<SkShader>(SkSafeRef(shader))); + shader3D = sk_make_sp<Sk3DShader>(sk_ref_sp(shader)); // we know we haven't initialized lazyPaint yet, so just do it - paint.writable()->setShader(shader3D)->unref(); - shader = shader3D; + paint.writable()->setShader(shader3D); + shader = shader3D.get(); } if (mode) { @@ -843,7 +843,8 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, */ if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) { SkPaint* p = paint.writable(); - shader = p->setShader(nullptr); + p->setShader(nullptr); + shader = nullptr; p->setColorFilter(nullptr); cf = nullptr; mode = p->setXfermodeMode(SkXfermode::kSrc_Mode); @@ -853,9 +854,9 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, if (nullptr == shader) { if (mode) { // xfermodes (and filters) require shaders for our current blitters - shader = new SkColorShader(paint->getColor()); - paint.writable()->setShader(shader)->unref(); + paint.writable()->setShader(SkShader::MakeColorShader(paint->getColor())); paint.writable()->setAlpha(0xFF); + shader = paint->getShader(); } else if (cf) { // if no shader && no xfermode, we just apply the colorfilter to // our color and move on. diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp index 02f75f3516..d8e88c9a0a 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -700,10 +700,10 @@ static bool bitmap_is_too_big(const SkBitmap& bm) { return bm.width() > kMaxSize || bm.height() > kMaxSize; } -SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& normal, - const Lights* lights, - const SkVector& invNormRotation, - const SkMatrix* diffLocalM, const SkMatrix* normLocalM) { +sk_sp<SkShader> SkLightingShader::Make(const SkBitmap& diffuse, const SkBitmap& normal, + const Lights* lights, + const SkVector& invNormRotation, + const SkMatrix* diffLocalM, const SkMatrix* normLocalM) { if (diffuse.isNull() || bitmap_is_too_big(diffuse) || normal.isNull() || bitmap_is_too_big(normal) || diffuse.width() != normal.width() || @@ -713,8 +713,8 @@ SkShader* SkLightingShader::Create(const SkBitmap& diffuse, const SkBitmap& norm SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1)); - return new SkLightingShaderImpl(diffuse, normal, lights, invNormRotation, diffLocalM, - normLocalM); + return sk_make_sp<SkLightingShaderImpl>(diffuse, normal, lights, invNormRotation, diffLocalM, + normLocalM); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkLightingShader.h b/src/core/SkLightingShader.h index e918f3b05f..30ce6559c5 100644 --- a/src/core/SkLightingShader.h +++ b/src/core/SkLightingShader.h @@ -1,4 +1,3 @@ - /* * Copyright 2015 Google Inc. * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkLightingShader_DEFINED #define SkLightingShader_DEFINED @@ -90,9 +88,9 @@ public: The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is (127, 127, 0). */ - static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal, - const Lights* lights, const SkVector& invNormRotation, - const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); + static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, + const Lights* lights, const SkVector& invNormRotation, + const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() }; diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 2ced3f6bef..6a54b9a6c3 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -374,7 +374,9 @@ SET_PTR(Typeface) SET_PTR(Rasterizer) #endif SET_PTR(ImageFilter) +#ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR SET_PTR(Shader) +#endif #ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR SET_PTR(ColorFilter) #endif |