3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkFlattenable_DEFINED
11 #define SkFlattenable_DEFINED
18 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
19 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
20 flattenable::GetFlattenableType());
22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenables();
24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
25 void flattenable::InitializeFlattenables() {
27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \
31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \
35 static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \
36 return SkNEW_ARGS(flattenable, (buffer)); \
39 /** For SkFlattenable derived objects with a valid type
40 This macro should only be used in base class objects in core
42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \
43 static Type GetFlattenableType() { \
44 return k##flattenable##_Type; \
47 /** \class SkFlattenable
49 SkFlattenable is the base class for objects that need to be flattened
50 into a data stream for either transport or as part of the key to the
53 class SK_API SkFlattenable : public SkRefCnt {
68 SK_DECLARE_INST_COUNT(SkFlattenable)
70 typedef SkFlattenable* (*Factory)(SkReadBuffer&);
74 /** Implement this to return a factory function pointer that can be called
75 to recreate your class given a buffer (previously written to by your
76 override of flatten().
78 virtual Factory getFactory() const = 0;
80 /** Returns the name of the object's class
82 const char* getTypeName() const { return FactoryToName(getFactory()); }
84 static Factory NameToFactory(const char name[]);
85 static const char* FactoryToName(Factory);
86 static bool NameToType(const char name[], Type* type);
88 static void Register(const char name[], Factory, Type);
92 Registrar(const char name[], Factory factory, Type type) {
93 SkFlattenable::Register(name, factory, type);
97 /** Override this to write data specific to your subclass into the buffer,
98 being sure to call your super-class' version first. This data will later
99 be passed to your Factory function, returned by getFactory().
101 virtual void flatten(SkWriteBuffer&) const;
104 SkFlattenable(SkReadBuffer&) {}
107 static void InitializeFlattenablesIfNeeded();
109 friend class SkGraphics;
111 typedef SkRefCnt INHERITED;