Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkWriter32 Class Reference

#include <SkWriter32.h>

Inheritance diagram for SkWriter32:
SkNoncopyable SkSWriter32< SIZE >

Public Member Functions

 SkWriter32 (void *external=nullptr, size_t externalBytes=0)
 
size_t bytesWritten () const
 
bool usingInitialStorage () const
 
void reset (void *external=nullptr, size_t externalBytes=0)
 
uint32_t * reserve (size_t size)
 
template<typename T >
const TreadTAt (size_t offset) const
 
template<typename T >
void overwriteTAt (size_t offset, const T &value)
 
bool writeBool (bool value)
 
void writeInt (int32_t value)
 
void write8 (int32_t value)
 
void write16 (int32_t value)
 
void write32 (int32_t value)
 
void writeScalar (SkScalar value)
 
void writePoint (const SkPoint &pt)
 
void writePoint3 (const SkPoint3 &pt)
 
void writeRect (const SkRect &rect)
 
void writeIRect (const SkIRect &rect)
 
void writeRRect (const SkRRect &rrect)
 
void writePath (const SkPath &path)
 
void writeMatrix (const SkMatrix &matrix)
 
void writeRegion (const SkRegion &rgn)
 
void writeSampling (const SkSamplingOptions &sampling)
 
void writeMul4 (const void *values, size_t size)
 
void write (const void *values, size_t size)
 
uint32_t * reservePad (size_t size)
 
void writePad (const void *src, size_t size)
 
void writeString (const char *str, size_t len=(size_t) -1)
 
void writeData (const SkData *data)
 
void rewindToOffset (size_t offset)
 
void flatten (void *dst) const
 
bool writeToStream (SkWStream *stream) const
 
size_t readFromStream (SkStream *stream, size_t length)
 
sk_sp< SkDatasnapshotAsData () const
 

Static Public Member Functions

static size_t WriteStringSize (const char *str, size_t len=(size_t) -1)
 
static size_t WriteDataSize (const SkData *data)
 

Detailed Description

Definition at line 34 of file SkWriter32.h.

Constructor & Destructor Documentation

◆ SkWriter32()

SkWriter32::SkWriter32 ( void *  external = nullptr,
size_t  externalBytes = 0 
)
inline

The caller can specify an initial block of storage, which the caller manages.

SkWriter32 will try to back reserve and write calls with this external storage until the first time an allocation doesn't fit. From then it will use dynamically allocated storage. This used to be optional behavior, but pipe now relies on it.

Definition at line 43 of file SkWriter32.h.

43 {
44 this->reset(external, externalBytes);
45 }
void reset(void *external=nullptr, size_t externalBytes=0)
Definition: SkWriter32.h:54

Member Function Documentation

◆ bytesWritten()

size_t SkWriter32::bytesWritten ( ) const
inline

Definition at line 48 of file SkWriter32.h.

48{ return fUsed; }

◆ flatten()

void SkWriter32::flatten ( void *  dst) const
inline

Definition at line 235 of file SkWriter32.h.

235 {
236 memcpy(dst, fData, fUsed);
237 }
dst
Definition: cp.py:12

◆ overwriteTAt()

template<typename T >
void SkWriter32::overwriteTAt ( size_t  offset,
const T value 
)
inline

Overwrite a T record at offset, which must be a multiple of 4. Only legal if the record was written atomically using the write methods below.

Definition at line 94 of file SkWriter32.h.

94 {
96 SkASSERT(offset < fUsed);
97 *(T*)(fData + offset) = value;
98 }
static constexpr T SkAlign4(T x)
Definition: SkAlign.h:16
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint8_t value
#define T
Definition: precompiler.cc:65
SeparatedVector2 offset

◆ readFromStream()

size_t SkWriter32::readFromStream ( SkStream stream,
size_t  length 
)
inline

Definition at line 245 of file SkWriter32.h.

245 {
246 return stream->read(this->reservePad(length), length);
247 }
uint32_t * reservePad(size_t size)
Definition: SkWriter32.h:179
size_t length

◆ readTAt()

template<typename T >
const T & SkWriter32::readTAt ( size_t  offset) const
inline

Read a T record at offset, which must be a multiple of 4. Only legal if the record was written atomically using the write methods below.

Definition at line 83 of file SkWriter32.h.

83 {
85 SkASSERT(offset < fUsed);
86 return *(T*)(fData + offset);
87 }

◆ reserve()

uint32_t * SkWriter32::reserve ( size_t  size)
inline

Definition at line 67 of file SkWriter32.h.

67 {
69 size_t offset = fUsed;
70 size_t totalRequired = fUsed + size;
71 if (totalRequired > fCapacity) {
72 this->growToAtLeast(totalRequired);
73 }
74 fUsed = totalRequired;
75 return (uint32_t*)(fData + offset);
76 }
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ reservePad()

uint32_t * SkWriter32::reservePad ( size_t  size)
inline

Reserve size bytes. Does not need to be 4 byte aligned. The remaining space (if any) will be filled in with zeroes.

