| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkFlattenable_DEFINED | 10 #ifndef SkFlattenable_DEFINED |
| 11 #define SkFlattenable_DEFINED | 11 #define SkFlattenable_DEFINED |
| 12 | 12 |
| 13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
| 14 | 14 |
| 15 class SkFlattenableReadBuffer; | 15 class SkFlattenableReadBuffer; |
| 16 class SkFlattenableWriteBuffer; | 16 class SkFlattenableWriteBuffer; |
| 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 | 21 |
| 21 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab
les(); | 22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab
les(); |
| 22 | 23 |
| 23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ | 24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ |
| 24 void flattenable::InitializeFlattenables() { | 25 void flattenable::InitializeFlattenables() { |
| 25 | 26 |
| 26 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ | 27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ |
| 27 } | 28 } |
| 28 | 29 |
| 29 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ | 30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ |
| 30 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } | 31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } |
| 31 | 32 |
| 32 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | 33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
| 33 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ | 34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ |
| 34 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ | 35 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ |
| 35 return SkNEW_ARGS(flattenable, (buffer)); \ | 36 return SkNEW_ARGS(flattenable, (buffer)); \ |
| 36 } | 37 } |
| 37 | 38 |
| 39 /** For SkFlattenable derived objects with a valid type |
| 40 This macro should only be used in base class objects in core |
| 41 */ |
| 42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ |
| 43 static Type GetFlattenableType() { \ |
| 44 return k##flattenable##_Type; \ |
| 45 } |
| 46 |
| 38 /** \class SkFlattenable | 47 /** \class SkFlattenable |
| 39 | 48 |
| 40 SkFlattenable is the base class for objects that need to be flattened | 49 SkFlattenable is the base class for objects that need to be flattened |
| 41 into a data stream for either transport or as part of the key to the | 50 into a data stream for either transport or as part of the key to the |
| 42 font cache. | 51 font cache. |
| 43 */ | 52 */ |
| 44 class SK_API SkFlattenable : public SkRefCnt { | 53 class SK_API SkFlattenable : public SkRefCnt { |
| 45 public: | 54 public: |
| 55 enum Type { |
| 56 kSkColorFilter_Type, |
| 57 kSkDrawLooper_Type, |
| 58 kSkImageFilter_Type, |
| 59 kSkMaskFilter_Type, |
| 60 kSkPathEffect_Type, |
| 61 kSkPixelRef_Type, |
| 62 kSkRasterizer_Type, |
| 63 kSkShader_Type, |
| 64 kSkUnitMapper_Type, |
| 65 kSkXfermode_Type, |
| 66 }; |
| 67 |
| 46 SK_DECLARE_INST_COUNT(SkFlattenable) | 68 SK_DECLARE_INST_COUNT(SkFlattenable) |
| 47 | 69 |
| 48 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); | 70 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); |
| 49 | 71 |
| 50 SkFlattenable() {} | 72 SkFlattenable() {} |
| 51 | 73 |
| 52 /** Implement this to return a factory function pointer that can be called | 74 /** Implement this to return a factory function pointer that can be called |
| 53 to recreate your class given a buffer (previously written to by your | 75 to recreate your class given a buffer (previously written to by your |
| 54 override of flatten(). | 76 override of flatten(). |
| 55 */ | 77 */ |
| 56 virtual Factory getFactory() const = 0; | 78 virtual Factory getFactory() const = 0; |
| 57 | 79 |
| 80 /** Returns the name of the object's class |
| 81 */ |
| 82 const char* getTypeName() const { return FactoryToName(getFactory()); } |
| 83 |
| 58 static Factory NameToFactory(const char name[]); | 84 static Factory NameToFactory(const char name[]); |
| 59 static const char* FactoryToName(Factory); | 85 static const char* FactoryToName(Factory); |
| 60 static void Register(const char name[], Factory); | 86 static bool NameToType(const char name[], Type* type); |
| 87 |
| 88 static void Register(const char name[], Factory, Type); |
| 61 | 89 |
| 62 class Registrar { | 90 class Registrar { |
| 63 public: | 91 public: |
| 64 Registrar(const char name[], Factory factory) { | 92 Registrar(const char name[], Factory factory, Type type) { |
| 65 SkFlattenable::Register(name, factory); | 93 SkFlattenable::Register(name, factory, type); |
| 66 } | 94 } |
| 67 }; | 95 }; |
| 68 | 96 |
| 69 protected: | 97 protected: |
| 70 SkFlattenable(SkFlattenableReadBuffer&) {} | 98 SkFlattenable(SkFlattenableReadBuffer&) {} |
| 71 /** Override this to write data specific to your subclass into the buffer, | 99 /** Override this to write data specific to your subclass into the buffer, |
| 72 being sure to call your super-class' version first. This data will later | 100 being sure to call your super-class' version first. This data will later |
| 73 be passed to your Factory function, returned by getFactory(). | 101 be passed to your Factory function, returned by getFactory(). |
| 74 */ | 102 */ |
| 75 virtual void flatten(SkFlattenableWriteBuffer&) const; | 103 virtual void flatten(SkFlattenableWriteBuffer&) const; |
| 76 | 104 |
| 77 private: | 105 private: |
| 78 static void InitializeFlattenables(); | 106 static void InitializeFlattenablesIfNeeded(); |
| 79 | 107 |
| 80 friend class SkGraphics; | 108 friend class SkGraphics; |
| 81 friend class SkFlattenableWriteBuffer; | 109 friend class SkFlattenableWriteBuffer; |
| 82 | 110 |
| 83 typedef SkRefCnt INHERITED; | 111 typedef SkRefCnt INHERITED; |
| 84 }; | 112 }; |
| 85 | 113 |
| 86 #endif | 114 #endif |
| OLD | NEW |