diff options
author | Mike Reed <reed@google.com> | 2017-12-19 15:31:57 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-20 03:20:43 +0000 |
commit | acd59ef08512a337b0ea274576d8d96eaec57e7e (patch) | |
tree | a6559abd81e5d5568e2f0850f39015490acd9954 /src/core/SkWriteBuffer.h | |
parent | f6eb1f9b63da45b7dbd4f26a6edf9d968ac4a517 (diff) |
move SkWriteBuffer.h to src
Need this to land first: https://chromium-review.googlesource.com/c/chromium/src/+/834714
Bug: skia:
Change-Id: I426bc3d9b5c4382b5b874b991e37fdd1725bd9a3
Reviewed-on: https://skia-review.googlesource.com/87301
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core/SkWriteBuffer.h')
-rw-r--r-- | src/core/SkWriteBuffer.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/src/core/SkWriteBuffer.h b/src/core/SkWriteBuffer.h new file mode 100644 index 0000000000..5d03e91caa --- /dev/null +++ b/src/core/SkWriteBuffer.h @@ -0,0 +1,165 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkWriteBuffer_DEFINED +#define SkWriteBuffer_DEFINED + +#include "SkData.h" +#include "SkImage.h" +#include "SkPath.h" +#include "SkPicture.h" +#include "SkRefCnt.h" +#include "SkSerialProcs.h" +#include "SkWriter32.h" +#include "../private/SkTHash.h" + +class SkBitmap; +class SkDeduper; +class SkFactorySet; +class SkFlattenable; +class SkRefCntSet; + +class SK_API SkWriteBuffer { +public: + SkWriteBuffer() {} + virtual ~SkWriteBuffer() {} + + virtual bool isCrossProcess() const = 0; + + virtual void writePad32(const void* buffer, size_t bytes) = 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 writeColor4f(const SkColor4f& color) = 0; + virtual void writeColor4fArray(const SkColor4f* 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 writeImage(const SkImage*) = 0; + virtual void writeTypeface(SkTypeface* typeface) = 0; + virtual void writePaint(const SkPaint& paint) = 0; + + void setDeduper(SkDeduper* deduper) { fDeduper = deduper; } + + /** + * Return a client specified context pointer. This is not interpreted by the writebuffer. + * It defaults to nullptr, but may be set with setClientContext(...). + */ + void* getClientContext() const { return fClientCtx; } + + /** + * Set the client specified context pointer. This is not interpreted by the writebuffer. + * It defaults to nullptr. It can be inspected by calling getClientContext(). + */ + void setClientContext(void* ctx) { fClientCtx = ctx; } + + void setSerialProcs(const SkSerialProcs& procs) { fProcs = procs; } + +protected: + SkDeduper* fDeduper = nullptr; + void* fClientCtx = nullptr; + SkSerialProcs fProcs; + + friend class SkPicture; // fProcs +}; + +/** + * Concrete implementation that serializes to a flat binary blob. + */ +class SK_API SkBinaryWriteBuffer : public SkWriteBuffer { +public: + enum Flags { + kCrossProcess_Flag = 1 << 0, + }; + + SkBinaryWriteBuffer(uint32_t flags = 0); + SkBinaryWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0); + ~SkBinaryWriteBuffer() override; + + bool isCrossProcess() const override { + return SkToBool(fFlags & kCrossProcess_Flag); + } + + void write(const void* buffer, size_t bytes) { + fWriter.write(buffer, bytes); + } + void writePad32(const void* buffer, size_t bytes) override { + fWriter.writePad(buffer, bytes); + } + + void reset(void* storage = nullptr, size_t storageSize = 0) { + fWriter.reset(storage, storageSize); + } + + size_t bytesWritten() const { return fWriter.bytesWritten(); } + + 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 writeColor4f(const SkColor4f& color) override; + void writeColor4fArray(const SkColor4f* 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 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* setTypefaceRecorder(SkRefCntSet*); + +private: + const uint32_t fFlags; + SkFactorySet* fFactorySet; + SkWriter32 fWriter; + + SkRefCntSet* fTFSet; + + // Only used if we do not have an fFactorySet + SkTHashMap<SkString, uint32_t> fFlattenableDict; +}; + +#endif // SkWriteBuffer_DEFINED |