From fc0f44a5f0a4001b894ecf357bbed2a0d93058c1 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 6 Apr 2016 07:44:01 -0700 Subject: Update DownSampleImageFilter to sk_sp TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1864583005 Review URL: https://codereview.chromium.org/1864583005 --- fuzz/FilterFuzz.cpp | 2 +- gm/testimagefilters.cpp | 8 ++++---- include/effects/SkTestImageFilters.h | 18 ++++++++++++------ samplecode/SampleFilterFuzz.cpp | 2 +- src/effects/SkTestImageFilters.cpp | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp index 87653a18bb..db3dc8f8a7 100644 --- a/fuzz/FilterFuzz.cpp +++ b/fuzz/FilterFuzz.cpp @@ -583,7 +583,7 @@ static sk_sp make_image_filter(bool canBeNull) { make_scalar(true))); break; case DOWN_SAMPLE: - filter = sk_sp(SkDownSampleImageFilter::Create(make_scalar())); + filter = SkDownSampleImageFilter::Make(make_scalar(), make_image_filter()); break; case XFERMODE: filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), diff --git a/gm/testimagefilters.cpp b/gm/testimagefilters.cpp index 0174fc1d5c..c6742b2a60 100644 --- a/gm/testimagefilters.cpp +++ b/gm/testimagefilters.cpp @@ -22,7 +22,7 @@ #define FILTER_HEIGHT SkIntToScalar(200) static sk_sp make0() { - return sk_sp(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + return SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr); } static sk_sp make1() { @@ -42,7 +42,7 @@ static sk_sp make4() { sk_sp outer(SkOffsetImageFilter::Make(SkIntToScalar(16), SkIntToScalar(16), nullptr)); - sk_sp inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + sk_sp inner(SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr)); return SkComposeImageFilter::Make(std::move(outer), std::move(inner)); } @@ -50,7 +50,7 @@ static sk_sp make5() { sk_sp first(SkOffsetImageFilter::Make(SkIntToScalar(16), SkIntToScalar(16), nullptr)); - sk_sp second(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + sk_sp second(SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr)); return SkMergeImageFilter::Make(std::move(first), std::move(second)); } @@ -58,7 +58,7 @@ static sk_sp make6() { sk_sp outer(SkOffsetImageFilter::Make(SkIntToScalar(16), SkIntToScalar(16), nullptr)); - sk_sp inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + sk_sp inner(SkDownSampleImageFilter::Make(SK_Scalar1 / 5, nullptr)); sk_sp compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner))); sk_sp cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode)); diff --git a/include/effects/SkTestImageFilters.h b/include/effects/SkTestImageFilters.h index 943bb53356..0f89759c1c 100644 --- a/include/effects/SkTestImageFilters.h +++ b/include/effects/SkTestImageFilters.h @@ -14,20 +14,26 @@ // Fun mode that scales down (only) and then scales back up to look pixelated class SK_API SkDownSampleImageFilter : public SkImageFilter { public: - static SkImageFilter* Create(SkScalar scale, SkImageFilter* input = NULL) { + static sk_sp Make(SkScalar scale, sk_sp input) { if (!SkScalarIsFinite(scale)) { - return NULL; + return nullptr; } // we don't support scale in this range if (scale > SK_Scalar1 || scale <= 0) { - return NULL; + return nullptr; } - return new SkDownSampleImageFilter(scale, input); + return sk_sp(new SkDownSampleImageFilter(scale, std::move(input))); } SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDownSampleImageFilter) +#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR + static SkImageFilter* Create(SkScalar scale, SkImageFilter* input = nullptr) { + return Make(scale, sk_ref_sp(input)).release(); + } +#endif + protected: void flatten(SkWriteBuffer&) const override; @@ -35,8 +41,8 @@ protected: SkIPoint* offset) const override; private: - SkDownSampleImageFilter(SkScalar scale, SkImageFilter* input) - : INHERITED(1, &input), fScale(scale) {} + SkDownSampleImageFilter(SkScalar scale, sk_sp input) + : INHERITED(&input, 1, nullptr), fScale(scale) {} SkScalar fScale; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 67c17fbe4c..685ad90da6 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -586,7 +586,7 @@ static sk_sp make_image_filter(bool canBeNull) { make_scalar(true))); break; case DOWN_SAMPLE: - filter = sk_sp(SkDownSampleImageFilter::Create(make_scalar())); + filter = SkDownSampleImageFilter::Make(make_scalar(), make_image_filter()); break; case XFERMODE: filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), diff --git a/src/effects/SkTestImageFilters.cpp b/src/effects/SkTestImageFilters.cpp index d62fc725cc..5cc890c848 100755 --- a/src/effects/SkTestImageFilters.cpp +++ b/src/effects/SkTestImageFilters.cpp @@ -82,7 +82,7 @@ sk_sp SkDownSampleImageFilter::onFilterImage(SkSpecialImage* sou sk_sp SkDownSampleImageFilter::CreateProc(SkReadBuffer& buffer) { SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); - return sk_sp(Create(buffer.readScalar(), common.getInput(0).get())); + return Make(buffer.readScalar(), common.getInput(0)); } void SkDownSampleImageFilter::flatten(SkWriteBuffer& buffer) const { -- cgit v1.2.3