OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
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 #ifndef SkFlattenableBuffers_DEFINED | 9 #ifndef SkFlattenableBuffers_DEFINED |
10 #define SkFlattenableBuffers_DEFINED | 10 #define SkFlattenableBuffers_DEFINED |
11 | 11 |
12 #include "SkColor.h" | 12 #include "SkColor.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkPaint.h" | 14 #include "SkPaint.h" |
15 #include "SkPoint.h" | 15 #include "SkPoint.h" |
16 | 16 |
17 class SkBitmap; | 17 class SkBitmap; |
18 class SkDrawLooper; | 18 class SkDrawLooper; |
19 class SkFlattenable; | 19 class SkFlattenable; |
20 struct SkIRect; | 20 struct SkIRect; |
21 class SkMatrix; | 21 class SkMatrix; |
22 class SkOrderedReadBuffer; | 22 class SkOrderedReadBuffer; |
23 class SkOrderedWriteBuffer; | 23 class SkOrderedWriteBuffer; |
24 class SkPath; | 24 class SkPath; |
25 class SkPixelRef; | 25 class SkPixelRef; |
26 struct SkRect; | 26 struct SkRect; |
27 class SkRefCnt; | |
28 class SkRegion; | 27 class SkRegion; |
29 class SkStream; | 28 class SkStream; |
30 class SkString; | 29 class SkString; |
31 class SkTypeface; | 30 class SkTypeface; |
32 class SkUnitMapper; | 31 class SkUnitMapper; |
33 class SkWStream; | 32 class SkWStream; |
34 | 33 |
35 enum SkEffectType { | |
36 kColorFilter_SkEffectType, | |
37 kDrawLooper_SkEffectType, | |
38 kImageFilter_SkEffectType, | |
39 kMaskFilter_SkEffectType, | |
40 kPathEffect_SkEffectType, | |
41 kPixelRef_SkEffectType, | |
42 kRasterizer_SkEffectType, | |
43 kShader_SkEffectType, | |
44 kUnitMapper_SkEffectType, | |
45 kXfermode_SkEffectType, | |
46 }; | |
47 | |
48 class SkFlattenableReadBuffer { | 34 class SkFlattenableReadBuffer { |
49 public: | 35 public: |
50 SkFlattenableReadBuffer(); | 36 SkFlattenableReadBuffer(); |
51 virtual ~SkFlattenableReadBuffer(); | 37 virtual ~SkFlattenableReadBuffer(); |
52 | 38 |
53 bool isOrderedBinaryBuffer() { return NULL != getOrderedBinaryBuffer(); } | 39 bool isOrderedBinaryBuffer() { return NULL != getOrderedBinaryBuffer(); } |
54 virtual SkOrderedReadBuffer* getOrderedBinaryBuffer() { return NULL; } | 40 virtual SkOrderedReadBuffer* getOrderedBinaryBuffer() { return NULL; } |
55 | 41 |
56 enum Flags { | 42 enum Flags { |
57 kCrossProcess_Flag = 1 << 0, | 43 kCrossProcess_Flag = 1 << 0, |
58 kScalarIsFloat_Flag = 1 << 1, | 44 kScalarIsFloat_Flag = 1 << 1, |
59 kPtrIs64Bit_Flag = 1 << 2, | 45 kPtrIs64Bit_Flag = 1 << 2, |
46 /** The kValidation_Flag is used to force stream validations (by making | |
47 * sure that no operation reads past the end of the stream, for example) | |
48 * and error handling if any reading operation yields an invalid value. | |
49 */ | |
50 kValidation_Flag = 1 << 3, | |
60 }; | 51 }; |
61 | 52 |
62 void setFlags(uint32_t flags) { fFlags = flags; } | 53 void setFlags(uint32_t flags) { fFlags = flags; } |
63 uint32_t getFlags() const { return fFlags; } | 54 uint32_t getFlags() const { return fFlags; } |
64 | 55 |
65 bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); } | 56 bool isCrossProcess() const { return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); } |
66 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); } | 57 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); } |
67 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } | 58 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } |
59 bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); } | |
68 | 60 |
69 // primitives | 61 // primitives |
70 virtual bool readBool() = 0; | 62 virtual bool readBool() = 0; |
71 virtual SkColor readColor() = 0; | 63 virtual SkColor readColor() = 0; |
72 virtual SkFixed readFixed() = 0; | 64 virtual SkFixed readFixed() = 0; |
73 virtual int32_t readInt() = 0; | 65 virtual int32_t readInt() = 0; |
74 virtual SkScalar readScalar() = 0; | 66 virtual SkScalar readScalar() = 0; |
75 virtual uint32_t readUInt() = 0; | 67 virtual uint32_t readUInt() = 0; |
76 virtual int32_t read32() = 0; | 68 virtual int32_t read32() = 0; |
77 | 69 |
78 // strings -- the caller is responsible for freeing the string contents | 70 // strings -- the caller is responsible for freeing the string contents |
79 virtual void readString(SkString* string) = 0; | 71 virtual void readString(SkString* string) = 0; |
80 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng) = 0; | 72 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng) = 0; |
81 | 73 |
82 virtual SkFlattenable* readFlattenable(SkEffectType) = 0; | 74 /** |
75 @param type This parameter is only used when using SkValidatingReadBuffe r. It will verify | |
76 that the object about to be deserialized is of the given typ e or early return | |
77 NULL otherwise. The type provided here is the type of the ba se class of the | |
78 object to deserialize. | |
79 */ | |
80 virtual SkFlattenable* readFlattenable(SkFlattenable::Type type) = 0; | |
83 | 81 |
84 SkColorFilter* readColorFilter() { | 82 SkColorFilter* readColorFilter(); |
85 return (SkColorFilter*)this->readFlattenable(kColorFilter_SkEffectType); | 83 SkDrawLooper* readDrawLooper(); |
86 } | 84 SkImageFilter* readImageFilter(); |
87 SkDrawLooper* readDrawLooper() { | 85 SkMaskFilter* readMaskFilter(); |
88 return (SkDrawLooper*)this->readFlattenable(kDrawLooper_SkEffectType); | 86 SkPathEffect* readPathEffect(); |
89 } | 87 SkPixelRef* readPixelRef(); |
90 SkImageFilter* readImageFilter() { | 88 SkRasterizer* readRasterizer(); |
91 return (SkImageFilter*)this->readFlattenable(kImageFilter_SkEffectType); | 89 SkShader* readShader(); |
92 } | 90 SkUnitMapper* readUnitMapper(); |
93 SkMaskFilter* readMaskFilter() { | 91 SkXfermode* readXfermode(); |
94 return (SkMaskFilter*)this->readFlattenable(kMaskFilter_SkEffectType); | |
95 } | |
96 SkPathEffect* readPathEffect() { | |
97 return (SkPathEffect*)this->readFlattenable(kPathEffect_SkEffectType); | |
98 } | |
99 SkPixelRef* readPixelRef() { | |
100 return (SkPixelRef*)this->readFlattenable(kPixelRef_SkEffectType); | |
101 } | |
102 SkRasterizer* readRasterizer() { | |
103 return (SkRasterizer*)this->readFlattenable(kRasterizer_SkEffectType); | |
104 } | |
105 SkShader* readShader() { | |
106 return (SkShader*)this->readFlattenable(kShader_SkEffectType); | |
107 } | |
108 SkUnitMapper* readUnitMapper() { | |
109 return (SkUnitMapper*)this->readFlattenable(kUnitMapper_SkEffectType); | |
110 } | |
111 SkXfermode* readXfermode() { | |
112 return (SkXfermode*)this->readFlattenable(kXfermode_SkEffectType); | |
113 } | |
114 | 92 |
115 // common data structures | 93 // common data structures |
116 virtual void readPoint(SkPoint* point) = 0; | 94 virtual void readPoint(SkPoint* point) = 0; |
117 virtual void readMatrix(SkMatrix* matrix) = 0; | 95 virtual void readMatrix(SkMatrix* matrix) = 0; |
118 virtual void readIRect(SkIRect* rect) = 0; | 96 virtual void readIRect(SkIRect* rect) = 0; |
119 virtual void readRect(SkRect* rect) = 0; | 97 virtual void readRect(SkRect* rect) = 0; |
120 virtual void readRegion(SkRegion* region) = 0; | 98 virtual void readRegion(SkRegion* region) = 0; |
121 virtual void readPath(SkPath* path) = 0; | 99 virtual void readPath(SkPath* path) = 0; |
122 | 100 |
123 // binary data and arrays | 101 // binary data and arrays |
(...skipping 22 matching lines...) Expand all Loading... | |
146 return point; | 124 return point; |
147 } | 125 } |
148 | 126 |
149 SkData* readByteArrayAsData() { | 127 SkData* readByteArrayAsData() { |
150 size_t len = this->getArrayCount(); | 128 size_t len = this->getArrayCount(); |
151 void* buffer = sk_malloc_throw(len); | 129 void* buffer = sk_malloc_throw(len); |
152 (void)this->readByteArray(buffer); | 130 (void)this->readByteArray(buffer); |
153 return SkData::NewFromMalloc(buffer, len); | 131 return SkData::NewFromMalloc(buffer, len); |
154 } | 132 } |
155 | 133 |
134 virtual void validate(bool isValid) {} | |
135 | |
156 private: | 136 private: |
137 template <typename T> T* readFlattenableT(); | |
reed1
2013/10/21 20:54:48
don't really care, but why is this guy private?
sugoi1
2013/10/22 12:12:54
We don't need it in any place except within the re
| |
157 uint32_t fFlags; | 138 uint32_t fFlags; |
158 }; | 139 }; |
159 | 140 |
160 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
161 | 142 |
162 class SkFlattenableWriteBuffer { | 143 class SkFlattenableWriteBuffer { |
163 public: | 144 public: |
164 SkFlattenableWriteBuffer(); | 145 SkFlattenableWriteBuffer(); |
165 virtual ~SkFlattenableWriteBuffer(); | 146 virtual ~SkFlattenableWriteBuffer(); |
166 | 147 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 virtual void writeFunctionPtr(void* ptr); | 179 virtual void writeFunctionPtr(void* ptr); |
199 virtual void writePaint(const SkPaint& paint); | 180 virtual void writePaint(const SkPaint& paint); |
200 | 181 |
201 virtual void writeBitmap(const SkBitmap& bitmap) = 0; | 182 virtual void writeBitmap(const SkBitmap& bitmap) = 0; |
202 virtual void writeTypeface(SkTypeface* typeface) = 0; | 183 virtual void writeTypeface(SkTypeface* typeface) = 0; |
203 | 184 |
204 virtual bool writeToStream(SkWStream*) = 0; | 185 virtual bool writeToStream(SkWStream*) = 0; |
205 | 186 |
206 enum Flags { | 187 enum Flags { |
207 kCrossProcess_Flag = 0x01, | 188 kCrossProcess_Flag = 0x01, |
189 /** The kValidation_Flag is used here to make sure the write operation | |
190 * is symmetric with the read operation using the equivalent flag | |
191 * SkFlattenableReadBuffer::kValidation_Flag. | |
192 */ | |
193 kValidation_Flag = 0x02, | |
208 }; | 194 }; |
209 | 195 |
210 uint32_t getFlags() const { return fFlags; } | 196 uint32_t getFlags() const { return fFlags; } |
211 void setFlags(uint32_t flags) { fFlags = flags; } | 197 void setFlags(uint32_t flags) { fFlags = flags; } |
212 | 198 |
213 bool isCrossProcess() const { | 199 bool isCrossProcess() const { |
214 return SkToBool(fFlags & kCrossProcess_Flag); | 200 return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); |
201 } | |
202 | |
203 bool isValidating() const { | |
204 return SkToBool(fFlags & kValidation_Flag); | |
215 } | 205 } |
216 | 206 |
217 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } | 207 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } |
218 | 208 |
219 void writeDataAsByteArray(SkData* data) { | 209 void writeDataAsByteArray(SkData* data) { |
220 this->writeByteArray(data->data(), data->size()); | 210 this->writeByteArray(data->data(), data->size()); |
221 } | 211 } |
222 | 212 |
223 protected: | 213 protected: |
224 // A helper function so that each subclass does not have to be a friend of S kFlattenable | 214 // A helper function so that each subclass does not have to be a friend of S kFlattenable |
225 void flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffe r); | 215 void flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffe r); |
226 | 216 |
227 uint32_t fFlags; | 217 uint32_t fFlags; |
228 }; | 218 }; |
229 | 219 |
230 #endif | 220 #endif |
OLD | NEW |