| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include <new> | 7 #include <new> |
| 8 #include "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
| 9 #include "SkOffsetTable.h" | 9 #include "SkOffsetTable.h" |
| 10 #include "SkPicturePlayback.h" | 10 #include "SkPicturePlayback.h" |
| 11 #include "SkPictureRecord.h" | 11 #include "SkPictureRecord.h" |
| 12 #include "SkPictureStateTree.h" | 12 #include "SkPictureStateTree.h" |
| 13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
| 14 #include "SkTypeface.h" | 14 #include "SkTypeface.h" |
| 15 #include "SkTSort.h" | 15 #include "SkTSort.h" |
| 16 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
| 17 | 17 |
| 18 template <typename T> int SafeCount(const T* obj) { | 18 template <typename T> int SafeCount(const T* obj) { |
| 19 return obj ? obj->count() : 0; | 19 return obj ? obj->count() : 0; |
| 20 } | 20 } |
| 21 | 21 |
| 22 /* Define this to spew out a debug statement whenever we skip the remainder of | 22 /* Define this to spew out a debug statement whenever we skip the remainder of |
| 23 a save/restore block because a clip... command returned false (empty). | 23 a save/restore block because a clip... command returned false (empty). |
| 24 */ | 24 */ |
| 25 #define SPEW_CLIP_SKIPPINGx | 25 #define SPEW_CLIP_SKIPPINGx |
| 26 | 26 |
| 27 SkPicturePlayback::SkPicturePlayback() { | 27 SkPicturePlayback::SkPicturePlayback(const SkPictInfo& info) : fInfo(info) { |
| 28 this->init(); | 28 this->init(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, bool deepCop
y) { | 31 SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, |
| 32 const SkPictInfo& info, |
| 33 bool deepCopy) |
| 34 : fInfo(info) { |
| 32 #ifdef SK_DEBUG_SIZE | 35 #ifdef SK_DEBUG_SIZE |
| 33 size_t overallBytes, bitmapBytes, matricesBytes, | 36 size_t overallBytes, bitmapBytes, matricesBytes, |
| 34 paintBytes, pathBytes, pictureBytes, regionBytes; | 37 paintBytes, pathBytes, pictureBytes, regionBytes; |
| 35 int bitmaps = record.bitmaps(&bitmapBytes); | 38 int bitmaps = record.bitmaps(&bitmapBytes); |
| 36 int matrices = record.matrices(&matricesBytes); | 39 int matrices = record.matrices(&matricesBytes); |
| 37 int paints = record.paints(&paintBytes); | 40 int paints = record.paints(&paintBytes); |
| 38 int paths = record.paths(&pathBytes); | 41 int paths = record.paths(&pathBytes); |
| 39 int pictures = record.pictures(&pictureBytes); | 42 int pictures = record.pictures(&pictureBytes); |
| 40 int regions = record.regions(®ionBytes); | 43 int regions = record.regions(®ionBytes); |
| 41 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(), | 44 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(), |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 */ | 154 */ |
| 152 | 155 |
| 153 return paint.getPathEffect() || | 156 return paint.getPathEffect() || |
| 154 paint.getShader() || | 157 paint.getShader() || |
| 155 paint.getMaskFilter() || | 158 paint.getMaskFilter() || |
| 156 paint.getRasterizer() || | 159 paint.getRasterizer() || |
| 157 paint.getLooper() || | 160 paint.getLooper() || |
| 158 paint.getImageFilter(); | 161 paint.getImageFilter(); |
| 159 } | 162 } |
| 160 | 163 |
| 161 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInf
o* deepCopyInfo) { | 164 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInf
o* deepCopyInfo) |
| 165 : fInfo(src.fInfo) { |
| 162 this->init(); | 166 this->init(); |
| 163 | 167 |
| 164 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); | 168 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); |
| 165 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); | 169 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); |
| 166 | 170 |
| 167 fOpData = SkSafeRef(src.fOpData); | 171 fOpData = SkSafeRef(src.fOpData); |
| 168 | 172 |
| 169 fBoundingHierarchy = src.fBoundingHierarchy; | 173 fBoundingHierarchy = src.fBoundingHierarchy; |
| 170 fStateTree = src.fStateTree; | 174 fStateTree = src.fStateTree; |
| 171 | 175 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 476 |
| 473 uint32_t rbMask = 0; | 477 uint32_t rbMask = 0; |
| 474 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { | 478 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { |
| 475 if (pictInfoFlags & gSD[i].fSrc) { | 479 if (pictInfoFlags & gSD[i].fSrc) { |
| 476 rbMask |= gSD[i].fDst; | 480 rbMask |= gSD[i].fDst; |
| 477 } | 481 } |
| 478 } | 482 } |
| 479 return rbMask; | 483 return rbMask; |
| 480 } | 484 } |
| 481 | 485 |
| 482 bool SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info,
uint32_t tag, | 486 bool SkPicturePlayback::parseStreamTag(SkStream* stream, |
| 483 size_t size, SkPicture::InstallPixelRefPr
oc proc) { | 487 uint32_t tag, |
| 488 size_t size, |
| 489 SkPicture::InstallPixelRefProc proc) { |
| 484 /* | 490 /* |
| 485 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen | 491 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen |
| 486 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required | 492 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required |
| 487 * but if they are present, they need to have been seen before the buffer. | 493 * but if they are present, they need to have been seen before the buffer. |
| 488 * | 494 * |
| 489 * We assert that if/when we see either of these, that we have not yet seen | 495 * We assert that if/when we see either of these, that we have not yet seen |
| 490 * the buffer tag, because if we have, then its too-late to deal with the | 496 * the buffer tag, because if we have, then its too-late to deal with the |
| 491 * factories or typefaces. | 497 * factories or typefaces. |
| 492 */ | 498 */ |
| 493 SkDEBUGCODE(bool haveBuffer = false;) | 499 SkDEBUGCODE(bool haveBuffer = false;) |
| 494 | 500 |
| 495 switch (tag) { | 501 switch (tag) { |
| 496 case SK_PICT_READER_TAG: { | 502 case SK_PICT_READER_TAG: { |
| 497 SkAutoMalloc storage(size); | 503 SkAutoMalloc storage(size); |
| 498 if (stream->read(storage.get(), size) != size) { | 504 if (stream->read(storage.get(), size) != size) { |
| 499 return false; | 505 return false; |
| 500 } | 506 } |
| 501 SkASSERT(NULL == fOpData); | 507 SkASSERT(NULL == fOpData); |
| 502 fOpData = SkData::NewFromMalloc(storage.detach(), size); | 508 fOpData = SkData::NewFromMalloc(storage.detach(), size); |
| 503 } break; | 509 } break; |
| 504 case SK_PICT_FACTORY_TAG: { | 510 case SK_PICT_FACTORY_TAG: { |
| 505 SkASSERT(!haveBuffer); | 511 SkASSERT(!haveBuffer); |
| 506 // Remove this code when v21 and below are no longer supported. At the | 512 // Remove this code when v21 and below are no longer supported. At the |
| 507 // same time add a new 'count' variable and use it rather then reusing '
size'. | 513 // same time add a new 'count' variable and use it rather then reusing '
size'. |
| 508 #ifndef DISABLE_V21_COMPATIBILITY_CODE | 514 #ifndef DISABLE_V21_COMPATIBILITY_CODE |
| 509 if (info.fVersion >= 22) { | 515 if (fInfo.fVersion >= 22) { |
| 510 // in v22 this tag's size represents the size of the chunk in by
tes | 516 // in v22 this tag's size represents the size of the chunk in by
tes |
| 511 // and the number of factory strings is written out separately | 517 // and the number of factory strings is written out separately |
| 512 #endif | 518 #endif |
| 513 size = stream->readU32(); | 519 size = stream->readU32(); |
| 514 #ifndef DISABLE_V21_COMPATIBILITY_CODE | 520 #ifndef DISABLE_V21_COMPATIBILITY_CODE |
| 515 } | 521 } |
| 516 #endif | 522 #endif |
| 517 fFactoryPlayback = SkNEW_ARGS(SkFactoryPlayback, (size)); | 523 fFactoryPlayback = SkNEW_ARGS(SkFactoryPlayback, (size)); |
| 518 for (size_t i = 0; i < size; i++) { | 524 for (size_t i = 0; i < size; i++) { |
| 519 SkString str; | 525 SkString str; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 return false; | 567 return false; |
| 562 } | 568 } |
| 563 } break; | 569 } break; |
| 564 case SK_PICT_BUFFER_SIZE_TAG: { | 570 case SK_PICT_BUFFER_SIZE_TAG: { |
| 565 SkAutoMalloc storage(size); | 571 SkAutoMalloc storage(size); |
| 566 if (stream->read(storage.get(), size) != size) { | 572 if (stream->read(storage.get(), size) != size) { |
| 567 return false; | 573 return false; |
| 568 } | 574 } |
| 569 | 575 |
| 570 SkReadBuffer buffer(storage.get(), size); | 576 SkReadBuffer buffer(storage.get(), size); |
| 571 buffer.setFlags(pictInfoFlagsToReadBufferFlags(info.fFlags)); | 577 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags)); |
| 578 buffer.setPictureVersion(fInfo.fVersion); |
| 572 | 579 |
| 573 fFactoryPlayback->setupBuffer(buffer); | 580 fFactoryPlayback->setupBuffer(buffer); |
| 574 fTFPlayback.setupBuffer(buffer); | 581 fTFPlayback.setupBuffer(buffer); |
| 575 buffer.setBitmapDecoder(proc); | 582 buffer.setBitmapDecoder(proc); |
| 576 | 583 |
| 577 while (!buffer.eof()) { | 584 while (!buffer.eof()) { |
| 578 tag = buffer.readUInt(); | 585 tag = buffer.readUInt(); |
| 579 size = buffer.readUInt(); | 586 size = buffer.readUInt(); |
| 580 if (!this->parseBufferTag(buffer, tag, size)) { | 587 if (!this->parseBufferTag(buffer, tag, size)) { |
| 581 return false; | 588 return false; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 default: | 654 default: |
| 648 // The tag was invalid. | 655 // The tag was invalid. |
| 649 return false; | 656 return false; |
| 650 } | 657 } |
| 651 return true; // success | 658 return true; // success |
| 652 } | 659 } |
| 653 | 660 |
| 654 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, | 661 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, |
| 655 const SkPictInfo& info, | 662 const SkPictInfo& info, |
| 656 SkPicture::InstallPixelRe
fProc proc) { | 663 SkPicture::InstallPixelRe
fProc proc) { |
| 657 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); | 664 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf
o))); |
| 658 | 665 |
| 659 if (!playback->parseStream(stream, info, proc)) { | 666 if (!playback->parseStream(stream, proc)) { |
| 660 return NULL; | 667 return NULL; |
| 661 } | 668 } |
| 662 return playback.detach(); | 669 return playback.detach(); |
| 663 } | 670 } |
| 664 | 671 |
| 665 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer) { | 672 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer, |
| 666 SkAutoTDelete<SkPicturePlayback> playback(SkNEW(SkPicturePlayback)); | 673 const SkPictInfo& info) { |
| 674 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf
o))); |
| 675 buffer.setPictureVersion(info.fVersion); |
| 667 | 676 |
| 668 if (!playback->parseBuffer(buffer)) { | 677 if (!playback->parseBuffer(buffer)) { |
| 669 return NULL; | 678 return NULL; |
| 670 } | 679 } |
| 671 return playback.detach(); | 680 return playback.detach(); |
| 672 } | 681 } |
| 673 | 682 |
| 674 bool SkPicturePlayback::parseStream(SkStream* stream, const SkPictInfo& info, | 683 bool SkPicturePlayback::parseStream(SkStream* stream, |
| 675 SkPicture::InstallPixelRefProc proc) { | 684 SkPicture::InstallPixelRefProc proc) { |
| 676 for (;;) { | 685 for (;;) { |
| 677 uint32_t tag = stream->readU32(); | 686 uint32_t tag = stream->readU32(); |
| 678 if (SK_PICT_EOF_TAG == tag) { | 687 if (SK_PICT_EOF_TAG == tag) { |
| 679 break; | 688 break; |
| 680 } | 689 } |
| 681 | 690 |
| 682 uint32_t size = stream->readU32(); | 691 uint32_t size = stream->readU32(); |
| 683 if (!this->parseStreamTag(stream, info, tag, size, proc)) { | 692 if (!this->parseStreamTag(stream, tag, size, proc)) { |
| 684 return false; // we're invalid | 693 return false; // we're invalid |
| 685 } | 694 } |
| 686 } | 695 } |
| 687 return true; | 696 return true; |
| 688 } | 697 } |
| 689 | 698 |
| 690 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) { | 699 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) { |
| 691 for (;;) { | 700 for (;;) { |
| 692 uint32_t tag = buffer.readUInt(); | 701 uint32_t tag = buffer.readUInt(); |
| 693 if (SK_PICT_EOF_TAG == tag) { | 702 if (SK_PICT_EOF_TAG == tag) { |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 for (index = 0; index < fPictureCount; index++) | 1831 for (index = 0; index < fPictureCount; index++) |
| 1823 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1832 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
| 1824 "picture%p, ", fPictureRefs[index]); | 1833 "picture%p, ", fPictureRefs[index]); |
| 1825 if (fPictureCount > 0) | 1834 if (fPictureCount > 0) |
| 1826 SkDebugf("%s0};\n", pBuffer); | 1835 SkDebugf("%s0};\n", pBuffer); |
| 1827 | 1836 |
| 1828 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1837 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
| 1829 } | 1838 } |
| 1830 | 1839 |
| 1831 #endif | 1840 #endif |
| OLD | NEW |