Chromium Code Reviews| 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->validate(this->isAvailable(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 whether there's at least "size" memory left to rea d in the stream. | |
| 169 * | |
| 170 * @param size amount of memory that should still be available | |
| 171 */ | |
| 172 virtual bool isAvailable(size_t size) const = 0; | |
|
reed1
2013/12/16 21:53:13
Do we really need this as a vritual? Do any of our
sugoi
2013/12/17 15:55:45
They all know their exact length, but their length
| |
| 173 | |
| 163 private: | 174 private: |
| 164 template <typename T> T* readFlattenableT(); | 175 template <typename T> T* readFlattenableT(); |
| 165 uint32_t fFlags; | 176 uint32_t fFlags; |
| 166 }; | 177 }; |
| 167 | 178 |
| 168 /////////////////////////////////////////////////////////////////////////////// | 179 /////////////////////////////////////////////////////////////////////////////// |
| 169 | 180 |
| 170 class SkFlattenableWriteBuffer { | 181 class SkFlattenableWriteBuffer { |
| 171 public: | 182 public: |
| 172 SkFlattenableWriteBuffer(); | 183 SkFlattenableWriteBuffer(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 } | 249 } |
| 239 | 250 |
| 240 protected: | 251 protected: |
| 241 // A helper function so that each subclass does not have to be a friend of S kFlattenable | 252 // 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); | 253 void flattenObject(const SkFlattenable* obj, SkFlattenableWriteBuffer& buffe r); |
| 243 | 254 |
| 244 uint32_t fFlags; | 255 uint32_t fFlags; |
| 245 }; | 256 }; |
| 246 | 257 |
| 247 #endif | 258 #endif |
| OLD | NEW |