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

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: Comments fixed 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, flattena ble::GetEffectType());
mtklein 2013/10/16 18:54:09 Sadly this has wrapped to 102 columns.
sugoi1 2013/10/16 20:07:41 Noooooo ! Fixed
20 20
21 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les(); 21 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les();
22 22
23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ 23 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
24 void flattenable::InitializeFlattenables() { 24 void flattenable::InitializeFlattenables() {
25 25
26 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ 26 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
27 } 27 }
28 28
29 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ 29 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \
30 virtual Factory getFactory() SK_OVERRIDE { return NULL; } 30 virtual Factory getFactory() SK_OVERRIDE { return NULL; }
31 31
32 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ 32 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
33 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \ 33 virtual Factory getFactory() SK_OVERRIDE { return CreateProc; } \
34 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ 34 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \
35 return SkNEW_ARGS(flattenable, (buffer)); \ 35 return SkNEW_ARGS(flattenable, (buffer)); \
36 } 36 }
37 37
38 /** For SkFlattenable derived objects with a valid type
39 This macro should only be used in base class objects in core
40 */
41 #define SK_DEFINE_FLATTENABLE_EFFECT_TYPE(flattenable) \
42 static SkEffectType GetEffectType() { \
43 return k##flattenable##_SkEffectType; \
44 }
45
46 enum SkEffectType {
47 kColorFilter_SkEffectType,
48 kDrawLooper_SkEffectType,
49 kImageFilter_SkEffectType,
50 kMaskFilter_SkEffectType,
51 kPathEffect_SkEffectType,
52 kPixelRef_SkEffectType,
53 kRasterizer_SkEffectType,
54 kShader_SkEffectType,
55 kUnitMapper_SkEffectType,
56 kXfermode_SkEffectType,
57 };
58
38 /** \class SkFlattenable 59 /** \class SkFlattenable
39 60
40 SkFlattenable is the base class for objects that need to be flattened 61 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 62 into a data stream for either transport or as part of the key to the
42 font cache. 63 font cache.
43 */ 64 */
44 class SK_API SkFlattenable : public SkRefCnt { 65 class SK_API SkFlattenable : public SkRefCnt {
45 public: 66 public:
46 SK_DECLARE_INST_COUNT(SkFlattenable) 67 SK_DECLARE_INST_COUNT(SkFlattenable)
47 68
48 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); 69 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&);
49 70
50 SkFlattenable() {} 71 SkFlattenable() {}
51 72
52 /** Implement this to return a factory function pointer that can be called 73 /** 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 74 to recreate your class given a buffer (previously written to by your
54 override of flatten(). 75 override of flatten().
55 */ 76 */
56 virtual Factory getFactory() = 0; 77 virtual Factory getFactory() = 0;
57 78
79 /** Returns the name of the object's class
80 */
81 const char* getTypeName() { return FactoryToName(getFactory()); }
82
58 static Factory NameToFactory(const char name[]); 83 static Factory NameToFactory(const char name[]);
59 static const char* FactoryToName(Factory); 84 static const char* FactoryToName(Factory);
60 static void Register(const char name[], Factory); 85 static bool NameToType(const char name[], SkEffectType& type);
86
87 static void Register(const char name[], Factory, SkEffectType);
61 88
62 class Registrar { 89 class Registrar {
63 public: 90 public:
64 Registrar(const char name[], Factory factory) { 91 Registrar(const char name[], Factory factory, SkEffectType type) {
65 SkFlattenable::Register(name, factory); 92 SkFlattenable::Register(name, factory, type);
66 } 93 }
67 }; 94 };
68 95
69 protected: 96 protected:
70 SkFlattenable(SkFlattenableReadBuffer&) {} 97 SkFlattenable(SkFlattenableReadBuffer&) {}
71 /** Override this to write data specific to your subclass into the buffer, 98 /** 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 99 being sure to call your super-class' version first. This data will later
73 be passed to your Factory function, returned by getFactory(). 100 be passed to your Factory function, returned by getFactory().
74 */ 101 */
75 virtual void flatten(SkFlattenableWriteBuffer&) const; 102 virtual void flatten(SkFlattenableWriteBuffer&) const;
76 103
77 private: 104 private:
78 static void InitializeFlattenables(); 105 static void InitializeFlattenablesIfNeeded();
79 106
80 friend class SkGraphics; 107 friend class SkGraphics;
81 friend class SkFlattenableWriteBuffer; 108 friend class SkFlattenableWriteBuffer;
82 109
83 typedef SkRefCnt INHERITED; 110 typedef SkRefCnt INHERITED;
84 }; 111 };
85 112
86 #endif 113 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698