Clean up SkImageFilter constructors.
Now that all creation of SkImageFilters goes through
factory Create() methods, there's no real reason for the
convenience constructors. Some SkImageFilter subclasses
which actually have zero DAG-able inputs were passing NULL
to the superclass constructor. This actually means 1 input,
with a NULL value, not zero inputs. This becomes more
relevant for the upcoming cache infrastructure, where this
indicates that the filter will use its src input, where in
fact some of these filters do not (they are image generators
only).
Limiting SkImageFilter to a single constructor resolves this
ambiguity.
Along the way, I removed all of the default parameters to
the constructors, since the Create methods always call them
with the full argument list.
BUG=skia:
R=reed@google.com
Author: senorblanco@chromium.org
Review URL: https://codereview.chromium.org/376953003
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 012a7f7..a571184 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -201,12 +201,6 @@
protected:
SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = NULL);
- // Convenience constructor for 1-input filters.
- explicit SkImageFilter(SkImageFilter* input, const CropRect* cropRect = NULL);
-
- // Convenience constructor for 2-input filters.
- SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const CropRect* cropRect = NULL);
-
virtual ~SkImageFilter();
/**
diff --git a/include/effects/SkAlphaThresholdFilter.h b/include/effects/SkAlphaThresholdFilter.h
index 23af56f..f409ee0 100644
--- a/include/effects/SkAlphaThresholdFilter.h
+++ b/include/effects/SkAlphaThresholdFilter.h
@@ -20,7 +20,8 @@
* The 0,0 point of the region corresponds to the upper left corner of the
* source image.
*/
- static SkImageFilter* Create(const SkRegion& region, SkScalar innerThreshold, SkScalar outerThreshold);
+ static SkImageFilter* Create(const SkRegion& region, SkScalar innerThreshold,
+ SkScalar outerThreshold, SkImageFilter* input = NULL);
};
#endif
diff --git a/include/effects/SkColorFilterImageFilter.h b/include/effects/SkColorFilterImageFilter.h
index 6c88361..b915e88 100644
--- a/include/effects/SkColorFilterImageFilter.h
+++ b/include/effects/SkColorFilterImageFilter.h
@@ -33,7 +33,7 @@
private:
SkColorFilterImageFilter(SkColorFilter* cf,
SkImageFilter* input,
- const CropRect* cropRect = NULL);
+ const CropRect* cropRect);
SkColorFilter* fColorFilter;
typedef SkImageFilter INHERITED;
diff --git a/include/effects/SkComposeImageFilter.h b/include/effects/SkComposeImageFilter.h
index 32304b9..068bcab 100644
--- a/include/effects/SkComposeImageFilter.h
+++ b/include/effects/SkComposeImageFilter.h
@@ -15,13 +15,14 @@
virtual ~SkComposeImageFilter();
static SkComposeImageFilter* Create(SkImageFilter* outer, SkImageFilter* inner) {
- return SkNEW_ARGS(SkComposeImageFilter, (outer, inner));
+ SkImageFilter* inputs[2] = { outer, inner };
+ return SkNEW_ARGS(SkComposeImageFilter, (inputs));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeImageFilter)
protected:
- SkComposeImageFilter(SkImageFilter* outer, SkImageFilter* inner) : INHERITED(outer, inner) {}
+ explicit SkComposeImageFilter(SkImageFilter* inputs[2]) : INHERITED(2, inputs) {}
explicit SkComposeImageFilter(SkReadBuffer& buffer);
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
diff --git a/include/effects/SkDisplacementMapEffect.h b/include/effects/SkDisplacementMapEffect.h
index 4d64aae..07f8ee9 100644
--- a/include/effects/SkDisplacementMapEffect.h
+++ b/include/effects/SkDisplacementMapEffect.h
@@ -28,8 +28,9 @@
SkScalar scale, SkImageFilter* displacement,
SkImageFilter* color = NULL,
const CropRect* cropRect = NULL) {
+ SkImageFilter* inputs[2] = { displacement, color };
return SkNEW_ARGS(SkDisplacementMapEffect, (xChannelSelector, yChannelSelector, scale,
- displacement, color, cropRect));
+ inputs, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDisplacementMapEffect)
@@ -53,9 +54,8 @@
protected:
SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
ChannelSelectorType yChannelSelector,
- SkScalar scale, SkImageFilter* displacement,
- SkImageFilter* color = NULL,
- const CropRect* cropRect = NULL);
+ SkScalar scale, SkImageFilter* inputs[2],
+ const CropRect* cropRect);
explicit SkDisplacementMapEffect(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
diff --git a/include/effects/SkLightingImageFilter.h b/include/effects/SkLightingImageFilter.h
index 4a76a9c..81e8f43 100644
--- a/include/effects/SkLightingImageFilter.h
+++ b/include/effects/SkLightingImageFilter.h
@@ -73,7 +73,7 @@
SkLightingImageFilter(SkLight* light,
SkScalar surfaceScale,
SkImageFilter* input,
- const CropRect* cropRect = NULL);
+ const CropRect* cropRect);
explicit SkLightingImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
const SkLight* light() const { return fLight; }
diff --git a/include/effects/SkMagnifierImageFilter.h b/include/effects/SkMagnifierImageFilter.h
index b992e28..3f799d6 100644
--- a/include/effects/SkMagnifierImageFilter.h
+++ b/include/effects/SkMagnifierImageFilter.h
@@ -14,14 +14,15 @@
class SK_API SkMagnifierImageFilter : public SkImageFilter {
public:
- static SkMagnifierImageFilter* Create(const SkRect& srcRect, SkScalar inset) {
- return SkNEW_ARGS(SkMagnifierImageFilter, (srcRect, inset));
+ static SkMagnifierImageFilter* Create(const SkRect& srcRect, SkScalar inset,
+ SkImageFilter* input = NULL) {
+ return SkNEW_ARGS(SkMagnifierImageFilter, (srcRect, inset, input));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter)
protected:
- SkMagnifierImageFilter(const SkRect& srcRect, SkScalar inset);
+ SkMagnifierImageFilter(const SkRect& srcRect, SkScalar inset, SkImageFilter* input);
explicit SkMagnifierImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
diff --git a/include/effects/SkMatrixImageFilter.h b/include/effects/SkMatrixImageFilter.h
index 004c6ef..14b0b8e 100644
--- a/include/effects/SkMatrixImageFilter.h
+++ b/include/effects/SkMatrixImageFilter.h
@@ -40,7 +40,7 @@
protected:
SkMatrixImageFilter(const SkMatrix& transform,
SkPaint::FilterLevel,
- SkImageFilter* input = NULL);
+ SkImageFilter* input);
SkMatrixImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
diff --git a/include/effects/SkMergeImageFilter.h b/include/effects/SkMergeImageFilter.h
index 3ac4aaa..ed316d7 100644
--- a/include/effects/SkMergeImageFilter.h
+++ b/include/effects/SkMergeImageFilter.h
@@ -19,7 +19,9 @@
static SkMergeImageFilter* Create(SkImageFilter* first, SkImageFilter* second,
SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
const CropRect* cropRect = NULL) {
- return SkNEW_ARGS(SkMergeImageFilter, (first, second, mode, cropRect));
+ SkImageFilter* inputs[2] = { first, second };
+ SkXfermode::Mode modes[2] = { mode, mode };
+ return SkNEW_ARGS(SkMergeImageFilter, (inputs, 2, modes, cropRect));
}
static SkMergeImageFilter* Create(SkImageFilter* filters[], int count,
const SkXfermode::Mode modes[] = NULL,
@@ -30,12 +32,9 @@
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMergeImageFilter)
protected:
- SkMergeImageFilter(SkImageFilter* first, SkImageFilter* second,
- SkXfermode::Mode = SkXfermode::kSrcOver_Mode,
- const CropRect* cropRect = NULL);
SkMergeImageFilter(SkImageFilter* filters[], int count,
- const SkXfermode::Mode modes[] = NULL,
- const CropRect* cropRect = NULL);
+ const SkXfermode::Mode modes[],
+ const CropRect* cropRect);
explicit SkMergeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
diff --git a/include/effects/SkMorphologyImageFilter.h b/include/effects/SkMorphologyImageFilter.h
index a464da3..75551b6 100644
--- a/include/effects/SkMorphologyImageFilter.h
+++ b/include/effects/SkMorphologyImageFilter.h
@@ -68,9 +68,7 @@
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter)
protected:
- SkDilateImageFilter(int radiusX, int radiusY,
- SkImageFilter* input = NULL,
- const CropRect* cropRect = NULL)
+ SkDilateImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect)
: INHERITED(radiusX, radiusY, input, cropRect) {}
explicit SkDilateImageFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}
@@ -96,9 +94,7 @@
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter)
protected:
- SkErodeImageFilter(int radiusX, int radiusY,
- SkImageFilter* input = NULL,
- const CropRect* cropRect = NULL)
+ SkErodeImageFilter(int radiusX, int radiusY, SkImageFilter* input, const CropRect* cropRect)
: INHERITED(radiusX, radiusY, input, cropRect) {}
explicit SkErodeImageFilter(SkReadBuffer& buffer) : INHERITED(buffer) {}
diff --git a/include/effects/SkTestImageFilters.h b/include/effects/SkTestImageFilters.h
index 4b20936..2836040 100644
--- a/include/effects/SkTestImageFilters.h
+++ b/include/effects/SkTestImageFilters.h
@@ -7,14 +7,15 @@
// Fun mode that scales down (only) and then scales back up to look pixelated
class SK_API SkDownSampleImageFilter : public SkImageFilter {
public:
- static SkDownSampleImageFilter* Create(SkScalar scale) {
- return SkNEW_ARGS(SkDownSampleImageFilter, (scale));
+ static SkDownSampleImageFilter* Create(SkScalar scale, SkImageFilter* input = NULL) {
+ return SkNEW_ARGS(SkDownSampleImageFilter, (scale, input));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDownSampleImageFilter)
protected:
- SkDownSampleImageFilter(SkScalar scale) : INHERITED(0), fScale(scale) {}
+ SkDownSampleImageFilter(SkScalar scale, SkImageFilter* input)
+ : INHERITED(1, &input), fScale(scale) {}
SkDownSampleImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
diff --git a/include/effects/SkTileImageFilter.h b/include/effects/SkTileImageFilter.h
index 01d6c64..29e3ca5 100644
--- a/include/effects/SkTileImageFilter.h
+++ b/include/effects/SkTileImageFilter.h
@@ -33,7 +33,7 @@
protected:
SkTileImageFilter(const SkRect& srcRect, const SkRect& dstRect, SkImageFilter* input)
- : INHERITED(input), fSrcRect(srcRect), fDstRect(dstRect) {}
+ : INHERITED(1, &input), fSrcRect(srcRect), fDstRect(dstRect) {}
explicit SkTileImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
diff --git a/include/effects/SkXfermodeImageFilter.h b/include/effects/SkXfermodeImageFilter.h
index a5404f9..05f96c4 100644
--- a/include/effects/SkXfermodeImageFilter.h
+++ b/include/effects/SkXfermodeImageFilter.h
@@ -26,7 +26,8 @@
static SkXfermodeImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL,
const CropRect* cropRect = NULL) {
- return SkNEW_ARGS(SkXfermodeImageFilter, (mode, background, foreground, cropRect));
+ SkImageFilter* inputs[2] = { background, foreground };
+ return SkNEW_ARGS(SkXfermodeImageFilter, (mode, inputs, cropRect));
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkXfermodeImageFilter)
@@ -43,8 +44,8 @@
#endif
protected:
- SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* background,
- SkImageFilter* foreground, const CropRect* cropRect);
+ SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* inputs[2],
+ const CropRect* cropRect);
explicit SkXfermodeImageFilter(SkReadBuffer& buffer);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;