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

Unified Diff: src/core/SkPictureData.cpp

Issue 2187613002: Deserialize pictures with custom image-deserializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix legacy case, remove null-check Created 4 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/SkPicturePlayback.cpp » ('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 1e946aaa9749d3cfccd98a5d0b6a6ad211c86084..8c641097dcac2b580dad60376996ccfde6db7679 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -43,7 +43,6 @@ SkPictureData::SkPictureData(const SkPictureRecord& record,
fContentInfo.set(record.fContentInfo);
- fBitmaps.reset(); // we never make bitmaps (anymore) during recording
fPaints = record.fPaints;
fPaths.reset(record.fPaths.count());
@@ -135,7 +134,7 @@ SkPictureData::~SkPictureData() {
}
bool SkPictureData::containsBitmaps() const {
- if (fBitmaps.count() > 0 || fImageCount > 0) {
+ if (fBitmapImageCount > 0 || fImageCount > 0) {
return true;
}
for (int i = 0; i < fPictureCount; ++i) {
@@ -223,9 +222,6 @@ void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) {
void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const {
int i, n;
- // we never record bitmaps anymore, only images
- SkASSERT(fBitmaps.count() == 0);
-
if ((n = fPaints.count()) > 0) {
write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
for (i = 0; i < n; i++) {
@@ -361,7 +357,7 @@ static uint32_t pictInfoFlagsToReadBufferFlags(uint32_t pictInfoFlags) {
bool SkPictureData::parseStreamTag(SkStream* stream,
uint32_t tag,
uint32_t size,
- SkPicture::InstallPixelRefProc proc,
+ SkImageDeserializer* factory,
SkTypefacePlayback* topLevelTFPlayback) {
/*
* By the time we encounter BUFFER_SIZE_TAG, we need to have already seen
@@ -414,7 +410,7 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
fPictureCount = 0;
fPictureRefs = new const SkPicture* [size];
for (uint32_t i = 0; i < size; i++) {
- fPictureRefs[i] = SkPicture::MakeFromStream(stream, proc, topLevelTFPlayback).release();
+ fPictureRefs[i] = SkPicture::MakeFromStream(stream, factory, topLevelTFPlayback).release();
if (!fPictureRefs[i]) {
return false;
}
@@ -436,7 +432,7 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
return false;
}
fFactoryPlayback->setupBuffer(buffer);
- buffer.setBitmapDecoder(proc);
+ buffer.setImageDeserializer(factory);
if (fTFPlayback.count() > 0) {
// .skp files <= v43 have typefaces serialized with each sub picture.
@@ -463,7 +459,11 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
}
static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) {
- return buffer.readImage();
+ return buffer.readImage().release();
+}
+
+static const SkImage* create_bitmap_image_from_buffer(SkReadBuffer& buffer) {
+ return buffer.readBitmapAsImage().release();
}
// Need a shallow wrapper to return const SkPicture* to match the other factories,
@@ -512,18 +512,12 @@ bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount,
bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t size) {
switch (tag) {
- case SK_PICT_BITMAP_BUFFER_TAG: {
- const int count = SkToInt(size);
- fBitmaps.reset(count);
- for (int i = 0; i < count; ++i) {
- SkBitmap* bm = &fBitmaps[i];
- if (buffer.readBitmap(bm)) {
- bm->setImmutable();
- } else {
- return false;
- }
+ case SK_PICT_BITMAP_BUFFER_TAG:
+ if (!new_array_from_buffer(buffer, size, &fBitmapImageRefs, &fBitmapImageCount,
+ create_bitmap_image_from_buffer)) {
+ return false;
}
- } break;
+ break;
case SK_PICT_PAINT_BUFFER_TAG: {
const int count = SkToInt(size);
fPaints.reset(count);
@@ -581,14 +575,14 @@ bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t
SkPictureData* SkPictureData::CreateFromStream(SkStream* stream,
const SkPictInfo& info,
- SkPicture::InstallPixelRefProc proc,
+ SkImageDeserializer* factory,
SkTypefacePlayback* topLevelTFPlayback) {
SkAutoTDelete<SkPictureData> data(new SkPictureData(info));
if (!topLevelTFPlayback) {
topLevelTFPlayback = &data->fTFPlayback;
}
- if (!data->parseStream(stream, proc, topLevelTFPlayback)) {
+ if (!data->parseStream(stream, factory, topLevelTFPlayback)) {
return nullptr;
}
return data.release();
@@ -606,7 +600,7 @@ SkPictureData* SkPictureData::CreateFromBuffer(SkReadBuffer& buffer,
}
bool SkPictureData::parseStream(SkStream* stream,
- SkPicture::InstallPixelRefProc proc,
+ SkImageDeserializer* factory,
SkTypefacePlayback* topLevelTFPlayback) {
for (;;) {
uint32_t tag = stream->readU32();
@@ -615,7 +609,7 @@ bool SkPictureData::parseStream(SkStream* stream,
}
uint32_t size = stream->readU32();
- if (!this->parseStreamTag(stream, tag, size, proc, topLevelTFPlayback)) {
+ if (!this->parseStreamTag(stream, tag, size, factory, topLevelTFPlayback)) {
return false; // we're invalid
}
}
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698