1 /* 2 * Copyright 2020 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkVerticesPriv_DEFINED 9 #define SkVerticesPriv_DEFINED 10 11 #include "include/core/SkVertices.h" 12 13 class SkReadBuffer; 14 class SkWriteBuffer; 15 16 struct SkVertices_DeprecatedBone { float values[6]; }; 17 18 /** Class that adds methods to SkVertices that are only intended for use internal to Skia. 19 This class is purely a privileged window into SkVertices. It should never have additional 20 data members or virtual methods. */ 21 class SK_API SkVerticesPriv { 22 public: mode()23 SkVertices::VertexMode mode() const { return fVertices->fMode; } 24 hasColors()25 bool hasColors() const { return SkToBool(fVertices->fColors); } hasTexCoords()26 bool hasTexCoords() const { return SkToBool(fVertices->fTexs); } hasIndices()27 bool hasIndices() const { return SkToBool(fVertices->fIndices); } 28 vertexCount()29 int vertexCount() const { return fVertices->fVertexCount; } indexCount()30 int indexCount() const { return fVertices->fIndexCount; } 31 positions()32 const SkPoint* positions() const { return fVertices->fPositions; } texCoords()33 const SkPoint* texCoords() const { return fVertices->fTexs; } colors()34 const SkColor* colors() const { return fVertices->fColors; } indices()35 const uint16_t* indices() const { return fVertices->fIndices; } 36 37 // Never called due to RVO in priv(), but must exist for MSVC 2017. 38 SkVerticesPriv(const SkVerticesPriv&) = default; 39 40 void encode(SkWriteBuffer&) const; 41 static sk_sp<SkVertices> Decode(SkReadBuffer&); 42 43 private: SkVerticesPriv(SkVertices * vertices)44 explicit SkVerticesPriv(SkVertices* vertices) : fVertices(vertices) {} 45 SkVerticesPriv& operator=(const SkVerticesPriv&) = delete; 46 47 // No taking addresses of this type 48 const SkVerticesPriv* operator&() const = delete; 49 SkVerticesPriv* operator&() = delete; 50 51 SkVertices* fVertices; 52 53 friend class SkVertices; // to construct this type 54 }; 55 priv()56inline SkVerticesPriv SkVertices::priv() { return SkVerticesPriv(this); } 57 priv()58inline const SkVerticesPriv SkVertices::priv() const { // NOLINT(readability-const-return-type) 59 return SkVerticesPriv(const_cast<SkVertices*>(this)); 60 } 61 62 #endif 63