Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: include/core/SkFlattenable.h

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Minor fixes Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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, \
20 flattenable::GetEffectType());
20 21
21 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les(); 22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les();
22 23
23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ 24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
24 void flattenable::InitializeFlattenables() { 25 void flattenable::InitializeFlattenables() {
25 26
26 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ 27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
27 } 28 }
28 29
29 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ 30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \
30 virtual Factory getFactory() SK_OVERRIDE { return NULL; } 31 virtual Factory getFactory() SK_OVERRIDE { return NULL; }
31 32
32 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ 33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
33 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \ 34 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \
34 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ 35 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \
35 return SkNEW_ARGS(flattenable, (buffer)); \ 36 return SkNEW_ARGS(flattenable, (buffer)); \
36 } 37 }
37 38
39 /** For SkFlattenable derived objects with a valid type
40 This macro should only be used in base class objects in core
41 */
42 #define SK_DEFINE_FLATTENABLE_EFFECT_TYPE(flattenable) \
43 static SkEffectType GetEffectType() { \
44 return k##flattenable##_SkEffectType; \
45 }
46
47 enum SkEffectType {
Stephen White 2013/10/16 20:27:24 Just to bikeshed a little, is SkEffectType a good
reed1 2013/10/16 20:38:16 Totally agree. I started that name, but it doesn't
48 kSkColorFilter_SkEffectType,
49 kSkDrawLooper_SkEffectType,
50 kSkImageFilter_SkEffectType,
51 kSkMaskFilter_SkEffectType,
52 kSkPathEffect_SkEffectType,
53 kSkPixelRef_SkEffectType,
54 kSkRasterizer_SkEffectType,
55 kSkShader_SkEffectType,
56 kSkUnitMapper_SkEffectType,
57 kSkXfermode_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 bool NameToType(const char name[], SkEffectType* type);
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698