aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/MatrixConvolutionBench.cpp13
-rw-r--r--fuzz/FilterFuzz.cpp22
-rw-r--r--gm/imagefilters.cpp21
-rw-r--r--gm/imagefiltersgraph.cpp17
-rw-r--r--gm/matrixconvolution.cpp20
-rw-r--r--include/effects/SkMatrixConvolutionImageFilter.h28
-rw-r--r--samplecode/SampleFilterFuzz.cpp22
-rw-r--r--src/effects/SkMatrixConvolutionImageFilter.cpp62
-rw-r--r--tests/ImageFilterTest.cpp45
9 files changed, 130 insertions, 120 deletions
diff --git a/bench/MatrixConvolutionBench.cpp b/bench/MatrixConvolutionBench.cpp
index 05f0193cec..da61891e73 100644
--- a/bench/MatrixConvolutionBench.cpp
+++ b/bench/MatrixConvolutionBench.cpp
@@ -23,11 +23,9 @@ public:
};
SkScalar gain = 0.3f, bias = SkIntToScalar(100);
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
- fFilter = SkMatrixConvolutionImageFilter::Create(kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha);
- }
-
- ~MatrixConvolutionBench() {
- fFilter->unref();
+ fFilter = SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, gain, bias,
+ kernelOffset, tileMode, convolveAlpha,
+ nullptr);
}
protected:
@@ -49,9 +47,10 @@ protected:
}
private:
- typedef Benchmark INHERITED;
- SkImageFilter* fFilter;
+ sk_sp<SkImageFilter> fFilter;
SkString fName;
+
+ typedef Benchmark INHERITED;
};
DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kClamp_TileMode, true); )
diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp
index ebb9de85c2..1cd20c034e 100644
--- a/fuzz/FilterFuzz.cpp
+++ b/fuzz/FilterFuzz.cpp
@@ -552,7 +552,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
filter = SkAlphaThresholdFilter::Make(make_region(),
make_scalar(),
make_scalar(),
- nullptr);
+ make_image_filter());
break;
case MERGE:
filter = SkMergeImageFilter::Make(make_image_filter(),
@@ -611,18 +611,16 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
}
SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())),
R(SkIntToScalar(size.height())));
- sk_sp<SkImageFilter> subFilter(make_image_filter());
- filter = sk_sp<SkImageFilter>(SkMatrixConvolutionImageFilter::Create(
- size,
- kernel.begin(),
- make_scalar(),
- make_scalar(),
- kernelOffset,
- (SkMatrixConvolutionImageFilter::TileMode)R(3),
- R(2) == 1,
- subFilter.get(),
- &cropR));
+ filter = SkMatrixConvolutionImageFilter::Make(size,
+ kernel.begin(),
+ make_scalar(),
+ make_scalar(),
+ kernelOffset,
+ (SkMatrixConvolutionImageFilter::TileMode)R(3),
+ R(2) == 1,
+ make_image_filter(),
+ &cropR);
break;
}
case COMPOSE:
diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp
index 4343f8b03c..fcb82a7242 100644
--- a/gm/imagefilters.cpp
+++ b/gm/imagefilters.cpp
@@ -114,7 +114,7 @@ DEF_SIMPLE_GM(fast_slow_blurimagefilter, canvas, 620, 260) {
#include "SkColorFilterImageFilter.h"
#include "SkRRect.h"
-static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) {
+static void draw_set(SkCanvas* canvas, sk_sp<SkImageFilter> filters[], int count) {
const SkRect r = SkRect::MakeXYWH(30, 30, 200, 200);
const SkScalar offset = 250;
SkScalar dx = 0, dy = 0;
@@ -123,7 +123,7 @@ static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) {
canvas->save();
SkRRect rr = SkRRect::MakeRectXY(r.makeOffset(dx, dy), 20, 20);
canvas->clipRRect(rr, SkRegion::kIntersect_Op, true);
- canvas->saveLayer({ &rr.getBounds(), nullptr, filters[i], 0 });
+ canvas->saveLayer({ &rr.getBounds(), nullptr, filters[i].get(), 0 });
canvas->drawColor(0x40FFFFFF);
canvas->restore();
canvas->restore();
@@ -142,13 +142,14 @@ DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
cm.setSaturation(10);
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::Make(8, 8, nullptr).release(),
- SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
+ sk_sp<SkImageFilter> filters[] = {
+ SkBlurImageFilter::Make(10, 10, nullptr),
+ SkDilateImageFilter::Make(8, 8, nullptr),
+ SkMatrixConvolutionImageFilter::Make(
+ { 3, 3 }, kernel, 1, 0, { 0, 0 },
SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
- true),
- SkColorFilterImageFilter::Make(std::move(cf), nullptr).release(),
+ true, nullptr),
+ SkColorFilterImageFilter::Make(std::move(cf), nullptr),
};
const struct {
@@ -173,8 +174,4 @@ DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
draw_set(canvas, filters, SK_ARRAY_COUNT(filters));
canvas->restore();
}
-
- for (auto& filter : filters) {
- filter->unref();
- }
}
diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp
index 8bf3930fec..8c80ca3379 100644
--- a/gm/imagefiltersgraph.cpp
+++ b/gm/imagefiltersgraph.cpp
@@ -216,15 +216,14 @@ protected:
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode;
bool convolveAlpha = false;
- sk_sp<SkImageFilter> convolve(
- SkMatrixConvolutionImageFilter::Create(kernelSize,
- kernel,
- gain,
- bias,
- kernelOffset,
- tileMode,
- convolveAlpha,
- dilate.get()));
+ sk_sp<SkImageFilter> convolve(SkMatrixConvolutionImageFilter::Make(kernelSize,
+ kernel,
+ gain,
+ bias,
+ kernelOffset,
+ tileMode,
+ convolveAlpha,
+ std::move(dilate)));
SkPaint paint;
paint.setImageFilter(std::move(convolve));
diff --git a/gm/matrixconvolution.cpp b/gm/matrixconvolution.cpp
index b02f743f29..153f7a530a 100644
--- a/gm/matrixconvolution.cpp
+++ b/gm/matrixconvolution.cpp
@@ -58,17 +58,15 @@ protected:
SkISize kernelSize = SkISize::Make(3, 3);
SkScalar gain = 0.3f, bias = SkIntToScalar(100);
SkPaint paint;
- SkAutoTUnref<SkImageFilter> filter(
- SkMatrixConvolutionImageFilter::Create(kernelSize,
- kernel,
- gain,
- bias,
- kernelOffset,
- tileMode,
- convolveAlpha,
- nullptr,
- cropRect));
- paint.setImageFilter(filter);
+ paint.setImageFilter(SkMatrixConvolutionImageFilter::Make(kernelSize,
+ kernel,
+ gain,
+ bias,
+ kernelOffset,
+ tileMode,
+ convolveAlpha,
+ nullptr,
+ cropRect));
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()),
diff --git a/include/effects/SkMatrixConvolutionImageFilter.h b/include/effects/SkMatrixConvolutionImageFilter.h
index 092af08f0c..7a36c84af2 100644
--- a/include/effects/SkMatrixConvolutionImageFilter.h
+++ b/include/effects/SkMatrixConvolutionImageFilter.h
@@ -52,6 +52,20 @@ public:
passed to filterImage() is used instead.
@param cropRect The rectangle to which the output processing will be limited.
*/
+ static sk_sp<SkImageFilter> Make(const SkISize& kernelSize,
+ const SkScalar* kernel,
+ SkScalar gain,
+ SkScalar bias,
+ const SkIPoint& kernelOffset,
+ TileMode tileMode,
+ bool convolveAlpha,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect = nullptr);
+
+ SK_TO_STRING_OVERRIDE()
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImageFilter)
+
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static SkImageFilter* Create(const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
@@ -60,10 +74,11 @@ public:
TileMode tileMode,
bool convolveAlpha,
SkImageFilter* input = NULL,
- const CropRect* cropRect = NULL);
-
- SK_TO_STRING_OVERRIDE()
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMatrixConvolutionImageFilter)
+ const CropRect* cropRect = NULL) {
+ return Make(kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha,
+ sk_ref_sp<SkImageFilter>(input), cropRect).release();
+ }
+#endif
protected:
SkMatrixConvolutionImageFilter(const SkISize& kernelSize,
@@ -73,7 +88,7 @@ protected:
const SkIPoint& kernelOffset,
TileMode tileMode,
bool convolveAlpha,
- SkImageFilter* input,
+ sk_sp<SkImageFilter> input,
const CropRect* cropRect);
void flatten(SkWriteBuffer&) const override;
@@ -95,7 +110,6 @@ private:
SkIPoint fKernelOffset;
TileMode fTileMode;
bool fConvolveAlpha;
- typedef SkImageFilter INHERITED;
template <class PixelFetcher, bool convolveAlpha>
void filterPixels(const SkBitmap& src,
@@ -115,6 +129,8 @@ private:
SkBitmap* result,
const SkIRect& rect,
const SkIRect& bounds) const;
+
+ typedef SkImageFilter INHERITED;
};
#endif
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index a7f4163b27..f09c6a57a0 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -555,7 +555,7 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
filter = SkAlphaThresholdFilter::Make(make_region(),
make_scalar(),
make_scalar(),
- nullptr);
+ make_image_filter());
break;
case MERGE:
filter = SkMergeImageFilter::Make(make_image_filter(),
@@ -614,18 +614,16 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
}
SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())),
R(SkIntToScalar(size.height())));
- sk_sp<SkImageFilter> subFilter(make_image_filter());
- filter = sk_sp<SkImageFilter>(SkMatrixConvolutionImageFilter::Create(
- size,
- kernel.begin(),
- make_scalar(),
- make_scalar(),
- kernelOffset,
- (SkMatrixConvolutionImageFilter::TileMode)R(3),
- R(2) == 1,
- subFilter.get(),
- &cropR));
+ filter = SkMatrixConvolutionImageFilter::Make(size,
+ kernel.begin(),
+ make_scalar(),
+ make_scalar(),
+ kernelOffset,
+ (SkMatrixConvolutionImageFilter::TileMode)R(3),
+ R(2) == 1,
+ make_image_filter(),
+ &cropR);
break;
}
case COMPOSE:
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index accebb5a4f..3104336628 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -22,23 +22,22 @@
// by the size of a scalar to know how many scalars we can read.
static const int32_t gMaxKernelSize = SK_MaxS32 / sizeof(SkScalar);
-SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(
- const SkISize& kernelSize,
- const SkScalar* kernel,
- SkScalar gain,
- SkScalar bias,
- const SkIPoint& kernelOffset,
- TileMode tileMode,
- bool convolveAlpha,
- SkImageFilter* input,
- const CropRect* cropRect)
- : INHERITED(1, &input, cropRect),
- fKernelSize(kernelSize),
- fGain(gain),
- fBias(bias),
- fKernelOffset(kernelOffset),
- fTileMode(tileMode),
- fConvolveAlpha(convolveAlpha) {
+SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(const SkISize& kernelSize,
+ const SkScalar* kernel,
+ SkScalar gain,
+ SkScalar bias,
+ const SkIPoint& kernelOffset,
+ TileMode tileMode,
+ bool convolveAlpha,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect)
+ : INHERITED(&input, 1, cropRect)
+ , fKernelSize(kernelSize)
+ , fGain(gain)
+ , fBias(bias)
+ , fKernelOffset(kernelOffset)
+ , fTileMode(tileMode)
+ , fConvolveAlpha(convolveAlpha) {
size_t size = (size_t) sk_64_mul(fKernelSize.width(), fKernelSize.height());
fKernel = new SkScalar[size];
memcpy(fKernel, kernel, size * sizeof(SkScalar));
@@ -47,16 +46,15 @@ SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(
SkASSERT(kernelOffset.fY >= 0 && kernelOffset.fY < kernelSize.fHeight);
}
-SkImageFilter* SkMatrixConvolutionImageFilter::Create(
- const SkISize& kernelSize,
- const SkScalar* kernel,
- SkScalar gain,
- SkScalar bias,
- const SkIPoint& kernelOffset,
- TileMode tileMode,
- bool convolveAlpha,
- SkImageFilter* input,
- const CropRect* cropRect) {
+sk_sp<SkImageFilter> SkMatrixConvolutionImageFilter::Make(const SkISize& kernelSize,
+ const SkScalar* kernel,
+ SkScalar gain,
+ SkScalar bias,
+ const SkIPoint& kernelOffset,
+ TileMode tileMode,
+ bool convolveAlpha,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect) {
if (kernelSize.width() < 1 || kernelSize.height() < 1) {
return nullptr;
}
@@ -70,8 +68,10 @@ SkImageFilter* SkMatrixConvolutionImageFilter::Create(
(kernelOffset.fY < 0) || (kernelOffset.fY >= kernelSize.fHeight)) {
return nullptr;
}
- return new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, kernelOffset,
- tileMode, convolveAlpha, input, cropRect);
+ return sk_sp<SkImageFilter>(new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain,
+ bias, kernelOffset,
+ tileMode, convolveAlpha,
+ std::move(input), cropRect));
}
sk_sp<SkFlattenable> SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& buffer) {
@@ -96,8 +96,8 @@ sk_sp<SkFlattenable> SkMatrixConvolutionImageFilter::CreateProc(SkReadBuffer& bu
kernelOffset.fY = buffer.readInt();
TileMode tileMode = (TileMode)buffer.readInt();
bool convolveAlpha = buffer.readBool();
- return sk_sp<SkFlattenable>(Create(kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode,
- convolveAlpha, common.getInput(0).get(), &common.cropRect()));
+ return Make(kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode,
+ convolveAlpha, common.getInput(0), &common.cropRect());
}
void SkMatrixConvolutionImageFilter::flatten(SkWriteBuffer& buffer) const {
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index e153cc0a92..f1df84e20b 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -191,10 +191,10 @@ public:
SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0,
input.get(), cropRect));
this->addFilter("matrix convolution",
- SkMatrixConvolutionImageFilter::Create(
+ SkMatrixConvolutionImageFilter::Make(
kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1),
SkMatrixConvolutionImageFilter::kRepeat_TileMode, false,
- input.get(), cropRect));
+ input, cropRect).release());
this->addFilter("merge", SkMergeImageFilter::Make(input, input,
SkXfermode::kSrcOver_Mode,
cropRect).release());
@@ -1033,10 +1033,11 @@ DEF_TEST(ImageFilterMatrixConvolution, reporter) {
SkScalar gain = SK_Scalar1, bias = 0;
SkIPoint kernelOffset = SkIPoint::Make(0, 0);
- SkAutoTUnref<SkImageFilter> filter(
- SkMatrixConvolutionImageFilter::Create(
- kernelSize, kernel, gain, bias, kernelOffset,
- SkMatrixConvolutionImageFilter::kRepeat_TileMode, false));
+ sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make(
+ kernelSize, kernel,
+ gain, bias, kernelOffset,
+ SkMatrixConvolutionImageFilter::kRepeat_TileMode,
+ false, nullptr));
SkBitmap result;
int width = 16, height = 16;
@@ -1045,7 +1046,7 @@ DEF_TEST(ImageFilterMatrixConvolution, reporter) {
canvas.clear(0);
SkPaint paint;
- paint.setImageFilter(filter);
+ paint.setImageFilter(std::move(filter));
SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height));
canvas.drawRect(rect, paint);
}
@@ -1060,10 +1061,10 @@ DEF_TEST(ImageFilterMatrixConvolutionBorder, reporter) {
SkScalar gain = SK_Scalar1, bias = 0;
SkIPoint kernelOffset = SkIPoint::Make(2, 0);
- SkAutoTUnref<SkImageFilter> filter(
- SkMatrixConvolutionImageFilter::Create(
- kernelSize, kernel, gain, bias, kernelOffset,
- SkMatrixConvolutionImageFilter::kClamp_TileMode, true));
+ sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make(
+ kernelSize, kernel, gain, bias, kernelOffset,
+ SkMatrixConvolutionImageFilter::kClamp_TileMode,
+ true, nullptr));
SkBitmap result;
@@ -1073,7 +1074,7 @@ DEF_TEST(ImageFilterMatrixConvolutionBorder, reporter) {
canvas.clear(0);
SkPaint filterPaint;
- filterPaint.setImageFilter(filter);
+ filterPaint.setImageFilter(std::move(filter));
SkRect bounds = SkRect::MakeWH(1, 10);
SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height));
SkPaint rectPaint;
@@ -1293,50 +1294,54 @@ DEF_TEST(MatrixConvolutionSanityTest, reporter) {
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
// Check that an enormous (non-allocatable) kernel gives a nullptr filter.
- SkAutoTUnref<SkImageFilter> conv(SkMatrixConvolutionImageFilter::Create(
+ sk_sp<SkImageFilter> conv(SkMatrixConvolutionImageFilter::Make(
SkISize::Make(1<<30, 1<<30),
kernel,
gain,
bias,
kernelOffset,
SkMatrixConvolutionImageFilter::kRepeat_TileMode,
- false));
+ false,
+ nullptr));
REPORTER_ASSERT(reporter, nullptr == conv.get());
// Check that a nullptr kernel gives a nullptr filter.
- conv.reset(SkMatrixConvolutionImageFilter::Create(
+ conv = SkMatrixConvolutionImageFilter::Make(
SkISize::Make(1, 1),
nullptr,
gain,
bias,
kernelOffset,
SkMatrixConvolutionImageFilter::kRepeat_TileMode,
- false));
+ false,
+ nullptr);
REPORTER_ASSERT(reporter, nullptr == conv.get());
// Check that a kernel width < 1 gives a nullptr filter.
- conv.reset(SkMatrixConvolutionImageFilter::Create(
+ conv = SkMatrixConvolutionImageFilter::Make(
SkISize::Make(0, 1),
kernel,
gain,
bias,
kernelOffset,
SkMatrixConvolutionImageFilter::kRepeat_TileMode,
- false));
+ false,
+ nullptr);
REPORTER_ASSERT(reporter, nullptr == conv.get());
// Check that kernel height < 1 gives a nullptr filter.
- conv.reset(SkMatrixConvolutionImageFilter::Create(
+ conv = SkMatrixConvolutionImageFilter::Make(
SkISize::Make(1, -1),
kernel,
gain,
bias,
kernelOffset,
SkMatrixConvolutionImageFilter::kRepeat_TileMode,
- false));
+ false,
+ nullptr);
REPORTER_ASSERT(reporter, nullptr == conv.get());
}