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

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

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Integrating readFoo changes 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 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 {
sugoi1 2013/10/16 15:05:32 Moved to SkFlattenable.h
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 SkColorFilter* readColorFilter();
sugoi1 2013/10/16 15:05:32 I'm still going to argue that have a duplicate int
83 75 SkDrawLooper* readDrawLooper();
84 SkColorFilter* readColorFilter() { 76 SkImageFilter* readImageFilter();
85 return (SkColorFilter*)this->readFlattenable(kColorFilter_SkEffectType); 77 SkMaskFilter* readMaskFilter();
86 } 78 SkPathEffect* readPathEffect();
87 SkDrawLooper* readDrawLooper() { 79 SkPixelRef* readPixelRef();
88 return (SkDrawLooper*)this->readFlattenable(kDrawLooper_SkEffectType); 80 SkRasterizer* readRasterizer();
89 } 81 SkShader* readShader();
90 SkImageFilter* readImageFilter() { 82 SkUnitMapper* readUnitMapper();
91 return (SkImageFilter*)this->readFlattenable(kImageFilter_SkEffectType); 83 SkXfermode* readXfermode();
92 }
93 SkMaskFilter* readMaskFilter() {
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 84
115 // common data structures 85 // common data structures
116 virtual void readPoint(SkPoint* point) = 0; 86 virtual void readPoint(SkPoint* point) = 0;
117 virtual void readMatrix(SkMatrix* matrix) = 0; 87 virtual void readMatrix(SkMatrix* matrix) = 0;
118 virtual void readIRect(SkIRect* rect) = 0; 88 virtual void readIRect(SkIRect* rect) = 0;
119 virtual void readRect(SkRect* rect) = 0; 89 virtual void readRect(SkRect* rect) = 0;
120 virtual void readRegion(SkRegion* region) = 0; 90 virtual void readRegion(SkRegion* region) = 0;
121 virtual void readPath(SkPath* path) = 0; 91 virtual void readPath(SkPath* path) = 0;
122 92
123 // binary data and arrays 93 // binary data and arrays
(...skipping 22 matching lines...) Expand all
146 return point; 116 return point;
147 } 117 }
148 118
149 SkData* readByteArrayAsData() { 119 SkData* readByteArrayAsData() {
150 size_t len = this->getArrayCount(); 120 size_t len = this->getArrayCount();
151 void* buffer = sk_malloc_throw(len); 121 void* buffer = sk_malloc_throw(len);
152 (void)this->readByteArray(buffer); 122 (void)this->readByteArray(buffer);
153 return SkData::NewFromMalloc(buffer, len); 123 return SkData::NewFromMalloc(buffer, len);
154 } 124 }
155 125
126 virtual void validate(bool isValid) SK_OVERRIDE {}
127
128 protected:
129 virtual SkFlattenable* readFlattenable(
reed1 2013/10/16 15:20:20 Why make this guy protected instead of public?
sugoi1 2013/10/16 15:36:26 So that everyone has to use the specialized readFo
130 /**
131 @param type This parameter is only used when using SkValidatingReadBuffe r. It will verify
reed1 2013/10/16 15:20:20 can we move the comment to above the function, ins
sugoi1 2013/10/16 15:36:26 Done.
132 that the object about to be deserialized is of the given typ e or early return
133 NULL otherwise. The type provided here is either the same ty pe or the type of
134 one of the base classes of the object to deserialize.
135 */
136 SkEffectType type) = 0;
137
156 private: 138 private:
139 template <typename T> T* readFlattenableT();
157 uint32_t fFlags; 140 uint32_t fFlags;
158 }; 141 };
159 142
160 /////////////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////////////
161 144
162 class SkFlattenableWriteBuffer { 145 class SkFlattenableWriteBuffer {
163 public: 146 public:
164 SkFlattenableWriteBuffer(); 147 SkFlattenableWriteBuffer();
165 virtual ~SkFlattenableWriteBuffer(); 148 virtual ~SkFlattenableWriteBuffer();
166 149
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 virtual void writeFunctionPtr(void* ptr); 181 virtual void writeFunctionPtr(void* ptr);
199 virtual void writePaint(const SkPaint& paint); 182 virtual void writePaint(const SkPaint& paint);
200 183
201 virtual void writeBitmap(const SkBitmap& bitmap) = 0; 184 virtual void writeBitmap(const SkBitmap& bitmap) = 0;
202 virtual void writeTypeface(SkTypeface* typeface) = 0; 185 virtual void writeTypeface(SkTypeface* typeface) = 0;
203 186
204 virtual bool writeToStream(SkWStream*) = 0; 187 virtual bool writeToStream(SkWStream*) = 0;
205 188
206 enum Flags { 189 enum Flags {
207 kCrossProcess_Flag = 0x01, 190 kCrossProcess_Flag = 0x01,
191 /** The kValidation_Flag is used here to make sure the write operation
192 * is symmetric with the read operation using the equivalent flag
193 * SkFlattenableReadBuffer::kValidation_Flag.
194 */
195 kValidation_Flag = 0x02,
208 }; 196 };
209 197
210 uint32_t getFlags() const { return fFlags; } 198 uint32_t getFlags() const { return fFlags; }
211 void setFlags(uint32_t flags) { fFlags = flags; } 199 void setFlags(uint32_t flags) { fFlags = flags; }
212 200
213 bool isCrossProcess() const { 201 bool isCrossProcess() const {
214 return SkToBool(fFlags & kCrossProcess_Flag); 202 return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag));
203 }
204
205 bool isValidating() const {
206 return SkToBool(fFlags & kValidation_Flag);
215 } 207 }
216 208
217 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } 209 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
218 210
219 void writeDataAsByteArray(SkData* data) { 211 void writeDataAsByteArray(SkData* data) {
220 this->writeByteArray(data->data(), data->size()); 212 this->writeByteArray(data->data(), data->size());
221 } 213 }
222 214
223 protected: 215 protected:
224 // A helper function so that each subclass does not have to be a friend of S kFlattenable 216 // A helper function so that each subclass does not have to be a friend of S kFlattenable
225 void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer); 217 void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer);
226 218
227 uint32_t fFlags; 219 uint32_t fFlags;
228 }; 220 };
229 221
230 #endif 222 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698