10 #ifndef SkWriter32_DEFINED
11 #define SkWriter32_DEFINED
13 #include "../private/SkTemplates.h"
34 SkWriter32(
void* external = NULL,
size_t externalBytes = 0) {
35 this->reset(external, externalBytes);
39 size_t bytesWritten()
const {
return fUsed; }
41 SK_ATTR_DEPRECATED(
"use bytesWritten")
42 size_t size()
const {
return this->bytesWritten(); }
44 void reset(
void* external = NULL,
size_t externalBytes = 0) {
45 SkASSERT(SkIsAlign4((uintptr_t)external));
46 SkASSERT(SkIsAlign4(externalBytes));
48 fData = (uint8_t*)external;
49 fCapacity = externalBytes;
55 uint32_t* reserve(
size_t size) {
56 SkASSERT(SkAlign4(size) == size);
57 size_t offset = fUsed;
58 size_t totalRequired = fUsed + size;
59 if (totalRequired > fCapacity) {
60 this->growToAtLeast(totalRequired);
62 fUsed = totalRequired;
63 return (uint32_t*)(fData + offset);
72 SkASSERT(SkAlign4(offset) == offset);
73 SkASSERT(offset < fUsed);
74 return *(T*)(fData + offset);
83 SkASSERT(SkAlign4(offset) == offset);
84 SkASSERT(offset < fUsed);
85 *(T*)(fData + offset) = value;
88 bool writeBool(
bool value) {
93 void writeInt(int32_t value) {
97 void write8(int32_t value) {
98 *(int32_t*)this->reserve(
sizeof(value)) = value & 0xFF;
101 void write16(int32_t value) {
102 *(int32_t*)this->reserve(
sizeof(value)) = value & 0xFFFF;
105 void write32(int32_t value) {
106 *(int32_t*)this->reserve(
sizeof(value)) = value;
109 void writePtr(
void* value) {
110 *(
void**)this->reserve(
sizeof(value)) = value;
113 void writeScalar(SkScalar value) {
114 *(SkScalar*)this->reserve(
sizeof(value)) = value;
117 void writePoint(
const SkPoint& pt) {
118 *(
SkPoint*)this->reserve(
sizeof(pt)) = pt;
121 void writeRect(
const SkRect& rect) {
122 *(
SkRect*)this->reserve(
sizeof(rect)) = rect;
125 void writeIRect(
const SkIRect& rect) {
126 *(
SkIRect*)this->reserve(
sizeof(rect)) = rect;
129 void writeRRect(
const SkRRect& rrect) {
133 void writePath(
const SkPath& path) {
135 SkASSERT(SkAlign4(size) == size);
139 void writeMatrix(
const SkMatrix& matrix) {
140 size_t size = matrix.writeToMemory(NULL);
141 SkASSERT(SkAlign4(size) == size);
142 matrix.writeToMemory(this->reserve(size));
145 void writeRegion(
const SkRegion& rgn) {
147 SkASSERT(SkAlign4(size) == size);
152 void writeMul4(
const void* values,
size_t size) {
153 this->write(values, size);
160 void write(
const void* values,
size_t size) {
161 SkASSERT(SkAlign4(size) == size);
170 size_t alignedSize = SkAlign4(size);
171 uint32_t* p = this->reserve(alignedSize);
172 if (alignedSize != size) {
173 SkASSERT(alignedSize >= 4);
174 p[alignedSize / 4 - 1] = 0;
194 void writeString(
const char* str,
size_t len = (
size_t)-1);
201 static size_t WriteStringSize(
const char* str,
size_t len = (
size_t)-1);
203 void writeData(
const SkData* data) {
204 uint32_t len = data ? SkToU32(data->
size()) : 0;
207 this->writePad(data->
data(), len);
211 static size_t WriteDataSize(
const SkData* data) {
212 return 4 + SkAlign4(data ? data->
size() : 0);
220 SkASSERT(SkAlign4(offset) == offset);
221 SkASSERT(offset <= bytesWritten());
226 void flatten(
void* dst)
const {
227 memcpy(dst, fData, fUsed);
230 bool writeToStream(
SkWStream* stream)
const {
231 return stream->
write(fData, fUsed);
236 size_t readFromStream(
SkStream* stream,
size_t length) {
237 return stream->
read(this->reservePad(length), length);
245 void growToAtLeast(
size_t size);
251 SkAutoTMalloc<uint8_t> fInternal;
264 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); }
269 double fDoubleAlignment;
void overwriteTAt(size_t offset, const T &value)
Overwrite a T record at offset, which must be a multiple of 4.
Definition: SkWriter32.h:82
uint32_t * reservePad(size_t size)
Reserve size bytes.
Definition: SkWriter32.h:169
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:48
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
size_t writeToMemory(void *buffer) const
Write the region to the buffer, and return the number of bytes written.
Definition: SkPoint.h:156
size_t size() const
Returns the number of bytes stored.
Definition: SkData.h:27
SkWriter32(void *external=NULL, size_t externalBytes=0)
The caller can specify an initial block of storage, which the caller manages.
Definition: SkWriter32.h:34
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
Definition: SkWriter32.h:25
SkData holds an immutable data buffer.
Definition: SkData.h:22
size_t writeToMemory(void *buffer) const
Write the path to the buffer, and return the number of bytes written.
const T & readTAt(size_t offset) const
Read a T record at offset, which must be a multiple of 4.
Definition: SkWriter32.h:71
size_t writeToMemory(void *buffer) const
Write the rrect into the specified buffer.
void rewindToOffset(size_t offset)
Move the cursor back to offset bytes from the beginning.
Definition: SkWriter32.h:219
The SkRegion class encapsulates the geometric region used to specify clipping areas for drawing...
Definition: SkRegion.h:30
SkStream – abstraction for a source of bytes.
Definition: SkStream.h:38
Definition: SkStream.h:182
void writePad(const void *src, size_t size)
Write size bytes from src, and pad to 4 byte alignment with zeroes.
Definition: SkWriter32.h:182
virtual size_t read(void *buffer, size_t size)=0
Reads or skips size number of bytes.
void write(const void *values, size_t size)
Write size bytes from values.
Definition: SkWriter32.h:160
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
sk_careful_memcpy() is just like memcpy(), but guards against undefined behavior. ...
Definition: SkTypes.h:51
virtual bool write(const void *buffer, size_t size)=0
Called to write bytes to a SkWStream.
const void * data() const
Returns the ptr to the data.
Definition: SkData.h:34
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
Helper class to allocated SIZE bytes as part of the writer, and to provide that storage to the constr...
Definition: SkWriter32.h:260