OLD | NEW |
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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 #define PICT_MATRIX_BUFFER_TAG SkSetFourByteTag('m', 't', 'r', 'x') | 327 #define PICT_MATRIX_BUFFER_TAG SkSetFourByteTag('m', 't', 'r', 'x') |
328 #define PICT_PAINT_BUFFER_TAG SkSetFourByteTag('p', 'n', 't', ' ') | 328 #define PICT_PAINT_BUFFER_TAG SkSetFourByteTag('p', 'n', 't', ' ') |
329 #define PICT_PATH_BUFFER_TAG SkSetFourByteTag('p', 't', 'h', ' ') | 329 #define PICT_PATH_BUFFER_TAG SkSetFourByteTag('p', 't', 'h', ' ') |
330 #define PICT_REGION_BUFFER_TAG SkSetFourByteTag('r', 'g', 'n', ' ') | 330 #define PICT_REGION_BUFFER_TAG SkSetFourByteTag('r', 'g', 'n', ' ') |
331 | 331 |
332 // Always write this guy last (with no length field afterwards) | 332 // Always write this guy last (with no length field afterwards) |
333 #define PICT_EOF_TAG SkSetFourByteTag('e', 'o', 'f', ' ') | 333 #define PICT_EOF_TAG SkSetFourByteTag('e', 'o', 'f', ' ') |
334 | 334 |
335 #include "SkStream.h" | 335 #include "SkStream.h" |
336 | 336 |
337 static void writeTagSize(SkOrderedWriteBuffer& buffer, uint32_t tag, | 337 static void writeTagSize(SkFlattenableWriteBuffer& buffer, uint32_t tag, |
338 uint32_t size) { | 338 uint32_t size) { |
339 buffer.writeUInt(tag); | 339 buffer.writeUInt(tag); |
340 buffer.writeUInt(size); | 340 buffer.writeUInt(size); |
341 } | 341 } |
342 | 342 |
343 static void writeTagSize(SkWStream* stream, uint32_t tag, | 343 static void writeTagSize(SkWStream* stream, uint32_t tag, |
344 uint32_t size) { | 344 uint32_t size) { |
345 stream->write32(tag); | 345 stream->write32(tag); |
346 stream->write32(size); | 346 stream->write32(size); |
347 } | 347 } |
(...skipping 27 matching lines...) Expand all Loading... |
375 | 375 |
376 SkAutoSTMalloc<16, SkTypeface*> storage(count); | 376 SkAutoSTMalloc<16, SkTypeface*> storage(count); |
377 SkTypeface** array = (SkTypeface**)storage.get(); | 377 SkTypeface** array = (SkTypeface**)storage.get(); |
378 rec.copyToArray((SkRefCnt**)array); | 378 rec.copyToArray((SkRefCnt**)array); |
379 | 379 |
380 for (int i = 0; i < count; i++) { | 380 for (int i = 0; i < count; i++) { |
381 array[i]->serialize(stream); | 381 array[i]->serialize(stream); |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 void SkPicturePlayback::flattenToBuffer(SkOrderedWriteBuffer& buffer) const { | 385 void SkPicturePlayback::flattenToBuffer(SkFlattenableWriteBuffer& buffer) const
{ |
386 int i, n; | 386 int i, n; |
387 | 387 |
388 if ((n = SafeCount(fBitmaps)) > 0) { | 388 if ((n = SafeCount(fBitmaps)) > 0) { |
389 writeTagSize(buffer, PICT_BITMAP_BUFFER_TAG, n); | 389 writeTagSize(buffer, PICT_BITMAP_BUFFER_TAG, n); |
390 for (i = 0; i < n; i++) { | 390 for (i = 0; i < n; i++) { |
391 buffer.writeBitmap((*fBitmaps)[i]); | 391 buffer.writeBitmap((*fBitmaps)[i]); |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 if ((n = SafeCount(fMatrices)) > 0) { | 395 if ((n = SafeCount(fMatrices)) > 0) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 writeFactories(stream, factSet); | 452 writeFactories(stream, factSet); |
453 writeTypefaces(stream, typefaceSet); | 453 writeTypefaces(stream, typefaceSet); |
454 | 454 |
455 writeTagSize(stream, PICT_BUFFER_SIZE_TAG, buffer.size()); | 455 writeTagSize(stream, PICT_BUFFER_SIZE_TAG, buffer.size()); |
456 buffer.writeToStream(stream); | 456 buffer.writeToStream(stream); |
457 } | 457 } |
458 | 458 |
459 stream->write32(PICT_EOF_TAG); | 459 stream->write32(PICT_EOF_TAG); |
460 } | 460 } |
461 | 461 |
| 462 void SkPicturePlayback::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 463 writeTagSize(buffer, PICT_READER_TAG, fOpData->size()); |
| 464 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); |
| 465 |
| 466 if (fPictureCount > 0) { |
| 467 writeTagSize(buffer, PICT_PICTURE_TAG, fPictureCount); |
| 468 for (int i = 0; i < fPictureCount; i++) { |
| 469 fPictureRefs[i]->flatten(buffer); |
| 470 } |
| 471 } |
| 472 |
| 473 // Write some of our data into a writebuffer |
| 474 this->flattenToBuffer(buffer); |
| 475 buffer.write32(PICT_EOF_TAG); |
| 476 } |
| 477 |
462 /////////////////////////////////////////////////////////////////////////////// | 478 /////////////////////////////////////////////////////////////////////////////// |
463 | 479 |
464 /** | 480 /** |
465 * Return the corresponding SkFlattenableReadBuffer flags, given a set of | 481 * Return the corresponding SkFlattenableReadBuffer flags, given a set of |
466 * SkPictInfo flags. | 482 * SkPictInfo flags. |
467 */ | 483 */ |
468 static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) { | 484 static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) { |
469 static const struct { | 485 static const struct { |
470 uint32_t fSrc; | 486 uint32_t fSrc; |
471 uint32_t fDst; | 487 uint32_t fDst; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if (!this->parseBufferTag(buffer, tag, size)) { | 590 if (!this->parseBufferTag(buffer, tag, size)) { |
575 return false; | 591 return false; |
576 } | 592 } |
577 } | 593 } |
578 SkDEBUGCODE(haveBuffer = true;) | 594 SkDEBUGCODE(haveBuffer = true;) |
579 } break; | 595 } break; |
580 } | 596 } |
581 return true; // success | 597 return true; // success |
582 } | 598 } |
583 | 599 |
584 bool SkPicturePlayback::parseBufferTag(SkOrderedReadBuffer& buffer, | 600 bool SkPicturePlayback::parseBufferTag(SkFlattenableReadBuffer& buffer, |
585 uint32_t tag, size_t size) { | 601 uint32_t tag, size_t size) { |
586 switch (tag) { | 602 switch (tag) { |
587 case PICT_BITMAP_BUFFER_TAG: { | 603 case PICT_BITMAP_BUFFER_TAG: { |
588 fBitmaps = SkTRefArray<SkBitmap>::Create(size); | 604 fBitmaps = SkTRefArray<SkBitmap>::Create(size); |
589 for (size_t i = 0; i < size; ++i) { | 605 for (size_t i = 0; i < size; ++i) { |
590 SkBitmap* bm = &fBitmaps->writableAt(i); | 606 SkBitmap* bm = &fBitmaps->writableAt(i); |
591 buffer.readBitmap(bm); | 607 buffer.readBitmap(bm); |
592 bm->setImmutable(); | 608 bm->setImmutable(); |
593 } | 609 } |
594 } break; | 610 } break; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 const SkPictInfo& info, | 642 const SkPictInfo& info, |
627 SkPicture::InstallPixelRe
fProc proc) { | 643 SkPicture::InstallPixelRe
fProc proc) { |
628 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); | 644 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); |
629 | 645 |
630 if (!playback->parseStream(stream, info, proc)) { | 646 if (!playback->parseStream(stream, info, proc)) { |
631 return NULL; | 647 return NULL; |
632 } | 648 } |
633 return playback.detach(); | 649 return playback.detach(); |
634 } | 650 } |
635 | 651 |
| 652 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkFlattenableReadBuffer&
buffer) { |
| 653 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); |
| 654 |
| 655 if (!playback->parseBuffer(buffer)) { |
| 656 return NULL; |
| 657 } |
| 658 return playback.detach(); |
| 659 } |
| 660 |
636 bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, | 661 bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, |
637 SkPicture::InstallPixelRefProc proc) { | 662 SkPicture::InstallPixelRefProc proc) { |
638 for (;;) { | 663 for (;;) { |
639 uint32_t tag = stream->readU32(); | 664 uint32_t tag = stream->readU32(); |
640 if (PICT_EOF_TAG == tag) { | 665 if (PICT_EOF_TAG == tag) { |
641 break; | 666 break; |
642 } | 667 } |
643 | 668 |
644 uint32_t size = stream->readU32(); | 669 uint32_t size = stream->readU32(); |
645 if (!this->parseStreamTag(stream, info, tag, size, proc)) { | 670 if (!this->parseStreamTag(stream, info, tag, size, proc)) { |
646 return false; // we're invalid | 671 return false; // we're invalid |
647 } | 672 } |
648 } | 673 } |
649 return true; | 674 return true; |
650 } | 675 } |
651 | 676 |
| 677 bool SkPicturePlayback::parseBuffer(SkFlattenableReadBuffer& buffer) { |
| 678 for (;;) { |
| 679 uint32_t tag = buffer.readUInt(); |
| 680 if (PICT_EOF_TAG == tag) { |
| 681 break; |
| 682 } |
| 683 |
| 684 uint32_t size = buffer.readUInt(); |
| 685 if (!this->parseBufferTag(buffer, tag, size)) { |
| 686 return false; // we're invalid |
| 687 } |
| 688 } |
| 689 return true; |
| 690 } |
| 691 |
652 /////////////////////////////////////////////////////////////////////////////// | 692 /////////////////////////////////////////////////////////////////////////////// |
653 /////////////////////////////////////////////////////////////////////////////// | 693 /////////////////////////////////////////////////////////////////////////////// |
654 | 694 |
655 #ifdef SPEW_CLIP_SKIPPING | 695 #ifdef SPEW_CLIP_SKIPPING |
656 struct SkipClipRec { | 696 struct SkipClipRec { |
657 int fCount; | 697 int fCount; |
658 size_t fSize; | 698 size_t fSize; |
659 | 699 |
660 SkipClipRec() { | 700 SkipClipRec() { |
661 fCount = 0; | 701 fCount = 0; |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 for (index = 0; index < fRegionCount; index++) | 1706 for (index = 0; index < fRegionCount; index++) |
1667 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1707 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
1668 "region%p, ", &fRegions[index]); | 1708 "region%p, ", &fRegions[index]); |
1669 if (fRegionCount > 0) | 1709 if (fRegionCount > 0) |
1670 SkDebugf("%s0};\n", pBuffer); | 1710 SkDebugf("%s0};\n", pBuffer); |
1671 | 1711 |
1672 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1712 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
1673 } | 1713 } |
1674 | 1714 |
1675 #endif | 1715 #endif |
OLD | NEW |