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"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
class SkBitmap;
|
2014-11-13 20:52:35 +00:00
|
|
|
class SkBitmapHeap;
|
2014-01-30 18:58:24 +00:00
|
|
|
class SkFactorySet;
|
|
|
|
class SkFlattenable;
|
|
|
|
class SkNamedFactorySet;
|
|
|
|
class SkRefCntSet;
|
|
|
|
|
|
|
|
class SkWriteBuffer {
|
|
|
|
public:
|
|
|
|
enum Flags {
|
|
|
|
kCrossProcess_Flag = 1 << 0,
|
|
|
|
kValidation_Flag = 1 << 1,
|
|
|
|
};
|
|
|
|
|
2014-01-30 22:16:32 +00:00
|
|
|
SkWriteBuffer(uint32_t flags = 0);
|
|
|
|
SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
|
|
|
|
~SkWriteBuffer();
|
|
|
|
|
2014-01-30 18:58:24 +00:00
|
|
|
bool isCrossProcess() const {
|
|
|
|
return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkWriter32* getWriter32() { return &fWriter; }
|
|
|
|
void reset(void* storage = NULL, size_t storageSize = 0) {
|
|
|
|
fWriter.reset(storage, storageSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t* reserve(size_t size) { 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 writeFixed(SkFixed 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);
|
2014-04-16 16:24:08 +00:00
|
|
|
void writeFunctionPtr(void* ptr) { fWriter.writePtr(ptr); }
|
2014-01-30 18:58:24 +00:00
|
|
|
|
|
|
|
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);
|
2015-06-22 19:48:26 +00:00
|
|
|
void writeImage(const SkImage*);
|
2014-01-30 18:58:24 +00:00
|
|
|
void writeTypeface(SkTypeface* typeface);
|
|
|
|
void writePaint(const SkPaint& paint) { paint.flatten(*this); }
|
|
|
|
|
|
|
|
bool writeToStream(SkWStream*);
|
|
|
|
void writeToMemory(void* dst) { fWriter.flatten(dst); }
|
|
|
|
|
|
|
|
SkFactorySet* setFactoryRecorder(SkFactorySet*);
|
|
|
|
SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
|
|
|
|
|
|
|
|
SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
|
|
|
|
SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an SkBitmapHeap to store bitmaps rather than flattening.
|
|
|
|
*
|
2014-12-11 18:53:58 +00:00
|
|
|
* Incompatible with an SkPixelSerializer. If an SkPixelSerializer is set,
|
|
|
|
* setting an SkBitmapHeap will set the SkPixelSerializer to NULL in release
|
|
|
|
* and crash in debug.
|
2014-01-30 18:58:24 +00:00
|
|
|
*/
|
|
|
|
void setBitmapHeap(SkBitmapHeap*);
|
|
|
|
|
|
|
|
/**
|
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.
|
|
|
|
*
|
|
|
|
* Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will
|
|
|
|
* be set to NULL in release and crash in debug.
|
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
|
|
|
bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
|
|
|
|
|
|
|
|
const uint32_t fFlags;
|
2014-01-30 18:58:24 +00:00
|
|
|
SkFactorySet* fFactorySet;
|
|
|
|
SkNamedFactorySet* fNamedFactorySet;
|
|
|
|
SkWriter32 fWriter;
|
|
|
|
|
|
|
|
SkBitmapHeap* fBitmapHeap;
|
|
|
|
SkRefCntSet* fTFSet;
|
|
|
|
|
2014-12-11 18:53:58 +00:00
|
|
|
SkAutoTUnref<SkPixelSerializer> fPixelSerializer;
|
2014-01-30 18:58:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkWriteBuffer_DEFINED
|