OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkFlattenable_DEFINED | 8 #ifndef SkFlattenable_DEFINED |
9 #define SkFlattenable_DEFINED | 9 #define SkFlattenable_DEFINED |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab
les(); | 37 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab
les(); |
38 | 38 |
39 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ | 39 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ |
40 void flattenable::InitializeFlattenables() { | 40 void flattenable::InitializeFlattenables() { |
41 | 41 |
42 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ | 42 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ |
43 } | 43 } |
44 | 44 |
45 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ | 45 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
46 SkFlattenable::Register(#flattenable, flattenable::CreateProc, \ | 46 SkFlattenable::Register(#flattenable, flattenable::CreateProc); |
47 flattenable::GetFlattenableType()); | |
48 | 47 |
49 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ | 48 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ |
50 private: \ | 49 private: \ |
51 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
\ | 50 static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&);
\ |
52 friend class SkFlattenable::PrivateInitializer; \ | 51 friend class SkFlattenable::PrivateInitializer; \ |
53 public: \ | 52 public: \ |
54 Factory getFactory() const override { return CreateProc; } | 53 Factory getFactory() const override { return CreateProc; } |
55 | 54 |
56 /** For SkFlattenable derived objects with a valid type | |
57 This macro should only be used in base class objects in core | |
58 */ | |
59 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ | |
60 static Type GetFlattenableType() { \ | |
61 return k##flattenable##_Type; \ | |
62 } | |
63 | |
64 /** \class SkFlattenable | 55 /** \class SkFlattenable |
65 | 56 |
66 SkFlattenable is the base class for objects that need to be flattened | 57 SkFlattenable is the base class for objects that need to be flattened |
67 into a data stream for either transport or as part of the key to the | 58 into a data stream for either transport or as part of the key to the |
68 font cache. | 59 font cache. |
69 */ | 60 */ |
70 class SK_API SkFlattenable : public SkRefCnt { | 61 class SK_API SkFlattenable : public SkRefCnt { |
71 public: | 62 public: |
72 enum Type { | |
73 kSkColorFilter_Type, | |
74 kSkDrawLooper_Type, | |
75 kSkImageFilter_Type, | |
76 kSkMaskFilter_Type, | |
77 kSkPathEffect_Type, | |
78 kSkPixelRef_Type, | |
79 kSkRasterizer_Type, | |
80 kSkShader_Type, | |
81 kSkUnused_Type, // used to be SkUnitMapper | |
82 kSkXfermode_Type, | |
83 }; | |
84 | |
85 typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&); | 63 typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&); |
86 | 64 |
87 SkFlattenable() {} | 65 SkFlattenable() {} |
88 | 66 |
89 /** Implement this to return a factory function pointer that can be called | 67 /** Implement this to return a factory function pointer that can be called |
90 to recreate your class given a buffer (previously written to by your | 68 to recreate your class given a buffer (previously written to by your |
91 override of flatten(). | 69 override of flatten(). |
92 */ | 70 */ |
93 virtual Factory getFactory() const = 0; | 71 virtual Factory getFactory() const = 0; |
94 | 72 |
95 /** Returns the name of the object's class | 73 /** Returns the name of the object's class |
96 */ | 74 */ |
97 const char* getTypeName() const { return FactoryToName(getFactory()); } | 75 const char* getTypeName() const { return FactoryToName(getFactory()); } |
98 | 76 |
99 static Factory NameToFactory(const char name[]); | 77 static Factory NameToFactory(const char name[]); |
100 static const char* FactoryToName(Factory); | 78 static const char* FactoryToName(Factory); |
101 static bool NameToType(const char name[], Type* type); | |
102 | 79 |
103 static void Register(const char name[], Factory, Type); | 80 static void Register(const char name[], Factory); |
104 | 81 |
105 /** | 82 /** |
106 * Override this if your subclass needs to record data that it will need to
recreate itself | 83 * Override this if your subclass needs to record data that it will need to
recreate itself |
107 * from its CreateProc (returned by getFactory()). | 84 * from its CreateProc (returned by getFactory()). |
108 */ | 85 */ |
109 virtual void flatten(SkWriteBuffer&) const {} | 86 virtual void flatten(SkWriteBuffer&) const {} |
110 | 87 |
111 protected: | 88 protected: |
112 class PrivateInitializer { | 89 class PrivateInitializer { |
113 public: | 90 public: |
114 static void InitCore(); | 91 static void InitCore(); |
115 static void InitEffects(); | 92 static void InitEffects(); |
116 }; | 93 }; |
117 | 94 |
118 private: | 95 private: |
119 static void InitializeFlattenablesIfNeeded(); | 96 static void InitializeFlattenablesIfNeeded(); |
120 | 97 |
121 friend class SkGraphics; | 98 friend class SkGraphics; |
122 | 99 |
123 typedef SkRefCnt INHERITED; | 100 typedef SkRefCnt INHERITED; |
124 }; | 101 }; |
125 | 102 |
126 #endif | 103 #endif |
OLD | NEW |