Remove macros that make it look like it's a good idea to not be able to flatten.
There are only a handful of SkFlattenables that are not flattenable. That
there are any seems highly illogical. To make this look less like a normal
thing, this removes both macros that marked SkFlattenables as non-flattenable
(in slightly different ways).
The handful of SkFlattenables in our codebase that can't be flattened now
assert violently that they can't be flattened. They're internal or
part of animator... places where we'll never actually flatten them.
TestLooper and DummyRasterizer were so trivial that I just made them flattenable.
BUG=skia:
Review URL: https://codereview.chromium.org/841753002
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 3cfa85a..e45627d 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -40,9 +40,6 @@
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
}
-#define SK_DECLARE_UNFLATTENABLE_OBJECT() \
- virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
-
#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
flattenable::GetFlattenableType());
@@ -54,10 +51,6 @@
public: \
virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; }
-// If your subclass will *never* need to be unflattened, declare this.
-#define SK_DECLARE_NOT_FLATTENABLE_PROCS(flattenable) \
- virtual Factory getFactory() const SK_OVERRIDE { return ReturnNullCreateProc; }
-
/** For SkFlattenable derived objects with a valid type
This macro should only be used in base class objects in core
*/
@@ -122,11 +115,6 @@
*/
virtual void flatten(SkWriteBuffer&) const {}
-protected:
- static SkFlattenable* ReturnNullCreateProc(SkReadBuffer&) {
- return NULL;
- }
-
private:
static void InitializeFlattenablesIfNeeded();
diff --git a/include/effects/Sk2DPathEffect.h b/include/effects/Sk2DPathEffect.h
index 97c86ec..404bf0a 100644
--- a/include/effects/Sk2DPathEffect.h
+++ b/include/effects/Sk2DPathEffect.h
@@ -16,8 +16,6 @@
public:
virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const SK_OVERRIDE;
- SK_DECLARE_UNFLATTENABLE_OBJECT()
-
protected:
/** New virtual, to be overridden by subclasses.
This is called once from filterPath, and provides the
diff --git a/src/animator/SkDrawExtraPathEffect.cpp b/src/animator/SkDrawExtraPathEffect.cpp
index cc097d0..dc58605 100644
--- a/src/animator/SkDrawExtraPathEffect.cpp
+++ b/src/animator/SkDrawExtraPathEffect.cpp
@@ -89,7 +89,8 @@
fDraw(draw), fMaker(maker) {
}
- SK_DECLARE_UNFLATTENABLE_OBJECT()
+ // For serialization. This will never be called.
+ Factory getFactory() const SK_OVERRIDE { sk_throw(); return NULL; }
protected:
virtual SkScalar begin(SkScalar contourLength) const SK_OVERRIDE {
@@ -228,6 +229,9 @@
const SkMatrix& matrix) : Sk2DPathEffect(matrix), fDraw(draw), fMaker(maker) {
}
+ // For serialization. This will never be called.
+ Factory getFactory() const SK_OVERRIDE { sk_throw(); return NULL; }
+
protected:
virtual void begin(const SkIRect& uvBounds, SkPath*) const SK_OVERRIDE {
const_cast<SkShape2DPathEffect*>(this)->setUVBounds(uvBounds);
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index 0a6365c..1e1ce07 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -2035,7 +2035,9 @@
};
SK_TO_STRING_OVERRIDE()
- SK_DECLARE_NOT_FLATTENABLE_PROCS(SkTriColorShader)
+
+ // For serialization. This will never be called.
+ Factory getFactory() const SK_OVERRIDE { sk_throw(); return NULL; }
protected:
virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE {
diff --git a/tests/LayerRasterizerTest.cpp b/tests/LayerRasterizerTest.cpp
index 4b236ac..b4edc14 100644
--- a/tests/LayerRasterizerTest.cpp
+++ b/tests/LayerRasterizerTest.cpp
@@ -33,7 +33,7 @@
static int GetCount() { return gCount; }
- SK_DECLARE_NOT_FLATTENABLE_PROCS(DummyRasterizer)
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(DummyRasterizer);
private:
static int gCount;
@@ -43,6 +43,10 @@
int DummyRasterizer::gCount;
+SkFlattenable* DummyRasterizer::CreateProc(SkReadBuffer&) {
+ return SkNEW(DummyRasterizer);
+}
+
// Check to make sure that the SkPaint in the layer has its destructor called.
DEF_TEST(LayerRasterizer_destructor, reporter) {
{
diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp
index 8f4357e..77bcd3c 100644
--- a/tests/QuickRejectTest.cpp
+++ b/tests/QuickRejectTest.cpp
@@ -28,6 +28,8 @@
}
#endif
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(TestLooper);
+
private:
class TestDrawLooperContext : public SkDrawLooper::Context {
public:
@@ -45,10 +47,10 @@
private:
bool fOnce;
};
-
- SK_DECLARE_UNFLATTENABLE_OBJECT()
};
+SkFlattenable* TestLooper::CreateProc(SkReadBuffer&) { return SkNEW(TestLooper); }
+
static void test_drawBitmap(skiatest::Reporter* reporter) {
SkBitmap src;
src.allocN32Pixels(10, 10);