1 /* 2 * Copyright 2021 Google LLC 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 SkCustomMeshPriv_DEFINED 9 #define SkCustomMeshPriv_DEFINED 10 11 #include "include/core/SkCustomMesh.h" 12 13 #ifdef SK_ENABLE_SKSL 14 #include "include/private/GrTypesPriv.h" 15 #include "src/core/SkSLTypeShared.h" 16 17 struct SkCustomMeshSpecificationPriv { 18 using Varying = SkCustomMeshSpecification::Varying; 19 using Attribute = SkCustomMeshSpecification::Attribute; 20 using ColorType = SkCustomMeshSpecification::ColorType; 21 VaryingsSkCustomMeshSpecificationPriv22 static SkSpan<const Varying> Varyings(const SkCustomMeshSpecification& spec) { 23 return SkMakeSpan(spec.fVaryings); 24 } 25 VSSkCustomMeshSpecificationPriv26 static const SkSL::Program* VS(const SkCustomMeshSpecification& spec) { return spec.fVS.get(); } FSSkCustomMeshSpecificationPriv27 static const SkSL::Program* FS(const SkCustomMeshSpecification& spec) { return spec.fFS.get(); } 28 HashSkCustomMeshSpecificationPriv29 static int Hash(const SkCustomMeshSpecification& spec) { return spec.fHash; } 30 GetColorTypeSkCustomMeshSpecificationPriv31 static ColorType GetColorType(const SkCustomMeshSpecification& spec) { return spec.fColorType; } HasColorsSkCustomMeshSpecificationPriv32 static bool HasColors(const SkCustomMeshSpecification& spec) { 33 return GetColorType(spec) != ColorType::kNone; 34 } 35 ColorSpaceSkCustomMeshSpecificationPriv36 static SkColorSpace* ColorSpace(const SkCustomMeshSpecification& spec) { 37 return spec.fColorSpace.get(); 38 } 39 AlphaTypeSkCustomMeshSpecificationPriv40 static SkAlphaType AlphaType(const SkCustomMeshSpecification& spec) { return spec.fAlphaType; } 41 HasLocalCoordsSkCustomMeshSpecificationPriv42 static bool HasLocalCoords(const SkCustomMeshSpecification& spec) { 43 return spec.fHasLocalCoords; 44 } 45 VaryingTypeAsSLTypeSkCustomMeshSpecificationPriv46 static SkSLType VaryingTypeAsSLType(Varying::Type type) { 47 switch (type) { 48 case Varying::Type::kFloat: return SkSLType::kFloat; 49 case Varying::Type::kFloat2: return SkSLType::kFloat2; 50 case Varying::Type::kFloat3: return SkSLType::kFloat3; 51 case Varying::Type::kFloat4: return SkSLType::kFloat4; 52 case Varying::Type::kHalf: return SkSLType::kHalf; 53 case Varying::Type::kHalf2: return SkSLType::kHalf2; 54 case Varying::Type::kHalf3: return SkSLType::kHalf3; 55 case Varying::Type::kHalf4: return SkSLType::kHalf4; 56 } 57 SkUNREACHABLE; 58 } 59 AttrTypeAsVertexAttribTypeSkCustomMeshSpecificationPriv60 static GrVertexAttribType AttrTypeAsVertexAttribType(Attribute::Type type) { 61 switch (type) { 62 case Attribute::Type::kFloat: return kFloat_GrVertexAttribType; 63 case Attribute::Type::kFloat2: return kFloat2_GrVertexAttribType; 64 case Attribute::Type::kFloat3: return kFloat3_GrVertexAttribType; 65 case Attribute::Type::kFloat4: return kFloat4_GrVertexAttribType; 66 case Attribute::Type::kUByte4_unorm: return kUByte4_norm_GrVertexAttribType; 67 } 68 SkUNREACHABLE; 69 } 70 AttrTypeAsSLTypeSkCustomMeshSpecificationPriv71 static SkSLType AttrTypeAsSLType(Attribute::Type type) { 72 switch (type) { 73 case Attribute::Type::kFloat: return SkSLType::kFloat; 74 case Attribute::Type::kFloat2: return SkSLType::kFloat2; 75 case Attribute::Type::kFloat3: return SkSLType::kFloat3; 76 case Attribute::Type::kFloat4: return SkSLType::kFloat4; 77 case Attribute::Type::kUByte4_unorm: return SkSLType::kHalf4; 78 } 79 SkUNREACHABLE; 80 } 81 }; 82 83 bool SkValidateCustomMesh(const SkCustomMesh&); 84 85 std::unique_ptr<const char[]> SkCopyCustomMeshVB(const SkCustomMesh& cm); 86 87 std::unique_ptr<const uint16_t[]> SkCopyCustomMeshIB(const SkCustomMesh& cm); 88 89 #endif // SK_ENABLE_SKSL 90 91 #endif 92