diff --git a/gm/testimagefilters.cpp b/gm/testimagefilters.cpp index 465d606e2b..2380b3438e 100644 --- a/gm/testimagefilters.cpp +++ b/gm/testimagefilters.cpp @@ -21,59 +21,55 @@ #define FILTER_WIDTH SkIntToScalar(150) #define FILTER_HEIGHT SkIntToScalar(200) -static SkImageFilter* make0() { return SkDownSampleImageFilter::Create(SK_Scalar1 / 5); } -static SkImageFilter* make1() { return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); } +static SkImageFilter* make0() { + return SkDownSampleImageFilter::Create(SK_Scalar1 / 5); +} + +static SkImageFilter* make1() { + return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); +} + static SkImageFilter* make2() { - auto cf = SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode); + sk_sp cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); return SkColorFilterImageFilter::Create(cf.get()); } + static SkImageFilter* make3() { return SkBlurImageFilter::Create(8, 0); } static SkImageFilter* make4() { - SkImageFilter* outer = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); - SkImageFilter* inner = SkDownSampleImageFilter::Create(SK_Scalar1 / 5); - SkAutoUnref aur0(outer); - SkAutoUnref aur1(inner); - return SkComposeImageFilter::Create(outer, inner); + sk_sp outer(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16))); + sk_sp inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + return SkComposeImageFilter::Make(std::move(outer), std::move(inner)).release(); } + static SkImageFilter* make5() { - SkImageFilter* first = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); - SkImageFilter* second = SkDownSampleImageFilter::Create(SK_Scalar1 / 5); - SkAutoUnref aur0(first); - SkAutoUnref aur1(second); - return SkMergeImageFilter::Create(first, second); + sk_sp first(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16))); + sk_sp second(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + return SkMergeImageFilter::Create(first.get(), second.get()); } static SkImageFilter* make6() { - SkImageFilter* outer = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); - SkImageFilter* inner = SkDownSampleImageFilter::Create(SK_Scalar1 / 5); - SkAutoUnref aur0(outer); - SkAutoUnref aur1(inner); - SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner); - SkAutoUnref aur2(compose); + sk_sp outer(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16))); + sk_sp inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); + sk_sp compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner))); - auto cf = SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode); - SkImageFilter* blue = SkColorFilterImageFilter::Create(cf.get()); - SkAutoUnref aur4(blue); + sk_sp cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode)); + sk_sp blue(SkColorFilterImageFilter::Create(cf.get())); - return SkMergeImageFilter::Create(compose, blue); + return SkMergeImageFilter::Create(compose.get(), blue.get()); } static SkImageFilter* make7() { - SkImageFilter* outer = SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); - SkImageFilter* inner = make3(); - SkAutoUnref aur0(outer); - SkAutoUnref aur1(inner); - SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner); - SkAutoUnref aur2(compose); + sk_sp outer(SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16))); + sk_sp inner(make3()); + sk_sp compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner))); - auto cf = SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode); - SkImageFilter* blue = SkColorFilterImageFilter::Create(cf.get()); - SkAutoUnref aur4(blue); + sk_sp cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode)); + sk_sp blue(SkColorFilterImageFilter::Create(cf.get())); - return SkMergeImageFilter::Create(compose, blue); + return SkMergeImageFilter::Create(compose.get(), blue.get()); } static void draw0(SkCanvas* canvas) { diff --git a/include/effects/SkComposeImageFilter.h b/include/effects/SkComposeImageFilter.h index cf73a001c8..49c7685415 100644 --- a/include/effects/SkComposeImageFilter.h +++ b/include/effects/SkComposeImageFilter.h @@ -12,25 +12,32 @@ class SK_API SkComposeImageFilter : public SkImageFilter { public: - static SkImageFilter* Create(SkImageFilter* outer, SkImageFilter* inner) { + static sk_sp Make(sk_sp outer, sk_sp inner) { if (!outer) { - return SkSafeRef(inner); + return inner; } if (!inner) { - return SkRef(outer); + return outer; } - SkImageFilter* inputs[2] = { outer, inner }; - return new SkComposeImageFilter(inputs); + sk_sp inputs[2] = { std::move(outer), std::move(inner) }; + return sk_sp(new SkComposeImageFilter(inputs)); } SkRect computeFastBounds(const SkRect& src) const override; SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeImageFilter) +#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR + static SkImageFilter* Create(SkImageFilter* outer, SkImageFilter* inner) { + return Make(sk_ref_sp(outer), + sk_ref_sp(inner)).release(); + } +#endif + protected: - explicit SkComposeImageFilter(SkImageFilter* inputs[2]) : INHERITED(2, inputs) { - SkASSERT(inputs[0]); - SkASSERT(inputs[1]); + explicit SkComposeImageFilter(sk_sp inputs[2]) : INHERITED(inputs, 2, nullptr) { + SkASSERT(inputs[0].get()); + SkASSERT(inputs[1].get()); } sk_sp onFilterImage(SkSpecialImage* source, const Context&, SkIPoint* offset) const override; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 751ef9be39..103d8c4a56 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -646,13 +646,9 @@ static sk_sp make_image_filter(bool canBeNull) { &cropR)); break; } - case COMPOSE: { - sk_sp subFilter1(make_image_filter()); - sk_sp subFilter2(make_image_filter()); - filter = sk_sp(SkComposeImageFilter::Create(subFilter1.get(), - subFilter2.get())); + case COMPOSE: + filter = SkComposeImageFilter::Make(make_image_filter(), make_image_filter()); break; - } case DISTANT_LIGHT: { sk_sp subFilter(make_image_filter()); diff --git a/src/effects/SkComposeImageFilter.cpp b/src/effects/SkComposeImageFilter.cpp index c6722d5458..3cd8a9e6fd 100644 --- a/src/effects/SkComposeImageFilter.cpp +++ b/src/effects/SkComposeImageFilter.cpp @@ -13,8 +13,8 @@ SkRect SkComposeImageFilter::computeFastBounds(const SkRect& src) const { - SkImageFilter* outer = getInput(0); - SkImageFilter* inner = getInput(1); + SkImageFilter* outer = this->getInput(0); + SkImageFilter* inner = this->getInput(1); return outer->computeFastBounds(inner->computeFastBounds(src)); } @@ -26,7 +26,7 @@ sk_sp SkComposeImageFilter::onFilterImage(SkSpecialImage* source // filter, so that the inner filter produces the pixels that the outer // filter requires as input. This matters if the outer filter moves pixels. SkIRect innerClipBounds; - innerClipBounds = getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm()); + innerClipBounds = this->getInput(0)->filterBounds(ctx.clipBounds(), ctx.ctm()); Context innerContext(ctx.ctm(), innerClipBounds, ctx.cache()); SkIPoint innerOffset = SkIPoint::Make(0, 0); sk_sp inner(this->filterInput(1, source, innerContext, &innerOffset)); @@ -60,7 +60,8 @@ SkIRect SkComposeImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& SkFlattenable* SkComposeImageFilter::CreateProc(SkReadBuffer& buffer) { SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2); - return SkComposeImageFilter::Create(common.getInput(0), common.getInput(1)); + return SkComposeImageFilter::Make(sk_ref_sp(common.getInput(0)), + sk_ref_sp(common.getInput(1))).release(); } #ifndef SK_IGNORE_TO_STRING diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index cd900e3df1..3cf73a8a9c 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -783,9 +783,10 @@ DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) { } DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { - SkAutoTUnref filter1(makeBlur()); - SkAutoTUnref filter2(makeBlur()); - SkAutoTUnref composedFilter(SkComposeImageFilter::Create(filter1.get(), filter2.get())); + sk_sp filter1(makeBlur()); + sk_sp filter2(makeBlur()); + sk_sp composedFilter(SkComposeImageFilter::Make(std::move(filter1), + std::move(filter2))); SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); SkRect expectedBounds = SkRect::MakeXYWH( @@ -1337,11 +1338,11 @@ static void test_composed_imagefilter_offset(SkImageFilter::Proxy* proxy, sk_sp srcImg(create_empty_special_image(context, proxy, 100)); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); - SkAutoTUnref offsetFilter(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect)); - SkAutoTUnref blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, - nullptr, &cropRect)); - SkAutoTUnref composedFilter(SkComposeImageFilter::Create(blurFilter, - offsetFilter.get())); + sk_sp offsetFilter(SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect)); + sk_sp blurFilter(SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1, + nullptr, &cropRect)); + sk_sp composedFilter(SkComposeImageFilter::Make(std::move(blurFilter), + std::move(offsetFilter))); SkIPoint offset; SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); @@ -1373,12 +1374,12 @@ static void test_composed_imagefilter_bounds(SkImageFilter::Proxy* proxy, SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100)); recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); recordingCanvas->clear(SK_ColorGREEN); - sk_sp picture = recorder.finishRecordingAsPicture(); + sk_sp picture(recorder.finishRecordingAsPicture()); sk_sp pictureFilter(SkPictureImageFilter::Make(picture)); SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); sk_sp offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullptr, &cropRect)); - sk_sp composedFilter( - SkComposeImageFilter::Create(offsetFilter.get(), pictureFilter.get())); + sk_sp composedFilter(SkComposeImageFilter::Make(std::move(offsetFilter), + std::move(pictureFilter))); sk_sp sourceImage(create_empty_special_image(context, proxy, 100)); SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);