2014-01-30 18:58:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
2016-03-24 17:41:47 +00:00
|
|
|
#include "SkImage.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPicture.h"
|
2014-12-11 18:53:58 +00:00
|
|
|
#include "SkPixelSerializer.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkWriter32.h"
|
2016-04-22 19:43:07 +00:00
|
|
|
#include "../private/SkTHash.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
|
|
|
|
class SkBitmap;
|
2016-09-13 15:09:45 +00:00
|
|
|
class SkDeduper;
|
2014-01-30 18:58:24 +00:00
|
|
|
class SkFactorySet;
|
|
|
|
class SkFlattenable;
|
|
|
|
class SkRefCntSet;
|
|
|
|
|
|
|
|
class SkWriteBuffer {
|
2016-05-04 18:06:28 +00:00
|
|
|
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;
|
2016-09-13 15:09:45 +00:00
|
|
|
|
|
|
|
void setDeduper(SkDeduper* deduper) { fDeduper = deduper; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkDeduper* fDeduper = nullptr;
|
2016-05-04 18:06:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete implementation that serializes to a flat binary blob.
|
|
|
|
*/
|
2016-09-13 15:09:45 +00:00
|
|
|
class SkBinaryWriteBuffer : public SkWriteBuffer {
|
2014-01-30 18:58:24 +00:00
|
|
|
public:
|
|
|
|
enum Flags {
|
2016-05-04 18:06:28 +00:00
|
|
|
kCrossProcess_Flag = 1 << 0,
|
2014-01-30 18:58:24 +00:00
|
|
|
};
|
|
|
|
|
2016-05-04 18:06:28 +00:00
|
|
|
SkBinaryWriteBuffer(uint32_t flags = 0);
|
|
|
|
SkBinaryWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
|
|
|
|
~SkBinaryWriteBuffer();
|
2014-01-30 22:16:32 +00:00
|
|
|
|
2016-05-04 18:06:28 +00:00
|
|
|
bool isCrossProcess() const override {
|
2016-04-22 19:43:07 +00:00
|
|
|
return SkToBool(fFlags & kCrossProcess_Flag);
|
2014-01-30 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
void write(const void* buffer, size_t bytes) {
|
|
|
|
fWriter.write(buffer, bytes);
|
|
|
|
}
|
|
|
|
|
2014-01-30 18:58:24 +00:00
|
|
|
void reset(void* storage = NULL, size_t storageSize = 0) {
|
|
|
|
fWriter.reset(storage, storageSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t bytesWritten() const { return fWriter.bytesWritten(); }
|
|
|
|
|
2016-05-04 18:06:28 +00:00
|
|
|
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;
|
2014-01-30 18:58:24 +00:00
|
|
|
|
|
|
|
bool writeToStream(SkWStream*);
|
|
|
|
void writeToMemory(void* dst) { fWriter.flatten(dst); }
|
|
|
|
|
|
|
|
SkFactorySet* setFactoryRecorder(SkFactorySet*);
|
|
|
|
SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
|
|
|
|
|
|
|
|
/**
|
2014-12-11 18:53:58 +00:00
|
|
|
* Set an SkPixelSerializer to store an encoded representation of pixels,
|
|
|
|
* e.g. SkBitmaps.
|
2014-01-30 18:58:24 +00:00
|
|
|
*
|
2014-12-11 18:53:58 +00:00
|
|
|
* Calls ref() on the serializer.
|
|
|
|
*
|
|
|
|
* TODO: Encode SkImage pixels as well.
|
2014-01-30 18:58:24 +00:00
|
|
|
*/
|
2014-12-11 18:53:58 +00:00
|
|
|
void setPixelSerializer(SkPixelSerializer*);
|
2015-06-22 19:48:26 +00:00
|
|
|
SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; }
|
2014-01-30 18:58:24 +00:00
|
|
|
|
|
|
|
private:
|
2014-01-30 22:16:32 +00:00
|
|
|
const uint32_t fFlags;
|
2014-01-30 18:58:24 +00:00
|
|
|
SkFactorySet* fFactorySet;
|
|
|
|
SkWriter32 fWriter;
|
|
|
|
|
|
|
|
SkRefCntSet* fTFSet;
|
|
|
|
|
2014-12-11 18:53:58 +00:00
|
|
|
SkAutoTUnref<SkPixelSerializer> fPixelSerializer;
|
2016-04-22 19:43:07 +00:00
|
|
|
|
|
|
|
// Only used if we do not have an fFactorySet
|
|
|
|
SkTHashMap<SkString, uint32_t> fFlattenableDict;
|
2014-01-30 18:58:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkWriteBuffer_DEFINED
|