Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkReadBuffer Class Reference

#include <SkReadBuffer.h>

Public Member Functions

 SkReadBuffer ()=default
 
 SkReadBuffer (const void *data, size_t size)
 
void setMemory (const void *, size_t)
 
bool isVersionLT (SkPicturePriv::Version targetVersion) const
 
uint32_t getVersion () const
 
void setVersion (int version)
 
size_t size () const
 
size_t offset () const
 
bool eof ()
 
const void * skip (size_t size)
 
const void * skip (size_t count, size_t size)
 
size_t available () const
 
template<typename T >
const TskipT ()
 
template<typename T >
const TskipT (size_t count)
 
bool readBool ()
 
SkColor readColor ()
 
int32_t readInt ()
 
SkScalar readScalar ()
 
uint32_t readUInt ()
 
int32_t read32 ()
 
template<typename T >
T read32LE (T max)
 
uint8_t peekByte ()
 
void readString (SkString *string)
 
void readColor4f (SkColor4f *color)
 
void readPoint (SkPoint *point)
 
SkPoint readPoint ()
 
void readPoint3 (SkPoint3 *point)
 
void read (SkM44 *)
 
void readMatrix (SkMatrix *matrix)
 
void readIRect (SkIRect *rect)
 
void readRect (SkRect *rect)
 
SkRect readRect ()
 
void readRRect (SkRRect *rrect)
 
void readRegion (SkRegion *region)
 
void readPath (SkPath *path)
 
SkPaint readPaint ()
 
SkFlattenablereadRawFlattenable ()
 
SkFlattenablereadFlattenable (SkFlattenable::Type)
 
template<typename T >
sk_sp< TreadFlattenable ()
 
sk_sp< SkColorFilterreadColorFilter ()
 
sk_sp< SkImageFilterreadImageFilter ()
 
sk_sp< SkBlenderreadBlender ()
 
sk_sp< SkMaskFilterreadMaskFilter ()
 
sk_sp< SkPathEffectreadPathEffect ()
 
sk_sp< SkShaderreadShader ()
 
bool readPad32 (void *buffer, size_t bytes)
 
bool readByteArray (void *value, size_t size)
 
bool readColorArray (SkColor *colors, size_t size)
 
bool readColor4fArray (SkColor4f *colors, size_t size)
 
bool readIntArray (int32_t *values, size_t size)
 
bool readPointArray (SkPoint *points, size_t size)
 
bool readScalarArray (SkScalar *values, size_t size)
 
const void * skipByteArray (size_t *size)
 
sk_sp< SkDatareadByteArrayAsData ()
 
uint32_t getArrayCount ()
 
sk_sp< SkImagereadImage ()
 
sk_sp< SkTypefacereadTypeface ()
 
void setTypefaceArray (sk_sp< SkTypeface > array[], int count)
 
void setFactoryPlayback (SkFlattenable::Factory array[], int count)
 
void setDeserialProcs (const SkDeserialProcs &procs)
 
const SkDeserialProcsgetDeserialProcs () const
 
bool allowSkSL () const
 
void setAllowSkSL (bool allow)
 
bool validate (bool isValid)
 
template<typename T >
bool validateCanReadN (size_t n)
 
bool isValid () const
 
bool validateIndex (int index, int count)
 
int32_t checkInt (int min, int max)
 
template<typename T >
T checkRange (T min, T max)
 
SkLegacyFQ checkFilterQuality ()
 
SkSamplingOptions readSampling ()
 

Detailed Description

Definition at line 52 of file SkReadBuffer.h.

Constructor & Destructor Documentation

◆ SkReadBuffer() [1/2]

SkReadBuffer::SkReadBuffer ( )
default

◆ SkReadBuffer() [2/2]

SkReadBuffer::SkReadBuffer ( const void *  data,
size_t  size 
)
inline

Definition at line 55 of file SkReadBuffer.h.

55 {
56 this->setMemory(data, size);
57 }
void setMemory(const void *, size_t)
size_t size() const

