OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | |
10 #ifndef SkFlattenable_DEFINED | 8 #ifndef SkFlattenable_DEFINED |
11 #define SkFlattenable_DEFINED | 9 #define SkFlattenable_DEFINED |
12 | 10 |
13 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
14 | 12 |
| 13 //#define SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 14 |
15 class SkReadBuffer; | 15 class SkReadBuffer; |
16 class SkWriteBuffer; | 16 class SkWriteBuffer; |
17 | 17 |
18 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ | 18 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
19 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ | 19 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ |
20 flattenable::GetFlattenableType()); | 20 flattenable::GetFlattenableType()); |
21 | 21 |
22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab
les(); | 22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab
les(); |
23 | 23 |
24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ | 24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ |
25 void flattenable::InitializeFlattenables() { | 25 void flattenable::InitializeFlattenables() { |
26 | 26 |
27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ | 27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ |
28 } | 28 } |
29 | 29 |
30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ | 30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ |
31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } | 31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } |
32 | 32 |
33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | 33 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ | 34 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
35 static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \ | 35 static SkFlattenable* CreateProc(SkReadBuffer&); \ |
36 return SkNEW_ARGS(flattenable, (buffer)); \ | 36 virtual Factory getFactory() const SK_OVERRIDE {return DeepCreateProc;} \ |
| 37 static SkFlattenable* DeepCreateProc(SkReadBuffer& buffer) { \ |
| 38 if (NeedsDeepUnflatten(buffer)) { \ |
| 39 return SkNEW_ARGS(flattenable, (buffer)); \ |
| 40 } \ |
| 41 return CreateProc(buffer); \ |
37 } | 42 } |
| 43 #else |
| 44 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
| 45 static SkFlattenable* CreateProc(SkReadBuffer&); \ |
| 46 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } |
| 47 #endif |
| 48 |
| 49 // If your subclass will *never* need to be unflattened, declar this. |
| 50 #define SK_DECLARE_NOT_FLATTENABLE_PROCS(flattenable) \ |
| 51 virtual Factory getFactory() const SK_OVERRIDE { return ReturnNullCreateProc
; } |
38 | 52 |
39 /** For SkFlattenable derived objects with a valid type | 53 /** For SkFlattenable derived objects with a valid type |
40 This macro should only be used in base class objects in core | 54 This macro should only be used in base class objects in core |
41 */ | 55 */ |
42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ | 56 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ |
43 static Type GetFlattenableType() { \ | 57 static Type GetFlattenableType() { \ |
44 return k##flattenable##_Type; \ | 58 return k##flattenable##_Type; \ |
45 } | 59 } |
46 | 60 |
47 /** \class SkFlattenable | 61 /** \class SkFlattenable |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 108 } |
95 }; | 109 }; |
96 | 110 |
97 /** Override this to write data specific to your subclass into the buffer, | 111 /** Override this to write data specific to your subclass into the buffer, |
98 being sure to call your super-class' version first. This data will later | 112 being sure to call your super-class' version first. This data will later |
99 be passed to your Factory function, returned by getFactory(). | 113 be passed to your Factory function, returned by getFactory(). |
100 */ | 114 */ |
101 virtual void flatten(SkWriteBuffer&) const; | 115 virtual void flatten(SkWriteBuffer&) const; |
102 | 116 |
103 protected: | 117 protected: |
| 118 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 119 enum { |
| 120 kNewFlattenVersion = 27 |
| 121 }; |
| 122 static bool NeedsDeepUnflatten(const SkReadBuffer&); |
104 SkFlattenable(SkReadBuffer&) {} | 123 SkFlattenable(SkReadBuffer&) {} |
| 124 #endif |
| 125 |
| 126 static SkFlattenable* ReturnNullCreateProc(SkReadBuffer&) { |
| 127 return NULL; |
| 128 } |
105 | 129 |
106 private: | 130 private: |
107 static void InitializeFlattenablesIfNeeded(); | 131 static void InitializeFlattenablesIfNeeded(); |
108 | 132 |
109 friend class SkGraphics; | 133 friend class SkGraphics; |
110 | 134 |
111 typedef SkRefCnt INHERITED; | 135 typedef SkRefCnt INHERITED; |
112 }; | 136 }; |
113 | 137 |
114 #endif | 138 #endif |
OLD | NEW |