aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPicture.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-08-18 08:29:59 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-18 08:29:59 -0700
commit0c263fa9f80b9a20b6f6161a2e9a263c2c586a9b (patch)
tree64e5dea42a1fe90995313c798ad39dea4ded1145 /src/core/SkPicture.cpp
parenta83593b88a38765eba5f349d4e12d66b3e626af9 (diff)
Deduplicate typefaces across sub-pictures
Old flow to serialize a picture: 1) serialize picture ops 2) serialize all sub pictures recursively 3) flatten the rest of this picture into a buffer, deduping flattenable factories and typefaces as we go 4) serialize the factories and typefaces 5) serialize the bytes from 3) This allows the data in step 5) to refer to the deduplicated factories and typefaces from step 4). But, each sub picture in step 2) is completely siloed, so they can't dedup with the parent picture or each other. New flow: 1) serialize picture ops 2) flatten the rest of this picture into a buffer, deduping flattenable factories and typefaces as we go 3) dummy-serialize sub pictures into /dev/null, with the effect of adding any new typefaces to our dedup set 4) serialize the factories and typefaces 5) serialize the bytes from 2) 6) serialize all sub pictures recursively, with perfect deduplication because of step 3). Now all typefaces in the top-level picture and all sub pictures recursively should end up deduplicated in the top-level typeface set. Decoding changes are similar: we just thread through the top-level typefaces to the sub pictures. What's convenient / surprising is that this new code correctly reads old pictures if we just have each picture prefer its local typeface set over the top-level one: old pictures always just use their own typefaces, and new pictures always use the top-level ones. BUG=skia:4092 Review URL: https://codereview.chromium.org/1233953004
Diffstat (limited to 'src/core/SkPicture.cpp')
-rw-r--r--src/core/SkPicture.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 02d495e4c6..26ec76184e 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -139,11 +139,18 @@ SkPicture* SkPicture::Forwardport(const SkPictInfo& info, const SkPictureData* d
}
SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
+ return CreateFromStream(stream, proc, nullptr);
+}
+
+SkPicture* SkPicture::CreateFromStream(SkStream* stream,
+ InstallPixelRefProc proc,
+ SkTypefacePlayback* typefaces) {
SkPictInfo info;
if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
return nullptr;
}
- SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromStream(stream, info, proc));
+ SkAutoTDelete<SkPictureData> data(
+ SkPictureData::CreateFromStream(stream, info, proc, typefaces));
return Forwardport(info, data);
}
@@ -166,13 +173,19 @@ SkPictureData* SkPicture::backport() const {
}
void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) const {
+ this->serialize(stream, pixelSerializer, nullptr);
+}
+
+void SkPicture::serialize(SkWStream* stream,
+ SkPixelSerializer* pixelSerializer,
+ SkRefCntSet* typefaceSet) const {
SkPictInfo info = this->createHeader();
SkAutoTDelete<SkPictureData> data(this->backport());
stream->write(&info, sizeof(info));
if (data) {
stream->writeBool(true);
- data->serialize(stream, pixelSerializer);
+ data->serialize(stream, pixelSerializer, typefaceSet);
} else {
stream->writeBool(false);
}