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

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: Serialization with strings as ID 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
(...skipping 23 matching lines...) Expand all
34 SkFlattenableReadBuffer(); 34 SkFlattenableReadBuffer();
35 virtual ~SkFlattenableReadBuffer(); 35 virtual ~SkFlattenableReadBuffer();
36 36
37 bool isOrderedBinaryBuffer() { return NULL != getOrderedBinaryBuffer(); } 37 bool isOrderedBinaryBuffer() { return NULL != getOrderedBinaryBuffer(); }
38 virtual SkOrderedReadBuffer* getOrderedBinaryBuffer() { return NULL; } 38 virtual SkOrderedReadBuffer* getOrderedBinaryBuffer() { return NULL; }
39 39
40 enum Flags { 40 enum Flags {
41 kCrossProcess_Flag = 1 << 0, 41 kCrossProcess_Flag = 1 << 0,
42 kScalarIsFloat_Flag = 1 << 1, 42 kScalarIsFloat_Flag = 1 << 1,
43 kPtrIs64Bit_Flag = 1 << 2, 43 kPtrIs64Bit_Flag = 1 << 2,
44 /** The kValidation_Flag is used to force stream validations (by making
45 * sure that no operation reads past the end of the stream, for example)
46 * and error handling if any reading operation yields an invalid value.
47 */
48 kValidation_Flag = 1 << 3,
44 }; 49 };
45 50
46 void setFlags(uint32_t flags) { fFlags = flags; } 51 void setFlags(uint32_t flags) { fFlags = flags; }
47 uint32_t getFlags() const { return fFlags; } 52 uint32_t getFlags() const { return fFlags; }
48 53
49 bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); } 54 bool isCrossProcess() const { return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); }
50 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); } 55 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
51 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } 56 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
57 bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
52 58
53 // primitives 59 // primitives
54 virtual bool readBool() = 0; 60 virtual bool readBool() = 0;
55 virtual SkColor readColor() = 0; 61 virtual SkColor readColor() = 0;
56 virtual SkFixed readFixed() = 0; 62 virtual SkFixed readFixed() = 0;
57 virtual int32_t readInt() = 0; 63 virtual int32_t readInt() = 0;
58 virtual SkScalar readScalar() = 0; 64 virtual SkScalar readScalar() = 0;
59 virtual uint32_t readUInt() = 0; 65 virtual uint32_t readUInt() = 0;
60 virtual int32_t read32() = 0; 66 virtual int32_t read32() = 0;
61 67
62 // strings -- the caller is responsible for freeing the string contents 68 // strings -- the caller is responsible for freeing the string contents
63 virtual void readString(SkString* string) = 0; 69 virtual void readString(SkString* string) = 0;
64 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng) = 0; 70 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng) = 0;
65 71
66 // common data structures 72 // common data structures
67 virtual SkFlattenable* readFlattenable() = 0; 73 virtual SkFlattenable* readFlattenable(
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 either the same ty pe or the type of
78 one of the base classes of the object to deserialize. This c an effectively be
79 bypassed by providing the type SkFlattenable::kSkFlattenable _Type here, since
mtklein 2013/10/07 19:29:56 kSkFlattenableType_Type -> GetName()?
sugoi1 2013/10/08 20:23:10 Done.
80 SkFlattenable is a base class to all other classes that can be deserialized.
81 */
82 const char* name = SkFlattenable::GetName()) = 0;
68 virtual void readPoint(SkPoint* point) = 0; 83 virtual void readPoint(SkPoint* point) = 0;
69 virtual void readMatrix(SkMatrix* matrix) = 0; 84 virtual void readMatrix(SkMatrix* matrix) = 0;
70 virtual void readIRect(SkIRect* rect) = 0; 85 virtual void readIRect(SkIRect* rect) = 0;
71 virtual void readRect(SkRect* rect) = 0; 86 virtual void readRect(SkRect* rect) = 0;
72 virtual void readRegion(SkRegion* region) = 0; 87 virtual void readRegion(SkRegion* region) = 0;
73 virtual void readPath(SkPath* path) = 0; 88 virtual void readPath(SkPath* path) = 0;
74 89
75 // binary data and arrays 90 // binary data and arrays
76 virtual uint32_t readByteArray(void* value) = 0; 91 virtual uint32_t readByteArray(void* value) = 0;
77 virtual uint32_t readColorArray(SkColor* colors) = 0; 92 virtual uint32_t readColorArray(SkColor* colors) = 0;
(...skipping 14 matching lines...) Expand all
92 virtual SkTypeface* readTypeface() = 0; 107 virtual SkTypeface* readTypeface() = 0;
93 108
94 // helper function for classes with const SkPoint members 109 // helper function for classes with const SkPoint members
95 SkPoint readPoint() { 110 SkPoint readPoint() {
96 SkPoint point; 111 SkPoint point;
97 this->readPoint(&point); 112 this->readPoint(&point);
98 return point; 113 return point;
99 } 114 }
100 115
101 template <typename T> T* readFlattenableT() { 116 template <typename T> T* readFlattenableT() {
102 return static_cast<T*>(this->readFlattenable()); 117 return static_cast<T*>(this->readFlattenable(T::GetName()));
103 } 118 }
104 119
120 void validate(bool isValid) {
121 fError = fError || !isValid;
122 }
123
124 protected:
125 bool fError;
mtklein 2013/10/07 19:29:56 This seems a little odd to add this state here if
sugoi1 2013/10/08 20:23:10 Done.
126
105 private: 127 private:
106 uint32_t fFlags; 128 uint32_t fFlags;
107 }; 129 };
108 130
109 /////////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////////
110 132
111 class SkFlattenableWriteBuffer { 133 class SkFlattenableWriteBuffer {
112 public: 134 public:
113 SkFlattenableWriteBuffer(); 135 SkFlattenableWriteBuffer();
114 virtual ~SkFlattenableWriteBuffer(); 136 virtual ~SkFlattenableWriteBuffer();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 virtual void writeFunctionPtr(void* ptr); 169 virtual void writeFunctionPtr(void* ptr);
148 virtual void writePaint(const SkPaint& paint); 170 virtual void writePaint(const SkPaint& paint);
149 171
150 virtual void writeBitmap(const SkBitmap& bitmap) = 0; 172 virtual void writeBitmap(const SkBitmap& bitmap) = 0;
151 virtual void writeTypeface(SkTypeface* typeface) = 0; 173 virtual void writeTypeface(SkTypeface* typeface) = 0;
152 174
153 virtual bool writeToStream(SkWStream*) = 0; 175 virtual bool writeToStream(SkWStream*) = 0;
154 176
155 enum Flags { 177 enum Flags {
156 kCrossProcess_Flag = 0x01, 178 kCrossProcess_Flag = 0x01,
179 /** The kValidation_Flag is used here to make sure the write operation
180 * is symmetric with the read operation using the equivalent flag
mtklein 2013/10/07 19:29:56 I don't think I understand what this comment is tr
sugoi1 2013/10/08 20:23:10 We can phrase it any other way, but essentially :
181 * SkFlattenableReadBuffer::kValidation_Flag.
182 */
183 kValidation_Flag = 0x02,
157 }; 184 };
158 185
159 uint32_t getFlags() const { return fFlags; } 186 uint32_t getFlags() const { return fFlags; }
160 void setFlags(uint32_t flags) { fFlags = flags; } 187 void setFlags(uint32_t flags) { fFlags = flags; }
161 188
162 bool isCrossProcess() const { 189 bool isCrossProcess() const {
163 return SkToBool(fFlags & kCrossProcess_Flag); 190 return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag));
191 }
192
193 bool isValidating() const {
194 return SkToBool(fFlags & kValidation_Flag);
164 } 195 }
165 196
166 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } 197 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
167 198
168 protected: 199 protected:
169 // A helper function so that each subclass does not have to be a friend of S kFlattenable 200 // A helper function so that each subclass does not have to be a friend of S kFlattenable
170 void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer); 201 void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer);
171 202
172 uint32_t fFlags; 203 uint32_t fFlags;
173 }; 204 };
174 205
175 #endif 206 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698