OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkValidatingReadBuffer.h" | 10 #include "SkValidatingReadBuffer.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return nullptr; | 236 return nullptr; |
237 } | 237 } |
238 | 238 |
239 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname); | 239 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(cname); |
240 if (nullptr == factory) { | 240 if (nullptr == factory) { |
241 return nullptr; // writer failed to give us the flattenable | 241 return nullptr; // writer failed to give us the flattenable |
242 } | 242 } |
243 | 243 |
244 // if we get here, factory may still be null, but if that is the case, the | 244 // if we get here, factory may still be null, but if that is the case, the |
245 // failure was ours, not the writer. | 245 // failure was ours, not the writer. |
246 SkFlattenable* obj = nullptr; | 246 sk_sp<SkFlattenable> obj; |
247 uint32_t sizeRecorded = this->readUInt(); | 247 uint32_t sizeRecorded = this->readUInt(); |
248 if (factory) { | 248 if (factory) { |
249 size_t offset = fReader.offset(); | 249 size_t offset = fReader.offset(); |
250 obj = (*factory)(*this); | 250 obj = (*factory)(*this); |
251 // check that we read the amount we expected | 251 // check that we read the amount we expected |
252 size_t sizeRead = fReader.offset() - offset; | 252 size_t sizeRead = fReader.offset() - offset; |
253 this->validate(sizeRecorded == sizeRead); | 253 this->validate(sizeRecorded == sizeRead); |
254 if (fError) { | 254 if (fError) { |
255 // we could try to fix up the offset... | |
256 SkSafeUnref(obj); | |
257 obj = nullptr; | 255 obj = nullptr; |
258 } | 256 } |
259 } else { | 257 } else { |
260 // we must skip the remaining data | 258 // we must skip the remaining data |
261 this->skip(sizeRecorded); | 259 this->skip(sizeRecorded); |
262 SkASSERT(false); | 260 SkASSERT(false); |
263 } | 261 } |
264 return obj; | 262 return obj.release(); |
265 } | 263 } |
266 | 264 |
267 void SkValidatingReadBuffer::skipFlattenable() { | 265 void SkValidatingReadBuffer::skipFlattenable() { |
268 SkString name; | 266 SkString name; |
269 this->readString(&name); | 267 this->readString(&name); |
270 if (fError) { | 268 if (fError) { |
271 return; | 269 return; |
272 } | 270 } |
273 uint32_t sizeRecorded = this->readUInt(); | 271 uint32_t sizeRecorded = this->readUInt(); |
274 this->skip(sizeRecorded); | 272 this->skip(sizeRecorded); |
275 } | 273 } |
OLD | NEW |