diff options
author | reed <reed@google.com> | 2016-03-22 08:10:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-22 08:10:17 -0700 |
commit | 4c9776b046dd5e9e46e2d1ce35154855c8fcb381 (patch) | |
tree | 3cdcc394a99b0483921eb86a8f5cc118f20d6433 /src | |
parent | 1eb81db650d31f50be67b12d60c4f9e7dd08432f (diff) |
Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.org/1822623002/ )"
Fixed legacy withColorFilter to call new(er) make method
This reverts commit 1eb81db650d31f50be67b12d60c4f9e7dd08432f.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1825073002
TBR=
Review URL: https://codereview.chromium.org/1825073002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBlitter.cpp | 5 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 14 | ||||
-rw-r--r-- | src/core/SkColorFilter.cpp | 34 | ||||
-rw-r--r-- | src/core/SkColorFilterShader.cpp | 24 | ||||
-rw-r--r-- | src/core/SkColorFilterShader.h | 6 | ||||
-rw-r--r-- | src/core/SkColorMatrixFilterRowMajor255.cpp | 14 | ||||
-rw-r--r-- | src/core/SkColorMatrixFilterRowMajor255.h | 7 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 3 | ||||
-rw-r--r-- | src/core/SkModeColorFilter.cpp | 10 | ||||
-rw-r--r-- | src/core/SkModeColorFilter.h | 7 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 4 | ||||
-rw-r--r-- | src/core/SkReadBuffer.h | 4 | ||||
-rw-r--r-- | src/core/SkShader.cpp | 3 | ||||
-rw-r--r-- | src/effects/SkBlurDrawLooper.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkColorCubeFilter.cpp | 18 | ||||
-rw-r--r-- | src/effects/SkColorFilterImageFilter.cpp | 18 | ||||
-rw-r--r-- | src/effects/SkColorMatrixFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkDropShadowImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkLayerDrawLooper.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkLumaColorFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkTableColorFilter.cpp | 24 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 5 | ||||
-rw-r--r-- | src/utils/SkLua.cpp | 2 | ||||
-rw-r--r-- | src/utils/SkRGBAToYUV.cpp | 2 |
24 files changed, 115 insertions, 107 deletions
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index 04897e3828..15562168e9 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -844,7 +844,8 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) { SkPaint* p = paint.writable(); shader = p->setShader(nullptr); - cf = p->setColorFilter(nullptr); + p->setColorFilter(nullptr); + cf = nullptr; mode = p->setXfermodeMode(SkXfermode::kSrc_Mode); p->setColor(0); } @@ -867,7 +868,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device, if (cf) { SkASSERT(shader); - paint.writable()->setShader(shader->makeWithColorFilter(cf)); + paint.writable()->setShader(shader->makeWithColorFilter(sk_ref_sp(cf))); shader = paint->getShader(); // blitters should ignore the presence/absence of a filter, since // if there is one, the shader will take care of it. diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 3efb44cc54..f7f870210d 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -391,16 +391,17 @@ static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { * If the paint has an imagefilter, but it can be simplified to just a colorfilter, return that * colorfilter, else return nullptr. */ -static SkColorFilter* image_to_color_filter(const SkPaint& paint) { +static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) { SkImageFilter* imgf = paint.getImageFilter(); if (!imgf) { return nullptr; } - SkColorFilter* imgCF; - if (!imgf->asAColorFilter(&imgCF)) { + SkColorFilter* imgCFPtr; + if (!imgf->asAColorFilter(&imgCFPtr)) { return nullptr; } + sk_sp<SkColorFilter> imgCF(imgCFPtr); SkColorFilter* paintCF = paint.getColorFilter(); if (nullptr == paintCF) { @@ -410,8 +411,7 @@ static SkColorFilter* image_to_color_filter(const SkPaint& paint) { // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF) // and we need to combine them into a single colorfilter. - SkAutoTUnref<SkColorFilter> autoImgCF(imgCF); - return SkColorFilter::CreateComposeFilter(imgCF, paintCF); + return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF)); } /** @@ -455,10 +455,10 @@ public: fTempLayerForImageFilter = false; fDone = false; - SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint); + auto simplifiedCF = image_to_color_filter(fOrigPaint); if (simplifiedCF) { SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); - paint->setColorFilter(simplifiedCF)->unref(); + paint->setColorFilter(std::move(simplifiedCF)); paint->setImageFilter(nullptr); fPaint = paint; } diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index dab4ccf7b5..59a625d0b6 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -114,14 +114,15 @@ public: protected: void flatten(SkWriteBuffer& buffer) const override { - buffer.writeFlattenable(fOuter); - buffer.writeFlattenable(fInner); + buffer.writeFlattenable(fOuter.get()); + buffer.writeFlattenable(fInner.get()); } private: - SkComposeColorFilter(SkColorFilter* outer, SkColorFilter* inner, int composedFilterCount) - : fOuter(SkRef(outer)) - , fInner(SkRef(inner)) + SkComposeColorFilter(sk_sp<SkColorFilter> outer, sk_sp<SkColorFilter> inner, + int composedFilterCount) + : fOuter(std::move(outer)) + , fInner(std::move(inner)) , fComposedFilterCount(composedFilterCount) { SkASSERT(composedFilterCount >= 2); @@ -132,9 +133,9 @@ private: return fComposedFilterCount; } - SkAutoTUnref<SkColorFilter> fOuter; - SkAutoTUnref<SkColorFilter> fInner; - const int fComposedFilterCount; + sk_sp<SkColorFilter> fOuter; + sk_sp<SkColorFilter> fInner; + const int fComposedFilterCount; friend class SkColorFilter; @@ -142,23 +143,24 @@ private: }; SkFlattenable* SkComposeColorFilter::CreateProc(SkReadBuffer& buffer) { - SkAutoTUnref<SkColorFilter> outer(buffer.readColorFilter()); - SkAutoTUnref<SkColorFilter> inner(buffer.readColorFilter()); - return CreateComposeFilter(outer, inner); + sk_sp<SkColorFilter> outer(buffer.readColorFilter()); + sk_sp<SkColorFilter> inner(buffer.readColorFilter()); + return MakeComposeFilter(std::move(outer), std::move(inner)).release(); } /////////////////////////////////////////////////////////////////////////////////////////////////// -SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) { +sk_sp<SkColorFilter> SkColorFilter::MakeComposeFilter(sk_sp<SkColorFilter> outer, + sk_sp<SkColorFilter> inner) { if (!outer) { - return SkSafeRef(inner); + return inner; } if (!inner) { - return SkSafeRef(outer); + return outer; } // Give the subclass a shot at a more optimal composition... - SkColorFilter* composition = outer->newComposed(inner); + auto composition = outer->makeComposed(inner); if (composition) { return composition; } @@ -167,7 +169,7 @@ SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorF if (count > SK_MAX_COMPOSE_COLORFILTER_COUNT) { return nullptr; } - return new SkComposeColorFilter(outer, inner, count); + return sk_sp<SkColorFilter>(new SkComposeColorFilter(std::move(outer), std::move(inner),count)); } #include "SkModeColorFilter.h" diff --git a/src/core/SkColorFilterShader.cpp b/src/core/SkColorFilterShader.cpp index 2e426a17ed..8a175024de 100644 --- a/src/core/SkColorFilterShader.cpp +++ b/src/core/SkColorFilterShader.cpp @@ -15,26 +15,26 @@ #include "GrFragmentProcessor.h" #endif -SkColorFilterShader::SkColorFilterShader(SkShader* shader, SkColorFilter* filter) - : fShader(SkRef(shader)) - , fFilter(SkRef(filter)) +SkColorFilterShader::SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter) + : fShader(std::move(shader)) + , fFilter(std::move(filter)) { - SkASSERT(shader); - SkASSERT(filter); + SkASSERT(fShader); + SkASSERT(fFilter); } SkFlattenable* SkColorFilterShader::CreateProc(SkReadBuffer& buffer) { auto shader = buffer.readShader(); - SkAutoTUnref<SkColorFilter> filter(buffer.readColorFilter()); - if (!shader || !filter.get()) { + auto filter = buffer.readColorFilter(); + if (!shader || !filter) { return nullptr; } - return new SkColorFilterShader(shader.get(), filter); + return new SkColorFilterShader(shader, filter); } void SkColorFilterShader::flatten(SkWriteBuffer& buffer) const { - buffer.writeFlattenable(fShader); - buffer.writeFlattenable(fFilter); + buffer.writeFlattenable(fShader.get()); + buffer.writeFlattenable(fFilter.get()); } uint32_t SkColorFilterShader::FilterShaderContext::getFlags() const { @@ -137,10 +137,10 @@ void SkColorFilterShader::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////////////////////////// -sk_sp<SkShader> SkShader::makeWithColorFilter(SkColorFilter* filter) const { +sk_sp<SkShader> SkShader::makeWithColorFilter(sk_sp<SkColorFilter> filter) const { SkShader* base = const_cast<SkShader*>(this); if (!filter) { return sk_ref_sp(base); } - return sk_make_sp<SkColorFilterShader>(base, filter); + return sk_make_sp<SkColorFilterShader>(sk_ref_sp(base), filter); } diff --git a/src/core/SkColorFilterShader.h b/src/core/SkColorFilterShader.h index 0f41a43c49..167a272fa4 100644 --- a/src/core/SkColorFilterShader.h +++ b/src/core/SkColorFilterShader.h @@ -13,7 +13,7 @@ class SkColorFilterShader : public SkShader { public: - SkColorFilterShader(SkShader* shader, SkColorFilter* filter); + SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter); #if SK_SUPPORT_GPU const GrFragmentProcessor* asFragmentProcessor(GrContext*, @@ -53,8 +53,8 @@ protected: Context* onCreateContext(const ContextRec&, void* storage) const override; private: - SkAutoTUnref<SkShader> fShader; - SkAutoTUnref<SkColorFilter> fFilter; + sk_sp<SkShader> fShader; + sk_sp<SkColorFilter> fFilter; typedef SkShader INHERITED; }; diff --git a/src/core/SkColorMatrixFilterRowMajor255.cpp b/src/core/SkColorMatrixFilterRowMajor255.cpp index 09df61699d..bd9a66a561 100644 --- a/src/core/SkColorMatrixFilterRowMajor255.cpp +++ b/src/core/SkColorMatrixFilterRowMajor255.cpp @@ -226,12 +226,13 @@ static void set_concat(SkScalar result[20], const SkScalar outer[20], const SkSc // End duplication ////// -SkColorFilter* SkColorMatrixFilterRowMajor255::newComposed(const SkColorFilter* innerFilter) const { +sk_sp<SkColorFilter> +SkColorMatrixFilterRowMajor255::makeComposed(sk_sp<SkColorFilter> innerFilter) const { SkScalar innerMatrix[20]; if (innerFilter->asColorMatrix(innerMatrix) && !needs_clamping(innerMatrix)) { SkScalar concat[20]; set_concat(concat, fMatrix, innerMatrix); - return new SkColorMatrixFilterRowMajor255(concat); + return sk_make_sp<SkColorMatrixFilterRowMajor255>(concat); } return nullptr; } @@ -417,15 +418,16 @@ void SkColorMatrixFilterRowMajor255::toString(SkString* str) const { /////////////////////////////////////////////////////////////////////////////// -SkColorFilter* SkColorFilter::CreateMatrixFilterRowMajor255(const SkScalar array[20]) { - return new SkColorMatrixFilterRowMajor255(array); +sk_sp<SkColorFilter> SkColorFilter::MakeMatrixFilterRowMajor255(const SkScalar array[20]) { + return sk_sp<SkColorFilter>(new SkColorMatrixFilterRowMajor255(array)); } /////////////////////////////////////////////////////////////////////////////// -SkColorFilter* SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(const SkScalar row[5]) { +sk_sp<SkColorFilter> +SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(const SkScalar row[5]) { SkASSERT(row); - SkColorMatrixFilterRowMajor255* cf = new SkColorMatrixFilterRowMajor255(); + auto cf = sk_make_sp<SkColorMatrixFilterRowMajor255>(); static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't match"); for (int i = 0; i < 4; ++i) { memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5); diff --git a/src/core/SkColorMatrixFilterRowMajor255.h b/src/core/SkColorMatrixFilterRowMajor255.h index 106d2bd882..0ad64fa2f0 100644 --- a/src/core/SkColorMatrixFilterRowMajor255.h +++ b/src/core/SkColorMatrixFilterRowMajor255.h @@ -12,16 +12,17 @@ class SK_API SkColorMatrixFilterRowMajor255 : public SkColorFilter { public: + SkColorMatrixFilterRowMajor255() {}; explicit SkColorMatrixFilterRowMajor255(const SkScalar array[20]); /** Creates a color matrix filter that returns the same value in all four channels. */ - static SkColorFilter* CreateSingleChannelOutput(const SkScalar row[5]); + static sk_sp<SkColorFilter> MakeSingleChannelOutput(const SkScalar row[5]); void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override; void filterSpan4f(const SkPM4f src[], int count, SkPM4f[]) const override; uint32_t getFlags() const override; bool asColorMatrix(SkScalar matrix[20]) const override; - SkColorFilter* newComposed(const SkColorFilter*) const override; + sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter>) const override; #if SK_SUPPORT_GPU const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; @@ -35,8 +36,6 @@ protected: void flatten(SkWriteBuffer&) const override; private: - SkColorMatrixFilterRowMajor255() {}; - SkScalar fMatrix[20]; float fTranspose[20]; // for Sk4s uint32_t fFlags; diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 90be52b403..fb4b48fdbd 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -207,8 +207,7 @@ void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkR pnt.setShader(std::move(shader)); if (colors) { - SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[i], mode)); - pnt.setColorFilter(cf); + pnt.setColorFilter(SkColorFilter::MakeModeFilter(colors[i], mode)); } path.rewind(); diff --git a/src/core/SkModeColorFilter.cpp b/src/core/SkModeColorFilter.cpp index 1e104d8dc7..3da51609a3 100644 --- a/src/core/SkModeColorFilter.cpp +++ b/src/core/SkModeColorFilter.cpp @@ -80,7 +80,7 @@ void SkModeColorFilter::updateCache() { SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) { SkColor color = buffer.readColor(); SkXfermode::Mode mode = (SkXfermode::Mode)buffer.readUInt(); - return SkColorFilter::CreateModeFilter(color, mode); + return SkColorFilter::MakeModeFilter(color, mode).release(); } /////////////////////////////////////////////////////////////////////////////// @@ -148,7 +148,7 @@ private: /////////////////////////////////////////////////////////////////////////////// -SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode mode) { +sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkXfermode::Mode mode) { if (!SkIsValidMode(mode)) { return nullptr; } @@ -183,10 +183,10 @@ SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode m switch (mode) { case SkXfermode::kSrc_Mode: - return new Src_SkModeColorFilter(color); + return sk_make_sp<Src_SkModeColorFilter>(color); case SkXfermode::kSrcOver_Mode: - return new SrcOver_SkModeColorFilter(color); + return sk_make_sp<SrcOver_SkModeColorFilter>(color); default: - return SkModeColorFilter::Create(color, mode); + return SkModeColorFilter::Make(color, mode); } } diff --git a/src/core/SkModeColorFilter.h b/src/core/SkModeColorFilter.h index 44e618a3ad..d73cab7932 100644 --- a/src/core/SkModeColorFilter.h +++ b/src/core/SkModeColorFilter.h @@ -13,9 +13,14 @@ class SkModeColorFilter : public SkColorFilter { public: + static sk_sp<SkColorFilter> Make(SkColor color, SkXfermode::Mode mode) { + return sk_sp<SkColorFilter>(new SkModeColorFilter(color, mode)); + } +#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR static SkColorFilter* Create(SkColor color, SkXfermode::Mode mode) { - return new SkModeColorFilter(color, mode); + return Make(color, mode).release(); } +#endif SkColor getColor() const { return fColor; } SkXfermode::Mode getMode() const { return fMode; } diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 19bdcaf0aa..6fe9d7599d 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -375,7 +375,9 @@ SET_PTR(Rasterizer) #endif SET_PTR(ImageFilter) SET_PTR(Shader) +#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR SET_PTR(ColorFilter) +#endif SET_PTR(Xfermode) #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR SET_PTR(PathEffect) @@ -1940,7 +1942,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { this->setShader(buffer.readShader()); SkSafeUnref(this->setXfermode(buffer.readXfermode())); SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter())); - SkSafeUnref(this->setColorFilter(buffer.readColorFilter())); + this->setColorFilter(buffer.readColorFilter()); this->setRasterizer(buffer.readRasterizer()); this->setLooper(buffer.readDrawLooper()); SkSafeUnref(this->setImageFilter(buffer.readImageFilter())); diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index 575375eded..46f6b818da 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -130,7 +130,9 @@ public: template <typename T> T* readFlattenable() { return (T*) this->readFlattenable(T::GetFlattenableType()); } - SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); } + sk_sp<SkColorFilter> readColorFilter() { + return sk_sp<SkColorFilter>(this->readFlattenable<SkColorFilter>()); + } sk_sp<SkDrawLooper> readDrawLooper() { return sk_sp<SkDrawLooper>(this->readFlattenable<SkDrawLooper>()); } diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 52d0064eb1..75fa6fc60c 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -449,4 +449,7 @@ SkShader* SkShader::CreatePictureShader(const SkPicture* src, TileMode tmx, Tile return MakePictureShader(sk_ref_sp(const_cast<SkPicture*>(src)), tmx, tmy, localMatrix, tile).release(); } +SkShader* SkShader::newWithColorFilter(SkColorFilter* filter) const { + return this->makeWithColorFilter(sk_ref_sp(filter)).release(); +} #endif diff --git a/src/effects/SkBlurDrawLooper.cpp b/src/effects/SkBlurDrawLooper.cpp index d8127eba4e..c8e20e1265 100644 --- a/src/effects/SkBlurDrawLooper.cpp +++ b/src/effects/SkBlurDrawLooper.cpp @@ -44,8 +44,7 @@ void SkBlurDrawLooper::initEffects() { // be baked into the blurred mask. SkColor opaqueColor = SkColorSetA(fBlurColor, 255); //The SrcIn xfer mode will multiply 'color' by the incoming alpha - fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor, - SkXfermode::kSrcIn_Mode); + fColorFilter = SkColorFilter::MakeModeFilter(opaqueColor, SkXfermode::kSrcIn_Mode); } else { fColorFilter = nullptr; } @@ -81,7 +80,6 @@ void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const { SkBlurDrawLooper::~SkBlurDrawLooper() { SkSafeUnref(fBlur); - SkSafeUnref(fColorFilter); } bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const { diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index d59f123a80..d80a02fef2 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -48,19 +48,19 @@ static bool is_valid_3D_lut(SkData* cubeData, int cubeDimension) { (nullptr != cubeData) && (cubeData->size() >= minMemorySize); } -SkColorFilter* SkColorCubeFilter::Create(SkData* cubeData, int cubeDimension) { - if (!is_valid_3D_lut(cubeData, cubeDimension)) { +sk_sp<SkColorFilter> SkColorCubeFilter::Make(sk_sp<SkData> cubeData, int cubeDimension) { + if (!is_valid_3D_lut(cubeData.get(), cubeDimension)) { return nullptr; } - return new SkColorCubeFilter(cubeData, cubeDimension); + return sk_sp<SkColorFilter>(new SkColorCubeFilter(std::move(cubeData), cubeDimension)); } -SkColorCubeFilter::SkColorCubeFilter(SkData* cubeData, int cubeDimension) - : fCubeData(SkRef(cubeData)) - , fUniqueID(SkNextColorCubeUniqueID()) - , fCache(cubeDimension) { -} +SkColorCubeFilter::SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension) + : fCubeData(std::move(cubeData)) + , fUniqueID(SkNextColorCubeUniqueID()) + , fCache(cubeDimension) +{} uint32_t SkColorCubeFilter::getFlags() const { return this->INHERITED::getFlags() | kAlphaUnchanged_Flag; @@ -142,7 +142,7 @@ SkFlattenable* SkColorCubeFilter::CreateProc(SkReadBuffer& buffer) { if (!buffer.validate(is_valid_3D_lut(cubeData.get(), cubeDimension))) { return nullptr; } - return Create(cubeData.get(), cubeDimension); + return Make(std::move(cubeData), cubeDimension).release(); } void SkColorCubeFilter::flatten(SkWriteBuffer& buffer) const { diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index 96ce5d9690..6eb66533d9 100644 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -25,10 +25,10 @@ SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter if (input && input->isColorFilterNode(&inputCF)) { // This is an optimization, as it collapses the hierarchy by just combining the two // colorfilters into a single one, which the new imagefilter will wrap. - SkAutoUnref autoUnref(inputCF); - SkAutoTUnref<SkColorFilter> newCF(SkColorFilter::CreateComposeFilter(cf, inputCF)); + sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf), + sk_sp<SkColorFilter>(inputCF))); if (newCF) { - return new SkColorFilterImageFilter(newCF, input->getInput(0), cropRect); + return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect); } } @@ -42,17 +42,13 @@ SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); - SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter()); - return Create(cf, common.getInput(0), &common.cropRect()); + sk_sp<SkColorFilter> cf(buffer.readColorFilter()); + return Create(cf.get(), common.getInput(0), &common.cropRect()); } void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { this->INHERITED::flatten(buffer); - buffer.writeFlattenable(fColorFilter); -} - -SkColorFilterImageFilter::~SkColorFilterImageFilter() { - fColorFilter->unref(); + buffer.writeFlattenable(fColorFilter.get()); } bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source, @@ -94,7 +90,7 @@ bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const SkASSERT(1 == this->countInputs()); if (!this->cropRectIsSet()) { if (filter) { - *filter = SkRef(fColorFilter); + *filter = SkRef(fColorFilter.get()); } return true; } diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index e122b6ac8e..82bd45b73d 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -16,7 +16,7 @@ static SkScalar byte_to_scale(U8CPU byte) { } } -SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor add) { +sk_sp<SkColorFilter> SkColorMatrixFilter::MakeLightingFilter(SkColor mul, SkColor add) { SkColorMatrix matrix; matrix.setScale(byte_to_scale(SkColorGetR(mul)), byte_to_scale(SkColorGetG(mul)), @@ -26,5 +26,5 @@ SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor ad SkIntToScalar(SkColorGetG(add)), SkIntToScalar(SkColorGetB(add)), 0); - return SkColorMatrixFilter::Create(matrix); + return SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat); } diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp index deece35b38..e32b89ee6d 100644 --- a/src/effects/SkDropShadowImageFilter.cpp +++ b/src/effects/SkDropShadowImageFilter.cpp @@ -79,11 +79,9 @@ bool SkDropShadowImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitm sigma.fX = SkMaxScalar(0, sigma.fX); sigma.fY = SkMaxScalar(0, sigma.fY); SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY)); - SkAutoTUnref<SkColorFilter> colorFilter( - SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); SkPaint paint; paint.setImageFilter(blurFilter.get()); - paint.setColorFilter(colorFilter.get()); + paint.setColorFilter(SkColorFilter::MakeModeFilter(fColor, SkXfermode::kSrcIn_Mode)); paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); SkVector offsetVec = SkVector::Make(fDx, fDy); ctx.ctm().mapVectors(&offsetVec, 1); diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp index ae31482ae7..8510767801 100644 --- a/src/effects/SkLayerDrawLooper.cpp +++ b/src/effects/SkLayerDrawLooper.cpp @@ -102,7 +102,7 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo( dst->setShader(src.getShader()); } if (bits & kColorFilter_Bit) { - dst->setColorFilter(src.getColorFilter()); + dst->setColorFilter(sk_ref_sp(src.getColorFilter())); } if (bits & kXfermode_Bit) { dst->setXfermode(src.getXfermode()); diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp index 0ca6342d56..18b2485a30 100644 --- a/src/effects/SkLumaColorFilter.cpp +++ b/src/effects/SkLumaColorFilter.cpp @@ -37,7 +37,9 @@ void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, } } -SkColorFilter* SkLumaColorFilter::Create() { return new SkLumaColorFilter; } +sk_sp<SkColorFilter> SkLumaColorFilter::Make() { + return sk_sp<SkColorFilter>(new SkLumaColorFilter); +} SkLumaColorFilter::SkLumaColorFilter() : INHERITED() {} diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 5ae175ffca..4ce0b4bb0e 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -46,7 +46,7 @@ public: virtual ~SkTable_ColorFilter() { delete fBitmap; } bool asComponentTable(SkBitmap* table) const override; - SkColorFilter* newComposed(const SkColorFilter* inner) const override; + sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override; #if SK_SUPPORT_GPU const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; @@ -251,7 +251,7 @@ SkFlattenable* SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) { b = ptr; ptr += 256; } - return SkTableColorFilter::CreateARGB(a, r, g, b); + return SkTableColorFilter::MakeARGB(a, r, g, b).release(); } bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const { @@ -287,7 +287,7 @@ static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin } } -SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter) const { +sk_sp<SkColorFilter> SkTable_ColorFilter::makeComposed(sk_sp<SkColorFilter> innerFilter) const { SkBitmap innerBM; if (!innerFilter->asComponentTable(&innerBM)) { return nullptr; @@ -326,7 +326,7 @@ SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter combine_tables(concatG, tableG, innerBM.getAddr8(0, 2)); combine_tables(concatB, tableB, innerBM.getAddr8(0, 3)); - return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB); + return SkTableColorFilter::MakeARGB(concatA, concatR, concatG, concatB); } #if SK_SUPPORT_GPU @@ -554,7 +554,7 @@ const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d) } } } - SkAutoTUnref<SkColorFilter> filter(SkTableColorFilter::CreateARGB( + auto filter(SkTableColorFilter::MakeARGB( (flags & (1 << 0)) ? luts[0] : nullptr, (flags & (1 << 1)) ? luts[1] : nullptr, (flags & (1 << 2)) ? luts[2] : nullptr, @@ -587,15 +587,15 @@ const GrFragmentProcessor* SkTable_ColorFilter::asFragmentProcessor(GrContext* c /////////////////////////////////////////////////////////////////////////////// -SkColorFilter* SkTableColorFilter::Create(const uint8_t table[256]) { - return new SkTable_ColorFilter(table, table, table, table); +sk_sp<SkColorFilter> SkTableColorFilter::Make(const uint8_t table[256]) { + return sk_make_sp<SkTable_ColorFilter>(table, table, table, table); } -SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], - const uint8_t tableR[256], - const uint8_t tableG[256], - const uint8_t tableB[256]) { - return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); +sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256], + const uint8_t tableR[256], + const uint8_t tableG[256], + const uint8_t tableB[256]) { + return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB); } SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 514cd88408..66048ff751 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -2114,8 +2114,7 @@ static SkSize rect_to_size(const SkRect& r) { return SkSize::Make(r.width(), r.height()); } -static const SkImage* color_filter(const SkImage* image, - SkColorFilter* colorFilter) { +static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFilter) { sk_sp<SkSurface> surface(SkSurface::NewRaster( SkImageInfo::MakeN32Premul(image->dimensions()))); if (!surface) { @@ -2124,7 +2123,7 @@ static const SkImage* color_filter(const SkImage* image, SkCanvas* canvas = surface->getCanvas(); canvas->clear(SK_ColorTRANSPARENT); SkPaint paint; - paint.setColorFilter(colorFilter); + paint.setColorFilter(sk_ref_sp(colorFilter)); canvas->drawImage(image, 0, 0, &paint); canvas->flush(); return surface->makeImageSnapshot().release(); diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 56e2b41a45..d0b6a4b1ac 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -1114,7 +1114,7 @@ static int lpaint_getColorFilter(lua_State* L) { static int lpaint_setColorFilter(lua_State* L) { SkPaint* paint = get_obj<SkPaint>(L, 1); - paint->setColorFilter(get_ref<SkColorFilter>(L, 2)); + paint->setColorFilter(sk_ref_sp(get_ref<SkColorFilter>(L, 2))); return 0; } diff --git a/src/utils/SkRGBAToYUV.cpp b/src/utils/SkRGBAToYUV.cpp index b7f78bac14..eebbda4869 100644 --- a/src/utils/SkRGBAToYUV.cpp +++ b/src/utils/SkRGBAToYUV.cpp @@ -49,7 +49,7 @@ bool SkRGBAToYUV(const SkImage* image, const SkISize sizes[3], void* const plane int rowStartIdx = 5 * i; const SkScalar* row = kYUVColorSpaceInvMatrices[colorSpace] + rowStartIdx; paint.setColorFilter( - SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(row))->unref(); + SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(row)); surface->getCanvas()->drawImageRect(image, SkIRect::MakeWH(image->width(), image->height()), SkRect::MakeIWH(surface->width(), surface->height()), &paint); |