| 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 "SkWriteBuffer.h" | 9 #include "SkWriteBuffer.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 * If we have a factoryset, then the first 32bits tell us... | 264 * If we have a factoryset, then the first 32bits tell us... |
| 265 * 0: failure to write the flattenable | 265 * 0: failure to write the flattenable |
| 266 * >0: (1-based) index into the SkFactorySet or SkNamedFactorySet | 266 * >0: (1-based) index into the SkFactorySet or SkNamedFactorySet |
| 267 * If we don't have a factoryset, then the first "ptr" is either the | 267 * If we don't have a factoryset, then the first "ptr" is either the |
| 268 * factory, or null for failure. | 268 * factory, or null for failure. |
| 269 * | 269 * |
| 270 * The distinction is important, since 0-index is 32bits (always), but a | 270 * The distinction is important, since 0-index is 32bits (always), but a |
| 271 * 0-functionptr might be 32 or 64 bits. | 271 * 0-functionptr might be 32 or 64 bits. |
| 272 */ | 272 */ |
| 273 | 273 if (NULL == flattenable) { |
| 274 SkFlattenable::Factory factory = NULL; | |
| 275 if (flattenable) { | |
| 276 factory = flattenable->getFactory(); | |
| 277 } | |
| 278 if (NULL == factory) { | |
| 279 if (this->isValidating()) { | 274 if (this->isValidating()) { |
| 280 this->writeString(""); | 275 this->writeString(""); |
| 281 SkASSERT(NULL == flattenable); // We shouldn't get in here in this s
cenario | |
| 282 } else if (fFactorySet != NULL || fNamedFactorySet != NULL) { | 276 } else if (fFactorySet != NULL || fNamedFactorySet != NULL) { |
| 283 this->write32(0); | 277 this->write32(0); |
| 284 } else { | 278 } else { |
| 285 this->writeFunctionPtr(NULL); | 279 this->writeFunctionPtr(NULL); |
| 286 } | 280 } |
| 287 return; | 281 return; |
| 288 } | 282 } |
| 289 | 283 |
| 284 SkFlattenable::Factory factory = flattenable->getFactory(); |
| 285 SkASSERT(factory != NULL); |
| 286 |
| 290 /* | 287 /* |
| 291 * We can write 1 of 3 versions of the flattenable: | 288 * We can write 1 of 3 versions of the flattenable: |
| 292 * 1. function-ptr : this is the fastest for the reader, but assumes that | 289 * 1. function-ptr : this is the fastest for the reader, but assumes that |
| 293 * the writer and reader are in the same process. | 290 * the writer and reader are in the same process. |
| 294 * 2. index into fFactorySet : This is assumes the writer will later | 291 * 2. index into fFactorySet : This is assumes the writer will later |
| 295 * resolve the function-ptrs into strings for its reader. SkPicture | 292 * resolve the function-ptrs into strings for its reader. SkPicture |
| 296 * does exactly this, by writing a table of names (matching the indices
) | 293 * does exactly this, by writing a table of names (matching the indices
) |
| 297 * up front in its serialized form. | 294 * up front in its serialized form. |
| 298 * 3. index into fNamedFactorySet. fNamedFactorySet will also store the | 295 * 3. index into fNamedFactorySet. fNamedFactorySet will also store the |
| 299 * name. SkGPipe uses this technique so it can write the name to its | 296 * name. SkGPipe uses this technique so it can write the name to its |
| (...skipping 16 matching lines...) Expand all Loading... |
| 316 // make room for the size of the flattened object | 313 // make room for the size of the flattened object |
| 317 (void)fWriter.reserve(sizeof(uint32_t)); | 314 (void)fWriter.reserve(sizeof(uint32_t)); |
| 318 // record the current size, so we can subtract after the object writes. | 315 // record the current size, so we can subtract after the object writes. |
| 319 size_t offset = fWriter.bytesWritten(); | 316 size_t offset = fWriter.bytesWritten(); |
| 320 // now flatten the object | 317 // now flatten the object |
| 321 flattenable->flatten(*this); | 318 flattenable->flatten(*this); |
| 322 size_t objSize = fWriter.bytesWritten() - offset; | 319 size_t objSize = fWriter.bytesWritten() - offset; |
| 323 // record the obj's size | 320 // record the obj's size |
| 324 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); | 321 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); |
| 325 } | 322 } |
| OLD | NEW |