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

Unified Diff: src/core/SkPictureData.cpp

Issue 499413002: SkTextBlob plumbing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: review comments Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureData.cpp
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 2bcf7798cce4bc630fc640e293985525333f1ffe..86a338899eb2ce4c32ec26e743639b53626926b5 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,16 @@ SkPictureData::SkPictureData(const SkPictureRecord& record,
fPictureRefs[i]->ref();
}
}
+
+ // templatize 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) {
+ fTextBlobRefs[i] = SkRef(blobs[i]);
+ }
+ }
}
#ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE
@@ -139,6 +150,8 @@ void SkPictureData::init() {
fPaints = NULL;
fPictureRefs = NULL;
fPictureCount = 0;
+ fTextBlobRefs = NULL;
+ fTextBlobCount = 0;
fOpData = NULL;
fFactoryPlayback = NULL;
fBoundingHierarchy = NULL;
@@ -158,6 +171,11 @@ SkPictureData::~SkPictureData() {
}
SkDELETE_ARRAY(fPictureRefs);
+ for (int i = 0; i < fTextBlobCount; i++) {
+ fTextBlobRefs[i]->unref();
+ }
+ SkDELETE_ARRAY(fTextBlobRefs);
+
SkDELETE(fFactoryPlayback);
}
@@ -268,6 +286,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 +510,33 @@ 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
+ SkDELETE_ARRAY(fTextBlobRefs);
+ fTextBlobRefs = NULL;
+ fTextBlobCount = 0;
+ return false;
+ }
+ } break;
case SK_PICT_READER_TAG: {
SkAutoMalloc storage(size);
if (!buffer.readByteArray(storage.get(), size) ||
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698