Index: include/core/SkFlattenable.h |
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h |
index f6d377a9d743b4838f6e2e6206053f0056729bee..1244f86f721a2b271b6bc162126a13bf5f3e555c 100644 |
--- a/include/core/SkFlattenable.h |
+++ b/include/core/SkFlattenable.h |
@@ -1,4 +1,3 @@ |
- |
/* |
* Copyright 2006 The Android Open Source Project |
* |
@@ -6,19 +5,16 @@ |
* found in the LICENSE file. |
*/ |
- |
#ifndef SkFlattenable_DEFINED |
#define SkFlattenable_DEFINED |
#include "SkRefCnt.h" |
+#define SK_SUPPORT_LEGACY_DEEPFLATTENING |
+ |
class SkReadBuffer; |
class SkWriteBuffer; |
-#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
- SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ |
- flattenable::GetFlattenableType()); |
- |
#define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables(); |
#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ |
@@ -30,11 +26,33 @@ class SkWriteBuffer; |
#define SK_DECLARE_UNFLATTENABLE_OBJECT() \ |
virtual Factory getFactory() const SK_OVERRIDE { return NULL; } |
-#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
- virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ |
- static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \ |
- return SkNEW_ARGS(flattenable, (buffer)); \ |
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
+ SkFlattenable::Registrar(#flattenable, flattenable::DeepCreateProc, \ |
+ flattenable::GetFlattenableType()); |
+ |
+#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
+ static SkFlattenable* CreateProc(SkReadBuffer&); \ |
+ virtual Factory getFactory() const SK_OVERRIDE {return DeepCreateProc;} \ |
+ static SkFlattenable* DeepCreateProc(SkReadBuffer& buffer) { \ |
+ if (NeedsDeepUnflatten(buffer)) { \ |
+ return SkNEW_ARGS(flattenable, (buffer)); \ |
+ } \ |
+ return CreateProc(buffer); \ |
} |
+#else |
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
+ SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ |
+ flattenable::GetFlattenableType()); |
+ |
+#define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
+ static SkFlattenable* CreateProc(SkReadBuffer&); \ |
+ virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } |
+#endif |
+ |
robertphillips
2014/08/19 15:23:27
typo (declar)
reed1
2014/08/19 19:58:05
Done.
|
+// If your subclass will *never* need to be unflattened, declar 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 |
@@ -101,7 +119,14 @@ public: |
virtual void flatten(SkWriteBuffer&) const; |
protected: |
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
+ static bool NeedsDeepUnflatten(const SkReadBuffer&); |
SkFlattenable(SkReadBuffer&) {} |
+#endif |
+ |
+ static SkFlattenable* ReturnNullCreateProc(SkReadBuffer&) { |
+ return NULL; |
+ } |
private: |
static void InitializeFlattenablesIfNeeded(); |