Member Function Documentation

◆ allowSkSL()

bool SkReadBuffer::allowSkSL ( ) const
inline

Definition at line 184 of file SkReadBuffer.h.

184{ return fAllowSkSL; }

◆ available()

size_t SkReadBuffer::available ( ) const
inline

Definition at line 82 of file SkReadBuffer.h.

82{ return fStop - fCurr; }

◆ checkFilterQuality()

SkLegacyFQ SkReadBuffer::checkFilterQuality ( )

Definition at line 563 of file SkReadBuffer.cpp.

563 {
564 return this->checkRange<SkLegacyFQ>(kNone_SkLegacyFQ, kLast_SkLegacyFQ);
565}
@ kLast_SkLegacyFQ
@ kNone_SkLegacyFQ
nearest-neighbor; fastest but lowest quality

◆ checkInt()

int32_t SkReadBuffer::checkInt ( int  min,
int  max 
)

Definition at line 553 of file SkReadBuffer.cpp.

553 {
554 SkASSERT(min <= max);
555 int32_t value = this->read32();
556 if (value < min || value > max) {
557 this->validate(false);
558 value = min;
559 }
560 return value;
561}
#define SkASSERT(cond)
Definition SkAssert.h:116
bool validate(bool isValid)
int32_t read32()
uint8_t value
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48

◆ checkRange()

template<typename T >
T SkReadBuffer::checkRange ( T  min,
T  max 
)
inline

Definition at line 219 of file SkReadBuffer.h.

219 {
220 return static_cast<T>(this->checkInt(static_cast<int32_t>(min),
221 static_cast<int32_t>(max)));
222 }
int32_t checkInt(int min, int max)
#define T

◆ eof()

bool SkReadBuffer::eof ( )
inline

Definition at line 79 of file SkReadBuffer.h.

79{ return fCurr >= fStop; }

◆ getArrayCount()

uint32_t SkReadBuffer::getArrayCount ( )

Definition at line 330 of file SkReadBuffer.cpp.

330 {
331 const size_t inc = sizeof(uint32_t);
332 if (!this->validate(IsPtrAlign4(fCurr) && this->isAvailable(inc))) {
333 return 0;
334 }
335 return *((const uint32_t*)fCurr);
336}

◆ getDeserialProcs()

const SkDeserialProcs & SkReadBuffer::getDeserialProcs ( ) const
inline

Definition at line 182 of file SkReadBuffer.h.

182{ return fProcs; }

◆ getVersion()

uint32_t SkReadBuffer::getVersion ( ) const
inline

Definition at line 69 of file SkReadBuffer.h.

69{ return fVersion; }

◆ isValid()

bool SkReadBuffer::isValid ( ) const
inline

Definition at line 208 of file SkReadBuffer.h.

208{ return !fError; }

◆ isVersionLT()

bool SkReadBuffer::isVersionLT ( SkPicturePriv::Version  targetVersion) const
inline

Returns true IFF the version is older than the specified version.

Definition at line 64 of file SkReadBuffer.h.

64 {
65 SkASSERT(targetVersion > 0);
66 return fVersion > 0 && fVersion < targetVersion;
67 }

◆ offset()

size_t SkReadBuffer::offset ( ) const
inline

Definition at line 78 of file SkReadBuffer.h.

78{ return fCurr - fBase; }

◆ peekByte()

uint8_t SkReadBuffer::peekByte ( )

Definition at line 130 of file SkReadBuffer.cpp.

130 {
131 if (this->available() <= 0) {
132 fError = true;
133 return 0;
134 }
135 return *((const uint8_t*)fCurr);
136}
size_t available() const

◆ read()

void SkReadBuffer::read ( SkM44 matrix)

Definition at line 184 of file SkReadBuffer.cpp.

