joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 GrGeometryProcessor_DEFINED |
| 9 | #define GrGeometryProcessor_DEFINED |
| 10 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 11 | #include "GrColor.h" |
joshualitt | c07379d | 2014-11-20 14:50:39 -0800 | [diff] [blame] | 12 | #include "GrGeometryData.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 13 | #include "GrProcessor.h" |
bsalomon | 6251d17 | 2014-10-15 10:50:36 -0700 | [diff] [blame] | 14 | #include "GrShaderVar.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 15 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 16 | /* |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 17 | * The GrPrimitiveProcessor represents some kind of geometric primitive. This includes the shape |
| 18 | * of the primitive and the inherent color of the primitive. The GrPrimitiveProcessor is |
| 19 | * responsible for providing a color and coverage input into the Ganesh rendering pipeline. Through |
| 20 | * optimization, Ganesh may decide a different color, no color, and / or no coverage are required |
| 21 | * from the GrPrimitiveProcessor, so the GrPrimitiveProcessor must be able to support this |
| 22 | * functionality. We also use the GrPrimitiveProcessor to make batching decisions. |
| 23 | * |
| 24 | * There are two feedback loops between the GrFragmentProcessors, the GrXferProcessor, and the |
| 25 | * GrPrimitiveProcessor. These loops run on the CPU and compute any invariant components which |
| 26 | * might be useful for correctness / optimization decisions. The GrPrimitiveProcessor seeds these |
| 27 | * loops, one with initial color and one with initial coverage, in its |
| 28 | * onComputeInvariantColor / Coverage calls. These seed values are processed by the subsequent |
| 29 | * stages of the rendering pipeline and the output is then fed back into the GrPrimitiveProcessor in |
| 30 | * the initBatchTracker call, where the GrPrimitiveProcessor can then initialize the GrBatchTracker |
| 31 | * struct with the appropriate values. |
| 32 | * |
| 33 | * We are evolving this system to move towards generating geometric meshes and their associated |
| 34 | * vertex data after we have batched and reordered draws. This system, known as 'deferred geometry' |
| 35 | * will allow the GrPrimitiveProcessor much greater control over how data is transmitted to shaders. |
| 36 | * |
| 37 | * In a deferred geometry world, the GrPrimitiveProcessor can always 'batch' To do this, each |
| 38 | * primitive type is associated with one GrPrimitiveProcessor, who has complete control of how |
| 39 | * it draws. Each primitive draw will bundle all required data to perform the draw, and these |
| 40 | * bundles of data will be owned by an instance of the associated GrPrimitiveProcessor. Bundles |
| 41 | * can be updated alongside the GrBatchTracker struct itself, ultimately allowing the |
| 42 | * GrPrimitiveProcessor complete control of how it gets data into the fragment shader as long as |
| 43 | * it emits the appropriate color, or none at all, as directed. |
| 44 | */ |
| 45 | |
| 46 | /* |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 47 | * A struct for tracking batching decisions. While this lives on GrOptState, it is managed |
| 48 | * entirely by the derived classes of the GP. |
| 49 | */ |
| 50 | class GrBatchTracker { |
| 51 | public: |
| 52 | template <typename T> const T& cast() const { |
| 53 | SkASSERT(sizeof(T) <= kMaxSize); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 54 | return *reinterpret_cast<const T*>(fData.get()); |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | template <typename T> T* cast() { |
| 58 | SkASSERT(sizeof(T) <= kMaxSize); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 59 | return reinterpret_cast<T*>(fData.get()); |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static const size_t kMaxSize = 32; |
| 63 | |
| 64 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 65 | SkAlignedSStorage<kMaxSize> fData; |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 68 | class GrGLCaps; |
| 69 | class GrGLGeometryProcessor; |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 70 | class GrOptDrawState; |
| 71 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 72 | struct GrInitInvariantOutput; |
| 73 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 74 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 75 | /* |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 76 | * This enum is shared by GrPrimitiveProcessors and GrGLPrimitiveProcessors to coordinate shaders |
| 77 | * with vertex attributes / uniforms. |
| 78 | */ |
| 79 | enum GrGPInput { |
| 80 | kAllOnes_GrGPInput, |
| 81 | kAttribute_GrGPInput, |
| 82 | kUniform_GrGPInput, |
| 83 | kIgnored_GrGPInput, |
| 84 | }; |
| 85 | |
| 86 | /* |
| 87 | * GrPrimitiveProcessor defines an interface which all subclasses must implement. All |
| 88 | * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh color / coverage |
| 89 | * pipelines, and they must provide some notion of equality |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 90 | */ |
| 91 | class GrPrimitiveProcessor : public GrProcessor { |
| 92 | public: |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 93 | // TODO let the PrimProc itself set this in its setData call, this should really live on the |
| 94 | // bundle of primitive data |
| 95 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 96 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 97 | /* |
| 98 | * This struct allows the optstate to communicate requirements to the GrPrimitiveProcessor. |
| 99 | */ |
| 100 | struct InitBT { |
| 101 | bool fColorIgnored; |
| 102 | bool fCoverageIgnored; |
| 103 | GrColor fOverrideColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 104 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; |
| 108 | |
| 109 | virtual bool canMakeEqual(const GrBatchTracker& mine, |
| 110 | const GrPrimitiveProcessor& that, |
| 111 | const GrBatchTracker& theirs) const = 0; |
| 112 | |
| 113 | /* |
| 114 | * We always call canMakeEqual before makeEqual so there is no need to do any kind of equality |
| 115 | * testing here |
| 116 | * TODO make this pure virtual when primProcs can actually use it |
| 117 | */ |
| 118 | virtual void makeEqual(GrBatchTracker*, const GrBatchTracker&) const {} |
| 119 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 120 | virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
| 121 | virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; |
| 122 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 123 | /** |
| 124 | * Sets a unique key on the GrProcessorKeyBuilder that is directly associated with this geometry |
| 125 | * processor's GL backend implementation. |
| 126 | */ |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 127 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 128 | const GrGLCaps& caps, |
| 129 | GrProcessorKeyBuilder* b) const = 0; |
| 130 | |
| 131 | |
| 132 | /** Returns a new instance of the appropriate *GL* implementation class |
| 133 | for the given GrProcessor; caller is responsible for deleting |
| 134 | the object. */ |
| 135 | virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) const = 0; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 136 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 137 | protected: |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 138 | GrPrimitiveProcessor(const SkMatrix& localMatrix) : fLocalMatrix(localMatrix) {} |
| 139 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 140 | /* |
| 141 | * CanCombineOutput will return true if two draws are 'batchable' from a color perspective. |
| 142 | * TODO remove this when GPs can upgrade to attribute color |
| 143 | */ |
| 144 | static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right, GrColor rColor) { |
| 145 | if (left != right) { |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | if (kUniform_GrGPInput == left && lColor != rColor) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | return true; |
| 154 | } |
| 155 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 156 | static bool CanCombineLocalMatrices(const GrPrimitiveProcessor& left, |
| 157 | bool leftUsesLocalCoords, |
| 158 | const GrPrimitiveProcessor& right, |
| 159 | bool rightUsesLocalCoords) { |
| 160 | if (leftUsesLocalCoords != rightUsesLocalCoords) { |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | if (leftUsesLocalCoords && !left.localMatrix().cheapEqualTo(right.localMatrix())) { |
| 165 | return false; |
| 166 | } |
| 167 | return true; |
| 168 | } |
| 169 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 170 | private: |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 171 | SkMatrix fLocalMatrix; |
| 172 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 173 | typedef GrProcessor INHERITED; |
| 174 | }; |
| 175 | |
| 176 | /** |
| 177 | * A GrGeometryProcessor is a flexible method for rendering a primitive. The GrGeometryProcessor |
| 178 | * has complete control over vertex attributes and uniforms(aside from the render target) but it |
| 179 | * must obey the same contract as any GrPrimitiveProcessor, specifically it must emit a color and |
| 180 | * coverage into the fragment shader. Where this color and coverage come from is completely the |
| 181 | * responsibility of the GrGeometryProcessor. |
| 182 | */ |
| 183 | class GrGeometryProcessor : public GrPrimitiveProcessor { |
| 184 | public: |
| 185 | // TODO the Hint can be handled in a much more clean way when we have deferred geometry or |
| 186 | // atleast bundles |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 187 | GrGeometryProcessor(GrColor color, |
| 188 | bool opaqueVertexColors = false, |
| 189 | const SkMatrix& localMatrix = SkMatrix::I()) |
| 190 | : INHERITED(localMatrix) |
| 191 | , fVertexStride(0) |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 192 | , fColor(color) |
| 193 | , fOpaqueVertexColors(opaqueVertexColors) |
| 194 | , fWillUseGeoShader(false) |
| 195 | , fHasVertexColor(false) |
| 196 | , fHasLocalCoords(false) {} |
| 197 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 198 | /* |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 199 | * This is a safeguard to prevent GPs from going beyond platform specific attribute limits. |
| 200 | * This number can almost certainly be raised if required. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 201 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 202 | static const int kMaxVertexAttribs = 6; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 203 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 204 | struct GrAttribute { |
| 205 | GrAttribute(const char* name, GrVertexAttribType type) |
| 206 | : fName(name) |
| 207 | , fType(type) |
| 208 | , fOffset(SkAlign4(GrVertexAttribTypeSize(type))) {} |
| 209 | const char* fName; |
| 210 | GrVertexAttribType fType; |
| 211 | size_t fOffset; |
| 212 | }; |
| 213 | |
| 214 | typedef SkTArray<GrAttribute, true> VertexAttribArray; |
| 215 | |
| 216 | const VertexAttribArray& getAttribs() const { return fAttribs; } |
| 217 | |
| 218 | // Returns the vertex stride of the GP. A common use case is to request geometry from a |
| 219 | // drawtarget based off of the stride, and to populate this memory using an implicit array of |
| 220 | // structs. In this case, it is best to assert the vertexstride == sizeof(VertexStruct). |
| 221 | size_t getVertexStride() const { return fVertexStride; } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 222 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 223 | bool willUseGeoShader() const { return fWillUseGeoShader; } |
| 224 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 225 | /* |
| 226 | * In an ideal world, two GrGeometryProcessors with the same class id and texture accesses |
| 227 | * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are the same then we |
| 228 | * will only keep one of them. The remaining GrGeometryProcessor then updates its |
| 229 | * GrBatchTracker to incorporate the draw information from the GrGeometryProcessor we discard. |
| 230 | * Any bundles associated with the discarded GrGeometryProcessor will be attached to the |
| 231 | * remaining GrGeometryProcessor. |
| 232 | */ |
| 233 | bool canMakeEqual(const GrBatchTracker& mine, |
| 234 | const GrPrimitiveProcessor& that, |
| 235 | const GrBatchTracker& theirs) const SK_OVERRIDE { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 236 | if (this->classID() != that.classID() || !this->hasSameTextureAccesses(that)) { |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 237 | return false; |
| 238 | } |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 239 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 240 | // TODO remove the hint |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 241 | const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); |
| 242 | if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 243 | return false; |
| 244 | } |
| 245 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 246 | // TODO this equality test should really be broken up, some of this can live on the batch |
| 247 | // tracker test and some of this should be in bundles |
| 248 | if (!this->onIsEqual(other)) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 249 | return false; |
| 250 | } |
| 251 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 252 | return this->onCanMakeEqual(mine, other, theirs); |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 253 | } |
| 254 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 255 | |
| 256 | // TODO we can remove color from the GrGeometryProcessor base class once we have bundles of |
| 257 | // primitive data |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 258 | GrColor color() const { return fColor; } |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 259 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 260 | // TODO this is a total hack until the gp can do deferred geometry |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 261 | bool hasVertexColor() const { return fHasVertexColor; } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 262 | |
| 263 | // TODO this is a total hack until gp can setup and manage local coords |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 264 | bool hasLocalCoords() const { return fHasLocalCoords; } |
| 265 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 266 | void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 267 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 268 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 269 | protected: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 270 | /* |
| 271 | * An optional simple helper function to determine by what means the GrGeometryProcessor should |
| 272 | * use to provide color. If we are given an override color(ie the given overridecolor is NOT |
| 273 | * GrColor_ILLEGAL) then we must always emit that color(currently overrides are only supported |
| 274 | * via uniform, but with deferred Geometry we could use attributes). Otherwise, if our color is |
| 275 | * ignored then we should not emit a color. Lastly, if we don't have vertex colors then we must |
| 276 | * emit a color via uniform |
| 277 | * TODO this function changes quite a bit with deferred geometry. There the GrGeometryProcessor |
| 278 | * can upload a new color via attribute if needed. |
| 279 | */ |
| 280 | static GrGPInput GetColorInputType(GrColor* color, GrColor primitiveColor, const InitBT& init, |
| 281 | bool hasVertexColor) { |
| 282 | if (init.fColorIgnored) { |
| 283 | *color = GrColor_ILLEGAL; |
| 284 | return kIgnored_GrGPInput; |
| 285 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 286 | *color = init.fOverrideColor; |
| 287 | return kUniform_GrGPInput; |
| 288 | } |
| 289 | |
| 290 | *color = primitiveColor; |
| 291 | if (hasVertexColor) { |
| 292 | return kAttribute_GrGPInput; |
| 293 | } else { |
| 294 | return kUniform_GrGPInput; |
| 295 | } |
| 296 | } |
| 297 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 298 | /** |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 299 | * Subclasses call this from their constructor to register vertex attributes. Attributes |
| 300 | * will be padded to the nearest 4 bytes for performance reasons. |
| 301 | * TODO After deferred geometry, we should do all of this inline in GenerateGeometry alongside |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 302 | * the struct used to actually populate the attributes. This is all extremely fragile, vertex |
| 303 | * attributes have to be added in the order they will appear in the struct which maps memory. |
| 304 | * The processor key should reflect the vertex attributes, or there lack thereof in the |
| 305 | * GrGeometryProcessor. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 306 | */ |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 307 | const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
| 308 | fVertexStride += attribute.fOffset; |
| 309 | return fAttribs.push_back(attribute); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 310 | } |
| 311 | |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 312 | void setWillUseGeoShader() { fWillUseGeoShader = true; } |
| 313 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 314 | // TODO hack see above |
| 315 | void setHasVertexColor() { fHasVertexColor = true; } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 316 | void setHasLocalCoords() { fHasLocalCoords = true; } |
| 317 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 318 | virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} |
| 319 | virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; |
| 320 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 321 | private: |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 322 | virtual bool onCanMakeEqual(const GrBatchTracker& mine, |
| 323 | const GrGeometryProcessor& that, |
| 324 | const GrBatchTracker& theirs) const = 0; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 325 | // TODO delete this when we have more advanced equality testing via bundles and the BT |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 326 | virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 327 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 328 | SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
| 329 | size_t fVertexStride; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 330 | GrColor fColor; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 331 | bool fOpaqueVertexColors; |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 332 | bool fWillUseGeoShader; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 333 | bool fHasVertexColor; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 334 | bool fHasLocalCoords; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 335 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 336 | typedef GrPrimitiveProcessor INHERITED; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 337 | }; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * The path equivalent of the GP. For now this just manages color. In the long term we plan on |
| 341 | * extending this class to handle all nvpr uniform / varying / program work. |
| 342 | */ |
| 343 | class GrPathProcessor : public GrPrimitiveProcessor { |
| 344 | public: |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 345 | static GrPathProcessor* Create(GrColor color, const SkMatrix& localMatrix = SkMatrix::I()) { |
| 346 | return SkNEW_ARGS(GrPathProcessor, (color, localMatrix)); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 347 | } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 348 | |
| 349 | void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; |
| 350 | |
| 351 | bool canMakeEqual(const GrBatchTracker& mine, |
| 352 | const GrPrimitiveProcessor& that, |
| 353 | const GrBatchTracker& theirs) const SK_OVERRIDE; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 354 | |
| 355 | const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 356 | |
| 357 | GrColor color() const { return fColor; } |
| 358 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 359 | void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 360 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 361 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 362 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 363 | const GrGLCaps& caps, |
| 364 | GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 365 | |
| 366 | virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) const SK_OVERRIDE; |
| 367 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 368 | private: |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 369 | GrPathProcessor(GrColor color, const SkMatrix& localMatrix); |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 370 | GrColor fColor; |
| 371 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 372 | typedef GrPrimitiveProcessor INHERITED; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 373 | }; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 374 | #endif |