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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 // helper function for classes with const SkPoint members | 133 // helper function for classes with const SkPoint members |
134 SkPoint readPoint() { | 134 SkPoint readPoint() { |
135 SkPoint point; | 135 SkPoint point; |
136 this->readPoint(&point); | 136 this->readPoint(&point); |
137 return point; | 137 return point; |
138 } | 138 } |
139 | 139 |
140 SkData* readByteArrayAsData() { | 140 SkData* readByteArrayAsData() { |
141 size_t len = this->getArrayCount(); | 141 size_t len = this->getArrayCount(); |
142 void* buffer = sk_malloc_throw(len); | 142 void* buffer = NULL; |
143 (void)this->readByteArray(buffer, len); | 143 if (this->validateAvailable(len)) { |
| 144 buffer = sk_malloc_throw(len); |
| 145 (void)this->readByteArray(buffer, len); |
| 146 } else { |
| 147 len = 0; |
| 148 } |
144 return SkData::NewFromMalloc(buffer, len); | 149 return SkData::NewFromMalloc(buffer, len); |
145 } | 150 } |
146 | 151 |
147 /** This function validates that the isValid input parameter is true | 152 /** This function validates that the isValid input parameter is true |
148 * If isValidating() is false, then true is always returned | 153 * If isValidating() is false, then true is always returned |
149 * If isValidating() is true, then true is returned until validate() is cal
led with isValid | 154 * If isValidating() is true, then true is returned until validate() is cal
led with isValid |
150 * set to false. When isValid is false, an error flag will be set internall
y and, from that | 155 * set to false. When isValid is false, an error flag will be set internall
y and, from that |
151 * point on, validate() will return false. The error flag cannot be unset. | 156 * point on, validate() will return false. The error flag cannot be unset. |
152 * | 157 * |
153 * @param isValid result of a test that is expected to be true | 158 * @param isValid result of a test that is expected to be true |
154 */ | 159 */ |
155 virtual bool validate(bool isValid); | 160 virtual bool validate(bool isValid); |
156 | 161 |
157 /** This function returns true by default | 162 /** This function returns true by default |
158 * If isValidating() is true, it will return false if the internal error fl
ag is set. | 163 * If isValidating() is true, it will return false if the internal error fl
ag is set. |
159 * Otherwise, it will return true. | 164 * Otherwise, it will return true. |
160 */ | 165 */ |
161 virtual bool isValid() const { return true; } | 166 virtual bool isValid() const { return true; } |
162 | 167 |
| 168 /** This function returns true by default |
| 169 * If isValidating() is true, it will return whether there's |
| 170 * at least "size" memory left to read in the stream. |
| 171 * |
| 172 * @param size amount of memory that should still be available |
| 173 */ |
| 174 virtual bool validateAvailable(size_t size) { return true; } |
| 175 |
163 private: | 176 private: |
164 template <typename T> T* readFlattenableT(); | 177 template <typename T> T* readFlattenableT(); |
165 uint32_t fFlags; | 178 uint32_t fFlags; |
166 }; | 179 }; |
167 | 180 |
168 /////////////////////////////////////////////////////////////////////////////// | 181 /////////////////////////////////////////////////////////////////////////////// |
169 | 182 |
170 class SkFlattenableWriteBuffer { | 183 class SkFlattenableWriteBuffer { |
171 public: | 184 public: |
172 SkFlattenableWriteBuffer(); | 185 SkFlattenableWriteBuffer(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 251 } |
239 | 252 |
240 protected: | 253 protected: |
241 // A helper function so that each subclass does not have to be a friend of S
kFlattenable | 254 // A helper function so that each subclass does not have to be a friend of S
kFlattenable |
242 void flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffe
r); | 255 void flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffe
r); |
243 | 256 |
244 uint32_t fFlags; | 257 uint32_t fFlags; |
245 }; | 258 }; |
246 | 259 |
247 #endif | 260 #endif |
OLD | NEW |