184 {
185 if (this->isValid()) {
186 if (const float* m = (const float*)this->skip(sizeof(float) * 16)) {
187 *matrix = SkM44::ColMajor(m);
188 }
189 }
190 if (!this->isValid()) {
191 *matrix = SkM44();
192 }
193}
Definition SkM44.h:150
static SkM44 ColMajor(const SkScalar c[16])
Definition SkM44.h:218
bool isValid() const
const void * skip(size_t size)

◆ read32()

int32_t SkReadBuffer::read32 ( )

Definition at line 126 of file SkReadBuffer.cpp.

126 {
127 return this->readInt();
128}
int32_t readInt()

◆ read32LE()

template<typename T >
T SkReadBuffer::read32LE ( T  max)
inline

Definition at line 99 of file SkReadBuffer.h.

99 {
100 uint32_t value = this->readUInt();
101 if (!this->validate(value <= static_cast<uint32_t>(max))) {
102 value = 0;
103 }
104 return static_cast<T>(value);
105 }
uint32_t readUInt()

◆ readBlender()

sk_sp< SkBlender > SkReadBuffer::readBlender ( )
inline

Definition at line 138 of file SkReadBuffer.h.

138{ return this->readFlattenable<SkBlenderBase>(); }

◆ readBool()

bool SkReadBuffer::readBool ( )

Definition at line 91 of file SkReadBuffer.cpp.

91 {
92 uint32_t value = this->readUInt();
93 // Boolean value should be either 0 or 1
94 this->validate(!(value & ~1));
95 return value != 0;
96}

◆ readByteArray()

bool SkReadBuffer::readByteArray ( void *  value,
size_t  size 
)

Definition at line 284 of file SkReadBuffer.cpp.

284 {
285 return this->readArray(value, size, sizeof(uint8_t));
286}

◆ readByteArrayAsData()

sk_sp< SkData > SkReadBuffer::readByteArrayAsData ( )

Definition at line 317 of file SkReadBuffer.cpp.

317 {
318 size_t numBytes = this->getArrayCount();
319 if (!this->validate(this->isAvailable(numBytes))) {
320 return nullptr;
321 }
322
323 SkAutoMalloc buffer(numBytes);
324 if (!this->readByteArray(buffer.get(), numBytes)) {
325 return nullptr;
326 }
327 return SkData::MakeFromMalloc(buffer.release(), numBytes);
328}
static sk_sp< SkData > MakeFromMalloc(const void *data, size_t length)
Definition SkData.cpp:107
bool readByteArray(void *value, size_t size)
uint32_t getArrayCount()
static const uint8_t buffer[]

◆ readColor()

SkColor SkReadBuffer::readColor ( )

Definition at line 98 of file SkReadBuffer.cpp.

98 {
99 return this->readUInt();
100}

◆ readColor4f()

void SkReadBuffer::readColor4f ( SkColor4f color)

Definition at line 169 of file SkReadBuffer.cpp.

169 {
170 if (!this->readPad32(color, sizeof(SkColor4f))) {
171 *color = {0, 0, 0, 0};
172 }
173}
SkColor4f color
bool readPad32(void *buffer, size_t bytes)

◆ readColor4fArray()

bool SkReadBuffer::readColor4fArray ( SkColor4f colors,
size_t  size 
)

Definition at line 292 of file SkReadBuffer.cpp.

292 {
293 return this->readArray(colors, size, sizeof(SkColor4f));
294}

◆ readColorArray()

bool SkReadBuffer::readColorArray ( SkColor colors,
size_t  size 
)

Definition at line 288 of file SkReadBuffer.cpp.

288 {
289 return this->readArray(colors, size, sizeof(SkColor));
290}
uint32_t SkColor
Definition SkColor.h:37

◆ readColorFilter()

sk_sp< SkColorFilter > SkReadBuffer::readColorFilter ( )
inline

Definition at line 136 of file SkReadBuffer.h.

136{ return this->readFlattenable<SkColorFilterBase>(); }

◆ readFlattenable() [1/2]

template<typename T >
sk_sp< T > SkReadBuffer::readFlattenable ( )
inline

