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 #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 (isSecure()) { |
|
sugoi1
2013/08/29 18:55:53
I added these 2 checks to the writer, but, hopeful
reed1
2013/08/29 19:08:22
style nit: this->isSecure()
sugoi1
2013/08/29 19:39:40
Done.
| |
| 274 this->writeString(NULL); | |
| 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: |
| 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 (isSecure()) { |
|
reed1
2013/08/29 19:08:22
style nit: this->isSecure()
sugoi1
2013/08/29 19:39:40
Done.
| |
| 296 const char* name = SkFlattenable::FactoryToName(factory); | |
| 297 this->writeString(name); | |
| 298 if (NULL == name) { | |
| 299 SkASSERT(!"Missing factory name"); | |
| 300 return; | |
| 301 } | |
| 302 } else if (fFactorySet) { | |
| 294 this->write32(fFactorySet->add(factory)); | 303 this->write32(fFactorySet->add(factory)); |
| 295 } else if (fNamedFactorySet) { | 304 } else if (fNamedFactorySet) { |
| 296 int32_t index = fNamedFactorySet->find(factory); | 305 int32_t index = fNamedFactorySet->find(factory); |
| 297 this->write32(index); | 306 this->write32(index); |
| 298 if (0 == index) { | 307 if (0 == index) { |
| 299 return; | 308 return; |
| 300 } | 309 } |
| 301 } else { | 310 } else { |
| 302 this->writeFunctionPtr((void*)factory); | 311 this->writeFunctionPtr((void*)factory); |
| 303 } | 312 } |
| 304 | 313 |
| 305 // make room for the size of the flattened object | 314 // make room for the size of the flattened object |
| 306 (void)fWriter.reserve(sizeof(uint32_t)); | 315 (void)fWriter.reserve(sizeof(uint32_t)); |
| 307 // record the current size, so we can subtract after the object writes. | 316 // record the current size, so we can subtract after the object writes. |
| 308 uint32_t offset = fWriter.size(); | 317 uint32_t offset = fWriter.size(); |
| 309 // now flatten the object | 318 // now flatten the object |
| 310 flattenObject(flattenable, *this); | 319 flattenObject(flattenable, *this); |
| 311 uint32_t objSize = fWriter.size() - offset; | 320 uint32_t objSize = fWriter.size() - offset; |
| 312 // record the obj's size | 321 // record the obj's size |
| 313 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; | 322 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; |
| 314 } | 323 } |
| OLD | NEW |