Index: samplecode/SampleFilterFuzz.cpp |
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp |
index d5fbc97a17397039d60f01560a1c3674eb208dff..751ef9be393db03f2345aa6ad4e2a5b344bf2925 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 |