Definition at line 179 of file SkWriter32.h.

179 {
180 size_t alignedSize = SkAlign4(size);
181 uint32_t* p = this->reserve(alignedSize);
182 if (alignedSize != size) {
183 SkASSERT(alignedSize >= 4);
184 p[alignedSize / 4 - 1] = 0;
185 }
186 return p;
187 }
uint32_t * reserve(size_t size)
Definition: SkWriter32.h:67

◆ reset()

void SkWriter32::reset ( void *  external = nullptr,
size_t  externalBytes = 0 
)
inline

Definition at line 54 of file SkWriter32.h.

54 {
55 // we cast this pointer to int* and float* at times, so assert that it is aligned.
56 SkASSERT(SkIsAlign4((uintptr_t)external));
57 // we always write multiples of 4-bytes, so truncate down the size to match that
58 externalBytes &= ~3;
59
60 fData = (uint8_t*)external;
61 fCapacity = externalBytes;
62 fUsed = 0;
63 fExternal = external;
64 }
static constexpr bool SkIsAlign4(T x)
Definition: SkAlign.h:20

◆ rewindToOffset()

void SkWriter32::rewindToOffset ( size_t  offset)
inline

Move the cursor back to offset bytes from the beginning. offset must be a multiple of 4 no greater than size().

Definition at line 228 of file SkWriter32.h.

228 {
231 fUsed = offset;
232 }
size_t bytesWritten() const
Definition: SkWriter32.h:48

◆ snapshotAsData()

sk_sp< SkData > SkWriter32::snapshotAsData ( ) const

Captures a snapshot of the data as it is right now, and return it.

Definition at line 78 of file SkWriter32.cpp.

78 {
79 return SkData::MakeWithCopy(fData, fUsed);
80}
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111

◆ usingInitialStorage()

bool SkWriter32::usingInitialStorage ( ) const
inline

Definition at line 52 of file SkWriter32.h.

52{ return fData == fExternal; }

◆ write()

void SkWriter32::write ( const void *  values,
size_t  size 
)
inline

Write size bytes from values. size must be a multiple of 4, though values need not be 4-byte aligned.

Definition at line 170 of file SkWriter32.h.

170 {
173 }
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition: SkMalloc.h:125

◆ write16()

void SkWriter32::write16 ( int32_t  value)
inline

Definition at line 113 of file SkWriter32.h.

113 {
114 *(int32_t*)this->reserve(sizeof(value)) = value & 0xFFFF;
115 }

◆ write32()

void SkWriter32::write32 ( int32_t  value)
inline

Definition at line 117 of file SkWriter32.h.

117 {
118 *(int32_t*)this->reserve(sizeof(value)) = value;
119 }

◆ write8()

void SkWriter32::write8 ( int32_t  value)
inline

Definition at line 109 of file SkWriter32.h.

109 {
110 *(int32_t*)this->reserve(sizeof(value)) = value & 0xFF;
111 }

◆ writeBool()

bool SkWriter32::writeBool ( bool  value)
inline

Definition at line 100 of file SkWriter32.h.

100 {
101 this->write32(value);
102 return value;
103 }
void write32(int32_t value)
Definition: SkWriter32.h:117

◆ writeData()

void SkWriter32::writeData ( const SkData data)
inline

Definition at line 212 of file SkWriter32.h.

212 {
213 uint32_t len = data ? SkToU32(data->size()) : 0;
214 this->write32(len);
215 if (data) {
216 this->writePad(data->data(), len);
217 }
218 }
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
const void * data() const
Definition: SkData.h:37
void writePad(const void *src, size_t size)
Definition: SkWriter32.h:192
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ WriteDataSize()

static size_t SkWriter32::WriteDataSize ( const SkData data)
inlinestatic

Definition at line 220 of file SkWriter32.h.

220 {
221 return 4 + SkAlign4(data ? data->size() : 0);
222 }

◆ writeInt()

void SkWriter32::writeInt ( int32_t  value)
inline

Definition at line 105 of file SkWriter32.h.

105 {
106 this->write32(value);
107 }

◆ writeIRect()

void SkWriter32::writeIRect ( const SkIRect rect)
inline

Definition at line 137 of file SkWriter32.h.

137 {
138 *(SkIRect*)this->reserve(sizeof(rect)) = rect;
139 }
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: SkRect.h:32

◆ writeMatrix()

void SkWriter32::writeMatrix ( const SkMatrix matrix)

Definition at line 18 of file SkWriter32.cpp.

18 {
19 size_t size = SkMatrixPriv::WriteToMemory(matrix, nullptr);
22}
static size_t WriteToMemory(const SkMatrix &matrix, void *buffer)
Definition: SkMatrixPriv.h:30
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ writeMul4()

void SkWriter32::writeMul4 ( const void *  values,
size_t  size 
)
inline

Definition at line 162 of file SkWriter32.h.

162 {
163 this->write(values, size);
164 }
void write(const void *values, size_t size)
Definition: SkWriter32.h:170

