aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/RecordingBench.cpp3
-rw-r--r--include/core/SkPicture.h26
-rw-r--r--include/core/SkSerialProcs.h4
-rw-r--r--src/core/SkPicture.cpp70
-rw-r--r--src/core/SkPictureData.cpp7
-rw-r--r--src/utils/SkMultiPictureDocument.cpp19
-rw-r--r--src/utils/SkMultiPictureDocument.h8
-rw-r--r--tests/ImageTest.cpp2
-rw-r--r--tests/SerialProcsTest.cpp10
-rw-r--r--tools/get_images_from_skps.cpp2
10 files changed, 86 insertions, 65 deletions
diff --git a/bench/RecordingBench.cpp b/bench/RecordingBench.cpp
index dc826553e7..d23d4f4947 100644
--- a/bench/RecordingBench.cpp
+++ b/bench/RecordingBench.cpp
@@ -107,8 +107,7 @@ SkIPoint DeserializePictureBench::onGetSize() {
}
void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
- SkDeserialProcs procs;
for (int i = 0; i < loops; ++i) {
- SkPicture::MakeFromData(fEncodedPicture, procs);
+ SkPicture::MakeFromData(fEncodedPicture.get());
}
}
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index ba01a929f6..85b2368814 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -38,13 +38,10 @@ public:
* Recreate a picture that was serialized into a stream or data.
*/
- static sk_sp<SkPicture> MakeFromStream(SkStream*);
- static sk_sp<SkPicture> MakeFromData(const SkData* data);
- static sk_sp<SkPicture> MakeFromData(const void* data, size_t size);
-
- static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs& procs);
- static sk_sp<SkPicture> MakeFromData(const SkData* data, const SkDeserialProcs& procs);
- static sk_sp<SkPicture> MakeFromData(sk_sp<SkData> data, const SkDeserialProcs& procs);
+ static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs* = nullptr);
+ static sk_sp<SkPicture> MakeFromData(const SkData* data, const SkDeserialProcs* = nullptr);
+ static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
+ const SkDeserialProcs* = nullptr);
/**
* Recreate a picture that was serialized into a buffer. If the creation requires bitmap
@@ -90,9 +87,16 @@ public:
/** Returns a non-zero value unique among all pictures. */
uint32_t uniqueID() const;
- sk_sp<SkData> serialize() const;
- void serialize(SkWStream*) const;
+ sk_sp<SkData> serialize(const SkSerialProcs* = nullptr) const;
+ void serialize(SkWStream*, const SkSerialProcs* = nullptr) const;
+
+#ifdef SK_SUPPORT_LEGACY_SERIALPROCS_REF
sk_sp<SkData> serialize(const SkSerialProcs&) const;
+ static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs& procs);
+ static sk_sp<SkPicture> MakeFromData(const SkData* data, const SkDeserialProcs& procs);
+ static sk_sp<SkPicture> MakeFromData(sk_sp<SkData> data, const SkDeserialProcs& procs);
+ static sk_sp<SkPicture> MakeFromData(sk_sp<SkData>, const SkDeserialProcs* = nullptr);
+#endif
/**
* Serialize to a buffer.
@@ -121,8 +125,8 @@ private:
friend class SkEmptyPicture;
template <typename> friend class SkMiniPicture;
- void serialize(SkWStream*, const SkSerialProcs&, SkRefCntSet* typefaces) const;
- static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs&, SkTypefacePlayback*);
+ void serialize(SkWStream*, const SkSerialProcs*, SkRefCntSet* typefaces) const;
+ static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs*, SkTypefacePlayback*);
friend class SkPictureData;
/** Return true if the SkStream/Buffer represents a serialized picture, and
diff --git a/include/core/SkSerialProcs.h b/include/core/SkSerialProcs.h
index cd8773255c..0c20f08b5c 100644
--- a/include/core/SkSerialProcs.h
+++ b/include/core/SkSerialProcs.h
@@ -36,7 +36,7 @@ typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t lengt
typedef sk_sp<SkImage> (*SkDeserialImageProc)(const void* data, size_t length, void* ctx);
typedef sk_sp<SkTypeface> (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx);
-struct SkSerialProcs {
+struct SK_API SkSerialProcs {
SkSerialPictureProc fPictureProc = nullptr;
void* fPictureCtx = nullptr;
@@ -47,7 +47,7 @@ struct SkSerialProcs {
void* fTypefaceCtx = nullptr;
};
-struct SkDeserialProcs {
+struct SK_API SkDeserialProcs {
SkDeserialPictureProc fPictureProc = nullptr;
void* fPictureCtx = nullptr;
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index b2a83601b0..0d8789a5d6 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -144,28 +144,20 @@ sk_sp<SkPicture> SkPicture::Forwardport(const SkPictInfo& info,
return r.finishRecordingAsPicture();
}
-sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
- return MakeFromStream(stream, SkDeserialProcs(), nullptr);
+sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialProcs* procs) {
+ return MakeFromStream(stream, procs, nullptr);
}
-sk_sp<SkPicture> SkPicture::MakeFromData(const void* data, size_t size) {
+sk_sp<SkPicture> SkPicture::MakeFromData(const void* data, size_t size,
+ const SkDeserialProcs* procs) {
if (!data) {
return nullptr;
}
SkMemoryStream stream(data, size);
- return MakeFromStream(&stream, SkDeserialProcs(), nullptr);
-}
-
-sk_sp<SkPicture> SkPicture::MakeFromData(const SkData* data) {
- if (!data) {
- return nullptr;
- }
- SkMemoryStream stream(data->data(), data->size());
- return MakeFromStream(&stream, SkDeserialProcs(), nullptr);
+ return MakeFromStream(&stream, procs, nullptr);
}
-
-sk_sp<SkPicture> SkPicture::MakeFromData(const SkData* data, const SkDeserialProcs& procs) {
+sk_sp<SkPicture> SkPicture::MakeFromData(const SkData* data, const SkDeserialProcs* procs) {
if (!data) {
return nullptr;
}
@@ -173,21 +165,18 @@ sk_sp<SkPicture> SkPicture::MakeFromData(const SkData* data, const SkDeserialPro
return MakeFromStream(&stream, procs, nullptr);
}
-sk_sp<SkPicture> SkPicture::MakeFromData(sk_sp<SkData> data, const SkDeserialProcs& procs) {
- return MakeFromData(data.get(), procs);
-}
-
-sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialProcs& procs) {
- return MakeFromStream(stream, procs, nullptr);
-}
-
-sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialProcs& procs,
+sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialProcs* procsPtr,
SkTypefacePlayback* typefaces) {
SkPictInfo info;
if (!StreamIsSKP(stream, &info)) {
return nullptr;
}
+ SkDeserialProcs procs;
+ if (procsPtr) {
+ procs = *procsPtr;
+ }
+
switch (stream->readU8()) {
case kPictureData_TrailingStreamByteAfterPictInfo: {
std::unique_ptr<SkPictureData> data(
@@ -244,22 +233,36 @@ SkPictureData* SkPicture::backport() const {
return new SkPictureData(rec, info);
}
-void SkPicture::serialize(SkWStream* stream) const {
- this->serialize(stream, SkSerialProcs(), nullptr);
+void SkPicture::serialize(SkWStream* stream, const SkSerialProcs* procs) const {
+ this->serialize(stream, procs, nullptr);
}
-sk_sp<SkData> SkPicture::serialize() const {
+sk_sp<SkData> SkPicture::serialize(const SkSerialProcs* procs) const {
SkDynamicMemoryWStream stream;
- this->serialize(&stream);
+ this->serialize(&stream, procs, nullptr);
return stream.detachAsData();
}
+#ifdef SK_SUPPORT_LEGACY_SERIALPROCS_REF
sk_sp<SkData> SkPicture::serialize(const SkSerialProcs& procs) const {
- SkDynamicMemoryWStream stream;
- this->serialize(&stream, procs, nullptr);
- return stream.detachAsData();
+ return this->serialize(&procs);
+}
+sk_sp<SkPicture> SkPicture::MakeFromData(const SkData* data, const SkDeserialProcs& procs) {
+ return SkPicture::MakeFromData(data, &procs);
}
+sk_sp<SkPicture> SkPicture::MakeFromData(sk_sp<SkData> data, const SkDeserialProcs& procs) {
+ return SkPicture::MakeFromData(std::move(data), &procs);
+}
+
+sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialProcs& procs) {
+ return SkPicture::MakeFromStream(stream, &procs);
+}
+sk_sp<SkPicture> SkPicture::MakeFromData(sk_sp<SkData> data, const SkDeserialProcs* procs) {
+ return SkPicture::MakeFromData(data.get(), procs);
+}
+#endif
+
static sk_sp<SkData> custom_serialize(const SkPicture* picture, const SkSerialProcs& procs) {
if (procs.fPictureProc) {
auto data = procs.fPictureProc(const_cast<SkPicture*>(picture), procs.fPictureCtx);
@@ -285,8 +288,13 @@ static bool write_pad32(SkWStream* stream, const void* data, size_t size) {
return true;
}
-void SkPicture::serialize(SkWStream* stream, const SkSerialProcs& procs,
+void SkPicture::serialize(SkWStream* stream, const SkSerialProcs* procsPtr,
SkRefCntSet* typefaceSet) const {
+ SkSerialProcs procs;
+ if (procsPtr) {
+ procs = *procsPtr;
+ }
+
SkPictInfo info = this->createHeader();
stream->write(&info, sizeof(info));
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 889e9db453..7c51bd936a 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -293,9 +293,8 @@ void SkPictureData::serialize(SkWStream* stream, const SkSerialProcs& procs,
bool write(const void*, size_t size) override { fBytesWritten += size; return true; }
size_t bytesWritten() const override { return fBytesWritten; }
} devnull;
- SkSerialProcs nullProcs;
for (int i = 0; i < fPictureCount; i++) {
- fPictureRefs[i]->serialize(&devnull, nullProcs, typefaceSet);
+ fPictureRefs[i]->serialize(&devnull, nullptr, typefaceSet);
}
// We need to write factories before we write the buffer.
@@ -313,7 +312,7 @@ void SkPictureData::serialize(SkWStream* stream, const SkSerialProcs& procs,
if (fPictureCount > 0) {
write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount);
for (int i = 0; i < fPictureCount; i++) {
- fPictureRefs[i]->serialize(stream, procs, typefaceSet);
+ fPictureRefs[i]->serialize(stream, &procs, typefaceSet);
}
}
@@ -424,7 +423,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, procs, topLevelTFPlayback).release();
+ fPictureRefs[i] = SkPicture::MakeFromStream(stream, &procs, topLevelTFPlayback).release();
if (!fPictureRefs[i]) {
return false;
}
diff --git a/src/utils/SkMultiPictureDocument.cpp b/src/utils/SkMultiPictureDocument.cpp
index 4ff2d079e3..b3e84dc74e 100644
--- a/src/utils/SkMultiPictureDocument.cpp
+++ b/src/utils/SkMultiPictureDocument.cpp
@@ -10,6 +10,7 @@
#include "SkNWayCanvas.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h"
+#include "SkSerialProcs.h"
#include "SkStream.h"
#include "SkTArray.h"
@@ -45,12 +46,15 @@ static SkSize join(const SkTArray<SkSize>& sizes) {
}
struct MultiPictureDocument final : public SkDocument {
+ const SkSerialProcs fProcs;
SkPictureRecorder fPictureRecorder;
SkSize fCurrentPageSize;
SkTArray<sk_sp<SkPicture>> fPages;
SkTArray<SkSize> fSizes;
- MultiPictureDocument(SkWStream* s, void (*d)(SkWStream*, bool))
- : SkDocument(s, d) {}
+ MultiPictureDocument(SkWStream* s, void (*d)(SkWStream*, bool), const SkSerialProcs* procs)
+ : SkDocument(s, d)
+ , fProcs(procs ? *procs : SkSerialProcs())
+ {}
~MultiPictureDocument() override { this->close(); }
SkCanvas* onBeginPage(SkScalar w, SkScalar h) override {
@@ -77,7 +81,7 @@ struct MultiPictureDocument final : public SkDocument {
c->drawAnnotation(SkRect::MakeEmpty(), kEndPage, nullptr);
}
sk_sp<SkPicture> p = fPictureRecorder.finishRecordingAsPicture();
- p->serialize(wStream);
+ p->serialize(wStream, &fProcs);
fPages.reset();
fSizes.reset();
return;
@@ -89,8 +93,8 @@ struct MultiPictureDocument final : public SkDocument {
};
}
-sk_sp<SkDocument> SkMakeMultiPictureDocument(SkWStream* wStream) {
- return sk_make_sp<MultiPictureDocument>(wStream, nullptr);
+sk_sp<SkDocument> SkMakeMultiPictureDocument(SkWStream* wStream, const SkSerialProcs* procs) {
+ return sk_make_sp<MultiPictureDocument>(wStream, nullptr, procs);
}
////////////////////////////////////////////////////////////////////////////////
@@ -171,7 +175,8 @@ struct PagerCanvas : public SkNWayCanvas {
bool SkMultiPictureDocumentRead(SkStreamSeekable* stream,
SkDocumentPage* dstArray,
- int dstArrayCount) {
+ int dstArrayCount,
+ const SkDeserialProcs* procs) {
if (!SkMultiPictureDocumentReadPageSizes(stream, dstArray, dstArrayCount)) {
return false;
}
@@ -181,7 +186,7 @@ bool SkMultiPictureDocumentRead(SkStreamSeekable* stream,
SkTMax(joined.height(), dstArray[i].fSize.height())};
}
- auto picture = SkPicture::MakeFromStream(stream);
+ auto picture = SkPicture::MakeFromStream(stream, procs);
PagerCanvas canvas(joined.toCeil(), dstArray, dstArrayCount);
// Must call playback(), not drawPicture() to reach
diff --git a/src/utils/SkMultiPictureDocument.h b/src/utils/SkMultiPictureDocument.h
index 0ca8c2de72..7d50683572 100644
--- a/src/utils/SkMultiPictureDocument.h
+++ b/src/utils/SkMultiPictureDocument.h
@@ -4,17 +4,20 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#ifndef SkMultiPictureDocument_DEFINED
#define SkMultiPictureDocument_DEFINED
#include "SkDocument.h"
+struct SkDeserialProcs;
+struct SkSerialProcs;
class SkStreamSeekable;
/**
* Writes into a file format that is similar to SkPicture::serialize()
*/
-SK_API sk_sp<SkDocument> SkMakeMultiPictureDocument(SkWStream* dst);
+SK_API sk_sp<SkDocument> SkMakeMultiPictureDocument(SkWStream* dst, const SkSerialProcs* = nullptr);
struct SkDocumentPage {
sk_sp<SkPicture> fPicture;
@@ -33,6 +36,7 @@ SK_API int SkMultiPictureDocumentReadPageCount(SkStreamSeekable* src);
*/
SK_API bool SkMultiPictureDocumentRead(SkStreamSeekable* src,
SkDocumentPage* dstArray,
- int dstArrayCount);
+ int dstArrayCount,
+ const SkDeserialProcs* = nullptr);
#endif // SkMultiPictureDocument_DEFINED
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index ff058f2ec7..ffccb85e45 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -244,7 +244,7 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
procs.fImageCtx = &was_called;
REPORTER_ASSERT(reporter, !was_called);
- auto data = picture->serialize(procs);
+ auto data = picture->serialize(&procs);
REPORTER_ASSERT(reporter, was_called);
REPORTER_ASSERT(reporter, data && data->size() > 0);
diff --git a/tests/SerialProcsTest.cpp b/tests/SerialProcsTest.cpp
index 0d13c035ec..c408dc7eb6 100644
--- a/tests/SerialProcsTest.cpp
+++ b/tests/SerialProcsTest.cpp
@@ -70,11 +70,11 @@ DEF_TEST(serial_procs_image, reporter) {
for (size_t i = 0; i < SK_ARRAY_COUNT(sprocs); ++i) {
sproc.fImageProc = sprocs[i];
- auto data = pic->serialize(sproc);
+ auto data = pic->serialize(&sproc);
REPORTER_ASSERT(reporter, data);
dproc.fImageProc = dprocs[i];
- auto new_pic = SkPicture::MakeFromData(data, dproc);
+ auto new_pic = SkPicture::MakeFromData(data.get(), &dproc);
REPORTER_ASSERT(reporter, data);
auto dst_img = picture_to_image(new_pic);
@@ -140,9 +140,11 @@ static void test_pictures(skiatest::Reporter* reporter, sk_sp<SkPicture> p0, int
ctx.fSkipMe = p0.get();
}
- auto d0 = p0->serialize(makes(array_serial_proc, &ctx));
+ SkSerialProcs sprocs = makes(array_serial_proc, &ctx);
+ auto d0 = p0->serialize(&sprocs);
REPORTER_ASSERT(reporter, ctx.fArray.count() == count);
- p0 = SkPicture::MakeFromData(d0.get(), maked(array_deserial_proc, &ctx));
+ SkDeserialProcs dprocs = maked(array_deserial_proc, &ctx);
+ p0 = SkPicture::MakeFromData(d0.get(), &dprocs);
REPORTER_ASSERT(reporter, ctx.fArray.count() == 0);
}
diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp
index c81254f2c7..da66e58bdc 100644
--- a/tools/get_images_from_skps.cpp
+++ b/tools/get_images_from_skps.cpp
@@ -141,7 +141,7 @@ static bool get_images_from_file(const SkString& file) {
return SkData::MakeEmpty();
};
procs.fImageCtx = &sniff;
- picture->serialize(procs);
+ picture->serialize(&procs);
return true;
}