Chromium Code Reviews| 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) \ | |
| 19 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ | |
| 20 flattenable::GetFlattenableType()); | |
| 21 | |
| 22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les(); | 18 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les(); |
| 23 | 19 |
| 24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ | 20 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ |
| 25 void flattenable::InitializeFlattenables() { | 21 void flattenable::InitializeFlattenables() { |
| 26 | 22 |
| 27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ | 23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ |
| 28 } | 24 } |
| 29 | 25 |
| 30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ | 26 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ |
| 31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } | 27 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } |
| 32 | 28 |
| 33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | 29 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ | 30 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
| 35 static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \ | 31 SkFlattenable::Registrar(#flattenable, flattenable::DeepCreateProc, \ |
| 36 return SkNEW_ARGS(flattenable, (buffer)); \ | 32 flattenable::GetFlattenableType()); |
| 33 | |
| 34 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | |
| 35 static SkFlattenable* CreateProc(SkReadBuffer&); \ | |
| 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_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ | |
| 45 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ | |
| 46 flattenable::GetFlattenableType()); | |
| 47 | |
| 48 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | |
| 49 static SkFlattenable* CreateProc(SkReadBuffer&); \ | |
| 50 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } | |
| 51 #endif | |
| 52 | |
|
robertphillips
2014/08/19 15:23:27
typo (declar)
reed1
2014/08/19 19:58:05
Done.
| |
| 53 // If your subclass will *never* need to be unflattened, declar this. | |
| 54 #define SK_DECLARE_NOT_FLATTENABLE_PROCS(flattenable) \ | |
| 55 virtual Factory getFactory() const SK_OVERRIDE { return ReturnNullCreateProc ; } | |
| 38 | 56 |
| 39 /** For SkFlattenable derived objects with a valid type | 57 /** For SkFlattenable derived objects with a valid type |
| 40 This macro should only be used in base class objects in core | 58 This macro should only be used in base class objects in core |
| 41 */ | 59 */ |
| 42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ | 60 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ |
| 43 static Type GetFlattenableType() { \ | 61 static Type GetFlattenableType() { \ |
| 44 return k##flattenable##_Type; \ | 62 return k##flattenable##_Type; \ |
| 45 } | 63 } |
| 46 | 64 |
| 47 /** \class SkFlattenable | 65 /** \class SkFlattenable |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 112 } |
| 95 }; | 113 }; |
| 96 | 114 |
| 97 /** Override this to write data specific to your subclass into the buffer, | 115 /** 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 | 116 being sure to call your super-class' version first. This data will later |
| 99 be passed to your Factory function, returned by getFactory(). | 117 be passed to your Factory function, returned by getFactory(). |
| 100 */ | 118 */ |
| 101 virtual void flatten(SkWriteBuffer&) const; | 119 virtual void flatten(SkWriteBuffer&) const; |
| 102 | 120 |
| 103 protected: | 121 protected: |
| 122 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
| 123 static bool NeedsDeepUnflatten(const SkReadBuffer&); | |
| 104 SkFlattenable(SkReadBuffer&) {} | 124 SkFlattenable(SkReadBuffer&) {} |
| 125 #endif | |
| 126 | |
| 127 static SkFlattenable* ReturnNullCreateProc(SkReadBuffer&) { | |
| 128 return NULL; | |
| 129 } | |
| 105 | 130 |
| 106 private: | 131 private: |
| 107 static void InitializeFlattenablesIfNeeded(); | 132 static void InitializeFlattenablesIfNeeded(); |
| 108 | 133 |
| 109 friend class SkGraphics; | 134 friend class SkGraphics; |
| 110 | 135 |
| 111 typedef SkRefCnt INHERITED; | 136 typedef SkRefCnt INHERITED; |
| 112 }; | 137 }; |
| 113 | 138 |
| 114 #endif | 139 #endif |
| OLD | NEW |