◆ writePad()

void SkWriter32::writePad ( const void *  src,
size_t  size 
)
inline

Write size bytes from src, and pad to 4 byte alignment with zeroes.

Definition at line 192 of file SkWriter32.h.

192 {
194 }

◆ writePath()

void SkWriter32::writePath ( const SkPath path)
inline

Definition at line 145 of file SkWriter32.h.

145 {
146 size_t size = path.writeToMemory(nullptr);
148 path.writeToMemory(this->reserve(size));
149 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ writePoint()

void SkWriter32::writePoint ( const SkPoint pt)
inline

Definition at line 125 of file SkWriter32.h.

125 {
126 *(SkPoint*)this->reserve(sizeof(pt)) = pt;
127 }

◆ writePoint3()

void SkWriter32::writePoint3 ( const SkPoint3 pt)
inline

Definition at line 129 of file SkWriter32.h.

129 {
130 *(SkPoint3*)this->reserve(sizeof(pt)) = pt;
131 }

◆ writeRect()

void SkWriter32::writeRect ( const SkRect rect)
inline

Definition at line 133 of file SkWriter32.h.

133 {
134 *(SkRect*)this->reserve(sizeof(rect)) = rect;
135 }

◆ writeRegion()

void SkWriter32::writeRegion ( const SkRegion rgn)
inline

Definition at line 153 of file SkWriter32.h.

153 {
154 size_t size = rgn.writeToMemory(nullptr);
156 rgn.writeToMemory(this->reserve(size));
157 }
size_t writeToMemory(void *buffer) const
Definition: SkRegion.cpp:1149

◆ writeRRect()

void SkWriter32::writeRRect ( const SkRRect rrect)
inline

Definition at line 141 of file SkWriter32.h.

141 {
143 }
size_t writeToMemory(void *buffer) const
Definition: SkRRect.cpp:599
static constexpr size_t kSizeInMemory
Definition: SkRRect.h:422
SkRRect rrect
Definition: SkRecords.h:232

◆ writeSampling()

void SkWriter32::writeSampling ( const SkSamplingOptions sampling)

Definition at line 24 of file SkWriter32.cpp.

24 {
25 this->write32(sampling.maxAniso);
26 if (!sampling.isAniso()) {
27 this->writeBool(sampling.useCubic);
28 if (sampling.useCubic) {
29 this->writeScalar(sampling.cubic.B);
30 this->writeScalar(sampling.cubic.C);
31 } else {
32 this->write32((unsigned)sampling.filter);
33 this->write32((unsigned)sampling.mipmap);
34 }
35 }
36}
void writeScalar(SkScalar value)
Definition: SkWriter32.h:121
bool writeBool(bool value)
Definition: SkWriter32.h:100
SkSamplingOptions sampling
Definition: SkRecords.h:337
const SkCubicResampler cubic
const SkFilterMode filter
const SkMipmapMode mipmap

◆ writeScalar()

void SkWriter32::writeScalar ( SkScalar  value)
inline

Definition at line 121 of file SkWriter32.h.

121 {
122 *(SkScalar*)this->reserve(sizeof(value)) = value;
123 }
float SkScalar
Definition: extension.cpp:12

◆ writeString()

void SkWriter32::writeString ( const char *  str,
size_t  len = (size_t)-1 
)

Writes a string to the writer, which can be retrieved with SkReadBuffer::readString(). The length can be specified, or if -1 is passed, it will be computed by calling strlen(). The length must be < max size_t.

If you write NULL, it will be read as "".

Definition at line 38 of file SkWriter32.cpp.

38 {
39 if (nullptr == str) {
40 str = "";
41 len = 0;
42 }
43 if ((long)len < 0) {
44 len = strlen(str);
45 }
46
47 // [ 4 byte len ] [ str ... ] [1 - 4 \0s]
48 uint32_t* ptr = this->reservePad(sizeof(uint32_t) + len + 1);
49 *ptr = SkToU32(len);
50 char* chars = (char*)(ptr + 1);
51 memcpy(chars, str, len);
52 chars[len] = '\0';
53}

◆ WriteStringSize()

size_t SkWriter32::WriteStringSize ( const char *  str,
size_t  len = (size_t)-1 
)
static

Computes the size (aligned to multiple of 4) need to write the string in a call to writeString(). If the length is not specified, it will be computed by calling strlen().

Definition at line 55 of file SkWriter32.cpp.

55 {
56 if ((long)len < 0) {
57 SkASSERT(str);
58 len = strlen(str);
59 }
60 const size_t lenBytes = 4; // we use 4 bytes to record the length
61 // add 1 since we also write a terminating 0
62 return SkAlign4(lenBytes + len + 1);
63}

◆ writeToStream()

bool SkWriter32::writeToStream ( SkWStream stream) const
inline

Definition at line 239 of file SkWriter32.h.

239 {
240 return stream->write(fData, fUsed);
241 }

The documentation for this class was generated from the following files: