| 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 SkVerticesPriv { | 
| 22 | public: | 
| 23 | SkVertices::VertexMode mode() const { return fVertices->fMode; } | 
| 24 | |
| 25 | bool hasCustomData() const { return SkToBool(fVertices->fCustomData); } | 
| 26 | bool hasColors() const { return SkToBool(fVertices->fColors); } | 
| 27 | bool hasTexCoords() const { return SkToBool(fVertices->fTexs); } | 
| 28 | bool hasIndices() const { return SkToBool(fVertices->fIndices); } | 
| 29 | |
| 30 | bool hasUsage(SkVertices::Attribute::Usage) const; | 
| 31 | |
| 32 | int vertexCount() const { return fVertices->fVertexCount; } | 
| 33 | int indexCount() const { return fVertices->fIndexCount; } | 
| 34 | int attributeCount() const { return fVertices->fAttributeCount; } | 
| 35 | size_t customDataSize() const; | 
| 36 | |
| 37 | const SkPoint* positions() const { return fVertices->fPositions; } | 
| 38 | const void* customData() const { return fVertices->fCustomData; } | 
| 39 | const SkPoint* texCoords() const { return fVertices->fTexs; } | 
| 40 | const SkColor* colors() const { return fVertices->fColors; } | 
| 41 | const uint16_t* indices() const { return fVertices->fIndices; } | 
| 42 | const SkVertices::Attribute* attributes() const { return fVertices->fAttributes; } | 
| 43 | |
| 44 | // Never called due to RVO in priv(), but must exist for MSVC 2017. | 
| 45 | SkVerticesPriv(const SkVerticesPriv&) = default; | 
| 46 | |
| 47 | void encode(SkWriteBuffer&) const; | 
| 48 | static sk_sp<SkVertices> Decode(SkReadBuffer&); | 
| 49 | |
| 50 | private: | 
| 51 | explicit SkVerticesPriv(SkVertices* vertices) : fVertices(vertices) {} | 
| 52 | SkVerticesPriv& operator=(const SkVerticesPriv&) = delete; | 
| 53 | |
| 54 | // No taking addresses of this type | 
| 55 | const SkVerticesPriv* operator&() const = delete; | 
| 56 | SkVerticesPriv* operator&() = delete; | 
| 57 | |
| 58 | SkVertices* fVertices; | 
| 59 | |
| 60 | friend class SkVertices; // to construct this type | 
| 61 | }; | 
| 62 | |
| 63 | inline SkVerticesPriv SkVertices::priv() { return SkVerticesPriv(this); } | 
| 64 | |
| 65 | inline const SkVerticesPriv SkVertices::priv() const { // NOLINT(readability-const-return-type) | 
| 66 | return SkVerticesPriv(const_cast<SkVertices*>(this)); | 
| 67 | } | 
| 68 | |
| 69 | #endif | 
| 70 | 
