aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-12-05 15:11:24 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-05 20:33:18 +0000
commit60691a5127852631b03250f15fa6cda9a504befc (patch)
tree3ee27fd4857e58c890c5f0a2292749885b2a14de /include
parentc8037dc5edda42cacd839df4e1c7d8cfd0953309 (diff)
add serial procs to pictures
Bug: skia:7380 Change-Id: Ic1b7e437316c7913711cf5cb119e3fe904cd2c05 Reviewed-on: https://skia-review.googlesource.com/76980 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkPicture.h12
-rw-r--r--include/core/SkSerialProcs.h60
-rw-r--r--include/core/SkWriteBuffer.h31
3 files changed, 90 insertions, 13 deletions
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index b3bc96bb88..1e32636ca3 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -17,6 +17,7 @@ class SkBigPicture;
class SkBitmap;
class SkCanvas;
class SkData;
+struct SkDeserialProcs;
class SkImage;
class SkImageDeserializer;
class SkPath;
@@ -24,6 +25,7 @@ class SkPictureData;
class SkPixelSerializer;
class SkReadBuffer;
class SkRefCntSet;
+struct SkSerialProcs;
class SkStream;
class SkTypefacePlayback;
class SkWStream;
@@ -62,6 +64,10 @@ public:
SkImageDeserializer* = nullptr);
static sk_sp<SkPicture> MakeFromData(const SkData* data, SkImageDeserializer* = nullptr);
+ 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);
+
/**
* Recreate a picture that was serialized into a buffer. If the creation requires bitmap
* decoding, the decoder must be set on the SkReadBuffer parameter by calling
@@ -112,6 +118,8 @@ public:
*/
sk_sp<SkData> serialize(SkPixelSerializer* = nullptr) const;
+ sk_sp<SkData> serialize(const SkSerialProcs&) const;
+
/**
* Serialize to a stream. If non nullptr, pixel-serializer will be used to
* customize how images reference by the picture are serialized/compressed.
@@ -169,8 +177,8 @@ private:
friend class SkEmptyPicture;
template <typename> friend class SkMiniPicture;
- void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet* typefaces) const;
- static sk_sp<SkPicture> MakeFromStream(SkStream*, SkImageDeserializer*, SkTypefacePlayback*);
+ void serialize(SkWStream*, const SkSerialProcs&, SkRefCntSet* typefaces) const;
+ static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs&, SkTypefacePlayback*);
friend class SkPictureData;
virtual int numSlowPaths() const = 0;
diff --git a/include/core/SkSerialProcs.h b/include/core/SkSerialProcs.h
new file mode 100644
index 0000000000..d55d1a8405
--- /dev/null
+++ b/include/core/SkSerialProcs.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSerialProcs_DEFINED
+#define SkSerialProcs_DEFINED
+
+#include "SkImage.h"
+#include "SkPicture.h"
+#include "SkTypeface.h"
+
+/**
+ * A serial-proc is asked to serialize the specified object (e.g. picture or image), by writing
+ * its serialized form into the specified stream. If the proc does this, it returns true.
+ *
+ * If the proc chooses to have Skia perform its default action, it ignores the stream parameter
+ * and just returns false.
+ */
+
+typedef bool (*SkSerialPictureProc)(SkPicture*, SkWStream*, void* ctx);
+typedef bool (*SkSerialImageProc)(SkImage*, SkWStream*, void* ctx);
+typedef bool (*SkSerialTypefaceProc)(SkTypeface*, SkWStream*, void* ctx);
+
+/**
+ * A deserial-proc is given the serialized form previously returned by the corresponding
+ * serial-proc, and should return the re-constituted object. In case of an error, the proc
+ * can return nullptr.
+ */
+
+typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx);
+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 {
+ SkSerialPictureProc fPictureProc = nullptr;
+ void* fPictureCtx = nullptr;
+
+ SkSerialImageProc fImageProc = nullptr;
+ void* fImageCtx = nullptr;
+
+ SkSerialTypefaceProc fTypefaceProc = nullptr;
+ void* fTypefaceCtx = nullptr;
+};
+
+struct SkDeserialProcs {
+ SkDeserialPictureProc fPictureProc = nullptr;
+ void* fPictureCtx = nullptr;
+
+ SkDeserialImageProc fImageProc = nullptr;
+ void* fImageCtx = nullptr;
+
+ SkDeserialTypefaceProc fTypefaceProc = nullptr;
+ void* fTypefaceCtx = nullptr;
+};
+
+#endif
+
diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h
index b2db00873a..42d8f96eb9 100644
--- a/include/core/SkWriteBuffer.h
+++ b/include/core/SkWriteBuffer.h
@@ -9,15 +9,21 @@
#ifndef SkWriteBuffer_DEFINED
#define SkWriteBuffer_DEFINED
+#define SK_SUPPORT_LEGACY_SERIAL_BUFFER_OBJECTS
+
#include "SkData.h"
#include "SkImage.h"
#include "SkPath.h"
#include "SkPicture.h"
-#include "SkPixelSerializer.h"
#include "SkRefCnt.h"
+#include "SkSerialProcs.h"
#include "SkWriter32.h"
#include "../private/SkTHash.h"
+#ifdef SK_SUPPORT_LEGACY_SERIAL_BUFFER_OBJECTS
+#include "SkPixelSerializer.h"
+#endif
+
class SkBitmap;
class SkDeduper;
class SkFactorySet;
@@ -102,6 +108,9 @@ public:
void write(const void* buffer, size_t bytes) {
fWriter.write(buffer, bytes);
}
+ void writePad32(const void* buffer, size_t bytes) {
+ fWriter.writePad(buffer, bytes);
+ }
void reset(void* storage = nullptr, size_t storageSize = 0) {
fWriter.reset(storage, storageSize);
@@ -141,26 +150,26 @@ public:
SkFactorySet* setFactoryRecorder(SkFactorySet*);
SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
- /**
- * Set an SkPixelSerializer to store an encoded representation of pixels,
- * e.g. SkBitmaps.
- *
- * TODO: Encode SkImage pixels as well.
- */
+ void setSerialProcs(const SkSerialProcs& procs) { fProcs = procs; }
+
+#ifdef SK_SUPPORT_LEGACY_SERIAL_BUFFER_OBJECTS
void setPixelSerializer(sk_sp<SkPixelSerializer>);
- SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer.get(); }
+#endif
private:
const uint32_t fFlags;
SkFactorySet* fFactorySet;
SkWriter32 fWriter;
- SkRefCntSet* fTFSet;
-
- sk_sp<SkPixelSerializer> fPixelSerializer;
+ SkRefCntSet* fTFSet;
+ SkSerialProcs fProcs;
// Only used if we do not have an fFactorySet
SkTHashMap<SkString, uint32_t> fFlattenableDict;
+
+#ifdef SK_SUPPORT_LEGACY_SERIAL_BUFFER_OBJECTS
+ sk_sp<SkPixelSerializer> fPS;
+#endif
};
#endif // SkWriteBuffer_DEFINED