Flutter Engine
The Flutter Engine
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
Definition: SkVertices.cpp:236
#define kHasTexs_Mask
Definition: SkVertices.cpp:237
#define kHasColors_Mask
Definition: SkVertices.cpp:238
@ 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
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
static DecodeResult decode(std::string path)
Definition: png_codec.cpp:124

◆ 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
Definition: SkVertices.cpp:96

◆ 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 Function 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: