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

Unified Diff: include/core/SkWriteBuffer.h

Issue 1920423002: Prototype code that turns any/every flattenable into JSON (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Interfacification. Tweaks to SkPaint and ordering of name vs. fields Created 4 years, 8 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
Index: include/core/SkWriteBuffer.h
diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h
index c931ad3fd294bf784f7c5939e3a8d755b9ba6b50..6798b91f6caa1a12028f6b437ffc92d41bdd9027 100644
--- a/include/core/SkWriteBuffer.h
+++ b/include/core/SkWriteBuffer.h
@@ -26,15 +26,59 @@ class SkRefCntSet;
class SkWriteBuffer {
public:
+ SkWriteBuffer() {}
+ virtual ~SkWriteBuffer() {}
+
+ virtual bool isCrossProcess() const = 0;
+
+ // This is the only really leaky abstraction in this interface:
+ virtual uint32_t* reserve(size_t size) = 0;
Brian Osman 2016/04/28 14:22:32 All of the other "binary" parts (and implementatio
+
+ virtual void writeByteArray(const void* data, size_t size) = 0;
+ virtual void writeDataAsByteArray(SkData* data) = 0;
+ virtual void writeBool(bool value) = 0;;
+ virtual void writeScalar(SkScalar value) = 0;
+ virtual void writeScalarArray(const SkScalar* value, uint32_t count) = 0;
+ virtual void writeInt(int32_t value) = 0;
+ virtual void writeIntArray(const int32_t* value, uint32_t count) = 0;
+ virtual void writeUInt(uint32_t value) = 0;
+ virtual void write32(int32_t value) = 0;
+ virtual void writeString(const char* value) = 0;
+ virtual void writeEncodedString(const void* value, size_t byteLength,
+ SkPaint::TextEncoding encoding) = 0;
+ virtual void writeFunctionPtr(void* ptr) = 0;
+
+ virtual void writeFlattenable(const SkFlattenable* flattenable) = 0;
+ virtual void writeColor(const SkColor& color) = 0;
+ virtual void writeColorArray(const SkColor* color, uint32_t count) = 0;
+ virtual void writePoint(const SkPoint& point) = 0;
+ virtual void writePointArray(const SkPoint* point, uint32_t count) = 0;
+ virtual void writeMatrix(const SkMatrix& matrix) = 0;
+ virtual void writeIRect(const SkIRect& rect) = 0;
+ virtual void writeRect(const SkRect& rect) = 0;
+ virtual void writeRegion(const SkRegion& region) = 0;
+ virtual void writePath(const SkPath& path) = 0;
+ virtual size_t writeStream(SkStream* stream, size_t length) = 0;
+ virtual void writeBitmap(const SkBitmap& bitmap) = 0;
+ virtual void writeImage(const SkImage*) = 0;
+ virtual void writeTypeface(SkTypeface* typeface) = 0;
+ virtual void writePaint(const SkPaint& paint) = 0;
+};
+
+/**
+ * Concrete implementation that serializes to a flat binary blob.
+ */
+class SkBinaryWriteBuffer : public SkWriteBuffer {
+public:
enum Flags {
- kCrossProcess_Flag = 1 << 0,
+ kCrossProcess_Flag = 1 << 0,
};
- SkWriteBuffer(uint32_t flags = 0);
- SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
- ~SkWriteBuffer();
+ SkBinaryWriteBuffer(uint32_t flags = 0);
+ SkBinaryWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
+ ~SkBinaryWriteBuffer();
- bool isCrossProcess() const {
+ bool isCrossProcess() const override {
return SkToBool(fFlags & kCrossProcess_Flag);
}
@@ -43,67 +87,68 @@ public:
fWriter.reset(storage, storageSize);
}
- uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
+ uint32_t* reserve(size_t size) override { return fWriter.reserve(size); }
size_t bytesWritten() const { return fWriter.bytesWritten(); }
- void writeByteArray(const void* data, size_t size);
- void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); }
- void writeBool(bool value);
- void writeScalar(SkScalar value);
- void writeScalarArray(const SkScalar* value, uint32_t count);
- void writeInt(int32_t value);
- void writeIntArray(const int32_t* value, uint32_t count);
- void writeUInt(uint32_t value);
- void write32(int32_t value);
- void writeString(const char* value);
- void writeEncodedString(const void* value, size_t byteLength, SkPaint::TextEncoding encoding);
- void writeFunctionPtr(void* ptr) { fWriter.writePtr(ptr); }
-
- void writeFlattenable(const SkFlattenable* flattenable);
- void writeColor(const SkColor& color);
- void writeColorArray(const SkColor* color, uint32_t count);
- void writePoint(const SkPoint& point);
- void writePointArray(const SkPoint* point, uint32_t count);
- void writeMatrix(const SkMatrix& matrix);
- void writeIRect(const SkIRect& rect);
- void writeRect(const SkRect& rect);
- void writeRegion(const SkRegion& region);
- void writePath(const SkPath& path);
- size_t writeStream(SkStream* stream, size_t length);
- void writeBitmap(const SkBitmap& bitmap);
- void writeImage(const SkImage*);
- void writeTypeface(SkTypeface* typeface);
- void writePaint(const SkPaint& paint) { paint.flatten(*this); }
+ void writeByteArray(const void* data, size_t size) override;
+ void writeDataAsByteArray(SkData* data) override {
+ this->writeByteArray(data->data(), data->size());
+ }
+ void writeBool(bool value) override;
+ void writeScalar(SkScalar value) override;
+ void writeScalarArray(const SkScalar* value, uint32_t count) override;
+ void writeInt(int32_t value) override;
+ void writeIntArray(const int32_t* value, uint32_t count) override;
+ void writeUInt(uint32_t value) override;
+ void write32(int32_t value) override;
+ void writeString(const char* value) override;
+ void writeEncodedString(const void* value, size_t byteLength,
+ SkPaint::TextEncoding encoding) override;
+ void writeFunctionPtr(void* ptr) override { fWriter.writePtr(ptr); }
+
+ void writeFlattenable(const SkFlattenable* flattenable) override;
+ void writeColor(const SkColor& color) override;
+ void writeColorArray(const SkColor* color, uint32_t count) override;
+ void writePoint(const SkPoint& point) override;
+ void writePointArray(const SkPoint* point, uint32_t count) override;
+ void writeMatrix(const SkMatrix& matrix) override;
+ void writeIRect(const SkIRect& rect) override;
+ void writeRect(const SkRect& rect) override;
+ void writeRegion(const SkRegion& region) override;
+ void writePath(const SkPath& path) override;
+ size_t writeStream(SkStream* stream, size_t length) override;
+ void writeBitmap(const SkBitmap& bitmap) override;
+ void writeImage(const SkImage*) override;
+ void writeTypeface(SkTypeface* typeface) override;
+ void writePaint(const SkPaint& paint) override { paint.flatten(*this); }
bool writeToStream(SkWStream*);
void writeToMemory(void* dst) { fWriter.flatten(dst); }
SkFactorySet* setFactoryRecorder(SkFactorySet*);
-
- SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
/**
- * Set an SkBitmapHeap to store bitmaps rather than flattening.
- *
- * Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set,
- * setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release
- * and crash in debug.
- */
+ * Set an SkBitmapHeap to store bitmaps rather than flattening.
+ *
+ * Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set,
+ * setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release
+ * and crash in debug.
+ */
void setBitmapHeap(SkBitmapHeap*);
/**
- * Set an SkPixelSerializer to store an encoded representation of pixels,
- * e.g. SkBitmaps.
- *
- * Calls ref() on the serializer.
- *
- * TODO: Encode SkImage pixels as well.
- *
- * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will
- * be set to NULL in release and crash in debug.
- */
+ * Set an SkPixelSerializer to store an encoded representation of pixels,
+ * e.g. SkBitmaps.
+ *
+ * Calls ref() on the serializer.
+ *
+ * TODO: Encode SkImage pixels as well.
+ *
+ * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will
+ * be set to NULL in release and crash in debug.
+ */
void setPixelSerializer(SkPixelSerializer*);
SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; }

Powered by Google App Engine
This is Rietveld 408576698