aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkFlattenableBuffers.h9
-rw-r--r--include/core/SkPicture.h11
-rw-r--r--include/core/SkSerializationHelpers.h35
-rw-r--r--include/core/SkWriter32.h9
4 files changed, 53 insertions, 11 deletions
diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h
index 763460b12f..f5b853c5ac 100644
--- a/include/core/SkFlattenableBuffers.h
+++ b/include/core/SkFlattenableBuffers.h
@@ -154,11 +154,6 @@ public:
enum Flags {
kCrossProcess_Flag = 0x01,
-
- /**
- * Instructs the writer to always serialize bitmap pixel data.
- */
- kForceFlattenBitmapPixels_Flag = 0x04,
};
uint32_t getFlags() const { return fFlags; }
@@ -168,10 +163,6 @@ public:
return SkToBool(fFlags & kCrossProcess_Flag);
}
- bool persistBitmapPixels() const {
- return (fFlags & (kCrossProcess_Flag | kForceFlattenBitmapPixels_Flag)) != 0;
- }
-
bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
protected:
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 00eadb83a6..203efde916 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -11,6 +11,7 @@
#define SkPicture_DEFINED
#include "SkRefCnt.h"
+#include "SkSerializationHelpers.h"
class SkBitmap;
class SkCanvas;
@@ -40,8 +41,10 @@ public:
/**
* Recreate a picture that was serialized into a stream. *success is set to
* true if the picture was deserialized successfully and false otherwise.
+ * decoder is used to decode any SkBitmaps that were encoded into the stream.
*/
- explicit SkPicture(SkStream*, bool* success = NULL);
+ explicit SkPicture(SkStream*, bool* success = NULL,
+ SkSerializationHelpers::DecodeBitmap decoder = NULL);
virtual ~SkPicture();
/**
@@ -132,7 +135,11 @@ public:
*/
int height() const { return fHeight; }
- void serialize(SkWStream*) const;
+ /**
+ * Serialize to a stream. If non NULL, encoder will be used to encode
+ * any bitmaps in the picture.
+ */
+ void serialize(SkWStream*, SkSerializationHelpers::EncodeBitmap encoder = NULL) const;
/** Signals that the caller is prematurely done replaying the drawing
commands. This can be called from a canvas virtual while the picture
diff --git a/include/core/SkSerializationHelpers.h b/include/core/SkSerializationHelpers.h
new file mode 100644
index 0000000000..8bb2a41d95
--- /dev/null
+++ b/include/core/SkSerializationHelpers.h
@@ -0,0 +1,35 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSerializationHelpers_DEFINED
+#define SkSerializationHelpers_DEFINED
+
+class SkBitmap;
+class SkStream;
+class SkWStream;
+
+namespace SkSerializationHelpers {
+ /**
+ * Function to encode an SkBitmap to an SkWStream. A function with this signature can be passed
+ * to SkPicture::serialize() and SkOrderedWriteBuffer. The function should return true if it
+ * succeeds. Otherwise it should return false so that SkOrderedWriteBuffer can switch to
+ * another method of storing SkBitmaps.
+ */
+ typedef bool (*EncodeBitmap)(SkWStream*, const SkBitmap&);
+
+ /**
+ * Function to decode an SkBitmap from an SkStream. A function with this signature can be
+ * passed to the SkStream constructor for SkPicture and SkOrderedReadBuffer to decode SkBitmaps
+ * which were previously encoded. The function should return true if it succeeds. Otherwise it
+ * should return false so that SkOrderedReadBuffer can skip the data and provide a dummy
+ * SkBitmap.
+ */
+ typedef bool (*DecodeBitmap)(SkStream*, SkBitmap*);
+}
+
+#endif // SkSerializationHelpers_DEFINED
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index fa30f0f8eb..9354d6d16d 100644
--- a/include/core/SkWriter32.h
+++ b/include/core/SkWriter32.h
@@ -143,6 +143,15 @@ public:
memcpy(this->reserve(size), values, size);
}
+ /**
+ * Reserve size bytes. Does not need to be 4 byte aligned. The remaining space (if any) will be
+ * filled in with zeroes.
+ */
+ uint32_t* reservePad(size_t size);
+
+ /**
+ * Write size bytes from src, and pad to 4 byte alignment with zeroes.
+ */
void writePad(const void* src, size_t size);
/**