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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&); | 85 typedef sk_sp<SkFlattenable> (*Factory)(SkReadBuffer&); |
86 | 86 |
87 SkFlattenable() {} | 87 SkFlattenable() {} |
88 | 88 |
89 /** Implement this to return a factory function pointer that can be called | 89 /** 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 | 90 to recreate your class given a buffer (previously written to by your |
91 override of flatten(). | 91 override of flatten(). |
92 */ | 92 */ |
93 virtual Factory getFactory() const = 0; | 93 virtual Factory getFactory() const = 0; |
94 | 94 |
95 /** Returns the name of the object's class | 95 /** |
96 */ | 96 * Returns the name of the object's class. |
97 const char* getTypeName() const { return FactoryToName(getFactory()); } | 97 * |
| 98 * Subclasses should override this function if they intend to provide |
| 99 * support for flattening without using the global registry. |
| 100 * |
| 101 * If the flattenable is registered, there is no need to override. |
| 102 */ |
| 103 virtual const char* getTypeName() const { return FactoryToName(getFactory())
; } |
98 | 104 |
99 static Factory NameToFactory(const char name[]); | 105 static Factory NameToFactory(const char name[]); |
100 static const char* FactoryToName(Factory); | 106 static const char* FactoryToName(Factory); |
101 static bool NameToType(const char name[], Type* type); | 107 static bool NameToType(const char name[], Type* type); |
102 | 108 |
103 static void Register(const char name[], Factory, Type); | 109 static void Register(const char name[], Factory, Type); |
104 | 110 |
105 /** | 111 /** |
106 * Override this if your subclass needs to record data that it will need to
recreate itself | 112 * Override this if your subclass needs to record data that it will need to
recreate itself |
107 * from its CreateProc (returned by getFactory()). | 113 * from its CreateProc (returned by getFactory()). |
108 */ | 114 */ |
109 virtual void flatten(SkWriteBuffer&) const {} | 115 virtual void flatten(SkWriteBuffer&) const {} |
110 | 116 |
111 protected: | 117 protected: |
112 class PrivateInitializer { | 118 class PrivateInitializer { |
113 public: | 119 public: |
114 static void InitCore(); | 120 static void InitCore(); |
115 static void InitEffects(); | 121 static void InitEffects(); |
116 }; | 122 }; |
117 | 123 |
118 private: | 124 private: |
119 static void InitializeFlattenablesIfNeeded(); | 125 static void InitializeFlattenablesIfNeeded(); |
120 | 126 |
121 friend class SkGraphics; | 127 friend class SkGraphics; |
122 | 128 |
123 typedef SkRefCnt INHERITED; | 129 typedef SkRefCnt INHERITED; |
124 }; | 130 }; |
125 | 131 |
126 #endif | 132 #endif |
OLD | NEW |