aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/MorphologyBench.cpp18
-rw-r--r--gm/imagefilters.cpp4
-rw-r--r--gm/imagefiltersclipped.cpp8
-rw-r--r--gm/imagefilterscropexpand.cpp14
-rw-r--r--gm/imagefilterscropped.cpp67
-rw-r--r--gm/imagefiltersgraph.cpp22
-rw-r--r--gm/imagefiltersscaled.cpp4
-rw-r--r--gm/imagefilterstransformed.cpp4
-rw-r--r--gm/localmatriximagefilter.cpp10
-rw-r--r--gm/morphology.cpp18
-rw-r--r--include/effects/SkMorphologyImageFilter.h50
-rw-r--r--samplecode/SampleFilterFuzz.cpp17
-rw-r--r--samplecode/SampleLayers.cpp6
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp10
-rw-r--r--tests/ImageFilterTest.cpp46
15 files changed, 161 insertions, 137 deletions
diff --git a/bench/MorphologyBench.cpp b/bench/MorphologyBench.cpp
index fd60ebed46..5edae6e299 100644
--- a/bench/MorphologyBench.cpp
+++ b/bench/MorphologyBench.cpp
@@ -46,11 +46,11 @@ public:
}
protected:
- virtual const char* onGetName() {
+ const char* onGetName() override {
return fName.c_str();
}
- virtual void onDraw(int loops, SkCanvas* canvas) {
+ void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
this->setupPaint(&paint);
@@ -63,18 +63,20 @@ protected:
r.offset(fRadius, fRadius);
if (fRadius > 0) {
- SkImageFilter* mf = nullptr;
+ sk_sp<SkImageFilter> mf;
switch (fStyle) {
case kDilate_MT:
- mf = SkDilateImageFilter::Create(SkScalarFloorToInt(fRadius),
- SkScalarFloorToInt(fRadius));
+ mf = SkDilateImageFilter::Make(SkScalarFloorToInt(fRadius),
+ SkScalarFloorToInt(fRadius),
+ nullptr);
break;
case kErode_MT:
- mf = SkErodeImageFilter::Create(SkScalarFloorToInt(fRadius),
- SkScalarFloorToInt(fRadius));
+ mf = SkErodeImageFilter::Make(SkScalarFloorToInt(fRadius),
+ SkScalarFloorToInt(fRadius),
+ nullptr);
break;
}
- paint.setImageFilter(mf)->unref();
+ paint.setImageFilter(std::move(mf));
}
canvas->drawOval(r, paint);
}
diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp
index 10072c897e..f1f1b80ac9 100644
--- a/gm/imagefilters.cpp
+++ b/gm/imagefilters.cpp
@@ -139,11 +139,11 @@ static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) {
DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
SkColorMatrix cm;
cm.setSaturation(10);
- auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 };
SkImageFilter* filters[] = {
SkBlurImageFilter::Make(10, 10, nullptr).release(),
- SkDilateImageFilter::Create(8, 8),
+ SkDilateImageFilter::Make(8, 8, nullptr).release(),
SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
true),
diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp
index 85c5438bca..b123094a80 100644
--- a/gm/imagefiltersclipped.cpp
+++ b/gm/imagefiltersclipped.cpp
@@ -103,11 +103,9 @@ protected:
SkIntToScalar(12),
gradient.get(),
checkerboard.get()),
- SkDilateImageFilter::Create(2, 2, checkerboard.get()),
- SkErodeImageFilter::Create(2, 2, checkerboard.get()),
- SkOffsetImageFilter::Make(SkIntToScalar(-16),
- SkIntToScalar(32),
- nullptr).release(),
+ SkDilateImageFilter::Make(2, 2, checkerboard).release(),
+ SkErodeImageFilter::Make(2, 2, checkerboard).release(),
+ SkOffsetImageFilter::Make(SkIntToScalar(-16), SkIntToScalar(32), nullptr).release(),
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1,
SkIntToScalar(2), checkerboard.get()),
diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp
index f1a132369a..8f36ba9041 100644
--- a/gm/imagefilterscropexpand.cpp
+++ b/gm/imagefilterscropexpand.cpp
@@ -88,15 +88,13 @@ protected:
noopCropped,
&bigRect));
- Draw(canvas, checkerboard, rect,
- sk_sp<SkImageFilter>(SkDilateImageFilter::Create(2, 2,
- noopCropped.get(),
- &bigRect)));
+ Draw(canvas, checkerboard, rect, SkDilateImageFilter::Make(2, 2,
+ noopCropped,
+ &bigRect));
- Draw(canvas, checkerboard, rect,
- sk_sp<SkImageFilter>(SkErodeImageFilter::Create(2, 2,
- noopCropped.get(),
- &bigRect)));
+ Draw(canvas, checkerboard, rect, SkErodeImageFilter::Make(2, 2,
+ noopCropped,
+ &bigRect));
Draw(canvas, checkerboard, rect,
sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
diff --git a/gm/imagefilterscropped.cpp b/gm/imagefilterscropped.cpp
index 1e880fe68a..66e4d870e9 100644
--- a/gm/imagefilterscropped.cpp
+++ b/gm/imagefilterscropped.cpp
@@ -20,9 +20,9 @@
///////////////////////////////////////////////////////////////////////////////
-static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setColor(SK_ColorBLACK);
canvas->save();
canvas->clipRect(r);
@@ -30,17 +30,17 @@ static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
canvas->restore();
}
-static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
paint.setColor(SK_ColorMAGENTA);
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setAntiAlias(true);
canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
}
-static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setColor(SK_ColorGREEN);
paint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&paint);
@@ -49,7 +49,7 @@ static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint);
}
-static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
SkIRect bounds;
@@ -61,7 +61,7 @@ static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
SkCanvas c(bm);
draw_path(&c, r, nullptr);
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
canvas->drawBitmap(bm, 0, 0, &paint);
}
@@ -111,13 +111,16 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) override {
- void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
+ void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
draw_bitmap, draw_path, draw_paint, draw_text
};
- auto cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge);
- SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge);
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+ SkXfermode::kSrcIn_Mode));
+ SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
+ SkImageFilter::CropRect::kHasAll_CropEdge);
+ SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)),
+ SkImageFilter::CropRect::kHasAll_CropEdge);
sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(SkIntToScalar(-10),
SkIntToScalar(-10),
@@ -125,25 +128,27 @@ protected:
sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get()));
- SkAutoTUnref<SkImageFilter> erodeX(SkErodeImageFilter::Create(8, 0, nullptr, &cropRect));
- SkAutoTUnref<SkImageFilter> erodeY(SkErodeImageFilter::Create(0, 8, nullptr, &cropRect));
+ sk_sp<SkImageFilter> erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect));
+ sk_sp<SkImageFilter> erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect));
- SkImageFilter* filters[] = {
+ sk_sp<SkImageFilter> filters[] = {
nullptr,
- SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect),
- SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect).release(),
- SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect).release(),
- SkErodeImageFilter::Create(1, 1, nullptr, &cropRect),
- SkErodeImageFilter::Create(8, 0, erodeY, &cropRect),
- SkErodeImageFilter::Create(0, 8, erodeX, &cropRect),
- SkErodeImageFilter::Create(8, 8, nullptr, &cropRect),
- SkMergeImageFilter::Make(nullptr, std::move(cfOffset),
- SkXfermode::kSrcOver_Mode, &cropRect).release(),
- SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect).release(),
- SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect),
+ sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect)),
+ SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(0.0f, 8.0f, nullptr, &cropRect),
+ SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &cropRect),
+ SkErodeImageFilter::Make(1, 1, nullptr, &cropRect),
+ SkErodeImageFilter::Make(8, 0, std::move(erodeY), &cropRect),
+ SkErodeImageFilter::Make(0, 8, std::move(erodeX), &cropRect),
+ SkErodeImageFilter::Make(8, 8, nullptr, &cropRect),
+ SkMergeImageFilter::Make(nullptr,
+ std::move(cfOffset),
+ SkXfermode::kSrcOver_Mode,
+ &cropRect),
+ SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect),
+ sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect)),
};
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
@@ -163,10 +168,6 @@ protected:
canvas->restore();
canvas->translate(DX, 0);
}
-
- for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
- SkSafeUnref(filters[j]);
- }
}
private:
diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp
index e7bcf707c3..eb5519a761 100644
--- a/gm/imagefiltersgraph.cpp
+++ b/gm/imagefiltersgraph.cpp
@@ -136,7 +136,7 @@ protected:
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode));
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource)));
- sk_sp<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, blur.get()));
+ sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur));
sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get(), erode.get()));
sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color));
@@ -146,7 +146,7 @@ protected:
canvas->translate(SkIntToScalar(100), 0);
}
{
- sk_sp<SkImageFilter> morph(SkDilateImageFilter::Create(5, 5));
+ sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr));
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
0, SK_Scalar1, 0, 0, 0,
@@ -199,7 +199,7 @@ protected:
// This tests that a filter using asFragmentProcessor (matrix
// convolution) correctly handles a non-zero source offset
// (supplied by the dilate).
- SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5));
+ sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr));
SkScalar kernel[9] = {
SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
@@ -211,7 +211,7 @@ protected:
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode;
bool convolveAlpha = false;
- SkAutoTUnref<SkImageFilter> convolve(
+ sk_sp<SkImageFilter> convolve(
SkMatrixConvolutionImageFilter::Create(kernelSize,
kernel,
gain,
@@ -219,10 +219,10 @@ protected:
kernelOffset,
tileMode,
convolveAlpha,
- dilate));
+ dilate.get()));
SkPaint paint;
- paint.setImageFilter(convolve);
+ paint.setImageFilter(std::move(convolve));
DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0);
}
@@ -234,11 +234,15 @@ protected:
SkIntToScalar(80), SkIntToScalar(80)));
SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
SkIntToScalar(60), SkIntToScalar(60)));
- SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(), nullptr, &outerRect));
- SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(), color1, &innerRect));
+ sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(),
+ nullptr,
+ &outerRect));
+ sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(),
+ color1.get(),
+ &innerRect));
SkPaint paint;
- paint.setImageFilter(color2);
+ paint.setImageFilter(std::move(color2));
paint.setColor(SK_ColorRED);
canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
canvas->translate(SkIntToScalar(100), 0);
diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp
index 56a1484f21..3f819d874a 100644
--- a/gm/imagefiltersscaled.cpp
+++ b/gm/imagefiltersscaled.cpp
@@ -82,8 +82,8 @@ protected:
SkIntToScalar(12),
gradient.get(),
checkerboard.get()),
- SkDilateImageFilter::Create(1, 1, checkerboard.get()),
- SkErodeImageFilter::Create(1, 1, checkerboard.get()),
+ SkDilateImageFilter::Make(1, 1, checkerboard).release(),
+ SkErodeImageFilter::Make(1, 1, checkerboard).release(),
SkOffsetImageFilter::Make(SkIntToScalar(32), 0, nullptr).release(),
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
SkPaintImageFilter::Make(noisePaint).release(),
diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp
index 687e458f1f..1ab52b9f58 100644
--- a/gm/imagefilterstransformed.cpp
+++ b/gm/imagefilterstransformed.cpp
@@ -74,8 +74,8 @@ protected:
12,
gradient.get(),
checkerboard.get()),
- SkDilateImageFilter::Create(2, 2, checkerboard.get()),
- SkErodeImageFilter::Create(2, 2, checkerboard.get()),
+ SkDilateImageFilter::Make(2, 2, checkerboard).release(),
+ SkErodeImageFilter::Make(2, 2, checkerboard).release(),
};
const SkScalar margin = SkIntToScalar(20);
diff --git a/gm/localmatriximagefilter.cpp b/gm/localmatriximagefilter.cpp
index baa44b9d0b..d5b7e3e50d 100644
--- a/gm/localmatriximagefilter.cpp
+++ b/gm/localmatriximagefilter.cpp
@@ -28,7 +28,7 @@ static sk_sp<SkImage> make_image(SkCanvas* rootCanvas) {
return surface->makeImageSnapshot();
}
-typedef SkImageFilter* (*ImageFilterFactory)();
+typedef sk_sp<SkImageFilter> (*ImageFilterFactory)();
// +[]{...} did not work on windows (VS)
// (ImageFilterFactory)[]{...} did not work on linux (gcc)
@@ -65,10 +65,10 @@ protected:
sk_sp<SkImage> image0(make_image(canvas));
const ImageFilterFactory factories[] = {
- IFCCast([]{ return SkBlurImageFilter::Make(8, 8, nullptr).release(); }),
- IFCCast([]{ return SkDilateImageFilter::Create(8, 8); }),
- IFCCast([]{ return SkErodeImageFilter::Create(8, 8); }),
- IFCCast([]{ return SkOffsetImageFilter::Make(8, 8, nullptr).release(); }),
+ IFCCast([]{ return SkBlurImageFilter::Make(8, 8, nullptr); }),
+ IFCCast([]{ return SkDilateImageFilter::Make(8, 8, nullptr); }),
+ IFCCast([]{ return SkErodeImageFilter::Make(8, 8, nullptr); }),
+ IFCCast([]{ return SkOffsetImageFilter::Make(8, 8, nullptr); }),
};
const SkMatrix matrices[] = {
diff --git a/gm/morphology.cpp b/gm/morphology.cpp
index c3326f9397..f60079b873 100644
--- a/gm/morphology.cpp
+++ b/gm/morphology.cpp
@@ -70,17 +70,15 @@ protected:
for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) {
const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : nullptr;
if (j & 0x01) {
- paint.setImageFilter(SkErodeImageFilter::Create(
- samples[i].fRadiusX,
- samples[i].fRadiusY,
- nullptr,
- cr))->unref();
+ paint.setImageFilter(SkErodeImageFilter::Make(samples[i].fRadiusX,
+ samples[i].fRadiusY,
+ nullptr,
+ cr));
} else {
- paint.setImageFilter(SkDilateImageFilter::Create(
- samples[i].fRadiusX,
- samples[i].fRadiusY,
- nullptr,
- cr))->unref();
+ paint.setImageFilter(SkDilateImageFilter::Make(samples[i].fRadiusX,
+ samples[i].fRadiusY,
+ nullptr,
+ cr));
}
this->drawClippedBitmap(canvas, paint, i * 140, j * 140);
}
diff --git a/include/effects/SkMorphologyImageFilter.h b/include/effects/SkMorphologyImageFilter.h
index 4e699a7633..27608ecd07 100644
--- a/include/effects/SkMorphologyImageFilter.h
+++ b/include/effects/SkMorphologyImageFilter.h
@@ -36,7 +36,8 @@ protected:
virtual Op op() const = 0;
- SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input,
+ SkMorphologyImageFilter(int radiusX, int radiusY,
+ sk_sp<SkImageFilter> input,
const CropRect* cropRect);
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source,
const Context&,
@@ -54,23 +55,37 @@ private:
///////////////////////////////////////////////////////////////////////////////
class SK_API SkDilateImageFilter : public SkMorphologyImageFilter {
public:
- static SkImageFilter* Create(int radiusX, int radiusY,
- SkImageFilter* input = nullptr,
- const CropRect* cropRect = nullptr) {
+ static sk_sp<SkImageFilter> Make(int radiusX, int radiusY,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect = nullptr) {
if (radiusX < 0 || radiusY < 0) {
return nullptr;
}
- return new SkDilateImageFilter(radiusX, radiusY, input, cropRect);
+ return sk_sp<SkImageFilter>(new SkDilateImageFilter(radiusX, radiusY,
+ std::move(input),
+ cropRect));
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter)
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ static SkImageFilter* Create(int radiusX, int radiusY,
+ SkImageFilter* input = nullptr,
+ const CropRect* cropRect = nullptr) {
+ return Make(radiusX, radiusY,
+ sk_ref_sp<SkImageFilter>(input),
+ cropRect).release();
+ }
+#endif
+
protected:
Op op() const override { return kDilate_Op; }
private:
- SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect)
+ SkDilateImageFilter(int radiusX, int radiusY,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect)
: INHERITED(radiusX, radiusY, input, cropRect) {}
typedef SkMorphologyImageFilter INHERITED;
@@ -79,23 +94,36 @@ private:
///////////////////////////////////////////////////////////////////////////////
class SK_API SkErodeImageFilter : public SkMorphologyImageFilter {
public:
- static SkImageFilter* Create(int radiusX, int radiusY,
- SkImageFilter* input = nullptr,
- const CropRect* cropRect = nullptr) {
+ static sk_sp<SkImageFilter> Make(int radiusX, int radiusY,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect = nullptr) {
if (radiusX < 0 || radiusY < 0) {
return nullptr;
}
- return new SkErodeImageFilter(radiusX, radiusY, input, cropRect);
+ return sk_sp<SkImageFilter>(new SkErodeImageFilter(radiusX, radiusY,
+ std::move(input),
+ cropRect));
}
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter)
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ static SkImageFilter* Create(int radiusX, int radiusY,
+ SkImageFilter* input = nullptr,
+ const CropRect* cropRect = nullptr) {
+ return Make(radiusX, radiusY,
+ sk_ref_sp<SkImageFilter>(input),
+ cropRect).release();
+ }
+#endif
+
protected:
Op op() const override { return kErode_Op; }
private:
- SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect)
+ SkErodeImageFilter(int radiusX, int radiusY,
+ sk_sp<SkImageFilter> input, const CropRect* cropRect)
: INHERITED(radiusX, radiusY, input, cropRect) {}
typedef SkMorphologyImageFilter INHERITED;
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 1b7d30be1d..5d433b5748 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -705,20 +705,17 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
nullptr));
break;
}
- case MORPHOLOGY: {
- sk_sp<SkImageFilter> subFilter(make_image_filter());
-
+ case MORPHOLOGY:
if (R(2) == 1) {
- filter = sk_sp<SkImageFilter>(SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSize)),
- R(static_cast<float>(kBitmapSize)),
- subFilter.get()));
+ filter = SkDilateImageFilter::Make(R(static_cast<float>(kBitmapSize)),
+ R(static_cast<float>(kBitmapSize)),
+ make_image_filter());
} else {
- filter = sk_sp<SkImageFilter>(SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize)),
- R(static_cast<float>(kBitmapSize)),
- subFilter.get()));
+ filter = SkErodeImageFilter::Make(R(static_cast<float>(kBitmapSize)),
+ R(static_cast<float>(kBitmapSize)),
+ make_image_filter());
}
break;
- }
case BITMAP: {
sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap()));
if (R(2) == 1) {
diff --git a/samplecode/SampleLayers.cpp b/samplecode/SampleLayers.cpp
index 8c2724ce95..194f0a70a9 100644
--- a/samplecode/SampleLayers.cpp
+++ b/samplecode/SampleLayers.cpp
@@ -245,13 +245,13 @@ class BackdropView : public SampleView {
SkPoint fCenter;
SkScalar fAngle;
sk_sp<SkImage> fImage;
- SkAutoTUnref<SkImageFilter> fFilter;
+ sk_sp<SkImageFilter> fFilter;
public:
BackdropView() {
fCenter.set(200, 150);
fAngle = 0;
fImage = GetResourceAsImage("mandrill_512.png");
- fFilter.reset(SkDilateImageFilter::Create(8, 8));
+ fFilter = SkDilateImageFilter::Make(8, 8, nullptr);
}
protected:
@@ -281,7 +281,7 @@ protected:
SkPaint paint;
paint.setAlpha(0xCC);
- canvas->saveLayer({ &bounds, &paint, fFilter, 0 });
+ canvas->saveLayer({ &bounds, &paint, fFilter.get(), 0 });
canvas->restore();
}
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index bf8811b887..ea714e59f6 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -30,9 +30,9 @@
SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX,
int radiusY,
- SkImageFilter* input,
+ sk_sp<SkImageFilter> input,
const CropRect* cropRect)
- : INHERITED(1, &input, cropRect)
+ : INHERITED(&input, 1, cropRect)
, fRadius(SkISize::Make(radiusX, radiusY)) {
}
@@ -76,16 +76,14 @@ sk_sp<SkFlattenable> SkErodeImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
const int width = buffer.readInt();
const int height = buffer.readInt();
- return sk_sp<SkFlattenable>(Create(width, height, common.getInput(0).get(),
- &common.cropRect()));
+ return Make(width, height, common.getInput(0), &common.cropRect());
}
sk_sp<SkFlattenable> SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
const int width = buffer.readInt();
const int height = buffer.readInt();
- return sk_sp<SkFlattenable>(Create(width, height, common.getInput(0).get(),
- &common.cropRect()));
+ return Make(width, height, common.getInput(0), &common.cropRect());
}
#ifndef SK_IGNORE_TO_STRING
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 21ddc162d2..58dc1a7161 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -143,7 +143,7 @@ SkBitmap make_gradient_circle(int width, int height) {
class FilterList {
public:
- FilterList(SkImageFilter* input = nullptr, const SkImageFilter::CropRect* cropRect = nullptr) {
+ FilterList(sk_sp<SkImageFilter> input, const SkImageFilter::CropRect* cropRect = nullptr) {
SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
SkScalar kernel[9] = {
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
@@ -164,7 +164,7 @@ public:
SkXfermode::kSrcIn_Mode));
this->addFilter("color filter",
- SkColorFilterImageFilter::Create(cf.get(), input, cropRect));
+ SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect));
}
{
@@ -174,27 +174,28 @@ public:
this->addFilter("displacement map", SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kB_ChannelSelectorType,
- 20.0f, gradientSource.get(), input, cropRect));
+ 20.0f, gradientSource.get(), input.get(), cropRect));
}
this->addFilter("blur", SkBlurImageFilter::Make(SK_Scalar1,
SK_Scalar1,
- sk_ref_sp<SkImageFilter>(input),
+ input,
cropRect).release());
this->addFilter("drop shadow", SkDropShadowImageFilter::Create(
SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN,
- SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, input, cropRect));
+ SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
+ input.get(), cropRect));
this->addFilter("diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse(
- location, SK_ColorGREEN, 0, 0, input, cropRect));
+ location, SK_ColorGREEN, 0, 0, input.get(), cropRect));
this->addFilter("specular lighting",
SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0,
- input, cropRect));
+ input.get(), cropRect));
this->addFilter("matrix convolution",
SkMatrixConvolutionImageFilter::Create(
kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1),
- SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, input, cropRect));
- this->addFilter("merge", SkMergeImageFilter::Make(sk_ref_sp<SkImageFilter>(input),
- sk_ref_sp<SkImageFilter>(input),
+ SkMatrixConvolutionImageFilter::kRepeat_TileMode, false,
+ input.get(), cropRect));
+ this->addFilter("merge", SkMergeImageFilter::Make(input, input,
SkXfermode::kSrcOver_Mode,
cropRect).release());
{
@@ -215,23 +216,21 @@ public:
}
this->addFilter("offset",
- SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1,
- sk_ref_sp<SkImageFilter>(input),
+ SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1, input,
cropRect).release());
- this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropRect));
- this->addFilter("erode", SkErodeImageFilter::Create(2, 3, input, cropRect));
+ this->addFilter("dilate", SkDilateImageFilter::Make(3, 2, input, cropRect).release());
+ this->addFilter("erode", SkErodeImageFilter::Make(2, 3, input, cropRect).release());
this->addFilter("tile", SkTileImageFilter::Create(
SkRect::MakeXYWH(0, 0, 50, 50),
cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100),
- input));
+ input.get()));
if (!cropRect) {
this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
- matrix, kLow_SkFilterQuality, input));
+ matrix, kLow_SkFilterQuality, input.get()));
}
{
- sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five,
- sk_ref_sp<SkImageFilter>(input)));
+ sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five, input));
this->addFilter("blur and offset", SkOffsetImageFilter::Make(five, five,
std::move(blur),
@@ -262,7 +261,8 @@ public:
cropRect).release());
}
this->addFilter("xfermode", SkXfermodeImageFilter::Make(
- SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).release());
+ SkXfermode::Make(SkXfermode::kSrc_Mode), input.get(), input.get(),
+ cropRect).release());
}
int count() const { return fFilters.count(); }
SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }
@@ -519,9 +519,9 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy,
SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
- SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
+ sk_sp<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
- FilterList filters(input.get(), &cropRect);
+ FilterList filters(input, &cropRect);
for (int i = 0; i < filters.count(); ++i) {
SkImageFilter* filter = filters.getFilter(i);
@@ -742,7 +742,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
// match the same filters drawn with a single full-canvas bitmap draw.
// Tests pass by not asserting.
- FilterList filters;
+ FilterList filters(nullptr);
SkBitmap untiledResult, tiledResult;
const int width = 64, height = 64;
@@ -875,7 +875,7 @@ DEF_TEST(ImageFilterShadowThenBlurBounds, reporter) {
}
DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) {
- sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Create(2, 2));
+ sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Make(2, 2, nullptr));
sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1)));
SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100);