10 #ifndef SkWriter32_DEFINED
11 #define SkWriter32_DEFINED
13 #include "../private/SkTemplates.h"
35 SkWriter32(
void* external = NULL,
size_t externalBytes = 0) {
36 this->reset(external, externalBytes);
40 size_t bytesWritten()
const {
return fUsed; }
42 SK_ATTR_DEPRECATED(
"use bytesWritten")
43 size_t size()
const {
return this->bytesWritten(); }
45 void reset(
void* external = NULL,
size_t externalBytes = 0) {
46 SkASSERT(SkIsAlign4((uintptr_t)external));
47 SkASSERT(SkIsAlign4(externalBytes));
49 fData = (uint8_t*)external;
50 fCapacity = externalBytes;
56 uint32_t* reserve(
size_t size) {
57 SkASSERT(SkAlign4(size) == size);
58 size_t offset = fUsed;
59 size_t totalRequired = fUsed + size;
60 if (totalRequired > fCapacity) {
61 this->growToAtLeast(totalRequired);
63 fUsed = totalRequired;
64 return (uint32_t*)(fData + offset);
73 SkASSERT(SkAlign4(offset) == offset);
74 SkASSERT(offset < fUsed);
75 return *(T*)(fData + offset);
84 SkASSERT(SkAlign4(offset) == offset);
85 SkASSERT(offset < fUsed);
86 *(T*)(fData + offset) = value;
89 bool writeBool(
bool value) {
94 void writeInt(int32_t value) {
98 void write8(int32_t value) {
99 *(int32_t*)this->reserve(
sizeof(value)) = value & 0xFF;
102 void write16(int32_t value) {
103 *(int32_t*)this->reserve(
sizeof(value)) = value & 0xFFFF;
106 void write32(int32_t value) {
107 *(int32_t*)this->reserve(
sizeof(value)) = value;
110 void writePtr(
void* value) {
111 *(
void**)this->reserve(
sizeof(value)) = value;
114 void writeScalar(SkScalar value) {
115 *(SkScalar*)this->reserve(
sizeof(value)) = value;
118 void writePoint(
const SkPoint& pt) {
119 *(
SkPoint*)this->reserve(
sizeof(pt)) = pt;
122 void writePoint3(
const SkPoint3& pt) {
123 *(
SkPoint3*)this->reserve(
sizeof(pt)) = pt;
126 void writeRect(
const SkRect& rect) {
127 *(
SkRect*)this->reserve(
sizeof(rect)) = rect;
130 void writeIRect(
const SkIRect& rect) {
131 *(
SkIRect*)this->reserve(
sizeof(rect)) = rect;
134 void writeRRect(
const SkRRect& rrect) {
138 void writePath(
const SkPath& path) {
140 SkASSERT(SkAlign4(size) == size);
144 void writeMatrix(
const SkMatrix& matrix) {
145 size_t size = matrix.writeToMemory(NULL);
146 SkASSERT(SkAlign4(size) == size);
147 matrix.writeToMemory(this->reserve(size));
150 void writeRegion(
const SkRegion& rgn) {
152 SkASSERT(SkAlign4(size) == size);
157 void writeMul4(
const void* values,
size_t size) {
158 this->write(values, size);
165 void write(
const void* values,
size_t size) {
166 SkASSERT(SkAlign4(size) == size);
167 sk_careful_memcpy(this->reserve(size), values, size);
175 size_t alignedSize = SkAlign4(size);
176 uint32_t* p = this->reserve(alignedSize);
177 if (alignedSize != size) {
178 SkASSERT(alignedSize >= 4);
179 p[alignedSize / 4 - 1] = 0;
188 sk_careful_memcpy(this->reservePad(size), src, size);
199 void writeString(
const char* str,
size_t len = (
size_t)-1);
206 static size_t WriteStringSize(
const char* str,
size_t len = (
size_t)-1);
208 void writeData(
const SkData* data) {
209 uint32_t len = data ? SkToU32(data->
size()) : 0;
212 this->writePad(data->
data(), len);
216 static size_t WriteDataSize(
const SkData* data) {
217 return 4 + SkAlign4(data ? data->
size() : 0);
225 SkASSERT(SkAlign4(offset) == offset);
226 SkASSERT(offset <= bytesWritten());
231 void flatten(
void* dst)
const {
232 memcpy(dst, fData, fUsed);
235 bool writeToStream(
SkWStream* stream)
const {
236 return stream->
write(fData, fUsed);
241 size_t readFromStream(
SkStream* stream,
size_t length) {
242 return stream->
read(this->reservePad(length), length);
250 void growToAtLeast(
size_t size);
256 SkAutoTMalloc<uint8_t> fInternal;
269 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); }
274 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:83
Definition: SkPoint3.h:13
uint32_t * reservePad(size_t size)
Reserve size bytes.
Definition: SkWriter32.h:174
The SkRRect class represents a rounded rect with a potentially different radii for each corner...
Definition: SkRRect.h:47
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:25
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:35
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:28
Definition: SkWriter32.h:26
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:72
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:224
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:40
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:187
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:165
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:265