Definition at line 133 of file SkReadBuffer.h.

133 {
134 return sk_sp<T>((T*)this->readFlattenable(T::GetFlattenableType()));
135 }
sk_sp< T > readFlattenable()

◆ readFlattenable() [2/2]

SkFlattenable * SkReadBuffer::readFlattenable ( SkFlattenable::Type  ft)

Definition at line 541 of file SkReadBuffer.cpp.

541 {
542 SkFlattenable* obj = this->readRawFlattenable();
543 if (obj && obj->getFlattenableType() != ft) {
544 this->validate(false);
545 obj->unref();
546 return nullptr;
547 }
548 return obj;
549}
virtual Type getFlattenableType() const =0
SkFlattenable * readRawFlattenable()
void unref() const
Definition SkRefCnt.h:72

◆ readImage()

sk_sp< SkImage > SkReadBuffer::readImage ( )

Definition at line 411 of file SkReadBuffer.cpp.

411 {
412 uint32_t flags = this->read32();
413
414 std::optional<SkAlphaType> alphaType = std::nullopt;
416 alphaType = kUnpremul_SkAlphaType;
417 }
419 {
421 if (!data) {
422 this->validate(false);
423 return nullptr;
424 }
425 image = deserialize_image(data, fProcs, alphaType);
426 }
427
428 // This flag is not written by new SKPs anymore.
430 SkIRect subset;
431 this->readIRect(&subset);
432 if (image) {
433 image = image->makeSubset(nullptr, subset);
434 }
435 }
436
439 if (!data) {
440 this->validate(false);
441 return nullptr;
442 }
443 if (image) {
444 image = add_mipmaps(image, std::move(data), fProcs, alphaType);
445 }
446 }
447 return image ? image : MakeEmptyImage(1, 1);
448}
kUnpremul_SkAlphaType
static sk_sp< SkImage > add_mipmaps(sk_sp< SkImage > img, sk_sp< SkData > data, SkDeserialProcs dProcs, std::optional< SkAlphaType > alphaType)
static sk_sp< SkImage > deserialize_image(sk_sp< SkData > data, SkDeserialProcs dProcs, std::optional< SkAlphaType > alphaType)
@ kUnpremul
@ kHasSubsetRect
@ kHasMipmap
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
sk_sp< SkData > readByteArrayAsData()
void readIRect(SkIRect *rect)
sk_sp< SkImage > image
Definition examples.cpp:29
FlutterSemanticsFlag flags
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ readImageFilter()

sk_sp< SkImageFilter > SkReadBuffer::readImageFilter ( )
inline

Definition at line 137 of file SkReadBuffer.h.

137{ return this->readFlattenable<SkImageFilter_Base>(); }

◆ readInt()

int32_t SkReadBuffer::readInt ( )

Definition at line 102 of file SkReadBuffer.cpp.

102 {
103 const size_t inc = sizeof(int32_t);
104 if (!this->validate(IsPtrAlign4(fCurr) && this->isAvailable(inc))) {
105 return 0;
106 }
107 int32_t value = *((const int32_t*)fCurr);
108 fCurr += inc;
109 return value;
110}

◆ readIntArray()

bool SkReadBuffer::readIntArray ( int32_t *  values,
size_t  size 
)

Definition at line 296 of file SkReadBuffer.cpp.

296 {
297 return this->readArray(values, size, sizeof(int32_t));
298}

◆ readIRect()

void SkReadBuffer::readIRect ( SkIRect rect)

Definition at line 207 of file SkReadBuffer.cpp.

207 {
208 if (!this->readPad32(rect, sizeof(SkIRect))) {
209 rect->setEmpty();
210 }
211}
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

◆ readMaskFilter()

sk_sp< SkMaskFilter > SkReadBuffer::readMaskFilter ( )
inline

Definition at line 139 of file SkReadBuffer.h.

139{ return this->readFlattenable<SkMaskFilterBase>(); }

◆ readMatrix()

