Chromium Code Reviews| Index: include/core/SkWriteBuffer.h |
| diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h |
| index 07d6fd1175d7fc193fefcee6f485594781e82b68..bf9c455f6c894f4117f503def1c9b2b1933dd5d2 100644 |
| --- a/include/core/SkWriteBuffer.h |
| +++ b/include/core/SkWriteBuffer.h |
| @@ -26,15 +26,56 @@ class SkRefCntSet; |
|
mtklein
2016/05/02 13:55:15
We might try moving this whole file to include/pri
|
| class SkWriteBuffer { |
| public: |
| + SkWriteBuffer() {} |
| + virtual ~SkWriteBuffer() {} |
| + |
| + virtual bool isCrossProcess() const = 0; |
|
reed1
2016/05/02 12:44:39
Can/should we consider making this non-virtual, an
mtklein
2016/05/02 13:55:15
If it's at all possible I'd prefer an interface he
reed1
2016/05/02 14:04:42
What are the advantages? I was motivated to just s
|
| + |
| + virtual void writeByteArray(const void* data, size_t size) = 0; |
| + virtual void writeDataAsByteArray(SkData* data) = 0; |
|
reed1
2016/05/02 12:44:39
does the "SkData" version need to be virtual?
mtklein
2016/05/02 13:55:15
Making these virtual gives us finer type informati
reed1
2016/05/02 14:04:42
Yea, I thought about that too, but thinking furthe
Brian Osman
2016/05/02 14:49:12
As discussed - I had split it off to capture the e
mtklein
2016/05/02 15:04:43
My preference for an interface here is mostly beca
|
| + virtual void writeBool(bool value) = 0;; |
|
mtklein
2016/05/02 13:55:14
Stray ;.
|
| + 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; |
|
reed1
2016/05/02 12:44:39
How is this different from writeInt? Lets either s
Brian Osman
2016/05/02 14:49:12
They appear to be totally interchangeable in their
mtklein
2016/05/02 15:04:43
Seems like another fine candidate to alias on the
|
| + virtual void writeString(const char* value) = 0; |
| + virtual void writeEncodedString(const void* value, size_t byteLength, |
|
reed1
2016/05/02 12:44:39
Do we use writeEncodedString?
mtklein
2016/05/02 13:55:15
No.
|
| + SkPaint::TextEncoding encoding) = 0; |
| + virtual void writeFunctionPtr(void* ptr) = 0; |
|
reed1
2016/05/02 12:44:39
do we still need writeFunctionPtr?
mtklein
2016/05/02 13:55:14
No. Its one use, in tests/ImageFilterTest.cpp, is
|
| + |
| + virtual void writeFlattenable(const SkFlattenable* flattenable) = 0; |
| + virtual void writeColor(const SkColor& color) = 0; |
|
reed1
2016/05/02 12:44:39
take param by value?
Brian Osman
2016/05/02 14:49:12
Sure.
mtklein
2016/05/02 15:04:43
I suspect points and rects are also faster to pass
|
| + 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; |
|
reed1
2016/05/02 12:44:39
doe writeStream need to be virtual? Doesn't it jus
mtklein
2016/05/02 13:55:15
Yes; no. If we devolve into writeByteArray(), tha
reed1
2016/05/02 14:04:42
Good point about efficiency. I wonder if that coul
mtklein
2016/05/02 15:04:42
We've got more streams than write buffers, so I th
|
| + virtual void writeBitmap(const SkBitmap& bitmap) = 0; |
|
reed1
2016/05/02 12:44:39
Does writeBitmap need to be virtual? i.e. does it
mtklein
2016/05/02 13:55:15
Yes, today writeBitmap() serializes some formats a
reed1
2016/05/02 14:04:42
Yea, but that distinction seems more historical th
mtklein
2016/05/02 15:04:42
Agreed. Generally I want to always do SkImage::Ma
|
| + 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); |
| } |
| @@ -45,41 +86,40 @@ 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 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; |
| + 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; |
| + |
| + 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; |
| bool writeToStream(SkWStream*); |
| void writeToMemory(void* dst) { fWriter.flatten(dst); } |
| SkFactorySet* setFactoryRecorder(SkFactorySet*); |
| - |
| - SkRefCntSet* getTypefaceRecorder() const { return fTFSet; } |
| SkRefCntSet* setTypefaceRecorder(SkRefCntSet*); |
| /** |