Chromium Code Reviews| Index: src/core/SkPictureData.cpp |
| diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp |
| index 2bcf7798cce4bc630fc640e293985525333f1ffe..c0fc4b4f12c9b7a7f703eef5dfdf9506baa92ffd 100644 |
| --- a/src/core/SkPictureData.cpp |
| +++ b/src/core/SkPictureData.cpp |
| @@ -10,6 +10,7 @@ |
| #include "SkPictureData.h" |
| #include "SkPictureRecord.h" |
| #include "SkReadBuffer.h" |
| +#include "SkTextBlob.h" |
| #include "SkTypeface.h" |
| #include "SkTSort.h" |
| #include "SkWriteBuffer.h" |
| @@ -76,6 +77,17 @@ SkPictureData::SkPictureData(const SkPictureRecord& record, |
| fPictureRefs[i]->ref(); |
| } |
| } |
| + |
|
robertphillips
2014/08/25 21:32:05
templatize (sp) ?
f(malita)
2014/08/25 23:56:02
Done.
|
| + // templetize to consolidate with similar picture logic? |
| + const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); |
| + fTextBlobCount = blobs.count(); |
| + if (fTextBlobCount > 0) { |
| + fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); |
| + for (int i = 0; i < fTextBlobCount; ++i) { |
|
robertphillips
2014/08/25 21:32:05
Could do "= SkRef(blobs[i]);"
f(malita)
2014/08/25 23:56:02
Done.
|
| + fTextBlobRefs[i] = blobs[i]; |
| + fTextBlobRefs[i]->ref(); |
| + } |
| + } |
| } |
| #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE |
| @@ -139,6 +151,8 @@ void SkPictureData::init() { |
| fPaints = NULL; |
| fPictureRefs = NULL; |
| fPictureCount = 0; |
| + fTextBlobRefs = NULL; |
| + fTextBlobCount = 0; |
| fOpData = NULL; |
| fFactoryPlayback = NULL; |
| fBoundingHierarchy = NULL; |
| @@ -158,6 +172,11 @@ SkPictureData::~SkPictureData() { |
| } |
| SkDELETE_ARRAY(fPictureRefs); |
| + for (int i = 0; i < fTextBlobCount; i++) { |
| + fTextBlobRefs[i]->unref(); |
| + } |
| + SkDELETE_ARRAY(fTextBlobRefs); |
| + |
| SkDELETE(fFactoryPlayback); |
| } |
| @@ -268,6 +287,13 @@ void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const { |
| write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); |
| fPathHeap->flatten(buffer); |
| } |
| + |
| + if (fTextBlobCount > 0) { |
| + write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount); |
| + for (i = 0; i < fTextBlobCount; ++i) { |
| + fTextBlobRefs[i]->flatten(buffer); |
| + } |
| + } |
| } |
| void SkPictureData::serialize(SkWStream* stream, |
| @@ -485,6 +511,32 @@ bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, |
| fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); |
| } |
| break; |
| + case SK_PICT_TEXTBLOB_BUFFER_TAG: { |
| + if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs))) { |
| + return false; |
| + } |
| + fTextBlobCount = size; |
| + fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); |
| + bool success = true; |
| + int i = 0; |
| + for ( ; i < fTextBlobCount; i++) { |
| + fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer); |
| + if (NULL == fTextBlobRefs[i]) { |
| + success = false; |
| + break; |
| + } |
| + } |
| + if (!success) { |
| + // Delete all of the blobs that were already created (up to but excluding i): |
| + for (int j = 0; j < i; j++) { |
| + fTextBlobRefs[j]->unref(); |
| + } |
| + // Delete the array |
|
robertphillips
2014/08/25 21:32:05
Don't we need an "fTextBlobRefs = NULL" after the
f(malita)
2014/08/25 23:56:02
That was my thought too, but it doesn't seem neede
|
| + SkDELETE_ARRAY(fTextBlobRefs); |
| + fTextBlobCount = 0; |
| + return false; |
| + } |
| + } break; |
| case SK_PICT_READER_TAG: { |
| SkAutoMalloc storage(size); |
| if (!buffer.readByteArray(storage.get(), size) || |