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