Simplify flattening to just write enough to call the factory/public-constructor for the class. We want to *not* rely on private constructors, and not rely on calling through the inheritance hierarchy for either flattening or unflattening(CreateProc).
Refactoring pattern:
1. guard the existing constructor(readbuffer) with the legacy build-flag
2. If you are a instancable subclass, implement CreateProc(readbuffer) to create a new instances from the buffer params (or return NULL).
If you're a shader subclass
1. You must read/write the local matrix if your class accepts that in its factory/constructor, else ignore it.
R=robertphillips@google.com, mtklein@google.com, senorblanco@google.com, senorblanco@chromium.org, sugoi@chromium.org
Author: reed@google.com
Review URL: https://codereview.chromium.org/395603002
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 67769f2..bb8478c 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -21,6 +21,7 @@
#include "effects/Gr1DKernelEffect.h"
#endif
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkMorphologyImageFilter::SkMorphologyImageFilter(SkReadBuffer& buffer)
: INHERITED(1, buffer) {
fRadius.fWidth = buffer.readInt();
@@ -28,6 +29,7 @@
buffer.validate((fRadius.fWidth >= 0) &&
(fRadius.fHeight >= 0));
}
+#endif
SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX,
int radiusY,
@@ -36,7 +38,6 @@
: INHERITED(1, &input, cropRect), fRadius(SkISize::Make(radiusX, radiusY)) {
}
-
void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeInt(fRadius.fWidth);
@@ -258,6 +259,20 @@
return true;
}
+SkFlattenable* SkErodeImageFilter::CreateProc(SkReadBuffer& buffer) {
+ SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
+ const int width = buffer.readInt();
+ const int height = buffer.readInt();
+ return Create(width, height, common.getInput(0), &common.cropRect());
+}
+
+SkFlattenable* SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) {
+ SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
+ const int width = buffer.readInt();
+ const int height = buffer.readInt();
+ return Create(width, height, common.getInput(0), &common.cropRect());
+}
+
#if SK_SUPPORT_GPU
///////////////////////////////////////////////////////////////////////////////