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

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

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 4 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
« no previous file with comments | « include/core/SkDrawLooper.h ('k') | include/core/SkImageFilter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
2 /* 1 /*
3 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9
10 #ifndef SkFlattenable_DEFINED 8 #ifndef SkFlattenable_DEFINED
11 #define SkFlattenable_DEFINED 9 #define SkFlattenable_DEFINED
12 10
13 #include "SkRefCnt.h" 11 #include "SkRefCnt.h"
14 12
15 class SkReadBuffer; 13 class SkReadBuffer;
16 class SkWriteBuffer; 14 class SkWriteBuffer;
17 15
18 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \ 16 #define SK_SUPPORT_LEGACY_DEEPFLATTENING
19 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \ 17
20 flattenable::GetFlattenableType()); 18 /*
19 * Flattening is straight-forward:
20 * 1. call getFactory() so we have a function-ptr to recreate the subclass
21 * 2. call flatten(buffer) to write out enough data for the factory to read
22 *
23 * Unflattening is easy for the caller: new_instance = factory(buffer)
24 *
25 * The complexity of supporting this is as follows.
26 *
27 * If your subclass wants to control unflattening, use this macro in your decla ration:
28 * SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS
29 * This will provide a getFactory(), and require that the subclass implements C reateProc.
30 *
31 * For older buffers (before the DEEPFLATTENING change, the macros below declar e
32 * a thin factory DeepCreateProc. It checks the version of the buffer, and if i t is pre-deep,
33 * then it calls through to a (usually protected) constructor, passing the buff er.
34 * If the buffer is newer, then it directly calls the "real" factory: CreatePro c.
35 */
21 36
22 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les(); 37 #define SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() static void InitializeFlattenab les();
23 38
24 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \ 39 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
25 void flattenable::InitializeFlattenables() { 40 void flattenable::InitializeFlattenables() {
26 41
27 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \ 42 #define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
28 } 43 }
29 44
30 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \ 45 #define SK_DECLARE_UNFLATTENABLE_OBJECT() \
31 virtual Factory getFactory() const SK_OVERRIDE { return NULL; } 46 virtual Factory getFactory() const SK_OVERRIDE { return NULL; }
32 47
33 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \ 48 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ 49 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
35 static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \ 50 SkFlattenable::Registrar(#flattenable, flattenable::DeepCreateProc, \
36 return SkNEW_ARGS(flattenable, (buffer)); \ 51 flattenable::GetFlattenableType());
37 } 52
53 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
54 private: \
55 static SkFlattenable* CreateProc(SkReadBuffer&); \
56 static SkFlattenable* DeepCreateProc(SkReadBuffer& buffer) { \
57 if (NeedsDeepUnflatten(buffer)) { \
58 return SkNEW_ARGS(flattenable, (buffer)); \
59 } \
60 return CreateProc(buffer); \
61 } \
62 friend class SkPrivateEffectInitializer; \
63 public: \
64 virtual Factory getFactory() const SK_OVERRIDE {return DeepCreateProc;}
65 #else
66 #define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
67 SkFlattenable::Registrar(#flattenable, flattenable::CreateProc, \
68 flattenable::GetFlattenableType());
69
70 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
71 private: \
72 static SkFlattenable* CreateProc(SkReadBuffer&); \
73 friend class SkPrivateEffectInitializer; \
74 public: \
75 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; }
76 #endif
77
78 // If your subclass will *never* need to be unflattened, declare this.
79 #define SK_DECLARE_NOT_FLATTENABLE_PROCS(flattenable) \
80 virtual Factory getFactory() const SK_OVERRIDE { return ReturnNullCreateProc ; }
38 81
39 /** For SkFlattenable derived objects with a valid type 82 /** For SkFlattenable derived objects with a valid type
40 This macro should only be used in base class objects in core 83 This macro should only be used in base class objects in core
41 */ 84 */
42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ 85 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \
43 static Type GetFlattenableType() { \ 86 static Type GetFlattenableType() { \
44 return k##flattenable##_Type; \ 87 return k##flattenable##_Type; \
45 } 88 }
46 89
47 /** \class SkFlattenable 90 /** \class SkFlattenable
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 130
88 static void Register(const char name[], Factory, Type); 131 static void Register(const char name[], Factory, Type);
89 132
90 class Registrar { 133 class Registrar {
91 public: 134 public:
92 Registrar(const char name[], Factory factory, Type type) { 135 Registrar(const char name[], Factory factory, Type type) {
93 SkFlattenable::Register(name, factory, type); 136 SkFlattenable::Register(name, factory, type);
94 } 137 }
95 }; 138 };
96 139
97 /** Override this to write data specific to your subclass into the buffer, 140 /**
98 being sure to call your super-class' version first. This data will later 141 * Override this if your subclass needs to record data that it will need to recreate itself
99 be passed to your Factory function, returned by getFactory(). 142 * from its CreateProc (returned by getFactory()).
100 */ 143 */
101 virtual void flatten(SkWriteBuffer&) const; 144 virtual void flatten(SkWriteBuffer&) const {}
102 145
103 protected: 146 protected:
147 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
148 static bool NeedsDeepUnflatten(const SkReadBuffer&);
104 SkFlattenable(SkReadBuffer&) {} 149 SkFlattenable(SkReadBuffer&) {}
150 #endif
151
152 static SkFlattenable* ReturnNullCreateProc(SkReadBuffer&) {
153 return NULL;
154 }
105 155
106 private: 156 private:
107 static void InitializeFlattenablesIfNeeded(); 157 static void InitializeFlattenablesIfNeeded();
108 158
109 friend class SkGraphics; 159 friend class SkGraphics;
110 160
111 typedef SkRefCnt INHERITED; 161 typedef SkRefCnt INHERITED;
112 }; 162 };
113 163
114 #endif 164 #endif
OLDNEW
« no previous file with comments | « include/core/SkDrawLooper.h ('k') | include/core/SkImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698