void SkReadBuffer::readMatrix ( SkMatrix matrix)

Definition at line 195 of file SkReadBuffer.cpp.

195 {
196 size_t size = 0;
197 if (this->isValid()) {
198 size = SkMatrixPriv::ReadFromMemory(matrix, fCurr, this->available());
199 (void)this->validate((SkAlign4(size) == size) && (0 != size));
200 }
201 if (!this->isValid()) {
202 matrix->reset();
203 }
204 (void)this->skip(size);
205}
static constexpr T SkAlign4(T x)
Definition SkAlign.h:16
static size_t ReadFromMemory(SkMatrix *matrix, const void *buffer, size_t length)
SkMatrix & reset()
Definition SkMatrix.cpp:49

◆ readPad32()

bool SkReadBuffer::readPad32 ( void *  buffer,
size_t  bytes 
)

Definition at line 138 of file SkReadBuffer.cpp.

138 {
139 if (const void* src = this->skip(bytes)) {
140 // buffer might be null if bytes is zero (see SkAutoMalloc), hence we call
141 // the careful version of memcpy.
142 sk_careful_memcpy(buffer, src, bytes);
143 return true;
144 }
145 return false;
146}
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition SkMalloc.h:125

◆ readPaint()

SkPaint SkReadBuffer::readPaint ( )
inline

Definition at line 127 of file SkReadBuffer.h.

127 {
128 return SkPaintPriv::Unflatten(*this);
129 }
static SkPaint Unflatten(SkReadBuffer &buffer)

◆ readPath()

void SkReadBuffer::readPath ( SkPath path)

Definition at line 267 of file SkReadBuffer.cpp.

267 {
268 size_t size = 0;
269 if (!fError) {
270 size = path->readFromMemory(fCurr, this->available());
271 if (!this->validate((SkAlign4(size) == size) && (0 != size))) {
272 path->reset();
273 }
274 }
275 (void)this->skip(size);
276}
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

◆ readPathEffect()

sk_sp< SkPathEffect > SkReadBuffer::readPathEffect ( )
inline

Definition at line 140 of file SkReadBuffer.h.

140{ return this->readFlattenable<SkPathEffect>(); }

◆ readPoint() [1/2]

SkPoint SkReadBuffer::readPoint ( )
inline

Definition at line 115 of file SkReadBuffer.h.

◆ readPoint() [2/2]

void SkReadBuffer::readPoint ( SkPoint point)

Definition at line 175 of file SkReadBuffer.cpp.

175 {
176 point->fX = this->readScalar();
177 point->fY = this->readScalar();
178}
SkScalar readScalar()
float fX
x-axis value
float fY
y-axis value

◆ readPoint3()

void SkReadBuffer::readPoint3 ( SkPoint3 point)

Definition at line 180 of file SkReadBuffer.cpp.

180 {
181 this->readPad32(point, sizeof(SkPoint3));
182}

◆ readPointArray()

bool SkReadBuffer::readPointArray ( SkPoint points,
size_t  size 
)

Definition at line 300 of file SkReadBuffer.cpp.

300 {
301 return this->readArray(points, size, sizeof(SkPoint));
302}
static const int points[]

◆ readRawFlattenable()

SkFlattenable * SkReadBuffer::readRawFlattenable ( )

Definition at line 474 of file SkReadBuffer.cpp.

