| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 kIgnored_GrGPInput, | 83 kIgnored_GrGPInput, |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 /* | 86 /* |
| 87 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All | 87 * GrPrimitiveProcessor defines an interface which all subclasses must implement
. All |
| 88 * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh co
lor / coverage | 88 * GrPrimitiveProcessors must proivide seed color and coverage for the Ganesh co
lor / coverage |
| 89 * pipelines, and they must provide some notion of equality | 89 * pipelines, and they must provide some notion of equality |
| 90 */ | 90 */ |
| 91 class GrPrimitiveProcessor : public GrProcessor { | 91 class GrPrimitiveProcessor : public GrProcessor { |
| 92 public: | 92 public: |
| 93 // TODO let the PrimProc itself set this in its setData call, this should re
ally live on the |
| 94 // bundle of primitive data |
| 95 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 96 |
| 93 /* | 97 /* |
| 94 * This struct allows the optstate to communicate requirements to the GrPrim
itiveProcessor. | 98 * This struct allows the optstate to communicate requirements to the GrPrim
itiveProcessor. |
| 95 */ | 99 */ |
| 96 struct InitBT { | 100 struct InitBT { |
| 97 bool fColorIgnored; | 101 bool fColorIgnored; |
| 98 bool fCoverageIgnored; | 102 bool fCoverageIgnored; |
| 99 GrColor fOverrideColor; | 103 GrColor fOverrideColor; |
| 104 bool fUsesLocalCoords; |
| 100 }; | 105 }; |
| 101 | 106 |
| 102 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; | 107 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; |
| 103 | 108 |
| 104 virtual bool canMakeEqual(const GrBatchTracker& mine, | 109 virtual bool canMakeEqual(const GrBatchTracker& mine, |
| 105 const GrPrimitiveProcessor& that, | 110 const GrPrimitiveProcessor& that, |
| 106 const GrBatchTracker& theirs) const = 0; | 111 const GrBatchTracker& theirs) const = 0; |
| 107 | 112 |
| 108 /* | 113 /* |
| 109 * We always call canMakeEqual before makeEqual so there is no need to do an
y kind of equality | 114 * We always call canMakeEqual before makeEqual so there is no need to do an
y kind of equality |
| (...skipping 13 matching lines...) Expand all Loading... |
| 123 const GrGLCaps& caps, | 128 const GrGLCaps& caps, |
| 124 GrProcessorKeyBuilder* b) const = 0; | 129 GrProcessorKeyBuilder* b) const = 0; |
| 125 | 130 |
| 126 | 131 |
| 127 /** Returns a new instance of the appropriate *GL* implementation class | 132 /** Returns a new instance of the appropriate *GL* implementation class |
| 128 for the given GrProcessor; caller is responsible for deleting | 133 for the given GrProcessor; caller is responsible for deleting |
| 129 the object. */ | 134 the object. */ |
| 130 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst = 0; | 135 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst = 0; |
| 131 | 136 |
| 132 protected: | 137 protected: |
| 138 GrPrimitiveProcessor(const SkMatrix& localMatrix) : fLocalMatrix(localMatrix
) {} |
| 139 |
| 133 /* | 140 /* |
| 134 * CanCombineOutput will return true if two draws are 'batchable' from a col
or perspective. | 141 * CanCombineOutput will return true if two draws are 'batchable' from a col
or perspective. |
| 135 * TODO remove this when GPs can upgrade to attribute color | 142 * TODO remove this when GPs can upgrade to attribute color |
| 136 */ | 143 */ |
| 137 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right
, GrColor rColor) { | 144 static bool CanCombineOutput(GrGPInput left, GrColor lColor, GrGPInput right
, GrColor rColor) { |
| 138 if (left != right) { | 145 if (left != right) { |
| 139 return false; | 146 return false; |
| 140 } | 147 } |
| 141 | 148 |
| 142 if (kUniform_GrGPInput == left && lColor != rColor) { | 149 if (kUniform_GrGPInput == left && lColor != rColor) { |
| 143 return false; | 150 return false; |
| 144 } | 151 } |
| 145 | 152 |
| 146 return true; | 153 return true; |
| 147 } | 154 } |
| 148 | 155 |
| 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.localM
atrix())) { |
| 165 return false; |
| 166 } |
| 167 return true; |
| 168 } |
| 169 |
| 149 private: | 170 private: |
| 171 SkMatrix fLocalMatrix; |
| 172 |
| 150 typedef GrProcessor INHERITED; | 173 typedef GrProcessor INHERITED; |
| 151 }; | 174 }; |
| 152 | 175 |
| 153 /** | 176 /** |
| 154 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor | 177 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor |
| 155 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it | 178 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it |
| 156 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and | 179 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and |
| 157 * coverage into the fragment shader. Where this color and coverage come from i
s completely the | 180 * coverage into the fragment shader. Where this color and coverage come from i
s completely the |
| 158 * responsibility of the GrGeometryProcessor. | 181 * responsibility of the GrGeometryProcessor. |
| 159 */ | 182 */ |
| 160 class GrGeometryProcessor : public GrPrimitiveProcessor { | 183 class GrGeometryProcessor : public GrPrimitiveProcessor { |
| 161 public: | 184 public: |
| 162 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or | 185 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or |
| 163 // atleast bundles | 186 // atleast bundles |
| 164 GrGeometryProcessor(GrColor color, bool opaqueVertexColors = false) | 187 GrGeometryProcessor(GrColor color, |
| 165 : fVertexStride(0) | 188 bool opaqueVertexColors = false, |
| 189 const SkMatrix& localMatrix = SkMatrix::I()) |
| 190 : INHERITED(localMatrix) |
| 191 , fVertexStride(0) |
| 166 , fColor(color) | 192 , fColor(color) |
| 167 , fOpaqueVertexColors(opaqueVertexColors) | 193 , fOpaqueVertexColors(opaqueVertexColors) |
| 168 , fWillUseGeoShader(false) | 194 , fWillUseGeoShader(false) |
| 169 , fHasVertexColor(false) | 195 , fHasVertexColor(false) |
| 170 , fHasLocalCoords(false) {} | 196 , fHasLocalCoords(false) {} |
| 171 | 197 |
| 172 /* | 198 /* |
| 173 * This is a safeguard to prevent GPs from going beyond platform specific at
tribute limits. | 199 * This is a safeguard to prevent GPs from going beyond platform specific at
tribute limits. |
| 174 * This number can almost certainly be raised if required. | 200 * This number can almost certainly be raised if required. |
| 175 */ | 201 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors)
{ | 242 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors)
{ |
| 217 return false; | 243 return false; |
| 218 } | 244 } |
| 219 | 245 |
| 220 // TODO this equality test should really be broken up, some of this can
live on the batch | 246 // TODO this equality test should really be broken up, some of this can
live on the batch |
| 221 // tracker test and some of this should be in bundles | 247 // tracker test and some of this should be in bundles |
| 222 if (!this->onIsEqual(other)) { | 248 if (!this->onIsEqual(other)) { |
| 223 return false; | 249 return false; |
| 224 } | 250 } |
| 225 | 251 |
| 226 return this->onCanMakeEqual(mine, theirs); | 252 return this->onCanMakeEqual(mine, other, theirs); |
| 227 } | 253 } |
| 228 | 254 |
| 229 | 255 |
| 230 // TODO we can remove color from the GrGeometryProcessor base class once we
have bundles of | 256 // TODO we can remove color from the GrGeometryProcessor base class once we
have bundles of |
| 231 // primitive data | 257 // primitive data |
| 232 GrColor color() const { return fColor; } | 258 GrColor color() const { return fColor; } |
| 233 | 259 |
| 234 // TODO this is a total hack until the gp can do deferred geometry | 260 // TODO this is a total hack until the gp can do deferred geometry |
| 235 bool hasVertexColor() const { return fHasVertexColor; } | 261 bool hasVertexColor() const { return fHasVertexColor; } |
| 236 | 262 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 312 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
| 287 | 313 |
| 288 // TODO hack see above | 314 // TODO hack see above |
| 289 void setHasVertexColor() { fHasVertexColor = true; } | 315 void setHasVertexColor() { fHasVertexColor = true; } |
| 290 void setHasLocalCoords() { fHasLocalCoords = true; } | 316 void setHasLocalCoords() { fHasLocalCoords = true; } |
| 291 | 317 |
| 292 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} | 318 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} |
| 293 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; | 319 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; |
| 294 | 320 |
| 295 private: | 321 private: |
| 296 virtual bool onCanMakeEqual(const GrBatchTracker& mine, const GrBatchTracker
& theirs) const = 0; | 322 virtual bool onCanMakeEqual(const GrBatchTracker& mine, |
| 323 const GrGeometryProcessor& that, |
| 324 const GrBatchTracker& theirs) const = 0; |
| 297 // TODO delete this when we have more advanced equality testing via bundles
and the BT | 325 // TODO delete this when we have more advanced equality testing via bundles
and the BT |
| 298 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 326 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 299 | 327 |
| 300 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | 328 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
| 301 size_t fVertexStride; | 329 size_t fVertexStride; |
| 302 GrColor fColor; | 330 GrColor fColor; |
| 303 bool fOpaqueVertexColors; | 331 bool fOpaqueVertexColors; |
| 304 bool fWillUseGeoShader; | 332 bool fWillUseGeoShader; |
| 305 bool fHasVertexColor; | 333 bool fHasVertexColor; |
| 306 bool fHasLocalCoords; | 334 bool fHasLocalCoords; |
| 307 | 335 |
| 308 typedef GrProcessor INHERITED; | 336 typedef GrPrimitiveProcessor INHERITED; |
| 309 }; | 337 }; |
| 310 | 338 |
| 311 /* | 339 /* |
| 312 * The path equivalent of the GP. For now this just manages color. In the long
term we plan on | 340 * The path equivalent of the GP. For now this just manages color. In the long
term we plan on |
| 313 * extending this class to handle all nvpr uniform / varying / program work. | 341 * extending this class to handle all nvpr uniform / varying / program work. |
| 314 */ | 342 */ |
| 315 class GrPathProcessor : public GrPrimitiveProcessor { | 343 class GrPathProcessor : public GrPrimitiveProcessor { |
| 316 public: | 344 public: |
| 317 static GrPathProcessor* Create(GrColor color) { | 345 static GrPathProcessor* Create(GrColor color, const SkMatrix& localMatrix =
SkMatrix::I()) { |
| 318 return SkNEW_ARGS(GrPathProcessor, (color)); | 346 return SkNEW_ARGS(GrPathProcessor, (color, localMatrix)); |
| 319 } | 347 } |
| 320 | 348 |
| 321 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; | 349 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; |
| 322 | 350 |
| 323 bool canMakeEqual(const GrBatchTracker& mine, | 351 bool canMakeEqual(const GrBatchTracker& mine, |
| 324 const GrPrimitiveProcessor& that, | 352 const GrPrimitiveProcessor& that, |
| 325 const GrBatchTracker& theirs) const SK_OVERRIDE; | 353 const GrBatchTracker& theirs) const SK_OVERRIDE; |
| 326 | 354 |
| 327 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | 355 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
| 328 | 356 |
| 329 GrColor color() const { return fColor; } | 357 GrColor color() const { return fColor; } |
| 330 | 358 |
| 331 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 359 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 332 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; | 360 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E; |
| 333 | 361 |
| 334 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 362 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 335 const GrGLCaps& caps, | 363 const GrGLCaps& caps, |
| 336 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 364 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 337 | 365 |
| 338 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; | 366 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co
nst SK_OVERRIDE; |
| 339 | 367 |
| 340 private: | 368 private: |
| 341 GrPathProcessor(GrColor color); | 369 GrPathProcessor(GrColor color, const SkMatrix& localMatrix); |
| 342 GrColor fColor; | 370 GrColor fColor; |
| 343 | 371 |
| 344 typedef GrProcessor INHERITED; | 372 typedef GrPrimitiveProcessor INHERITED; |
| 345 }; | 373 }; |
| 346 #endif | 374 #endif |
| OLD | NEW |