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 class GrDefaultGeoProcFactory { 22 public: 23 // Structs for adding vertex attributes 24 struct PositionAttr { 25 SkPoint fPosition; 26 }; 27 28 struct PositionCoverageAttr { 29 SkPoint fPosition; 30 GrColor fCoverage; 31 }; 32 33 struct PositionColorAttr { 34 SkPoint fPosition; 35 SkColor fColor; 36 }; 37 38 struct PositionColorCoverageAttr { 39 SkPoint fPosition; 40 SkColor fColor; 41 GrColor fCoverage; 42 }; 43 44 struct PositionLocalCoordAttr { 45 SkPoint fPosition; 46 SkPoint fLocalCoord; 47 }; 48 49 struct PositionLocalCoordCoverageAttr { 50 SkPoint fPosition; 51 SkPoint fLocalCoord; 52 GrColor fCoverage; 53 }; 54 55 struct PositionColorLocalCoordAttr { 56 SkPoint fPosition; 57 GrColor fColor; 58 SkPoint fLocalCoord; 59 }; 60 61 struct PositionColorLocalCoordCoverage { 62 SkPoint fPosition; 63 GrColor fColor; 64 SkPoint fLocalCoord; 65 GrColor fCoverage; 66 }; 67 68 enum GPType { 69 kPosition_GPType = 0x0, // we ALWAYS have position 70 kColor_GPType = 0x01, 71 kLocalCoord_GPType = 0x02, 72 kCoverage_GPType= 0x04, 73 kLastGPType = kCoverage_GPType 74 }; 75 76 /* 77 * The following functions are used to create default GPs. If you just need to create 78 * attributes seperately from creating the default GP, use the SetAttribs function followed 79 * by the Create function. Otherwise use CreateAndSetAttribs to do both at once. 80 * 81 * You must unref the return from Create. 82 */ 83 // TODO clean this up 84 static const GrGeometryProcessor* Create(uint32_t gpTypeFlags, 85 GrColor, 86 const SkMatrix& viewMatrix = SkMatrix::I(), 87 const SkMatrix& localMatrix = SkMatrix::I(), 88 uint8_t coverage = 0xff); 89 DefaultVertexStride()90 static size_t DefaultVertexStride() { return sizeof(PositionAttr); } 91 }; 92 93 #endif 94