474 {
475 SkFlattenable::Factory factory = nullptr;
476
477 if (fFactoryCount > 0) {
478 int32_t index = this->read32();
479 if (0 == index || !this->isValid()) {
480 return nullptr; // writer failed to give us the flattenable
481 }
482 if (index < 0) {
483 this->validate(false);
484 return nullptr;
485 }
486 index -= 1; // we stored the index-base-1
487 if ((unsigned)index >= (unsigned)fFactoryCount) {
488 this->validate(false);
489 return nullptr;
490 }
491 factory = fFactoryArray[index];
492 } else {
493 if (this->peekByte() != 0) {
494 // If the first byte is non-zero, the flattenable is specified by a string.
495 size_t ignored_length;
496 if (const char* name = this->readString(&ignored_length)) {
498 fFlattenableDict.set(fFlattenableDict.count() + 1, factory);
499 }
500 } else {
501 // Read the index. We are guaranteed that the first byte
502 // is zeroed, so we must shift down a byte.
503 uint32_t index = this->readUInt() >> 8;
504 if (index == 0) {
505 return nullptr; // writer failed to give us the flattenable
506 }
507
508 if (SkFlattenable::Factory* found = fFlattenableDict.find(index)) {
509 factory = *found;
510 }
511 }
512
513 if (!this->validate(factory != nullptr)) {
514 return nullptr;
515 }
516 }
517
518 // if we get here, factory may still be null, but if that is the case, the
519 // failure was ours, not the writer.
521 uint32_t sizeRecorded = this->read32();
522 if (factory) {
523 size_t offset = this->offset();
524 obj = (*factory)(*this);
525 // check that we read the amount we expected
526 size_t sizeRead = this->offset() - offset;
527 if (sizeRecorded != sizeRead) {
528 this->validate(false);
529 return nullptr;
530 }
531 } else {
532 // we must skip the remaining data
533 this->skip(sizeRecorded);
534 }
535 if (!this->isValid()) {
536 return nullptr;
537 }
538 return obj.release();
539}
sk_sp< SkFlattenable >(* Factory)(SkReadBuffer &)
static Factory NameToFactory(const char name[])
uint8_t peekByte()
void readString(SkString *string)
size_t offset() const
T * release()
Definition SkRefCnt.h:324
int count() const
Definition SkTHash.h:460
V * find(const K &key) const
Definition SkTHash.h:479
V * set(K key, V val)
Definition SkTHash.h:472
const char * name
Definition fuchsia.cc:50

◆ readRect() [1/2]

SkRect SkReadBuffer::readRect ( )

Definition at line 219 of file SkReadBuffer.cpp.

219 {
220 SkRect r;
221 if (!this->readPad32(&r, sizeof(SkRect))) {
222 r.setEmpty();
223 }
224 return r;
225}
void setEmpty()
Definition SkRect.h:842

◆ readRect() [2/2]

void SkReadBuffer::readRect ( SkRect rect)

Definition at line 213 of file SkReadBuffer.cpp.

213 {
214 if (!this->readPad32(rect, sizeof(SkRect))) {
215 rect->setEmpty();
216 }
217}

◆ readRegion()

void SkReadBuffer::readRegion ( SkRegion region)

Definition at line 256 of file SkReadBuffer.cpp.

256 {
257 size_t size = 0;
258 if (!fError) {
259 size = region->readFromMemory(fCurr, this->available());
260 if (!this->validate((SkAlign4(size) == size) && (0 != size))) {
261 region->setEmpty();
262 }
263 }
264 (void)this->skip(size);
265}
size_t readFromMemory(const void *buffer, size_t length)
bool setEmpty()
Definition SkRegion.cpp:185
ClipOpAndAA opAA SkRegion region
Definition SkRecords.h:238

◆ readRRect()

void SkReadBuffer::readRRect ( SkRRect rrect)

Definition at line 245 of file SkReadBuffer.cpp.

245 {
246 size_t size = 0;
247 if (!fError) {
248 size = rrect->readFromMemory(fCurr, this->available());
249 if (!this->validate((SkAlign4(size) == size) && (0 != size))) {
250 rrect->setEmpty();
251 }
252 }
253 (void)this->skip(size);
254}
void setEmpty()
Definition SkRRect.h:118
size_t readFromMemory(const void *buffer, size_t length)
Definition SkRRect.cpp:610
SkRRect rrect
Definition SkRecords.h:232

◆ readSampling()

SkSamplingOptions SkReadBuffer::readSampling ( )

Definition at line 227 of file SkReadBuffer.cpp.

