diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/animator/SkDrawPaint.cpp | 2 | ||||
-rw-r--r-- | src/c/sk_paint.cpp | 3 | ||||
-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 | ||||
-rw-r--r-- | src/effects/SkLayerDrawLooper.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkPerlinNoiseShader.cpp | 39 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 4 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.cpp | 16 | ||||
-rw-r--r-- | src/pdf/SkPDFShader.h | 2 | ||||
-rw-r--r-- | src/utils/SkLua.cpp | 2 |
12 files changed, 57 insertions, 50 deletions
diff --git a/src/animator/SkDrawPaint.cpp b/src/animator/SkDrawPaint.cpp index 5f6efd8cc9..fc1a413244 100644 --- a/src/animator/SkDrawPaint.cpp +++ b/src/animator/SkDrawPaint.cpp @@ -237,7 +237,7 @@ void SkDrawPaint::setupPaint(SkPaint* paint) const { if (shader == nullptr) paint->setShader(nullptr); else if (shader != (SkDrawShader*) -1) - SkSafeUnref(paint->setShader(shader->getShader())); + paint->setShader(sk_ref_sp(shader->getShader())); if (strikeThru != -1) paint->setStrikeThruText(SkToBool(strikeThru)); if (strokeCap != -1) diff --git a/src/c/sk_paint.cpp b/src/c/sk_paint.cpp index dd0733f02e..b48e28fb6d 100644 --- a/src/c/sk_paint.cpp +++ b/src/c/sk_paint.cpp @@ -6,6 +6,7 @@ */ #include "SkPaint.h" +#include "SkShader.h" #include "sk_paint.h" #include "sk_types_priv.h" @@ -63,7 +64,7 @@ void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { } void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) { - AsPaint(cpaint)->setShader(AsShader(cshader)); + AsPaint(cpaint)->setShader(sk_ref_sp(AsShader(cshader))); } void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) { 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 diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index 8510767801..526fb4d7e3 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -99,7 +99,7 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo( dst->setMaskFilter(src.getMaskFilter()); } if (bits & kShader_Bit) { - dst->setShader(src.getShader()); + dst->setShader(sk_ref_sp(src.getShader())); } if (bits & kColorFilter_Bit) { dst->setColorFilter(sk_ref_sp(src.getColorFilter())); diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index ef528751dd..72b7e0280d 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -249,18 +249,21 @@ public: #endif }; -SkShader* SkPerlinNoiseShader::CreateFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, - int numOctaves, SkScalar seed, - const SkISize* tileSize) { - return new SkPerlinNoiseShader(kFractalNoise_Type, baseFrequencyX, baseFrequencyY, numOctaves, - seed, tileSize); +sk_sp<SkShader> SkPerlinNoiseShader::MakeFractalNoise(SkScalar baseFrequencyX, + SkScalar baseFrequencyY, + int numOctaves, SkScalar seed, + const SkISize* tileSize) { + return sk_sp<SkShader>(new SkPerlinNoiseShader(kFractalNoise_Type, baseFrequencyX, + baseFrequencyY, numOctaves, + seed, tileSize)); } -SkShader* SkPerlinNoiseShader::CreateTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY, - int numOctaves, SkScalar seed, - const SkISize* tileSize) { - return new SkPerlinNoiseShader(kTurbulence_Type, baseFrequencyX, baseFrequencyY, numOctaves, - seed, tileSize); +sk_sp<SkShader> SkPerlinNoiseShader::MakeTurbulence(SkScalar baseFrequencyX, + SkScalar baseFrequencyY, + int numOctaves, SkScalar seed, + const SkISize* tileSize) { + return sk_sp<SkShader>(new SkPerlinNoiseShader(kTurbulence_Type, baseFrequencyX, baseFrequencyY, + numOctaves, seed, tileSize)); } SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, @@ -295,9 +298,11 @@ SkFlattenable* SkPerlinNoiseShader::CreateProc(SkReadBuffer& buffer) { switch (type) { case kFractalNoise_Type: - return SkPerlinNoiseShader::CreateFractalNoise(freqX, freqY, octaves, seed, &tileSize); + return SkPerlinNoiseShader::MakeFractalNoise(freqX, freqY, octaves, seed, + &tileSize).release(); case kTurbulence_Type: - return SkPerlinNoiseShader::CreateTubulence(freqX, freqY, octaves, seed, &tileSize); + return SkPerlinNoiseShader::MakeTurbulence(freqX, freqY, octaves, seed, + &tileSize).release(); default: return nullptr; } @@ -580,11 +585,11 @@ const GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 0.99f); - SkAutoTUnref<SkShader> shader(d->fRandom->nextBool() ? - SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, - stitchTiles ? &tileSize : nullptr) : - SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, - stitchTiles ? &tileSize : nullptr)); + sk_sp<SkShader> shader(d->fRandom->nextBool() ? + SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, + stitchTiles ? &tileSize : nullptr) : + SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, + stitchTiles ? &tileSize : nullptr)); return shader->asFragmentProcessor(d->fContext, GrTest::TestMatrix(d->fRandom), nullptr, diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 0054143a9a..b6a5b519e8 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1983,7 +1983,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( // PDF treats a shader as a color, so we only set one or the other. sk_sp<SkPDFObject> pdfShader; - const SkShader* shader = paint.getShader(); + SkShader* shader = paint.getShader(); SkColor color = paint.getColor(); if (shader) { // PDF positions patterns relative to the initial transform, so @@ -2005,7 +2005,7 @@ void SkPDFDevice::populateGraphicStateEntryFromPaint( SkScalar rasterScale = SkIntToScalar(fRasterDpi) / DPI_FOR_RASTER_SCALE_ONE; pdfShader.reset(SkPDFShader::GetPDFShader( - fDocument, fRasterDpi, *shader, transform, bounds, rasterScale)); + fDocument, fRasterDpi, shader, transform, bounds, rasterScale)); if (pdfShader.get()) { // pdfShader has been canonicalized so we can directly compare diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp index 7fb1f899f1..eaac84921c 100644 --- a/src/pdf/SkPDFShader.cpp +++ b/src/pdf/SkPDFShader.cpp @@ -434,7 +434,7 @@ public: uint32_t fPixelGeneration; SkShader::TileMode fImageTileModes[2]; - State(const SkShader& shader, const SkMatrix& canvasTransform, + State(SkShader* shader, const SkMatrix& canvasTransform, const SkIRect& bbox, SkScalar rasterScale); bool operator==(const State& b) const; @@ -515,7 +515,7 @@ static SkPDFObject* get_pdf_shader_by_state( // static SkPDFObject* SkPDFShader::GetPDFShader(SkPDFDocument* doc, SkScalar dpi, - const SkShader& shader, + SkShader* shader, const SkMatrix& matrix, const SkIRect& surfaceBBox, SkScalar rasterScale) { @@ -1091,7 +1091,7 @@ bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { return true; } -SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransform, +SkPDFShader::State::State(SkShader* shader, const SkMatrix& canvasTransform, const SkIRect& bbox, SkScalar rasterScale) : fCanvasTransform(canvasTransform), fBBox(bbox), @@ -1099,14 +1099,14 @@ SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransfor fInfo.fColorCount = 0; fInfo.fColors = nullptr; fInfo.fColorOffsets = nullptr; - fShaderTransform = shader.getLocalMatrix(); + fShaderTransform = shader->getLocalMatrix(); fImageTileModes[0] = fImageTileModes[1] = SkShader::kClamp_TileMode; - fType = shader.asAGradient(&fInfo); + fType = shader->asAGradient(&fInfo); if (fType == SkShader::kNone_GradientType) { SkMatrix matrix; - if (shader.isABitmap(&fImage, &matrix, fImageTileModes)) { + if (shader->isABitmap(&fImage, &matrix, fImageTileModes)) { SkASSERT(matrix.isIdentity()); } else { // Generic fallback for unsupported shaders: @@ -1139,7 +1139,7 @@ SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransfor fImage.eraseColor(SK_ColorTRANSPARENT); SkPaint p; - p.setShader(const_cast<SkShader*>(&shader)); + p.setShader(sk_ref_sp(shader)); SkCanvas canvas(fImage); canvas.scale(scale.width(), scale.height()); @@ -1152,7 +1152,7 @@ SkPDFShader::State::State(const SkShader& shader, const SkMatrix& canvasTransfor fPixelGeneration = fImage.getGenerationID(); } else { AllocateGradientInfoStorage(); - shader.asAGradient(&fInfo); + shader->asAGradient(&fInfo); } } diff --git a/src/pdf/SkPDFShader.h b/src/pdf/SkPDFShader.h index a646aef75c..999dc02070 100644 --- a/src/pdf/SkPDFShader.h +++ b/src/pdf/SkPDFShader.h @@ -45,7 +45,7 @@ public: */ static SkPDFObject* GetPDFShader(SkPDFDocument* doc, SkScalar dpi, - const SkShader& shader, + SkShader* shader, const SkMatrix& matrix, const SkIRect& surfaceBBox, SkScalar rasterScale); diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index c25bbf4409..01bf507f17 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -1146,7 +1146,7 @@ static int lpaint_getShader(lua_State* L) { static int lpaint_setShader(lua_State* L) { SkPaint* paint = get_obj<SkPaint>(L, 1); - paint->setShader(get_ref<SkShader>(L, 2)); + paint->setShader(sk_ref_sp(get_ref<SkShader>(L, 2))); return 0; } |