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