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 class GrDrawState; 14 15 /* 16 * A factory for creating default Geometry Processors which simply multiply position by the uniform 17 * view matrix and wire through color, coverage, UV coords if requested. Right now this is only 18 * used in the creation of optimized draw states because adding default GPs to the drawstate can 19 * interfere with batching due to updating the drawstate. 20 */ 21 namespace GrDefaultGeoProcFactory { 22 // Structs for adding vertex attributes 23 struct PositionAttr { 24 SkPoint fPosition; 25 }; 26 27 struct PositionCoverageAttr { 28 SkPoint fPosition; 29 GrColor fCoverage; 30 }; 31 32 struct PositionColorAttr { 33 SkPoint fPosition; 34 SkColor fColor; 35 }; 36 37 struct PositionColorCoverageAttr { 38 SkPoint fPosition; 39 SkColor fColor; 40 GrColor fCoverage; 41 }; 42 43 struct PositionLocalCoordAttr { 44 SkPoint fPosition; 45 SkPoint fLocalCoord; 46 }; 47 48 struct PositionLocalCoordCoverageAttr { 49 SkPoint fPosition; 50 SkPoint fLocalCoord; 51 GrColor fCoverage; 52 }; 53 54 struct PositionColorLocalCoordAttr { 55 SkPoint fPosition; 56 GrColor fColor; 57 SkPoint fLocalCoord; 58 }; 59 60 struct PositionColorLocalCoordCoverage { 61 SkPoint fPosition; 62 GrColor fColor; 63 SkPoint fLocalCoord; 64 GrColor fCoverage; 65 }; 66 67 struct Color { 68 enum Type { 69 kNone_Type, 70 kUniform_Type, 71 kAttribute_Type, 72 }; ColorColor73 Color(GrColor color) : fType(kUniform_Type), fColor(color) {} ColorColor74 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) { 75 SkASSERT(type != kUniform_Type); 76 77 // TODO This is temporary 78 if (kAttribute_Type == type) { 79 fColor = GrColor_WHITE; 80 } 81 } 82 83 Type fType; 84 GrColor fColor; 85 }; 86 87 struct Coverage { 88 enum Type { 89 kNone_Type, 90 kSolid_Type, 91 kUniform_Type, 92 kAttribute_Type, 93 }; CoverageCoverage94 Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} CoverageCoverage95 Coverage(Type type) : fType(type), fCoverage(0xff) { 96 SkASSERT(type != kUniform_Type); 97 } 98 99 Type fType; 100 uint8_t fCoverage; 101 }; 102 103 struct LocalCoords { 104 enum Type { 105 kUnused_Type, 106 kUsePosition_Type, 107 kHasExplicit_Type, 108 kHasTransformed_Type, 109 }; LocalCoordsLocalCoords110 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} LocalCoordsLocalCoords111 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { 112 SkASSERT(kUnused_Type != type); 113 } hasLocalMatrixLocalCoords114 bool hasLocalMatrix() const { return nullptr != fMatrix; } 115 116 Type fType; 117 const SkMatrix* fMatrix; 118 }; 119 120 const GrGeometryProcessor* Create(const Color&, 121 const Coverage&, 122 const LocalCoords&, 123 const SkMatrix& viewMatrix); 124 125 /* 126 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position 127 * attribute. The view matrix must still be provided to compute correctly transformed 128 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. 129 */ 130 const GrGeometryProcessor* CreateForDeviceSpace(const Color&, 131 const Coverage&, 132 const LocalCoords&, 133 const SkMatrix& viewMatrix); 134 DefaultVertexStride()135 inline size_t DefaultVertexStride() { return sizeof(PositionAttr); } 136 }; 137 138 #endif 139