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 |
(...skipping 23 matching lines...) Expand all Loading... | |
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( |
mtklein
2013/09/24 22:52:18
Add a note about what the argument means? Presuma
sugoi1
2013/09/25 21:15:27
Done.
| |
74 SkFlattenable::Type type = SkFlattenable::kSkFlattenable) = 0; | |
68 virtual void readPoint(SkPoint* point) = 0; | 75 virtual void readPoint(SkPoint* point) = 0; |
69 virtual void readMatrix(SkMatrix* matrix) = 0; | 76 virtual void readMatrix(SkMatrix* matrix) = 0; |
70 virtual void readIRect(SkIRect* rect) = 0; | 77 virtual void readIRect(SkIRect* rect) = 0; |
71 virtual void readRect(SkRect* rect) = 0; | 78 virtual void readRect(SkRect* rect) = 0; |
72 virtual void readRegion(SkRegion* region) = 0; | 79 virtual void readRegion(SkRegion* region) = 0; |
73 virtual void readPath(SkPath* path) = 0; | 80 virtual void readPath(SkPath* path) = 0; |
74 | 81 |
75 // binary data and arrays | 82 // binary data and arrays |
76 virtual uint32_t readByteArray(void* value) = 0; | 83 virtual uint32_t readByteArray(void* value) = 0; |
77 virtual uint32_t readColorArray(SkColor* colors) = 0; | 84 virtual uint32_t readColorArray(SkColor* colors) = 0; |
(...skipping 14 matching lines...) Expand all Loading... | |
92 virtual SkTypeface* readTypeface() = 0; | 99 virtual SkTypeface* readTypeface() = 0; |
93 | 100 |
94 // helper function for classes with const SkPoint members | 101 // helper function for classes with const SkPoint members |
95 SkPoint readPoint() { | 102 SkPoint readPoint() { |
96 SkPoint point; | 103 SkPoint point; |
97 this->readPoint(&point); | 104 this->readPoint(&point); |
98 return point; | 105 return point; |
99 } | 106 } |
100 | 107 |
101 template <typename T> T* readFlattenableT() { | 108 template <typename T> T* readFlattenableT() { |
102 return static_cast<T*>(this->readFlattenable()); | 109 return static_cast<T*>(this->readFlattenable(T::GetType())); |
103 } | 110 } |
104 | 111 |
112 void validate(bool isValid) { | |
113 fError |= !isValid; | |
114 } | |
115 | |
116 protected: | |
117 bool fError; | |
118 | |
105 private: | 119 private: |
106 uint32_t fFlags; | 120 uint32_t fFlags; |
107 }; | 121 }; |
108 | 122 |
109 /////////////////////////////////////////////////////////////////////////////// | 123 /////////////////////////////////////////////////////////////////////////////// |
110 | 124 |
111 class SkFlattenableWriteBuffer { | 125 class SkFlattenableWriteBuffer { |
112 public: | 126 public: |
113 SkFlattenableWriteBuffer(); | 127 SkFlattenableWriteBuffer(); |
114 virtual ~SkFlattenableWriteBuffer(); | 128 virtual ~SkFlattenableWriteBuffer(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 virtual void writeFunctionPtr(void* ptr); | 161 virtual void writeFunctionPtr(void* ptr); |
148 virtual void writePaint(const SkPaint& paint); | 162 virtual void writePaint(const SkPaint& paint); |
149 | 163 |
150 virtual void writeBitmap(const SkBitmap& bitmap) = 0; | 164 virtual void writeBitmap(const SkBitmap& bitmap) = 0; |
151 virtual void writeTypeface(SkTypeface* typeface) = 0; | 165 virtual void writeTypeface(SkTypeface* typeface) = 0; |
152 | 166 |
153 virtual bool writeToStream(SkWStream*) = 0; | 167 virtual bool writeToStream(SkWStream*) = 0; |
154 | 168 |
155 enum Flags { | 169 enum Flags { |
156 kCrossProcess_Flag = 0x01, | 170 kCrossProcess_Flag = 0x01, |
171 /** The kValidation_Flag is used here to make sure the write operation | |
172 * is symmetric with the read operation using the equivalent flag | |
173 * SkFlattenableReadBuffer::kValidation_Flag. | |
174 */ | |
175 kValidation_Flag = 0x02, | |
157 }; | 176 }; |
158 | 177 |
159 uint32_t getFlags() const { return fFlags; } | 178 uint32_t getFlags() const { return fFlags; } |
160 void setFlags(uint32_t flags) { fFlags = flags; } | 179 void setFlags(uint32_t flags) { fFlags = flags; } |
161 | 180 |
162 bool isCrossProcess() const { | 181 bool isCrossProcess() const { |
163 return SkToBool(fFlags & kCrossProcess_Flag); | 182 return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); |
183 } | |
184 | |
185 bool isValidating() const { | |
186 return SkToBool(fFlags & kValidation_Flag); | |
164 } | 187 } |
165 | 188 |
166 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } | 189 bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } |
167 | 190 |
168 protected: | 191 protected: |
169 // A helper function so that each subclass does not have to be a friend of S kFlattenable | 192 // A helper function so that each subclass does not have to be a friend of S kFlattenable |
170 void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer); | 193 void flattenObject(SkFlattenable* obj, SkFlattenableWriteBuffer& buffer); |
171 | 194 |
172 uint32_t fFlags; | 195 uint32_t fFlags; |
173 }; | 196 }; |
174 | 197 |
175 #endif | 198 #endif |
OLD | NEW |