| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGeometryProcessor_DEFINED | 8 #ifndef GrGeometryProcessor_DEFINED |
| 9 #define GrGeometryProcessor_DEFINED | 9 #define GrGeometryProcessor_DEFINED |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 static const size_t kMaxSize = 32; | 32 static const size_t kMaxSize = 32; |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 uint8_t fData[kMaxSize]; | 35 uint8_t fData[kMaxSize]; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 class GrGLCaps; | 38 class GrGLCaps; |
| 39 class GrGLGeometryProcessor; | 39 class GrGLGeometryProcessor; |
| 40 class GrOptDrawState; | 40 class GrOptDrawState; |
| 41 | 41 |
| 42 struct GrInitInvariantOutput; |
| 43 |
| 44 /* |
| 45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor |
| 46 */ |
| 47 class GrPrimitiveProcessor : public GrProcessor { |
| 48 public: |
| 49 // TODO GPs and PPs have to provide an initial coverage because the coverage
invariant code is |
| 50 // broken right now |
| 51 virtual uint8_t coverage() const = 0; |
| 52 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; |
| 53 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const =
0; |
| 54 |
| 55 private: |
| 56 typedef GrProcessor INHERITED; |
| 57 }; |
| 58 |
| 42 /** | 59 /** |
| 43 * A GrGeometryProcessor is used to perform computation in the vertex shader and | 60 * A GrGeometryProcessor is used to perform computation in the vertex shader and |
| 44 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 61 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
| 45 * tied to the code that does a specific type of high-level primitive rendering | 62 * tied to the code that does a specific type of high-level primitive rendering |
| 46 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is | 63 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is |
| 47 * specified using GrDrawState. There can only be one geometry processor active
for | 64 * specified using GrDrawState. There can only be one geometry processor active
for |
| 48 * a draw. The custom vertex attributes required by the geometry processor must
be | 65 * a draw. The custom vertex attributes required by the geometry processor must
be |
| 49 * added to the vertex attribute array specified on the GrDrawState. | 66 * added to the vertex attribute array specified on the GrDrawState. |
| 50 * GrGeometryProcessor subclasses should be immutable after construction. | 67 * GrGeometryProcessor subclasses should be immutable after construction. |
| 51 */ | 68 */ |
| 52 class GrGeometryProcessor : public GrProcessor { | 69 class GrGeometryProcessor : public GrPrimitiveProcessor { |
| 53 public: | 70 public: |
| 54 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) | 71 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or |
| 72 // atleast bundles |
| 73 GrGeometryProcessor(GrColor color, bool opaqueVertexColors = false, uint8_t
coverage = 0xff) |
| 55 : fVertexStride(0) | 74 : fVertexStride(0) |
| 56 , fColor(color) | 75 , fColor(color) |
| 57 , fCoverage(coverage) | 76 , fCoverage(coverage) |
| 77 , fOpaqueVertexColors(opaqueVertexColors) |
| 58 , fWillUseGeoShader(false) | 78 , fWillUseGeoShader(false) |
| 59 , fHasVertexColor(false) | 79 , fHasVertexColor(false) |
| 60 , fHasVertexCoverage(false) | 80 , fHasVertexCoverage(false) |
| 61 , fHasLocalCoords(false) {} | 81 , fHasLocalCoords(false) {} |
| 62 | 82 |
| 63 virtual const char* name() const = 0; | 83 virtual const char* name() const = 0; |
| 64 | 84 |
| 65 /** | 85 /** |
| 66 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this geometry | 86 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this geometry |
| 67 * processor's GL backend implementation. | 87 * processor's GL backend implementation. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 true when the two prcoessors are of the same subclass (i.e. they return
the same object from | 127 true when the two prcoessors are of the same subclass (i.e. they return
the same object from |
| 108 from getFactory()). | 128 from getFactory()). |
| 109 A return value of true from isEqual() should not be used to test whether
the processors | 129 A return value of true from isEqual() should not be used to test whether
the processors |
| 110 would generate the same shader code. To test for identical code generati
on use the | 130 would generate the same shader code. To test for identical code generati
on use the |
| 111 processors' keys computed by the GrBackendEffectFactory. */ | 131 processors' keys computed by the GrBackendEffectFactory. */ |
| 112 bool isEqual(const GrGeometryProcessor& that) const { | 132 bool isEqual(const GrGeometryProcessor& that) const { |
| 113 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { | 133 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { |
| 114 return false; | 134 return false; |
| 115 } | 135 } |
| 116 | 136 |
| 117 if (!fHasVertexColor && this->getColor() != that.getColor()) { | 137 // TODO remove the hint |
| 138 if (fHasVertexColor && fOpaqueVertexColors != that.fOpaqueVertexColors)
{ |
| 118 return false; | 139 return false; |
| 119 } | 140 } |
| 120 | 141 |
| 121 if (!fHasVertexCoverage && this->getCoverage() != that.getCoverage()) { | 142 if (!fHasVertexColor && this->color() != that.color()) { |
| 143 return false; |
| 144 } |
| 145 |
| 146 // TODO this is fragile, most gps set their coverage to 0xff so this is
okay. In the long |
| 147 // term this should move to subclasses which set explicit coverage |
| 148 if (!fHasVertexCoverage && this->coverage() != that.coverage()) { |
| 122 return false; | 149 return false; |
| 123 } | 150 } |
| 124 return this->onIsEqual(that); | 151 return this->onIsEqual(that); |
| 125 } | 152 } |
| 126 | 153 |
| 127 struct InitBT { | 154 struct InitBT { |
| 128 bool fOutputColor; | 155 bool fOutputColor; |
| 129 bool fOutputCoverage; | 156 bool fOutputCoverage; |
| 130 GrColor fColor; | 157 GrColor fColor; |
| 131 GrColor fCoverage; | 158 GrColor fCoverage; |
| 132 }; | 159 }; |
| 133 | 160 |
| 134 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} | 161 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const {} |
| 135 | 162 |
| 136 GrColor getColor() const { return fColor; } | 163 GrColor color() const { return fColor; } |
| 137 uint8_t getCoverage() const { return fCoverage; } | 164 uint8_t coverage() const { return fCoverage; } |
| 138 | 165 |
| 139 // TODO this is a total hack until the gp can own whether or not it uses uni
form | 166 // TODO this is a total hack until the gp can own whether or not it uses uni
form |
| 140 // color / coverage | 167 // color / coverage |
| 141 bool hasVertexColor() const { return fHasVertexColor; } | 168 bool hasVertexColor() const { return fHasVertexColor; } |
| 142 bool hasVertexCoverage() const { return fHasVertexCoverage; } | 169 bool hasVertexCoverage() const { return fHasVertexCoverage; } |
| 143 bool hasLocalCoords() const { return fHasLocalCoords; } | 170 bool hasLocalCoords() const { return fHasLocalCoords; } |
| 144 | 171 |
| 145 void computeInvariantColor(GrInvariantOutput* inout) const; | 172 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 173 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; |
| 146 | 174 |
| 147 protected: | 175 protected: |
| 148 /** | 176 /** |
| 149 * Subclasses call this from their constructor to register vertex attributes
. Attributes | 177 * Subclasses call this from their constructor to register vertex attributes
. Attributes |
| 150 * will be padded to the nearest 4 bytes for performance reasons. | 178 * will be padded to the nearest 4 bytes for performance reasons. |
| 151 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | 179 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside |
| 152 * the struct used to actually populate the attributes | 180 * the struct used to actually populate the attributes |
| 153 */ | 181 */ |
| 154 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 182 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
| 155 fVertexStride += attribute.fOffset; | 183 fVertexStride += attribute.fOffset; |
| 156 return fAttribs.push_back(attribute); | 184 return fAttribs.push_back(attribute); |
| 157 } | 185 } |
| 158 | 186 |
| 159 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 187 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
| 160 | 188 |
| 161 // TODO hack see above | 189 // TODO hack see above |
| 162 void setHasVertexColor() { fHasVertexColor = true; } | 190 void setHasVertexColor() { fHasVertexColor = true; } |
| 163 void setHasVertexCoverage() { fHasVertexCoverage = true; } | 191 void setHasVertexCoverage() { fHasVertexCoverage = true; } |
| 164 void setHasLocalCoords() { fHasLocalCoords = true; } | 192 void setHasLocalCoords() { fHasLocalCoords = true; } |
| 165 | 193 |
| 194 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} |
| 195 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; |
| 196 |
| 166 private: | 197 private: |
| 167 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 198 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 168 | 199 |
| 169 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | 200 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
| 170 size_t fVertexStride; | 201 size_t fVertexStride; |
| 171 GrColor fColor; | 202 GrColor fColor; |
| 172 uint8_t fCoverage; | 203 uint8_t fCoverage; |
| 204 bool fOpaqueVertexColors; |
| 173 bool fWillUseGeoShader; | 205 bool fWillUseGeoShader; |
| 174 bool fHasVertexColor; | 206 bool fHasVertexColor; |
| 175 bool fHasVertexCoverage; | 207 bool fHasVertexCoverage; |
| 176 bool fHasLocalCoords; | 208 bool fHasLocalCoords; |
| 177 | 209 |
| 178 typedef GrProcessor INHERITED; | 210 typedef GrProcessor INHERITED; |
| 179 }; | 211 }; |
| 212 |
| 213 /* |
| 214 * The path equivalent of the GP. For now this just manages color. In the long
term we plan on |
| 215 * extending this class to handle all nvpr uniform / varying / program work. |
| 216 */ |
| 217 class GrPathProcessor : public GrPrimitiveProcessor { |
| 218 public: |
| 219 static GrPathProcessor* Create(GrColor color) { |
| 220 return SkNEW_ARGS(GrPathProcessor, (color)); |
| 221 } |
| 222 |
| 223 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
| 224 uint8_t coverage() const SK_OVERRIDE { return 0xff; } |
| 225 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 226 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; |
| 227 |
| 228 private: |
| 229 GrPathProcessor(GrColor color) : fColor(color) {} |
| 230 GrColor fColor; |
| 231 |
| 232 typedef GrProcessor INHERITED; |
| 233 }; |
| 180 #endif | 234 #endif |
| OLD | NEW |