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

#include <SkVerticesPriv.h>

Public Member Functions

SkVertices::VertexMode mode () const
 
bool hasColors () const
 
bool hasTexCoords () const
 
bool hasIndices () const
 
int vertexCount () const
 
int indexCount () const
 
const SkPointpositions () const
 
const SkPointtexCoords () const
 
const SkColorcolors () const
 
const uint16_t * indices () const
 
 SkVerticesPriv (const SkVerticesPriv &)=default
 
void encode (SkWriteBuffer &) const
 

Static Public Member Functions

static sk_sp< SkVerticesDecode (SkReadBuffer &)
 

Friends

class SkVertices
 

Detailed Description

Class that adds methods to SkVertices that are only intended for use internal to Skia. This class is purely a privileged window into SkVertices. It should never have additional data members or virtual methods.

Definition at line 23 of file SkVerticesPriv.h.

Constructor & Destructor Documentation

◆ SkVerticesPriv()

SkVerticesPriv::SkVerticesPriv ( const SkVerticesPriv )
default

Member Function Documentation

◆ colors()

const SkColor * SkVerticesPriv::colors ( ) const
inline

Definition at line 36 of file SkVerticesPriv.h.

36{ return fVertices->fColors; }

◆ Decode()

sk_sp< SkVertices > SkVerticesPriv::Decode ( SkReadBuffer buffer)
static

Definition at line 267 of file SkVertices.cpp.

267 {
269 SkSafeRange safe;
270 bool hasCustomData = buffer.isVersionLT(SkPicturePriv::kVerticesRemoveCustomData_Version);
271
272 const uint32_t packed = buffer.readUInt();
273 const int vertexCount = safe.checkGE(buffer.readInt(), 0);
274 const int indexCount = safe.checkGE(buffer.readInt(), 0);
275 const int attrCount = hasCustomData ? safe.checkGE(buffer.readInt(), 0) : 0;
278 const bool hasTexs = SkToBool(packed & kHasTexs_Mask);
279 const bool hasColors = SkToBool(packed & kHasColors_Mask);
280
281 // Check that the header fields and buffer are valid. If this is data with the experimental
282 // custom attributes feature - we don't support that any more.
283 // We also don't support serialized triangle-fan data. We stopped writing that long ago,
284 // so it should never appear in valid encoded data.
285 if (!safe || !buffer.isValid() || attrCount ||
287 return nullptr;
288 }
289
291 SkVertices::Sizes sizes(desc);
292 if (!sizes.isValid() || sizes.fArrays > buffer.available()) {
293 return nullptr;
294 }
295
297 if (!builder.isValid()) {
298 return nullptr;
299 }
300
301 buffer.readByteArray(builder.positions(), sizes.fVSize);
302 if (hasCustomData) {
303 size_t customDataSize = 0;
304 buffer.skipByteArray(&customDataSize);
305 if (customDataSize != 0) {
306 return nullptr;
307 }
308 }
309 buffer.readByteArray(builder.texCoords(), sizes.fTSize);
310 buffer.readByteArray(builder.colors(), sizes.fCSize);
311 buffer.readByteArray(builder.indices(), sizes.fISize);
312
313 if (!buffer.isValid()) {
314 return nullptr;
315 }
316
317 if (indexCount > 0) {
318 // validate that the indices are in range
319 const uint16_t* indices = builder.indices();
320 for (int i = 0; i < indexCount; ++i) {
321 if (indices[i] >= (unsigned)vertexCount) {
322 return nullptr;
323 }
324 }
325 }
326
327 return builder.detach();
328 };
329
330 if (auto verts = decode(buffer)) {
331 return verts;
332 }
333 buffer.validate(false);
334 return nullptr;
335}
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define kMode_Mask
#define kHasTexs_Mask
#define kHasColors_Mask
@ kVerticesRemoveCustomData_Version
int checkGE(int value, int min)
Definition SkSafeRange.h:37
T checkLE(uint64_t value, T max)
Definition SkSafeRange.h:28
bool hasColors() const
SkVertices::VertexMode mode() const
const uint16_t * indices() const
int indexCount() const
int vertexCount() const
@ kLast_VertexMode
Definition SkVertices.h:35
@ kTriangleFan_VertexMode
Definition SkVertices.h:33
static const uint8_t buffer[]
static DecodeResult decode(std::string path)

◆ encode()

void SkVerticesPriv::encode ( SkWriteBuffer buffer) const

Definition at line 240 of file SkVertices.cpp.

240 {
241 // packed has room for additional flags in the future
242 uint32_t packed = static_cast<uint32_t>(fVertices->fMode);
243 SkASSERT((packed & ~kMode_Mask) == 0); // our mode fits in the mask bits
244 if (fVertices->fTexs) {
245 packed |= kHasTexs_Mask;
246 }
247 if (fVertices->fColors) {
248 packed |= kHasColors_Mask;
249 }
250
251 SkVertices::Sizes sizes = fVertices->getSizes();
253
254 // Header
255 buffer.writeUInt(packed);
256 buffer.writeInt(fVertices->fVertexCount);
257 buffer.writeInt(fVertices->fIndexCount);
258
259 // Data arrays
260 buffer.writeByteArray(fVertices->fPositions, sizes.fVSize);
261 buffer.writeByteArray(fVertices->fTexs, sizes.fTSize);
262 buffer.writeByteArray(fVertices->fColors, sizes.fCSize);
263 // if index-count is odd, we won't be 4-bytes aligned, so we call the pad version
264 buffer.writeByteArray(fVertices->fIndices, sizes.fISize);
265}
#define SkASSERT(cond)
Definition SkAssert.h:116
size_t fBuilderTriFanISize

◆ hasColors()

bool SkVerticesPriv::hasColors ( ) const
inline

Definition at line 27 of file SkVerticesPriv.h.

27{ return SkToBool(fVertices->fColors); }

◆ hasIndices()

bool SkVerticesPriv::hasIndices ( ) const
inline

Definition at line 29 of file SkVerticesPriv.h.

29{ return SkToBool(fVertices->fIndices); }

◆ hasTexCoords()

bool SkVerticesPriv::hasTexCoords ( ) const
inline

Definition at line 28 of file SkVerticesPriv.h.

28{ return SkToBool(fVertices->fTexs); }

◆ indexCount()

int SkVerticesPriv::indexCount ( ) const
inline

Definition at line 32 of file SkVerticesPriv.h.

32{ return fVertices->fIndexCount; }

◆ indices()

const uint16_t * SkVerticesPriv::indices ( ) const
inline

Definition at line 37 of file SkVerticesPriv.h.

37{ return fVertices->fIndices; }

◆ mode()

SkVertices::VertexMode SkVerticesPriv::mode ( ) const
inline

Definition at line 25 of file SkVerticesPriv.h.

25{ return fVertices->fMode; }

◆ positions()

const SkPoint * SkVerticesPriv::positions ( ) const
inline

Definition at line 34 of file SkVerticesPriv.h.

34{ return fVertices->fPositions; }

◆ texCoords()

const SkPoint * SkVerticesPriv::texCoords ( ) const
inline

Definition at line 35 of file SkVerticesPriv.h.

35{ return fVertices->fTexs; }

◆ vertexCount()

int SkVerticesPriv::vertexCount ( ) const
inline

Definition at line 31 of file SkVerticesPriv.h.

31{ return fVertices->fVertexCount; }

Friends And Related Symbol Documentation

◆ SkVertices

friend class SkVertices
friend

Definition at line 55 of file SkVerticesPriv.h.


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