227 {
229 int maxAniso = this->readInt();
230 if (maxAniso != 0) {
231 return SkSamplingOptions::Aniso(maxAniso);
232 }
233 }
234 if (this->readBool()) {
235 float B = this->readScalar();
236 float C = this->readScalar();
237 return SkSamplingOptions({B, C});
238 } else {
241 return SkSamplingOptions(filter, mipmap);
242 }
243}
SkFilterMode
SkMipmapMode
T read32LE(T max)
bool isVersionLT(SkPicturePriv::Version targetVersion) const
#define B
static constexpr SkSamplingOptions Aniso(int maxAniso)

◆ readScalar()

SkScalar SkReadBuffer::readScalar ( )

Definition at line 112 of file SkReadBuffer.cpp.

112 {
113 const size_t inc = sizeof(SkScalar);
114 if (!this->validate(IsPtrAlign4(fCurr) && this->isAvailable(inc))) {
115 return 0;
116 }
117 SkScalar value = *((const SkScalar*)fCurr);
118 fCurr += inc;
119 return value;
120}
float SkScalar
Definition extension.cpp:12

◆ readScalarArray()

bool SkReadBuffer::readScalarArray ( SkScalar values,
size_t  size 
)

Definition at line 304 of file SkReadBuffer.cpp.

304 {
305 return this->readArray(values, size, sizeof(SkScalar));
306}

◆ readShader()

sk_sp< SkShader > SkReadBuffer::readShader ( )
inline

Definition at line 141 of file SkReadBuffer.h.

141{ return this->readFlattenable<SkShaderBase>(); }

◆ readString()

void SkReadBuffer::readString ( SkString string)

Definition at line 160 of file SkReadBuffer.cpp.

160 {
161 size_t len;
162 if (const char* c_str = this->readString(&len)) {
163 string->set(c_str, len);
164 return;
165 }
166 string->reset();
167}

◆ readTypeface()

sk_sp< SkTypeface > SkReadBuffer::readTypeface ( )

Definition at line 450 of file SkReadBuffer.cpp.

450 {
451 // Read 32 bits (signed)
452 // 0 -- return null (empty font)
453 // >0 -- index
454 // <0 -- custom (serial procs) : negative size in bytes
455
456 int32_t index = this->read32();
457 if (index == 0) {
458 return nullptr;
459 } else if (index > 0) {
460 if (!this->validate(index <= fTFCount)) {
461 return nullptr;
462 }
463 return fTFArray[index - 1];
464 } else { // custom
465 size_t size = sk_negate_to_size_t(index);
466 const void* data = this->skip(size);
467 if (!this->validate(data != nullptr && fProcs.fTypefaceProc)) {
468 return nullptr;
469 }
470 return fProcs.fTypefaceProc(data, size, fProcs.fTypefaceCtx);
471 }
472}
static size_t sk_negate_to_size_t(int32_t value)
Definition SkMathPriv.h:76
SkDeserialTypefaceProc fTypefaceProc

◆ readUInt()

uint32_t SkReadBuffer::readUInt ( )

Definition at line 122 of file SkReadBuffer.cpp.

122 {
123 return this->readInt();
124}

◆ setAllowSkSL()

void SkReadBuffer::setAllowSkSL ( bool  allow)
inline

Definition at line 185 of file SkReadBuffer.h.

185{ fAllowSkSL = allow; }

◆ setDeserialProcs()

void SkReadBuffer::setDeserialProcs ( const SkDeserialProcs procs)

Definition at line 86 of file SkReadBuffer.cpp.

86 {
87 fProcs = procs;
88 this->setAllowSkSL(procs.fAllowSkSL);
89}
void setAllowSkSL(bool allow)

◆ setFactoryPlayback()

void SkReadBuffer::setFactoryPlayback ( SkFlattenable::Factory  array[],
int  count 
)
inline

Call this with a pre-loaded array of Factories, in the same order as were created/written by the writer. SkPicture uses this.

