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

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

Issue 182153003: Add debug check of chunk size written to skp (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 9 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 | « no previous file | no next file » | 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 2011 Google Inc. 3 * Copyright 2011 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 #include "SkPicturePlayback.h" 8 #include "SkPicturePlayback.h"
9 #include "SkPictureRecord.h" 9 #include "SkPictureRecord.h"
10 #include "SkTypeface.h" 10 #include "SkTypeface.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 int count = rec.count(); 338 int count = rec.count();
339 339
340 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count); 340 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count);
341 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get(); 341 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get();
342 rec.copyToArray(array); 342 rec.copyToArray(array);
343 343
344 size_t size = compute_chunk_size(array, count); 344 size_t size = compute_chunk_size(array, count);
345 345
346 // TODO: write_tag_size should really take a size_t 346 // TODO: write_tag_size should really take a size_t
347 write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size); 347 write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size);
348 SkDEBUGCODE(size_t start = stream->bytesWritten());
348 stream->write32(count); 349 stream->write32(count);
349 350
350 for (int i = 0; i < count; i++) { 351 for (int i = 0; i < count; i++) {
351 const char* name = SkFlattenable::FactoryToName(array[i]); 352 const char* name = SkFlattenable::FactoryToName(array[i]);
352 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name); 353 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name);
353 if (NULL == name || 0 == *name) { 354 if (NULL == name || 0 == *name) {
354 stream->writePackedUInt(0); 355 stream->writePackedUInt(0);
355 } else { 356 } else {
356 uint32_t len = strlen(name); 357 uint32_t len = strlen(name);
357 stream->writePackedUInt(len); 358 stream->writePackedUInt(len);
358 stream->write(name, len); 359 stream->write(name, len);
359 } 360 }
360 } 361 }
361 362
362 363 SkASSERT(size == (stream->bytesWritten() - start));
363 } 364 }
364 365
365 static void writeTypefaces(SkWStream* stream, const SkRefCntSet& rec) { 366 static void write_typefaces(SkWStream* stream, const SkRefCntSet& rec) {
366 int count = rec.count(); 367 int count = rec.count();
367 368
368 write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count); 369 write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count);
369 370
370 SkAutoSTMalloc<16, SkTypeface*> storage(count); 371 SkAutoSTMalloc<16, SkTypeface*> storage(count);
371 SkTypeface** array = (SkTypeface**)storage.get(); 372 SkTypeface** array = (SkTypeface**)storage.get();
372 rec.copyToArray((SkRefCnt**)array); 373 rec.copyToArray((SkRefCnt**)array);
373 374
374 for (int i = 0; i < count; i++) { 375 for (int i = 0; i < count; i++) {
375 array[i]->serialize(stream); 376 array[i]->serialize(stream);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 buffer.setTypefaceRecorder(&typefaceSet); 422 buffer.setTypefaceRecorder(&typefaceSet);
422 buffer.setFactoryRecorder(&factSet); 423 buffer.setFactoryRecorder(&factSet);
423 buffer.setBitmapEncoder(encoder); 424 buffer.setBitmapEncoder(encoder);
424 425
425 this->flattenToBuffer(buffer); 426 this->flattenToBuffer(buffer);
426 427
427 // We have to write these two sets into the stream *before* we write 428 // We have to write these two sets into the stream *before* we write
428 // the buffer, since parsing that buffer will require that we already 429 // the buffer, since parsing that buffer will require that we already
429 // have these sets available to use. 430 // have these sets available to use.
430 write_factories(stream, factSet); 431 write_factories(stream, factSet);
431 writeTypefaces(stream, typefaceSet); 432 write_typefaces(stream, typefaceSet);
432 433
433 write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten()); 434 write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten());
434 buffer.writeToStream(stream); 435 buffer.writeToStream(stream);
435 } 436 }
436 437
437 stream->write32(SK_PICT_EOF_TAG); 438 stream->write32(SK_PICT_EOF_TAG);
438 } 439 }
439 440
440 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const { 441 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const {
441 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); 442 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size());
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 for (index = 0; index < fPictureCount; index++) 1681 for (index = 0; index < fPictureCount; index++)
1681 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), 1682 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1682 "picture%p, ", fPictureRefs[index]); 1683 "picture%p, ", fPictureRefs[index]);
1683 if (fPictureCount > 0) 1684 if (fPictureCount > 0)
1684 SkDebugf("%s0};\n", pBuffer); 1685 SkDebugf("%s0};\n", pBuffer);
1685 1686
1686 const_cast<SkPicturePlayback*>(this)->dumpStream(); 1687 const_cast<SkPicturePlayback*>(this)->dumpStream();
1687 } 1688 }
1688 1689
1689 #endif 1690 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698