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::GetEffectType()); |
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_EFFECT_TYPE(flattenable) \ | |
42 static SkEffectType GetEffectType() { \ | |
43 return k##flattenable##_SkEffectType; \ | |
44 } | |
45 | |
46 enum SkEffectType { | |
sugoi1
2013/10/16 15:05:32
I need this here for NameToType(), and so that all
| |
47 kInvalid_SkEffectType, | |
reed1
2013/10/16 15:20:20
Hmmm, that might be the right way. I think sometim
sugoi1
2013/10/16 15:36:26
Done.
| |
48 kColorFilter_SkEffectType, | |
49 kDrawLooper_SkEffectType, | |
50 kImageFilter_SkEffectType, | |
51 kMaskFilter_SkEffectType, | |
52 kPathEffect_SkEffectType, | |
53 kPixelRef_SkEffectType, | |
54 kRasterizer_SkEffectType, | |
55 kShader_SkEffectType, | |
56 kUnitMapper_SkEffectType, | |
57 kXfermode_SkEffectType, | |
58 }; | |
59 | |
38 /** \class SkFlattenable | 60 /** \class SkFlattenable |
39 | 61 |
40 SkFlattenable is the base class for objects that need to be flattened | 62 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 | 63 into a data stream for either transport or as part of the key to the |
42 font cache. | 64 font cache. |
43 */ | 65 */ |
44 class SK_API SkFlattenable : public SkRefCnt { | 66 class SK_API SkFlattenable : public SkRefCnt { |
45 public: | 67 public: |
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() = 0; | 78 virtual Factory getFactory() = 0; |
57 | 79 |
80 /** Returns the name of the object's class | |
81 */ | |
82 const char* getTypeName() { 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 SkEffectType NameToType(const char name[]); |
87 | |
88 static void Register(const char name[], Factory, SkEffectType); | |
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, SkEffectType 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 |