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

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

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: original write flags were fine Created 6 years, 10 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
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 SkReadBuffer;
16 class SkFlattenableWriteBuffer; 16 class SkWriteBuffer;
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::GetFlattenableType()); 20 flattenable::GetFlattenableType());
21 21
22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les(); 22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les();
23 23
24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ 24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
25 void flattenable::InitializeFlattenables() { 25 void flattenable::InitializeFlattenables() {
26 26
27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ 27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
28 } 28 }
29 29
30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ 30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \
31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } 31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
32 32
33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ 33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ 34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \
35 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { \ 35 static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \
36 return SkNEW_ARGS(flattenable, (buffer)); \ 36 return SkNEW_ARGS(flattenable, (buffer)); \
37 } 37 }
38 38
39 /** For SkFlattenable derived objects with a valid type 39 /** For SkFlattenable derived objects with a valid type
40 This macro should only be used in base class objects in core 40 This macro should only be used in base class objects in core
41 */ 41 */
42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ 42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \
43 static Type GetFlattenableType() { \ 43 static Type GetFlattenableType() { \
44 return k##flattenable##_Type; \ 44 return k##flattenable##_Type; \
45 } 45 }
(...skipping 14 matching lines...) Expand all
60 kSkPathEffect_Type, 60 kSkPathEffect_Type,
61 kSkPixelRef_Type, 61 kSkPixelRef_Type,
62 kSkRasterizer_Type, 62 kSkRasterizer_Type,
63 kSkShader_Type, 63 kSkShader_Type,
64 kSkUnitMapper_Type, 64 kSkUnitMapper_Type,
65 kSkXfermode_Type, 65 kSkXfermode_Type,
66 }; 66 };
67 67
68 SK_DECLARE_INST_COUNT(SkFlattenable) 68 SK_DECLARE_INST_COUNT(SkFlattenable)
69 69
70 typedef SkFlattenable* (*Factory)(SkFlattenableReadBuffer&); 70 typedef SkFlattenable* (*Factory)(SkReadBuffer&);
71 71
72 SkFlattenable() {} 72 SkFlattenable() {}
73 73
74 /** 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
75 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
76 override of flatten(). 76 override of flatten().
77 */ 77 */
78 virtual Factory getFactory() const = 0; 78 virtual Factory getFactory() const = 0;
79 79
80 /** Returns the name of the object's class 80 /** Returns the name of the object's class
81 */ 81 */
82 const char* getTypeName() const { return FactoryToName(getFactory()); } 82 const char* getTypeName() const { return FactoryToName(getFactory()); }
83 83
84 static Factory NameToFactory(const char name[]); 84 static Factory NameToFactory(const char name[]);
85 static const char* FactoryToName(Factory); 85 static const char* FactoryToName(Factory);
86 static bool NameToType(const char name[], Type* type); 86 static bool NameToType(const char name[], Type* type);
87 87
88 static void Register(const char name[], Factory, Type); 88 static void Register(const char name[], Factory, Type);
89 89
90 class Registrar { 90 class Registrar {
91 public: 91 public:
92 Registrar(const char name[], Factory factory, Type type) { 92 Registrar(const char name[], Factory factory, Type type) {
93 SkFlattenable::Register(name, factory, type); 93 SkFlattenable::Register(name, factory, type);
94 } 94 }
95 }; 95 };
96 96
97 protected:
98 SkFlattenable(SkFlattenableReadBuffer&) {}
99 /** Override this to write data specific to your subclass into the buffer, 97 /** Override this to write data specific to your subclass into the buffer,
100 being sure to call your super-class' version first. This data will later 98 being sure to call your super-class' version first. This data will later
101 be passed to your Factory function, returned by getFactory(). 99 be passed to your Factory function, returned by getFactory().
102 */ 100 */
103 virtual void flatten(SkFlattenableWriteBuffer&) const; 101 virtual void flatten(SkWriteBuffer&) const;
102
103 protected:
104 SkFlattenable(SkReadBuffer&) {}
104 105
105 private: 106 private:
106 static void InitializeFlattenablesIfNeeded(); 107 static void InitializeFlattenablesIfNeeded();
107 108
108 friend class SkGraphics; 109 friend class SkGraphics;
109 friend class SkFlattenableWriteBuffer;
110 110
111 typedef SkRefCnt INHERITED; 111 typedef SkRefCnt INHERITED;
112 }; 112 };
113 113
114 #endif 114 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698