1 /* 2 * Copyright 2014 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 GrDefaultGeoProcFactory_DEFINED 9 #define GrDefaultGeoProcFactory_DEFINED 10 11 #include "GrColorSpaceXform.h" 12 #include "GrGeometryProcessor.h" 13 #include "GrShaderCaps.h" 14 15 constexpr int kMaxBones = 80; // Supports up to 80 bones per mesh. 16 17 /* 18 * A factory for creating default Geometry Processors which simply multiply position by the uniform 19 * view matrix and wire through color, coverage, UV coords if requested. 20 */ 21 namespace GrDefaultGeoProcFactory { 22 struct Color { 23 enum Type { 24 kPremulGrColorUniform_Type, 25 kPremulGrColorAttribute_Type, 26 kPremulWideColorAttribute_Type, 27 kUnpremulSkColorAttribute_Type, 28 }; 29 explicit Color(const SkPMColor4f& color) 30 : fType(kPremulGrColorUniform_Type) 31 , fColor(color) 32 , fColorSpaceXform(nullptr) {} 33 Color(Type type) 34 : fType(type) 35 , fColor(SK_PMColor4fILLEGAL) 36 , fColorSpaceXform(nullptr) { 37 SkASSERT(type != kPremulGrColorUniform_Type); 38 } 39 40 Type fType; 41 SkPMColor4f fColor; 42 43 // This only applies to SkColor. Any GrColors are assumed to have been color converted 44 // during paint conversion. 45 sk_sp<GrColorSpaceXform> fColorSpaceXform; 46 }; 47 48 struct Coverage { 49 enum Type { 50 kSolid_Type, 51 kUniform_Type, 52 kAttribute_Type, 53 kAttributeTweakAlpha_Type, 54 }; 55 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} 56 Coverage(Type type) : fType(type), fCoverage(0xff) { 57 SkASSERT(type != kUniform_Type); 58 } 59 60 Type fType; 61 uint8_t fCoverage; 62 }; 63 64 struct LocalCoords { 65 enum Type { 66 kUnused_Type, 67 kUsePosition_Type, 68 kHasExplicit_Type, 69 kHasTransformed_Type, 70 }; 71 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} 72 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { 73 SkASSERT(kUnused_Type != type); 74 } 75 bool hasLocalMatrix() const { return nullptr != fMatrix; } 76 77 Type fType; 78 const SkMatrix* fMatrix; 79 }; 80 81 struct Bones { 82 Bones(const float bones[], int boneCount) 83 : fBones(bones) 84 , fBoneCount(boneCount) {} 85 86 const float* fBones; 87 int fBoneCount; 88 }; 89 90 sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*, 91 const Color&, 92 const Coverage&, 93 const LocalCoords&, 94 const SkMatrix& viewMatrix); 95 96 /* 97 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position 98 * attribute. The view matrix must still be provided to compute correctly transformed 99 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. 100 */ 101 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*, 102 const Color&, 103 const Coverage&, 104 const LocalCoords&, 105 const SkMatrix& viewMatrix); 106 107 /* 108 * Use this factory to create a GrGeometryProcessor that supports skeletal animation through 109 * deformation of vertices using matrices that are passed in. This should only be called from 110 * GrDrawVerticesOp. 111 */ 112 sk_sp<GrGeometryProcessor> MakeWithBones(const GrShaderCaps*, 113 const Color&, 114 const Coverage&, 115 const LocalCoords&, 116 const Bones&, 117 const SkMatrix& viewMatrix); 118 }; 119 120 #endif 121