joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 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. |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 20 | */ |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame^] | 21 | namespace GrDefaultGeoProcFactory { |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 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 | enum GPType { |
| 68 | kPosition_GPType = 0x0, // we ALWAYS have position |
| 69 | kColor_GPType = 0x01, |
| 70 | kLocalCoord_GPType = 0x02, |
| 71 | kCoverage_GPType= 0x04, |
| 72 | kLastGPType = kCoverage_GPType |
| 73 | }; |
| 74 | |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 75 | struct Color { |
| 76 | enum Type { |
| 77 | kNone_Type, |
| 78 | kUniform_Type, |
| 79 | kAttribute_Type, |
| 80 | }; |
| 81 | Color(GrColor color) : fType(kUniform_Type), fColor(color) {} |
| 82 | Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) { |
| 83 | SkASSERT(type != kUniform_Type); |
| 84 | |
| 85 | // TODO This is temporary |
| 86 | if (kAttribute_Type == type) { |
| 87 | fColor = GrColor_WHITE; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | Type fType; |
| 92 | GrColor fColor; |
| 93 | }; |
| 94 | |
| 95 | struct Coverage { |
| 96 | enum Type { |
| 97 | kNone_Type, |
| 98 | kSolid_Type, |
| 99 | kUniform_Type, |
| 100 | kAttribute_Type, |
| 101 | }; |
| 102 | Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
| 103 | Coverage(Type type) : fType(type), fCoverage(0xff) { |
| 104 | SkASSERT(type != kUniform_Type); |
| 105 | } |
| 106 | |
| 107 | Type fType; |
| 108 | uint8_t fCoverage; |
| 109 | }; |
| 110 | |
| 111 | struct LocalCoords { |
| 112 | enum Type { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 113 | kUnused_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 114 | kUsePosition_Type, |
| 115 | kHasExplicit_Type, |
| 116 | }; |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 117 | LocalCoords(Type type) : fType(type), fMatrix(NULL) {} |
| 118 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
| 119 | SkASSERT(kUnused_Type != type); |
| 120 | } |
| 121 | bool hasLocalMatrix() const { return NULL != fMatrix; } |
| 122 | |
| 123 | Type fType; |
| 124 | const SkMatrix* fMatrix; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame^] | 127 | const GrGeometryProcessor* Create(const Color&, |
| 128 | const Coverage&, |
| 129 | const LocalCoords&, |
| 130 | const SkMatrix& viewMatrix = SkMatrix::I()); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 131 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 132 | /* |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 133 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
| 134 | * attribute. The view matrix must still be provided to compute correctly transformed |
| 135 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 136 | */ |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame^] | 137 | const GrGeometryProcessor* CreateForDeviceSpace(const Color&, |
| 138 | const Coverage&, |
| 139 | const LocalCoords&, |
| 140 | const SkMatrix& viewMatrix); |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 141 | |
| 142 | // TODO deprecate this |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame^] | 143 | const GrGeometryProcessor* Create(uint32_t gpTypeFlags, |
| 144 | GrColor, |
| 145 | bool localCoordsWillBeRead, |
| 146 | bool coverageWillBeIgnored, |
| 147 | const SkMatrix& viewMatrix = SkMatrix::I(), |
| 148 | const SkMatrix& localMatrix = SkMatrix::I(), |
| 149 | uint8_t coverage = 0xff); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 150 | |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame^] | 151 | inline size_t DefaultVertexStride() { return sizeof(PositionAttr); } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | #endif |