aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-03-29 13:54:26 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-29 13:54:26 -0700
commita33cf07a2273315363c0b6fb5d3ce811742f5a85 (patch)
treec3eab040c77ea20073c82c3eaa3711f203468d6d
parent9b2ef62d4708081979ff954e1ac0623d1d4ffada (diff)
Switch SkLocalMatrixImageFilter and SkPaintImageFilter over to sk_sp
-rw-r--r--gm/imagefiltersclipped.cpp4
-rw-r--r--gm/imagefiltersscaled.cpp2
-rw-r--r--gm/localmatriximagefilter.cpp8
-rw-r--r--include/core/SkImageFilter.h12
-rw-r--r--include/effects/SkPaintImageFilter.h10
-rw-r--r--samplecode/SampleFilterFuzz.cpp254
-rw-r--r--src/core/SkCanvas.cpp3
-rw-r--r--src/core/SkImageFilter.cpp24
-rw-r--r--src/core/SkLocalMatrixImageFilter.cpp21
-rw-r--r--src/core/SkLocalMatrixImageFilter.h21
-rw-r--r--src/effects/SkPaintImageFilter.cpp11
-rw-r--r--src/effects/SkPictureImageFilter.cpp4
-rw-r--r--tests/ImageFilterTest.cpp13
-rw-r--r--tests/PaintImageFilterTest.cpp4
14 files changed, 249 insertions, 142 deletions
diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp
index 7c75bf3951..5401ef537f 100644
--- a/gm/imagefiltersclipped.cpp
+++ b/gm/imagefiltersclipped.cpp
@@ -138,11 +138,11 @@ protected:
SkPaint noisePaint;
noisePaint.setShader(noise);
- SkAutoTUnref<SkImageFilter> rectFilter(SkPaintImageFilter::Create(noisePaint));
+ sk_sp<SkImageFilter> rectFilter(SkPaintImageFilter::Make(noisePaint));
canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
for (int xOffset = 0; xOffset < 80; xOffset += 16) {
bounds.fLeft = SkIntToScalar(xOffset);
- draw_clipped_filter(canvas, rectFilter, 0, r, bounds);
+ draw_clipped_filter(canvas, rectFilter.get(), 0, r, bounds);
canvas->translate(0, r.height() + margin);
}
}
diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp
index b0c55dca73..9bfac68c12 100644
--- a/gm/imagefiltersscaled.cpp
+++ b/gm/imagefiltersscaled.cpp
@@ -86,7 +86,7 @@ protected:
SkErodeImageFilter::Create(1, 1, checkerboard.get()),
SkOffsetImageFilter::Create(SkIntToScalar(32), 0),
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
- SkPaintImageFilter::Create(noisePaint),
+ SkPaintImageFilter::Make(noisePaint).release(),
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
cutoffAngle, white, surfaceScale, kd),
diff --git a/gm/localmatriximagefilter.cpp b/gm/localmatriximagefilter.cpp
index d53380b858..5414fe341c 100644
--- a/gm/localmatriximagefilter.cpp
+++ b/gm/localmatriximagefilter.cpp
@@ -49,7 +49,7 @@ protected:
return SkISize::Make(640, 640);
}
- static void show_image(SkCanvas* canvas, SkImage* image, SkImageFilter* filter) {
+ static void show_image(SkCanvas* canvas, SkImage* image, sk_sp<SkImageFilter> filter) {
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
SkRect r = SkRect::MakeIWH(image->width(), image->height()).makeOutset(SK_ScalarHalf,
@@ -81,14 +81,14 @@ protected:
canvas->translate(40, 40);
for (auto&& factory : factories) {
- SkAutoTUnref<SkImageFilter> filter(factory());
+ sk_sp<SkImageFilter> filter(factory());
canvas->save();
show_image(canvas, image0.get(), filter);
for (const auto& matrix : matrices) {
- SkAutoTUnref<SkImageFilter> localFilter(filter->newWithLocalMatrix(matrix));
+ sk_sp<SkImageFilter> localFilter(filter->makeWithLocalMatrix(matrix));
canvas->translate(spacer, 0);
- show_image(canvas, image0.get(), localFilter);
+ show_image(canvas, image0.get(), std::move(localFilter));
}
canvas->restore();
canvas->translate(0, spacer);
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index ab72547fed..f4273cb8da 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -255,7 +255,13 @@ public:
* If this filter can be represented by another filter + a localMatrix, return that filter,
* else return null.
*/
- SkImageFilter* newWithLocalMatrix(const SkMatrix& matrix) const;
+ sk_sp<SkImageFilter> makeWithLocalMatrix(const SkMatrix&) const;
+
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ SkImageFilter* newWithLocalMatrix(const SkMatrix& matrix) const {
+ this->makeWithLocalMatrix(matrix).release();
+ }
+#endif
/**
* Create an SkMatrixImageFilter, which transforms its input by the given matrix.
@@ -320,7 +326,9 @@ protected:
void allocInputs(int count);
};
- SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = NULL);
+ SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = nullptr);
+
+ SkImageFilter(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect);
virtual ~SkImageFilter();
diff --git a/include/effects/SkPaintImageFilter.h b/include/effects/SkPaintImageFilter.h
index 51d375f44d..2876c0431b 100644
--- a/include/effects/SkPaintImageFilter.h
+++ b/include/effects/SkPaintImageFilter.h
@@ -22,13 +22,21 @@ public:
* not specified, the source primitive's bounds are used
* instead.
*/
- static SkImageFilter* Create(const SkPaint& paint, const CropRect* rect = NULL);
+ static sk_sp<SkImageFilter> Make(const SkPaint& paint, const CropRect* cropRect = nullptr) {
+ return sk_sp<SkImageFilter>(new SkPaintImageFilter(paint, cropRect));
+ }
bool canComputeFastBounds() const override;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPaintImageFilter)
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ static SkImageFilter* Create(const SkPaint& paint, const CropRect* rect = nullptr) {
+ return Make(paint, rect).release();
+ }
+#endif
+
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index d5fbc97a17..751ef9be39 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -487,7 +487,7 @@ static SkMaskFilter* make_mask_filter() {
return maskFilter;
}
-static SkImageFilter* make_image_filter(bool canBeNull = true);
+static sk_sp<SkImageFilter> make_image_filter(bool canBeNull = true);
static SkPaint make_paint() {
SkPaint paint;
@@ -540,11 +540,13 @@ static SkPaint make_paint() {
return paint;
}
-static SkImageFilter* make_image_filter(bool canBeNull) {
- SkImageFilter* filter = 0;
+static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
+ sk_sp<SkImageFilter> filter;
// Add a 1 in 3 chance to get a nullptr input
- if (canBeNull && (R(3) == 1)) { return filter; }
+ if (canBeNull && (R(3) == 1)) {
+ return filter;
+ }
enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
@@ -553,49 +555,73 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
switch (R(NUM_FILTERS)) {
case ALPHA_THRESHOLD:
- filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), make_scalar());
+ filter = sk_sp<SkImageFilter>(SkAlphaThresholdFilter::Create(make_region(),
+ make_scalar(),
+ make_scalar()));
break;
- case MERGE:
- filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filter(), make_xfermode());
+ case MERGE: {
+ sk_sp<SkImageFilter> subFilter1(make_image_filter());
+ sk_sp<SkImageFilter> subFilter2(make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkMergeImageFilter::Create(subFilter1.get(),
+ subFilter2.get(),
+ make_xfermode()));
break;
- case COLOR:
- {
- sk_sp<SkColorFilter> cf(make_color_filter());
- filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
}
+ case COLOR: {
+ sk_sp<SkColorFilter> cf(make_color_filter());
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+ filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(),
+ subFilter.get()))
+ : nullptr;
break;
- case LUT3D:
- {
+ }
+ case LUT3D: {
int cubeDimension;
sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension));
- filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
- }
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+ filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(),
+ subFilter.get()))
+ : nullptr;
break;
- case BLUR:
- filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
+ }
+ case BLUR: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkBlurImageFilter::Create(make_scalar(true),
+ make_scalar(true),
+ subFilter.get()));
break;
+ }
case MAGNIFIER:
- filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
+ filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect(),
+ make_scalar(true)));
break;
case DOWN_SAMPLE:
- filter = SkDownSampleImageFilter::Create(make_scalar());
+ filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scalar()));
break;
- case XFERMODE:
+ case XFERMODE: {
+ sk_sp<SkImageFilter> subFilter1(make_image_filter());
+ sk_sp<SkImageFilter> subFilter2(make_image_filter());
filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()),
- make_image_filter(), make_image_filter(),
- nullptr).release();
+ subFilter1.get(),
+ subFilter2.get(),
+ nullptr);
break;
- case OFFSET:
- filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_image_filter());
+ }
+ case OFFSET: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkOffsetImageFilter::Create(make_scalar(), make_scalar(),
+ subFilter.get()));
break;
- case MATRIX:
- filter = SkImageFilter::CreateMatrixFilter(make_matrix(),
- (SkFilterQuality)R(4),
- make_image_filter());
+ }
+ case MATRIX: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_matrix(),
+ (SkFilterQuality)R(4),
+ subFilter.get()));
break;
- case MATRIX_CONVOLUTION:
- {
+ }
+ case MATRIX_CONVOLUTION: {
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
SkIntToScalar(kBitmapSize)));
SkISize size = SkISize::Make(R(10)+1, R(10)+1);
@@ -606,47 +632,68 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
}
SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())),
R(SkIntToScalar(size.height())));
- filter = SkMatrixConvolutionImageFilter::Create(size,
+ 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,
- make_image_filter(),
- &cropR);
- }
+ subFilter.get(),
+ &cropR));
break;
- case COMPOSE:
- filter = SkComposeImageFilter::Create(make_image_filter(), make_image_filter());
+ }
+ case COMPOSE: {
+ sk_sp<SkImageFilter> subFilter1(make_image_filter());
+ sk_sp<SkImageFilter> subFilter2(make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkComposeImageFilter::Create(subFilter1.get(),
+ subFilter2.get()));
break;
- case DISTANT_LIGHT:
- filter = (R(2) == 1) ?
- SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
- make_color(), make_scalar(), make_scalar(), make_image_filter()) :
- SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
- make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)),
- make_image_filter());
+ }
+ case DISTANT_LIGHT: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+
+ filter = (R(2) == 1)
+ ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
+ make_color(), make_scalar(), make_scalar(),
+ subFilter.get()))
+ : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
+ make_color(), make_scalar(),
+ make_scalar(), SkIntToScalar(R(10)),
+ subFilter.get()));
break;
- case POINT_LIGHT:
- filter = (R(2) == 1) ?
- SkLightingImageFilter::CreatePointLitDiffuse(make_point(),
- make_color(), make_scalar(), make_scalar(), make_image_filter()) :
- SkLightingImageFilter::CreatePointLitSpecular(make_point(),
- make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)),
- make_image_filter());
+ }
+ case POINT_LIGHT: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+
+ filter = (R(2) == 1)
+ ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffuse(make_point(),
+ make_color(), make_scalar(), make_scalar(),
+ subFilter.get()))
+ : sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitSpecular(make_point(),
+ make_color(), make_scalar(), make_scalar(),
+ SkIntToScalar(R(10)),
+ subFilter.get()));
break;
- case SPOT_LIGHT:
- filter = (R(2) == 1) ?
- SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
- make_point(), make_scalar(), make_scalar(), make_color(),
- make_scalar(), make_scalar(), make_image_filter()) :
- SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0, 0, 0),
- make_point(), make_scalar(), make_scalar(), make_color(),
- make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_filter());
+ }
+ case SPOT_LIGHT: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+
+ filter = (R(2) == 1)
+ ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
+ make_point(), make_scalar(), make_scalar(),
+ make_color(), make_scalar(), make_scalar(),
+ subFilter.get()))
+ : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0, 0, 0),
+ make_point(), make_scalar(), make_scalar(),
+ make_color(), make_scalar(), make_scalar(),
+ SkIntToScalar(R(10)), subFilter.get()));
break;
- case NOISE:
- {
+ }
+ case NOISE: {
sk_sp<SkShader> shader((R(2) == 1) ?
SkPerlinNoiseShader::MakeFractalNoise(
make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
@@ -656,43 +703,68 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
paint.setShader(shader);
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
SkIntToScalar(kBitmapSize)));
- filter = SkPaintImageFilter::Create(paint, &cropR);
- }
+ filter = SkPaintImageFilter::Make(paint, &cropR);
break;
- case DROP_SHADOW:
- filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), make_scalar(true),
- make_scalar(true), make_color(), make_shadow_mode(), make_image_filter(),
- nullptr);
+ }
+ case DROP_SHADOW: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+
+ filter = sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(make_scalar(),
+ make_scalar(),
+ make_scalar(true),
+ make_scalar(true),
+ make_color(),
+ make_shadow_mode(),
+ subFilter.get(),
+ nullptr));
break;
- case MORPHOLOGY:
+ }
+ case MORPHOLOGY: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter());
+
if (R(2) == 1) {
- filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSize)),
- R(static_cast<float>(kBitmapSize)), make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSize)),
+ R(static_cast<float>(kBitmapSize)),
+ subFilter.get()));
} else {
- filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize)),
- R(static_cast<float>(kBitmapSize)), make_image_filter());
+ filter = sk_sp<SkImageFilter>(SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize)),
+ R(static_cast<float>(kBitmapSize)),
+ subFilter.get()));
}
break;
- case BITMAP:
- {
+ }
+ case BITMAP: {
sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap()));
if (R(2) == 1) {
- filter = SkImageSource::Create(image.get(), make_rect(), make_rect(), kHigh_SkFilterQuality);
+ filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get(),
+ make_rect(),
+ make_rect(),
+ kHigh_SkFilterQuality));
} else {
- filter = SkImageSource::Create(image.get());
+ filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get()));
}
- }
break;
- case DISPLACE:
- filter = SkDisplacementMapEffect::Create(make_channel_selector_type(),
- make_channel_selector_type(), make_scalar(),
- make_image_filter(false), make_image_filter());
+ }
+ 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()));
break;
- case TILE:
- filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_filter(false));
+ }
+ case TILE: {
+ sk_sp<SkImageFilter> subFilter(make_image_filter(false));
+
+ filter = sk_sp<SkImageFilter>(SkTileImageFilter::Create(make_rect(),
+ make_rect(),
+ subFilter.get()));
break;
- case PICTURE:
- {
+ }
+ case PICTURE: {
SkRTreeFactory factory;
SkPictureRecorder recorder;
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitmapSize),
@@ -700,13 +772,13 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
&factory, 0);
drawSomething(recordingCanvas);
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
- filter = SkPictureImageFilter::Make(pict, make_rect()).release();
- }
+ filter = SkPictureImageFilter::Make(pict, make_rect());
break;
- case PAINT:
- {
+ }
+ case PAINT: {
SkImageFilter::CropRect cropR(make_rect());
- filter = SkPaintImageFilter::Create(make_paint(), &cropR);
+ filter = SkPaintImageFilter::Make(make_paint(), &cropR);
+ break;
}
default:
break;
@@ -715,8 +787,8 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
}
static SkImageFilter* make_serialized_image_filter() {
- SkAutoTUnref<SkImageFilter> filter(make_image_filter(false));
- SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
+ sk_sp<SkImageFilter> filter(make_image_filter(false));
+ SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
const unsigned char* ptr = static_cast<const unsigned char*>(data->data());
size_t len = data->size();
#ifdef SK_ADD_RANDOM_BIT_FLIPS
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f1777441d6..2f6477c41d 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1161,9 +1161,8 @@ static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt
SkCanvas c(dst);
- SkAutoTUnref<SkImageFilter> localF(filter->newWithLocalMatrix(ctm));
SkPaint p;
- p.setImageFilter(localF);
+ p.setImageFilter(filter->makeWithLocalMatrix(ctm));
const SkScalar x = SkIntToScalar(src->getOrigin().x());
const SkScalar y = SkIntToScalar(src->getOrigin().y());
c.drawBitmap(srcBM, x, y, &p);
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 06076c6891..e999d3aebb 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -158,6 +158,22 @@ bool SkImageFilter::Common::unflatten(SkReadBuffer& buffer, int expectedCount) {
///////////////////////////////////////////////////////////////////////////////////////////////////
+SkImageFilter::SkImageFilter(sk_sp<SkImageFilter>* inputs,
+ int inputCount,
+ const CropRect* cropRect)
+ : fInputCount(inputCount),
+ fInputs(new SkImageFilter*[inputCount]),
+ fUsesSrcInput(false),
+ fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)),
+ fUniqueID(next_image_filter_unique_id()) {
+ for (int i = 0; i < inputCount; ++i) {
+ if (nullptr == inputs[i] || inputs[i]->usesSrcInput()) {
+ fUsesSrcInput = true;
+ }
+ fInputs[i] = SkSafeRef(inputs[i].get());
+ }
+}
+
SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
: fInputCount(inputCount),
fInputs(new SkImageFilter*[inputCount]),
@@ -168,8 +184,7 @@ SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
if (nullptr == inputs[i] || inputs[i]->usesSrcInput()) {
fUsesSrcInput = true;
}
- fInputs[i] = inputs[i];
- SkSafeRef(fInputs[i]);
+ fInputs[i] = SkSafeRef(inputs[i]);
}
}
@@ -556,11 +571,12 @@ SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix,
return SkMatrixImageFilter::Create(matrix, filterQuality, input);
}
-SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& matrix) const {
+sk_sp<SkImageFilter> SkImageFilter::makeWithLocalMatrix(const SkMatrix& matrix) const {
// SkLocalMatrixImageFilter takes SkImage* in its factory, but logically that parameter
// is *always* treated as a const ptr. Hence the const-cast here.
//
- return SkLocalMatrixImageFilter::Create(matrix, const_cast<SkImageFilter*>(this));
+ SkImageFilter* nonConstThis = const_cast<SkImageFilter*>(this);
+ return SkLocalMatrixImageFilter::Make(matrix, sk_ref_sp<SkImageFilter>(nonConstThis));
}
sk_sp<SkSpecialImage> SkImageFilter::filterInput(int index,
diff --git a/src/core/SkLocalMatrixImageFilter.cpp b/src/core/SkLocalMatrixImageFilter.cpp
index 15f2f0ef00..d1b5715b7f 100644
--- a/src/core/SkLocalMatrixImageFilter.cpp
+++ b/src/core/SkLocalMatrixImageFilter.cpp
@@ -10,21 +10,9 @@
#include "SkSpecialImage.h"
#include "SkString.h"
-SkImageFilter* SkLocalMatrixImageFilter::Create(const SkMatrix& localM, SkImageFilter* input) {
- if (!input) {
- return nullptr;
- }
- if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
- return nullptr;
- }
- if (localM.isIdentity()) {
- return SkRef(input);
- }
- return new SkLocalMatrixImageFilter(localM, input);
-}
-
-SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input)
- : INHERITED(1, &input)
+SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM,
+ sk_sp<SkImageFilter> input)
+ : INHERITED(&input, 1, nullptr)
, fLocalM(localM) {
}
@@ -32,7 +20,8 @@ SkFlattenable* SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
SkMatrix lm;
buffer.readMatrix(&lm);
- return SkLocalMatrixImageFilter::Create(lm, common.getInput(0));
+ return SkLocalMatrixImageFilter::Make(lm,
+ sk_ref_sp<SkImageFilter>(common.getInput(0))).release();
}
void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
diff --git a/src/core/SkLocalMatrixImageFilter.h b/src/core/SkLocalMatrixImageFilter.h
index 412b391e18..eb112b0f0d 100644
--- a/src/core/SkLocalMatrixImageFilter.h
+++ b/src/core/SkLocalMatrixImageFilter.h
@@ -16,11 +16,28 @@
*/
class SkLocalMatrixImageFilter : public SkImageFilter {
public:
- static SkImageFilter* Create(const SkMatrix& localM, SkImageFilter* input);
+ static sk_sp<SkImageFilter> Make(const SkMatrix& localM, sk_sp<SkImageFilter> input) {
+ if (!input) {
+ return nullptr;
+ }
+ if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
+ return nullptr;
+ }
+ if (localM.isIdentity()) {
+ return input;
+ }
+ return sk_sp<SkImageFilter>(new SkLocalMatrixImageFilter(localM, input));
+ }
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixImageFilter)
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ static SkImageFilter* Create(const SkMatrix& localM, SkImageFilter* input) {
+ return Make(localM, sk_sp<SkImageFilter>(SkSafeRef(input))).release();
+ }
+#endif
+
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
@@ -28,7 +45,7 @@ protected:
SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override;
private:
- SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input);
+ SkLocalMatrixImageFilter(const SkMatrix& localM, sk_sp<SkImageFilter> input);
SkMatrix fLocalM;
diff --git a/src/effects/SkPaintImageFilter.cpp b/src/effects/SkPaintImageFilter.cpp
index 7056f26863..cbd793a692 100644
--- a/src/effects/SkPaintImageFilter.cpp
+++ b/src/effects/SkPaintImageFilter.cpp
@@ -12,20 +12,16 @@
#include "SkSpecialSurface.h"
#include "SkWriteBuffer.h"
-SkImageFilter* SkPaintImageFilter::Create(const SkPaint& paint, const CropRect* cropRect) {
- return new SkPaintImageFilter(paint, cropRect);
-}
-
SkPaintImageFilter::SkPaintImageFilter(const SkPaint& paint, const CropRect* cropRect)
- : INHERITED(0, nullptr, cropRect)
- , fPaint(paint) {
+ : INHERITED(nullptr, 0, cropRect)
+ , fPaint(paint) {
}
SkFlattenable* SkPaintImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
SkPaint paint;
buffer.readPaint(&paint);
- return Create(paint, &common.cropRect());
+ return SkPaintImageFilter::Make(paint, &common.cropRect()).release();
}
void SkPaintImageFilter::flatten(SkWriteBuffer& buffer) const {
@@ -80,6 +76,7 @@ bool SkPaintImageFilter::canComputeFastBounds() const {
#ifndef SK_IGNORE_TO_STRING
void SkPaintImageFilter::toString(SkString* str) const {
str->appendf("SkPaintImageFilter: (");
+ fPaint.toString(str);
str->append(")");
}
#endif
diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp
index f5e3d4680b..2005463bd4 100644
--- a/src/effects/SkPictureImageFilter.cpp
+++ b/src/effects/SkPictureImageFilter.cpp
@@ -14,7 +14,7 @@
#include "SkValidationUtils.h"
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
- : INHERITED(0, 0, nullptr)
+ : INHERITED(nullptr, 0, nullptr)
, fPicture(std::move(picture))
, fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty())
, fPictureResolution(kDeviceSpace_PictureResolution)
@@ -24,7 +24,7 @@ SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
PictureResolution pictureResolution,
SkFilterQuality filterQuality)
- : INHERITED(0, 0, nullptr)
+ : INHERITED(nullptr, 0, nullptr)
, fPicture(std::move(picture))
, fCropRect(cropRect)
, fPictureResolution(pictureResolution)
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 9d2039687d..cd900e3df1 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -138,17 +138,17 @@ public:
SkPaint paint;
paint.setShader(shader);
- SkAutoTUnref<SkImageFilter> paintFilter(SkPaintImageFilter::Create(paint));
+ sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint));
sk_sp<SkShader> greenColorShader(SkShader::MakeColorShader(SK_ColorGREEN));
SkPaint greenColorShaderPaint;
greenColorShaderPaint.setShader(greenColorShader);
SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64));
- SkAutoTUnref<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Create(
- greenColorShaderPaint, &leftSideCropRect));
+ sk_sp<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Make(greenColorShaderPaint,
+ &leftSideCropRect));
SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64));
- SkAutoTUnref<SkImageFilter> paintFilterRight(SkPaintImageFilter::Create(
- greenColorShaderPaint, &rightSideCropRect));
+ sk_sp<SkImageFilter> paintFilterRight(SkPaintImageFilter::Make(greenColorShaderPaint,
+ &rightSideCropRect));
this->addFilter("color filter",
SkColorFilterImageFilter::Create(cf.get(), input, cropRect));
@@ -172,7 +172,8 @@ public:
this->addFilter("merge", SkMergeImageFilter::Create(input, input, SkXfermode::kSrcOver_Mode,
cropRect));
this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Create(
- paintFilterLeft, paintFilterRight, SkXfermode::kSrcOver_Mode, cropRect));
+ paintFilterLeft.get(), paintFilterRight.get(),
+ SkXfermode::kSrcOver_Mode, cropRect));
this->addFilter("offset",
SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input, cropRect));
this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropRect));
diff --git a/tests/PaintImageFilterTest.cpp b/tests/PaintImageFilterTest.cpp
index f1c0c2eb97..03653368ab 100644
--- a/tests/PaintImageFilterTest.cpp
+++ b/tests/PaintImageFilterTest.cpp
@@ -38,7 +38,7 @@ static void test_unscaled(skiatest::Reporter* reporter) {
{
SkPaint paint;
SkImageFilter::CropRect cr(r);
- paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->unref();
+ paint.setImageFilter(SkPaintImageFilter::Make(gradientPaint, &cr));
canvasFilter.drawRect(r, paint);
}
@@ -84,7 +84,7 @@ static void test_scaled(skiatest::Reporter* reporter) {
{
SkPaint paint;
SkImageFilter::CropRect cr(r);
- paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->unref();
+ paint.setImageFilter(SkPaintImageFilter::Make(gradientPaint, &cr));
canvasFilter.scale(SkIntToScalar(2), SkIntToScalar(2));
canvasFilter.drawRect(r, paint);
}