aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkWriteBuffer.h
diff options
context:
space:
mode:
authorGravatar brianosman <brianosman@google.com>2016-05-04 11:06:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-04 11:06:28 -0700
commitfad98562d8f9db63839a8d902a301b174320f27f (patch)
treeb7a94c15a06a7c046308264bef4a9b28e6b69e3d /include/core/SkWriteBuffer.h
parentd9cca4a11a30f1391b56dd53ca2c6615298e2b14 (diff)
Prototype code that turns any/every flattenable into JSON
This makes inspecting things in SkDebugger far more useful - any filter or other complex object on the paint is ultimately visible. You still have to do some guess work to figure out what the fields actually mean, but you can at least cross-reference with the code in flatten(). Screenshots: Before: https://screenshot.googleplex.com/a6JM5HBBe6G.png After : https://screenshot.googleplex.com/XQfr4YJ6mnH.png Changes to public API are just removals and changes to make some functions virtual. TBR=reed@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1920423002 Review-Url: https://codereview.chromium.org/1920423002
Diffstat (limited to 'include/core/SkWriteBuffer.h')
-rw-r--r--include/core/SkWriteBuffer.h104
1 files changed, 71 insertions, 33 deletions
diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h
index b69a75ab12..87ac8bf214 100644
--- a/include/core/SkWriteBuffer.h
+++ b/include/core/SkWriteBuffer.h
@@ -25,15 +25,57 @@ class SkRefCntSet;
class SkWriteBuffer {
public:
+ SkWriteBuffer() {}
+ virtual ~SkWriteBuffer() {}
+
+ virtual bool isCrossProcess() const = 0;
+
+ virtual void writeByteArray(const void* data, size_t size) = 0;
+ void writeDataAsByteArray(SkData* data) {
+ this->writeByteArray(data->data(), data->size());
+ }
+ 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;
+ void write32(int32_t value) {
+ this->writeInt(value);
+ }
+ virtual void writeString(const char* value) = 0;
+
+ virtual void writeFlattenable(const SkFlattenable* flattenable) = 0;
+ virtual void writeColor(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 final : 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,39 +85,35 @@ public:
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 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 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 writeString(const char* value) override;
+
+ void writeFlattenable(const SkFlattenable* flattenable) override;
+ void writeColor(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;
bool writeToStream(SkWStream*);
void writeToMemory(void* dst) { fWriter.flatten(dst); }
SkFactorySet* setFactoryRecorder(SkFactorySet*);
-
- SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
/**