Chromium Code Reviews| Index: include/core/SkFlattenable.h |
| diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h |
| index 58e69fd416cb049b56d881942f6f77ebb676e93d..ca05adf96675356feb1675d8633a4f72c6bfc2cf 100644 |
| --- a/include/core/SkFlattenable.h |
| +++ b/include/core/SkFlattenable.h |
| @@ -16,7 +16,7 @@ class SkFlattenableReadBuffer; |
| class SkFlattenableWriteBuffer; |
| #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ |
| - SkFlattenable::Registrar(#flattenable, flattenable::CreateProc); |
| + SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, flattenable::GetType()); |
| #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables(); |
| @@ -35,6 +35,14 @@ class SkFlattenableWriteBuffer; |
| return SkNEW_ARGS(flattenable, (buffer)); \ |
| } |
| +/** For SkFlattenable derived objects with a valid type |
| + This macro should only be used in base class objects in core |
| + */ |
| +#define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ |
| + 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.
|
| + return k##flattenable##_Type; \ |
| + } |
| + |
| /** \class SkFlattenable |
| SkFlattenable is the base class for objects that need to be flattened |
| @@ -43,6 +51,19 @@ class SkFlattenableWriteBuffer; |
| */ |
| class SK_API SkFlattenable : public SkRefCnt { |
| public: |
| + enum Type { |
| + kSkColorFilter_Type, |
| + kSkDrawLooper_Type, |
| + kSkImageFilter_Type, |
| + kSkMaskFilter_Type, |
| + kSkPathEffect_Type, |
| + kSkPixelRef_Type, |
| + kSkRasterizer_Type, |
| + kSkShader_Type, |
| + kSkUnitMapper_Type, |
| + kSkXfermode_Type, |
| + }; |
| + |
| SK_DECLARE_INST_COUNT(SkFlattenable) |
| typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); |
| @@ -55,14 +76,20 @@ public: |
| */ |
| virtual Factory getFactory() = 0; |
| + /** Returns the name of the object's class |
| + */ |
| + const char* getTypeName() { return FactoryToName(getFactory()); } |
| + |
| static Factory NameToFactory(const char name[]); |
| static const char* FactoryToName(Factory); |
| - static void Register(const char name[], Factory); |
| + static bool NameToType(const char name[], Type* type); |
| + |
| + static void Register(const char name[], Factory, Type); |
| class Registrar { |
| public: |
| - Registrar(const char name[], Factory factory) { |
| - SkFlattenable::Register(name, factory); |
| + Registrar(const char name[], Factory factory, Type type) { |
| + SkFlattenable::Register(name, factory, type); |
| } |
| }; |
| @@ -75,7 +102,7 @@ protected: |
| virtual void flatten(SkFlattenableWriteBuffer&) const; |
| private: |
| - static void InitializeFlattenables(); |
| + static void InitializeFlattenablesIfNeeded(); |
| friend class SkGraphics; |
| friend class SkFlattenableWriteBuffer; |