Definition at line 176 of file SkReadBuffer.h.

176 {
177 fFactoryArray = array;
178 fFactoryCount = count;
179 }
int count

◆ setMemory()

void SkReadBuffer::setMemory ( const void *  data,
size_t  size 
)

Definition at line 53 of file SkReadBuffer.cpp.

53 {
54 this->validate(IsPtrAlign4(data) && (SkAlign4(size) == size));
55 if (!fError) {
56 fBase = fCurr = (const char*)data;
57 fStop = fBase + size;
58 }
59}

◆ setTypefaceArray()

void SkReadBuffer::setTypefaceArray ( sk_sp< SkTypeface array[],
int  count 
)
inline

Definition at line 167 of file SkReadBuffer.h.

167 {
168 fTFArray = array;
169 fTFCount = count;
170 }

◆ setVersion()

void SkReadBuffer::setVersion ( int  version)
inline

This may be called at most once; most clients of SkReadBuffer should not mess with it.

Definition at line 72 of file SkReadBuffer.h.

72 {
73 SkASSERT(0 == fVersion || version == fVersion);
74 fVersion = version;
75 }

◆ size()

size_t SkReadBuffer::size ( ) const
inline

Definition at line 77 of file SkReadBuffer.h.

77{ return fStop - fBase; }

◆ skip() [1/2]

const void * SkReadBuffer::skip ( size_t  count,
size_t  size 
)

Definition at line 82 of file SkReadBuffer.cpp.

82 {
83 return this->skip(SkSafeMath::Mul(count, size));
84}
static size_t Mul(size_t x, size_t y)

◆ skip() [2/2]

const void * SkReadBuffer::skip ( size_t  size)

Definition at line 69 of file SkReadBuffer.cpp.

69 {
70 size_t inc = SkAlign4(size);
71 this->validate(inc >= size);
72 const void* addr = fCurr;
73 this->validate(IsPtrAlign4(addr) && this->isAvailable(inc));
74 if (fError) {
75 return nullptr;
76 }
77
78 fCurr += inc;
79 return addr;
80}

◆ skipByteArray()

const void * SkReadBuffer::skipByteArray ( size_t *  size)

Definition at line 308 of file SkReadBuffer.cpp.

308 {
309 const uint32_t count = this->readUInt();
310 const void* buf = this->skip(count);
311 if (size) {
312 *size = this->isValid() ? count : 0;
313 }
314 return buf;
315}

◆ skipT() [1/2]

template<typename T >
const T * SkReadBuffer::skipT ( )
inline

Definition at line 84 of file SkReadBuffer.h.

84 {
85 return static_cast<const T*>(this->skip(sizeof(T)));
86 }

◆ skipT() [2/2]

template<typename T >
const T * SkReadBuffer::skipT ( size_t  count)
inline

Definition at line 87 of file SkReadBuffer.h.

87 {
88 return static_cast<const T*>(this->skip(count, sizeof(T)));
89 }

◆ validate()

bool SkReadBuffer::validate ( bool  isValid)
inline

If isValid is false, sets the buffer to be "invalid". Returns true if the buffer is still valid.

Definition at line 191 of file SkReadBuffer.h.

191 {
192 if (!isValid) {
193 this->setInvalid();
194 }
195 return !fError;
196 }

◆ validateCanReadN()

template<typename T >
bool SkReadBuffer::validateCanReadN ( size_t  n)
inline

Helper function to do a preflight check before a large allocation or read. Returns true if there is enough bytes in the buffer to read n elements of T. If not, the buffer will be "invalid" and false will be returned.

Definition at line 204 of file SkReadBuffer.h.

204 {
205 return this->validate(n <= (this->available() / sizeof(T)));
206 }

◆ validateIndex()

bool SkReadBuffer::validateIndex ( int  index,
int  count 
)
inline

Definition at line 209 of file SkReadBuffer.h.

209 {
210 return this->validate(index >= 0 && index < count);
211 }

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