3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef SkWriteBuffer_DEFINED
10 #define SkWriteBuffer_DEFINED
12 #include "SkBitmapHeap.h"
15 #include "SkPicture.h"
17 #include "SkWriter32.h"
22 class SkNamedFactorySet;
28 kCrossProcess_Flag = 1 << 0,
29 kValidation_Flag = 1 << 1,
32 SkWriteBuffer(uint32_t flags = 0);
33 SkWriteBuffer(void* initialStorage, size_t storageSize, uint32_t flags = 0);
36 bool isCrossProcess() const {
37 return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag);
40 SkWriter32* getWriter32() { return &fWriter; }
41 void reset(void* storage = NULL, size_t storageSize = 0) {
42 fWriter.reset(storage, storageSize);
45 uint32_t* reserve(size_t size) { return fWriter.reserve(size); }
47 size_t bytesWritten() const { return fWriter.bytesWritten(); }
49 void writeByteArray(const void* data, size_t size);
50 void writeDataAsByteArray(SkData* data) { this->writeByteArray(data->data(), data->size()); }
51 void writeBool(bool value);
52 void writeFixed(SkFixed value);
53 void writeScalar(SkScalar value);
54 void writeScalarArray(const SkScalar* value, uint32_t count);
55 void writeInt(int32_t value);
56 void writeIntArray(const int32_t* value, uint32_t count);
57 void writeUInt(uint32_t value);
58 void write32(int32_t value);
59 void writeString(const char* value);
60 void writeEncodedString(const void* value, size_t byteLength, SkPaint::TextEncoding encoding);
61 void writeFunctionPtr(void* ptr) { this->writeByteArray(&ptr, sizeof(ptr)); }
63 void writeFlattenable(const SkFlattenable* flattenable);
64 void writeColor(const SkColor& color);
65 void writeColorArray(const SkColor* color, uint32_t count);
66 void writePoint(const SkPoint& point);
67 void writePointArray(const SkPoint* point, uint32_t count);
68 void writeMatrix(const SkMatrix& matrix);
69 void writeIRect(const SkIRect& rect);
70 void writeRect(const SkRect& rect);
71 void writeRegion(const SkRegion& region);
72 void writePath(const SkPath& path);
73 size_t writeStream(SkStream* stream, size_t length);
74 void writeBitmap(const SkBitmap& bitmap);
75 void writeTypeface(SkTypeface* typeface);
76 void writePaint(const SkPaint& paint) { paint.flatten(*this); }
78 bool writeToStream(SkWStream*);
79 void writeToMemory(void* dst) { fWriter.flatten(dst); }
81 SkFactorySet* setFactoryRecorder(SkFactorySet*);
82 SkNamedFactorySet* setNamedFactoryRecorder(SkNamedFactorySet*);
84 SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
85 SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
88 * Set an SkBitmapHeap to store bitmaps rather than flattening.
90 * Incompatible with an EncodeBitmap function. If an EncodeBitmap function is set, setting an
91 * SkBitmapHeap will set the function to NULL in release mode and crash in debug.
93 void setBitmapHeap(SkBitmapHeap*);
96 * Provide a function to encode an SkBitmap to an SkData. writeBitmap will attempt to use
97 * bitmapEncoder to store the SkBitmap. If the reader does not provide a function to decode, it
98 * will not be able to restore SkBitmaps, but will still be able to read the rest of the stream.
99 * bitmapEncoder will never be called with a NULL pixelRefOffset.
101 * Incompatible with the SkBitmapHeap. If an encoder is set fBitmapHeap will be set to NULL in
102 * release and crash in debug.
104 void setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder);
107 bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
109 const uint32_t fFlags;
110 SkFactorySet* fFactorySet;
111 SkNamedFactorySet* fNamedFactorySet;
114 SkBitmapHeap* fBitmapHeap;
117 SkPicture::EncodeBitmap fBitmapEncoder;
120 #endif // SkWriteBuffer_DEFINED