diff options
author | robertphillips <robertphillips@google.com> | 2016-04-15 04:37:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-15 04:37:07 -0700 |
commit | a53011ef44705a091a8e24f7ea289a3f9ad759f2 (patch) | |
tree | b3cca836becb797f55d0caacb3f4cca0bf4e910e | |
parent | 834d9e109298ae704043128005f8c1bc622350f4 (diff) |
Update DisplacementMapEffect to sk_sp
TBR=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1877783003
Review URL: https://codereview.chromium.org/1877783003
-rw-r--r-- | bench/DisplacementBench.cpp | 36 | ||||
-rw-r--r-- | bench/ImageFilterDAGBench.cpp | 7 | ||||
-rw-r--r-- | fuzz/FilterFuzz.cpp | 16 | ||||
-rw-r--r-- | gm/displacement.cpp | 154 | ||||
-rw-r--r-- | gm/imagefiltersclipped.cpp | 11 | ||||
-rw-r--r-- | gm/imagefilterscropexpand.cpp | 13 | ||||
-rw-r--r-- | gm/imagefiltersscaled.cpp | 11 | ||||
-rw-r--r-- | gm/imagefilterstransformed.cpp | 11 | ||||
-rw-r--r-- | include/effects/SkDisplacementMapEffect.h | 28 | ||||
-rw-r--r-- | samplecode/SampleFilterFuzz.cpp | 16 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 27 | ||||
-rw-r--r-- | tests/ImageFilterTest.cpp | 8 |
12 files changed, 171 insertions, 167 deletions
diff --git a/bench/DisplacementBench.cpp b/bench/DisplacementBench.cpp index 82857e630f..9edf21476c 100644 --- a/bench/DisplacementBench.cpp +++ b/bench/DisplacementBench.cpp @@ -18,9 +18,7 @@ class DisplacementBaseBench : public Benchmark { public: - DisplacementBaseBench(bool small) : - fInitialized(false), fIsSmall(small) { - } + DisplacementBaseBench(bool small) : fInitialized(false), fIsSmall(small) { } protected: void onDelayedSetup() override { @@ -92,8 +90,7 @@ private: class DisplacementZeroBench : public DisplacementBaseBench { public: - DisplacementZeroBench(bool small) : INHERITED(small) { - } + DisplacementZeroBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { @@ -104,9 +101,10 @@ protected: SkPaint paint; sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); // No displacement effect - paint.setImageFilter(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))->unref(); + paint.setImageFilter(SkDisplacementMapEffect::Make( + SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kG_ChannelSelectorType, + 0.0f, std::move(displ), nullptr)); for (int i = 0; i < loops; i++) { this->drawClippedBitmap(canvas, 0, 0, paint); @@ -119,8 +117,7 @@ private: class DisplacementAlphaBench : public DisplacementBaseBench { public: - DisplacementAlphaBench(bool small) : INHERITED(small) { - } + DisplacementAlphaBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { @@ -131,11 +128,12 @@ protected: SkPaint paint; sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); // Displacement, with 1 alpha component (which isn't pre-multiplied) - paint.setImageFilter(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kB_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get()))->unref(); + paint.setImageFilter(SkDisplacementMapEffect::Make( + SkDisplacementMapEffect::kB_ChannelSelectorType, + SkDisplacementMapEffect::kA_ChannelSelectorType, + 16.0f, std::move(displ), nullptr)); for (int i = 0; i < loops; i++) { - drawClippedBitmap(canvas, 100, 0, paint); + this->drawClippedBitmap(canvas, 100, 0, paint); } } @@ -145,8 +143,7 @@ private: class DisplacementFullBench : public DisplacementBaseBench { public: - DisplacementFullBench(bool small) : INHERITED(small) { - } + DisplacementFullBench(bool small) : INHERITED(small) { } protected: const char* onGetName() override { @@ -157,9 +154,10 @@ protected: SkPaint paint; sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); // Displacement, with 2 non-alpha components - paint.setImageFilter(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get()))->unref(); + paint.setImageFilter(SkDisplacementMapEffect::Make( + SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kB_ChannelSelectorType, + 32.0f, std::move(displ), nullptr)); for (int i = 0; i < loops; ++i) { this->drawClippedBitmap(canvas, 200, 0, paint); } diff --git a/bench/ImageFilterDAGBench.cpp b/bench/ImageFilterDAGBench.cpp index 308b3b0037..776ee787fd 100644 --- a/bench/ImageFilterDAGBench.cpp +++ b/bench/ImageFilterDAGBench.cpp @@ -62,10 +62,11 @@ protected: auto xSelector = SkDisplacementMapEffect::kR_ChannelSelectorType; auto ySelector = SkDisplacementMapEffect::kB_ChannelSelectorType; SkScalar scale = 2; - sk_sp<SkImageFilter> displ(SkDisplacementMapEffect::Create(xSelector, ySelector, scale, - blur.get(), blur.get())); + SkPaint paint; - paint.setImageFilter(std::move(displ)); + paint.setImageFilter(SkDisplacementMapEffect::Make(xSelector, ySelector, scale, + blur, blur)); + SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); canvas->drawRect(rect, paint); } diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp index 791fe01a33..484bbf7624 100644 --- a/fuzz/FilterFuzz.cpp +++ b/fuzz/FilterFuzz.cpp @@ -706,17 +706,13 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { } break; } - case DISPLACE: { - sk_sp<SkImageFilter> subFilter1(make_image_filter(false)); - sk_sp<SkImageFilter> subFilter2(make_image_filter()); - - filter = sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(make_channel_selector_type(), - make_channel_selector_type(), - make_scalar(), - subFilter1.get(), - subFilter2.get())); + case DISPLACE: + filter = SkDisplacementMapEffect::Make(make_channel_selector_type(), + make_channel_selector_type(), + make_scalar(), + make_image_filter(false), + make_image_filter()); break; - } case TILE: { sk_sp<SkImageFilter> subFilter(make_image_filter(false)); diff --git a/gm/displacement.cpp b/gm/displacement.cpp index 9b62a60ab3..9fea0188df 100644 --- a/gm/displacement.cpp +++ b/gm/displacement.cpp @@ -58,142 +58,142 @@ protected: canvas->clear(SK_ColorBLACK); SkPaint paint; sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 0, 0, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 0, 0, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kB_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 100, 0, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 100, 0, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 200, 0, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 200, 0, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 300, 0, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 300, 0, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 400, 0, paint); + SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 400, 0, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 0, 100, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 0, 100, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kB_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 100, 100, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 100, 100, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 200, 100, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 200, 100, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 300, 100, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 300, 100, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 400, 100, paint); + SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ, nullptr)); + this->drawClippedBitmap(canvas, 400, 100, paint); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40)); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, - 0.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 0, 200, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 0.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 0, 200, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 16.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 100, 200, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 16.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 100, 200, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, - 32.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 200, 200, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 32.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 200, 200, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 48.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 300, 200, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 48.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 300, 200, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 64.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 400, 200, paint); + 64.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 400, 200, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, - 40.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 0, 300, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 40.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 0, 300, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 100, 300, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 40.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 100, 300, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, - 40.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 200, 300, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 40.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 200, 300, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 300, 300, paint); - paint.setImageFilter(SkDisplacementMapEffect::Create( + 40.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 300, 300, paint); + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ.get(), nullptr, &cropRect))->unref(); - drawClippedBitmap(canvas, 400, 300, paint); + 40.0f, displ, nullptr, &cropRect)); + this->drawClippedBitmap(canvas, 400, 300, paint); // Test for negative scale. - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - -40.0f, displ.get()))->unref(); + -40.0f, displ, nullptr)); this->drawClippedBitmap(canvas, 500, 0, paint); // Tests for images of different sizes displ = SkImageSource::Make(fSmall); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kG_ChannelSelectorType, - 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 0, 400, paint); + 40.0f, std::move(displ), nullptr)); + this->drawClippedBitmap(canvas, 0, 400, paint); displ = SkImageSource::Make(fLarge); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kB_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 100, 400, paint); + 40.0f, std::move(displ), nullptr)); + this->drawClippedBitmap(canvas, 100, 400, paint); displ = SkImageSource::Make(fLargeW); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kR_ChannelSelectorType, SkDisplacementMapEffect::kB_ChannelSelectorType, - 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 200, 400, paint); + 40.0f, std::move(displ), nullptr)); + this->drawClippedBitmap(canvas, 200, 400, paint); displ = SkImageSource::Make(fLargeH); - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, displ.get()))->unref(); - drawClippedBitmap(canvas, 300, 400, paint); + 40.0f, std::move(displ), nullptr)); + this->drawClippedBitmap(canvas, 300, 400, paint); // Test for no given displacement input. In this case, both displacement // and color should use the same bitmap, given to SkCanvas::drawBitmap() // as an input argument. - paint.setImageFilter(SkDisplacementMapEffect::Create( + paint.setImageFilter(SkDisplacementMapEffect::Make( SkDisplacementMapEffect::kG_ChannelSelectorType, SkDisplacementMapEffect::kA_ChannelSelectorType, - 40.0f, nullptr))->unref(); - drawClippedBitmap(canvas, 400, 400, paint); + 40.0f, nullptr, nullptr)); + this->drawClippedBitmap(canvas, 400, 400, paint); } private: diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp index f2434112fa..7989f8b4b0 100644 --- a/gm/imagefiltersclipped.cpp +++ b/gm/imagefiltersclipped.cpp @@ -100,12 +100,11 @@ protected: SkIntToScalar(3), SkIntToScalar(3), SK_ColorGREEN, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr), - sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkIntToScalar(12), - gradient.get(), - checkerboard.get())), + SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kR_ChannelSelectorType, + SkIntToScalar(12), + std::move(gradient), + checkerboard), SkDilateImageFilter::Make(2, 2, checkerboard), SkErodeImageFilter::Make(2, 2, checkerboard), SkOffsetImageFilter::Make(SkIntToScalar(-16), SkIntToScalar(32), nullptr), diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index 3d5fcf3612..f3084435fe 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -107,13 +107,12 @@ protected: &bigRect)); Draw(canvas, checkerboard, rect, - sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkIntToScalar(12), - gradientCircleSource.get(), - noopCropped.get(), - &bigRect))); + SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kR_ChannelSelectorType, + SkIntToScalar(12), + std::move(gradientCircleSource), + noopCropped, + &bigRect)); Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Make(SkIntToScalar(-8), SkIntToScalar(16), diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp index 4c48aec869..756b7c624c 100644 --- a/gm/imagefiltersscaled.cpp +++ b/gm/imagefiltersscaled.cpp @@ -98,12 +98,11 @@ protected: SkIntToScalar(3), SkIntToScalar(3), SK_ColorYELLOW, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr), - sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkIntToScalar(12), - gradient.get(), - checkerboard.get())), + SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kR_ChannelSelectorType, + SkIntToScalar(12), + std::move(gradient), + checkerboard), SkDilateImageFilter::Make(1, 1, checkerboard), SkErodeImageFilter::Make(1, 1, checkerboard), SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr), diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp index 291d1d46ec..ce7ba5d6e0 100644 --- a/gm/imagefilterstransformed.cpp +++ b/gm/imagefilterstransformed.cpp @@ -69,12 +69,11 @@ protected: SkBlurImageFilter::Make(12, 0, nullptr), SkDropShadowImageFilter::Make(0, 15, 8, 0, SK_ColorGREEN, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr), - sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kR_ChannelSelectorType, - 12, - gradient.get(), - checkerboard.get())), + SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kR_ChannelSelectorType, + 12, + std::move(gradient), + checkerboard), SkDilateImageFilter::Make(2, 2, checkerboard), SkErodeImageFilter::Make(2, 2, checkerboard), }; diff --git a/include/effects/SkDisplacementMapEffect.h b/include/effects/SkDisplacementMapEffect.h index 4b6f321a22..f93f2c4454 100644 --- a/include/effects/SkDisplacementMapEffect.h +++ b/include/effects/SkDisplacementMapEffect.h @@ -20,13 +20,14 @@ public: kA_ChannelSelectorType }; - ~SkDisplacementMapEffect(); + ~SkDisplacementMapEffect() override; - static SkImageFilter* Create(ChannelSelectorType xChannelSelector, - ChannelSelectorType yChannelSelector, - SkScalar scale, SkImageFilter* displacement, - SkImageFilter* color = NULL, - const CropRect* cropRect = NULL); + static sk_sp<SkImageFilter> Make(ChannelSelectorType xChannelSelector, + ChannelSelectorType yChannelSelector, + SkScalar scale, + sk_sp<SkImageFilter> displacement, + sk_sp<SkImageFilter> color, + const CropRect* cropRect = nullptr); SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect) @@ -38,13 +39,26 @@ public: SK_TO_STRING_OVERRIDE() +#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR + static SkImageFilter* Create(ChannelSelectorType xChannelSelector, + ChannelSelectorType yChannelSelector, + SkScalar scale, SkImageFilter* displacement, + SkImageFilter* color = nullptr, + const CropRect* cropRect = nullptr) { + return Make(xChannelSelector, yChannelSelector, scale, + sk_ref_sp<SkImageFilter>(displacement), + sk_ref_sp<SkImageFilter>(color), + cropRect).release(); + } +#endif + protected: sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, SkIPoint* offset) const override; SkDisplacementMapEffect(ChannelSelectorType xChannelSelector, ChannelSelectorType yChannelSelector, - SkScalar scale, SkImageFilter* inputs[2], + SkScalar scale, sk_sp<SkImageFilter> inputs[2], const CropRect* cropRect); void flatten(SkWriteBuffer&) const override; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 5f06731ae5..12b6a8af99 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -709,17 +709,13 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { } break; } - case DISPLACE: { - sk_sp<SkImageFilter> subFilter1(make_image_filter(false)); - sk_sp<SkImageFilter> subFilter2(make_image_filter()); - - filter = sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(make_channel_selector_type(), - make_channel_selector_type(), - make_scalar(), - subFilter1.get(), - subFilter2.get())); + case DISPLACE: + filter = SkDisplacementMapEffect::Make(make_channel_selector_type(), + make_channel_selector_type(), + make_scalar(), + make_image_filter(false), + make_image_filter()); break; - } case TILE: { sk_sp<SkImageFilter> subFilter(make_image_filter(false)); diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index aee15ef753..b715f6a4f3 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -163,27 +163,29 @@ bool channel_selector_type_is_valid(SkDisplacementMapEffect::ChannelSelectorType /////////////////////////////////////////////////////////////////////////////// -SkImageFilter* SkDisplacementMapEffect::Create(ChannelSelectorType xChannelSelector, - ChannelSelectorType yChannelSelector, - SkScalar scale, - SkImageFilter* displacement, - SkImageFilter* color, - const CropRect* cropRect) { +sk_sp<SkImageFilter> SkDisplacementMapEffect::Make(ChannelSelectorType xChannelSelector, + ChannelSelectorType yChannelSelector, + SkScalar scale, + sk_sp<SkImageFilter> displacement, + sk_sp<SkImageFilter> color, + const CropRect* cropRect) { if (!channel_selector_type_is_valid(xChannelSelector) || !channel_selector_type_is_valid(yChannelSelector)) { return nullptr; } - SkImageFilter* inputs[2] = { displacement, color }; - return new SkDisplacementMapEffect(xChannelSelector, yChannelSelector, scale, inputs, cropRect); + sk_sp<SkImageFilter> inputs[2] = { std::move(displacement), std::move(color) }; + return sk_sp<SkImageFilter>(new SkDisplacementMapEffect(xChannelSelector, + yChannelSelector, + scale, inputs, cropRect)); } SkDisplacementMapEffect::SkDisplacementMapEffect(ChannelSelectorType xChannelSelector, ChannelSelectorType yChannelSelector, SkScalar scale, - SkImageFilter* inputs[2], + sk_sp<SkImageFilter> inputs[2], const CropRect* cropRect) - : INHERITED(2, inputs, cropRect) + : INHERITED(inputs, 2, cropRect) , fXChannelSelector(xChannelSelector) , fYChannelSelector(yChannelSelector) , fScale(scale) { @@ -197,8 +199,9 @@ sk_sp<SkFlattenable> SkDisplacementMapEffect::CreateProc(SkReadBuffer& buffer) { ChannelSelectorType xsel = (ChannelSelectorType)buffer.readInt(); ChannelSelectorType ysel = (ChannelSelectorType)buffer.readInt(); SkScalar scale = buffer.readScalar(); - return sk_sp<SkFlattenable>(Create(xsel, ysel, scale, common.getInput(0).get(), - common.getInput(1).get(), &common.cropRect())); + return Make(xsel, ysel, scale, + common.getInput(0), common.getInput(1), + &common.cropRect()); } void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const { diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 114c342ada..172f84fa77 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -160,10 +160,10 @@ public: sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gradientImage))); this->addFilter("displacement map", - sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create( - SkDisplacementMapEffect::kR_ChannelSelectorType, - SkDisplacementMapEffect::kB_ChannelSelectorType, - 20.0f, gradientSource.get(), input.get(), cropRect))); + SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, + SkDisplacementMapEffect::kB_ChannelSelectorType, + 20.0f, + std::move(gradientSource), input, cropRect)); } this->addFilter("blur", SkBlurImageFilter::Make(SK_Scalar1, |