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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 writeFactories(stream, factSet); | 424 writeFactories(stream, factSet); |
425 writeTypefaces(stream, typefaceSet); | 425 writeTypefaces(stream, typefaceSet); |
426 | 426 |
427 writeTagSize(stream, PICT_BUFFER_SIZE_TAG, buffer.bytesWritten()); | 427 writeTagSize(stream, PICT_BUFFER_SIZE_TAG, buffer.bytesWritten()); |
428 buffer.writeToStream(stream); | 428 buffer.writeToStream(stream); |
429 } | 429 } |
430 | 430 |
431 stream->write32(PICT_EOF_TAG); | 431 stream->write32(PICT_EOF_TAG); |
432 } | 432 } |
433 | 433 |
| 434 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const { |
| 435 writeTagSize(buffer, PICT_READER_TAG, fOpData->size()); |
| 436 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); |
| 437 |
| 438 if (fPictureCount > 0) { |
| 439 writeTagSize(buffer, PICT_PICTURE_TAG, fPictureCount); |
| 440 for (int i = 0; i < fPictureCount; i++) { |
| 441 fPictureRefs[i]->flatten(buffer); |
| 442 } |
| 443 } |
| 444 |
| 445 // Write this picture playback's data into a writebuffer |
| 446 this->flattenToBuffer(buffer); |
| 447 buffer.write32(PICT_EOF_TAG); |
| 448 } |
| 449 |
434 /////////////////////////////////////////////////////////////////////////////// | 450 /////////////////////////////////////////////////////////////////////////////// |
435 | 451 |
436 /** | 452 /** |
437 * Return the corresponding SkReadBuffer flags, given a set of | 453 * Return the corresponding SkReadBuffer flags, given a set of |
438 * SkPictInfo flags. | 454 * SkPictInfo flags. |
439 */ | 455 */ |
440 static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) { | 456 static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) { |
441 static const struct { | 457 static const struct { |
442 uint32_t fSrc; | 458 uint32_t fSrc; |
443 uint32_t fDst; | 459 uint32_t fDst; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 const SkPictInfo& info, | 602 const SkPictInfo& info, |
587 SkPicture::InstallPixelRe
fProc proc) { | 603 SkPicture::InstallPixelRe
fProc proc) { |
588 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); | 604 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); |
589 | 605 |
590 if (!playback->parseStream(stream, info, proc)) { | 606 if (!playback->parseStream(stream, info, proc)) { |
591 return NULL; | 607 return NULL; |
592 } | 608 } |
593 return playback.detach(); | 609 return playback.detach(); |
594 } | 610 } |
595 | 611 |
| 612 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer) { |
| 613 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); |
| 614 |
| 615 if (!playback->parseBuffer(buffer)) { |
| 616 return NULL; |
| 617 } |
| 618 return playback.detach(); |
| 619 } |
| 620 |
596 bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, | 621 bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, |
597 SkPicture::InstallPixelRefProc proc) { | 622 SkPicture::InstallPixelRefProc proc) { |
598 for (;;) { | 623 for (;;) { |
599 uint32_t tag = stream->readU32(); | 624 uint32_t tag = stream->readU32(); |
600 if (PICT_EOF_TAG == tag) { | 625 if (PICT_EOF_TAG == tag) { |
601 break; | 626 break; |
602 } | 627 } |
603 | 628 |
604 uint32_t size = stream->readU32(); | 629 uint32_t size = stream->readU32(); |
605 if (!this->parseStreamTag(stream, info, tag, size, proc)) { | 630 if (!this->parseStreamTag(stream, info, tag, size, proc)) { |
606 return false; // we're invalid | 631 return false; // we're invalid |
607 } | 632 } |
608 } | 633 } |
609 return true; | 634 return true; |
610 } | 635 } |
611 | 636 |
| 637 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) { |
| 638 for (;;) { |
| 639 uint32_t tag = buffer.readUInt(); |
| 640 if (PICT_EOF_TAG == tag) { |
| 641 break; |
| 642 } |
| 643 |
| 644 uint32_t size = buffer.readUInt(); |
| 645 if (!this->parseBufferTag(buffer, tag, size)) { |
| 646 return false; // we're invalid |
| 647 } |
| 648 } |
| 649 return true; |
| 650 } |
| 651 |
612 /////////////////////////////////////////////////////////////////////////////// | 652 /////////////////////////////////////////////////////////////////////////////// |
613 /////////////////////////////////////////////////////////////////////////////// | 653 /////////////////////////////////////////////////////////////////////////////// |
614 | 654 |
615 #ifdef SPEW_CLIP_SKIPPING | 655 #ifdef SPEW_CLIP_SKIPPING |
616 struct SkipClipRec { | 656 struct SkipClipRec { |
617 int fCount; | 657 int fCount; |
618 size_t fSize; | 658 size_t fSize; |
619 | 659 |
620 SkipClipRec() { | 660 SkipClipRec() { |
621 fCount = 0; | 661 fCount = 0; |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 for (index = 0; index < fPictureCount; index++) | 1630 for (index = 0; index < fPictureCount; index++) |
1591 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1631 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
1592 "picture%p, ", fPictureRefs[index]); | 1632 "picture%p, ", fPictureRefs[index]); |
1593 if (fPictureCount > 0) | 1633 if (fPictureCount > 0) |
1594 SkDebugf("%s0};\n", pBuffer); | 1634 SkDebugf("%s0};\n", pBuffer); |
1595 | 1635 |
1596 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1636 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
1597 } | 1637 } |
1598 | 1638 |
1599 #endif | 1639 #endif |
OLD | NEW |