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