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

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: Created 6 years, 5 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
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
13 //#define SK_SUPPORT_LEGACY_DEEPFLATTENING
14
15 class SkReadBuffer; 15 class SkReadBuffer;
16 class SkWriteBuffer; 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 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
34 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } \ 34 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
35 static SkFlattenable* CreateProc(SkReadBuffer& buffer) { \ 35 static SkFlattenable* CreateProc(SkReadBuffer&); \
36 return SkNEW_ARGS(flattenable, (buffer)); \ 36 virtual Factory getFactory() const SK_OVERRIDE {return DeepCreateProc;} \
37 static SkFlattenable* DeepCreateProc(SkReadBuffer& buffer) { \
38 if (NeedsDeepUnflatten(buffer)) { \
39 return SkNEW_ARGS(flattenable, (buffer)); \
40 } \
41 return CreateProc(buffer); \
37 } 42 }
43 #else
44 #define SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(flattenable) \
45 static SkFlattenable* CreateProc(SkReadBuffer&); \
46 virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; }
47 #endif
38 48
39 /** For SkFlattenable derived objects with a valid type 49 /** For SkFlattenable derived objects with a valid type
40 This macro should only be used in base class objects in core 50 This macro should only be used in base class objects in core
41 */ 51 */
42 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \ 52 #define SK_DEFINE_FLATTENABLE_TYPE(flattenable) \
43 static Type GetFlattenableType() { \ 53 static Type GetFlattenableType() { \
44 return k##flattenable##_Type; \ 54 return k##flattenable##_Type; \
45 } 55 }
46 56
47 /** \class SkFlattenable 57 /** \class SkFlattenable
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 104 }
95 }; 105 };
96 106
97 /** Override this to write data specific to your subclass into the buffer, 107 /** 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 108 being sure to call your super-class' version first. This data will later
99 be passed to your Factory function, returned by getFactory(). 109 be passed to your Factory function, returned by getFactory().
100 */ 110 */
101 virtual void flatten(SkWriteBuffer&) const; 111 virtual void flatten(SkWriteBuffer&) const;
102 112
103 protected: 113 protected:
114 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
115 enum {
116 kNewFlattenVersion = 27
117 };
118 static bool NeedsDeepUnflatten(const SkReadBuffer&);
104 SkFlattenable(SkReadBuffer&) {} 119 SkFlattenable(SkReadBuffer&) {}
120 #endif
105 121
106 private: 122 private:
107 static void InitializeFlattenablesIfNeeded(); 123 static void InitializeFlattenablesIfNeeded();
108 124
109 friend class SkGraphics; 125 friend class SkGraphics;
110 126
111 typedef SkRefCnt INHERITED; 127 typedef SkRefCnt INHERITED;
112 }; 128 };
113 129
114 #endif 130 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698