Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: src/core/SkOrderedWriteBuffer.cpp

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Adapting code to sk_once changes Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkOrderedReadBuffer.cpp ('k') | src/core/SkScalerContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()) {
274 this->writeString("");
275 SkASSERT(NULL == flattenable); // We shouldn't get in here in this s cenario
276 } else if (fFactorySet != NULL || fNamedFactorySet != NULL) {
274 this->write32(0); 277 this->write32(0);
275 } else { 278 } else {
276 this->writeFunctionPtr(NULL); 279 this->writeFunctionPtr(NULL);
277 } 280 }
278 return; 281 return;
279 } 282 }
280 283
281 /* 284 /*
282 * We can write 1 of 3 versions of the flattenable: 285 * We can write 1 of 3 versions of the flattenable:
283 * 1. function-ptr : this is the fastest for the reader, but assumes that 286 * 1. function-ptr : this is the fastest for the reader, but assumes that
284 * the writer and reader are in the same process. 287 * the writer and reader are in the same process.
285 * 2. index into fFactorySet : This is assumes the writer will later 288 * 2. index into fFactorySet : This is assumes the writer will later
286 * resolve the function-ptrs into strings for its reader. SkPicture 289 * resolve the function-ptrs into strings for its reader. SkPicture
287 * does exactly this, by writing a table of names (matching the indices ) 290 * does exactly this, by writing a table of names (matching the indices )
288 * up front in its serialized form. 291 * up front in its serialized form.
289 * 3. index into fNamedFactorySet. fNamedFactorySet will also store the 292 * 3. index into fNamedFactorySet. fNamedFactorySet will also store the
290 * name. SkGPipe uses this technique so it can write the name to its 293 * name. SkGPipe uses this technique so it can write the name to its
291 * stream before writing the flattenable. 294 * stream before writing the flattenable.
292 */ 295 */
293 if (fFactorySet) { 296 if (this->isValidating()) {
297 this->writeString(flattenable->getTypeName());
298 } else if (fFactorySet) {
294 this->write32(fFactorySet->add(factory)); 299 this->write32(fFactorySet->add(factory));
295 } else if (fNamedFactorySet) { 300 } else if (fNamedFactorySet) {
296 int32_t index = fNamedFactorySet->find(factory); 301 int32_t index = fNamedFactorySet->find(factory);
297 this->write32(index); 302 this->write32(index);
298 if (0 == index) { 303 if (0 == index) {
299 return; 304 return;
300 } 305 }
301 } else { 306 } else {
302 this->writeFunctionPtr((void*)factory); 307 this->writeFunctionPtr((void*)factory);
303 } 308 }
304 309
305 // make room for the size of the flattened object 310 // make room for the size of the flattened object
306 (void)fWriter.reserve(sizeof(uint32_t)); 311 (void)fWriter.reserve(sizeof(uint32_t));
307 // record the current size, so we can subtract after the object writes. 312 // record the current size, so we can subtract after the object writes.
308 uint32_t offset = fWriter.size(); 313 uint32_t offset = fWriter.size();
309 // now flatten the object 314 // now flatten the object
310 flattenObject(flattenable, *this); 315 flattenObject(flattenable, *this);
311 uint32_t objSize = fWriter.size() - offset; 316 uint32_t objSize = fWriter.size() - offset;
312 // record the obj's size 317 // record the obj's size
313 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize; 318 *fWriter.peek32(offset - sizeof(uint32_t)) = objSize;
314 } 319 }
OLDNEW
« no previous file with comments | « src/core/SkOrderedReadBuffer.cpp ('k') | src/core/SkScalerContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698