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 #include "SkOrderedWriteBuffer.h" | 9 #include "SkOrderedWriteBuffer.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 * | 263 * |
264 * The distinction is important, since 0-index is 32bits (always), but a | 264 * The distinction is important, since 0-index is 32bits (always), but a |
265 * 0-functionptr might be 32 or 64 bits. | 265 * 0-functionptr might be 32 or 64 bits. |
266 */ | 266 */ |
267 | 267 |
268 SkFlattenable::Factory factory = NULL; | 268 SkFlattenable::Factory factory = NULL; |
269 if (flattenable) { | 269 if (flattenable) { |
270 factory = flattenable->getFactory(); | 270 factory = flattenable->getFactory(); |
271 } | 271 } |
272 if (NULL == factory) { | 272 if (NULL == factory) { |
273 if (fFactorySet != NULL || fNamedFactorySet != NULL) { | 273 if (this->isValidating()) { |
mtklein
2013/09/24 22:52:18
Seems like we just shouldn't get into this situati
sugoi1
2013/09/25 21:15:27
I added an assert.
| |
274 this->writeInt(SkFlattenable::kNone); | |
275 } else if (fFactorySet != NULL || fNamedFactorySet != NULL) { | |
274 this->write32(0); | 276 this->write32(0); |
275 } else { | 277 } else { |
276 this->writeFunctionPtr(NULL); | 278 this->writeFunctionPtr(NULL); |
277 } | 279 } |
278 return; | 280 return; |
279 } | 281 } |
280 | 282 |
281 /* | 283 /* |
282 * We can write 1 of 3 versions of the flattenable: | 284 * We can write 1 of 3 versions of the flattenable: |
mtklein
2013/09/24 22:52:18
Needs an update :)
| |
283 * 1. function-ptr : this is the fastest for the reader, but assumes that | 285 * 1. function-ptr : this is the fastest for the reader, but assumes that |
284 * the writer and reader are in the same process. | 286 * the writer and reader are in the same process. |
285 * 2. index into fFactorySet : This is assumes the writer will later | 287 * 2. index into fFactorySet : This is assumes the writer will later |
286 * resolve the function-ptrs into strings for its reader. SkPicture | 288 * resolve the function-ptrs into strings for its reader. SkPicture |
287 * does exactly this, by writing a table of names (matching the indices ) | 289 * does exactly this, by writing a table of names (matching the indices ) |
288 * up front in its serialized form. | 290 * up front in its serialized form. |
289 * 3. index into fNamedFactorySet. fNamedFactorySet will also store the | 291 * 3. index into fNamedFactorySet. fNamedFactorySet will also store the |
290 * name. SkGPipe uses this technique so it can write the name to its | 292 * name. SkGPipe uses this technique so it can write the name to its |
291 * stream before writing the flattenable. | 293 * stream before writing the flattenable. |
292 */ | 294 */ |
293 if (fFactorySet) { | 295 if (this->isValidating()) { |
296 this->writeInt(flattenable->getFlattenableType()); | |
297 } else if (fFactorySet) { | |
294 this->write32(fFactorySet->add(factory)); | 298 this->write32(fFactorySet->add(factory)); |
295 } else if (fNamedFactorySet) { | 299 } else if (fNamedFactorySet) { |
296 int32_t index = fNamedFactorySet->find(factory); | 300 int32_t index = fNamedFactorySet->find(factory); |
297 this->write32(index); | 301 this->write32(index); |
298 if (0 == index) { | 302 if (0 == index) { |
299 return; | 303 return; |
300 } | 304 } |
301 } else { | 305 } else { |
302 this->writeFunctionPtr((void*)factory); | 306 this->writeFunctionPtr((void*)factory); |
303 } | 307 } |
304 | 308 |
305 // make room for the size of the flattened object | 309 // make room for the size of the flattened object |
306 (void)fWriter.reserve(sizeof(uint32_t)); | 310 (void)fWriter.reserve(sizeof(uint32_t)); |
307 // record the current size, so we can subtract after the object writes. | 311 // record the current size, so we can subtract after the object writes. |
308 uint32_t offset = fWriter.size(); | 312 uint32_t offset = fWriter.size(); |
309 // now flatten the object | 313 // now flatten the object |
310 flattenObject(flattenable, *this); | 314 flattenObject(flattenable, *this); |
311 uint32_t objSize = fWriter.size() - offset; | 315 uint32_t objSize = fWriter.size() - offset; |
312 // record the obj's size | 316 // record the obj's size |
313 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; | 317 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; |
314 } | 318 } |
OLD | NEW |