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 "GrGeometryProcessor.h" 12 13 /* 14 * A factory for creating default Geometry Processors which simply multiply position by the uniform 15 * view matrix and wire through color, coverage, UV coords if requested. 16 */ 17 namespace GrDefaultGeoProcFactory { 18 // Structs for adding vertex attributes 19 struct PositionAttr { 20 SkPoint fPosition; 21 }; 22 23 struct PositionCoverageAttr { 24 SkPoint fPosition; 25 float fCoverage; 26 }; 27 28 struct PositionColorAttr { 29 SkPoint fPosition; 30 SkColor fColor; 31 }; 32 33 struct PositionColorCoverageAttr { 34 SkPoint fPosition; 35 SkColor fColor; 36 float fCoverage; 37 }; 38 39 struct PositionLocalCoordAttr { 40 SkPoint fPosition; 41 SkPoint fLocalCoord; 42 }; 43 44 struct PositionLocalCoordCoverageAttr { 45 SkPoint fPosition; 46 SkPoint fLocalCoord; 47 float fCoverage; 48 }; 49 50 struct PositionColorLocalCoordAttr { 51 SkPoint fPosition; 52 GrColor fColor; 53 SkPoint fLocalCoord; 54 }; 55 56 struct PositionColorLocalCoordCoverage { 57 SkPoint fPosition; 58 GrColor fColor; 59 SkPoint fLocalCoord; 60 float fCoverage; 61 }; 62 63 struct Color { 64 enum Type { 65 kPremulGrColorUniform_Type, 66 kPremulGrColorAttribute_Type, 67 kUnpremulSkColorAttribute_Type, 68 }; ColorColor69 explicit Color(GrColor color) : fType(kPremulGrColorUniform_Type), fColor(color) {} ColorColor70 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) { 71 SkASSERT(type != kPremulGrColorUniform_Type); 72 } 73 74 Type fType; 75 GrColor fColor; 76 }; 77 78 struct Coverage { 79 enum Type { 80 kSolid_Type, 81 kUniform_Type, 82 kAttribute_Type, 83 }; CoverageCoverage84 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} CoverageCoverage85 Coverage(Type type) : fType(type), fCoverage(0xff) { 86 SkASSERT(type != kUniform_Type); 87 } 88 89 Type fType; 90 uint8_t fCoverage; 91 }; 92 93 struct LocalCoords { 94 enum Type { 95 kUnused_Type, 96 kUsePosition_Type, 97 kHasExplicit_Type, 98 kHasTransformed_Type, 99 }; LocalCoordsLocalCoords100 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} LocalCoordsLocalCoords101 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { 102 SkASSERT(kUnused_Type != type); 103 } hasLocalMatrixLocalCoords104 bool hasLocalMatrix() const { return nullptr != fMatrix; } 105 106 Type fType; 107 const SkMatrix* fMatrix; 108 }; 109 110 sk_sp<GrGeometryProcessor> Make(const Color&, 111 const Coverage&, 112 const LocalCoords&, 113 const SkMatrix& viewMatrix); 114 115 /* 116 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position 117 * attribute. The view matrix must still be provided to compute correctly transformed 118 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. 119 */ 120 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&, 121 const Coverage&, 122 const LocalCoords&, 123 const SkMatrix& viewMatrix); 124 }; 125 126 #endif 127