Chromium Code Reviews| 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 virtual const SkMatrix& localMatrix() const = 0; | |
|
bsalomon
2014/12/19 14:15:53
Why not just have the base class own a protected m
| |
| 94 | |
| 93 /* | 95 /* |
| 94 * This struct allows the optstate to communicate requirements to the GrPrim itiveProcessor. | 96 * This struct allows the optstate to communicate requirements to the GrPrim itiveProcessor. |
| 95 */ | 97 */ |
| 96 struct InitBT { | 98 struct InitBT { |
| 97 bool fColorIgnored; | 99 bool fColorIgnored; |
| 98 bool fCoverageIgnored; | 100 bool fCoverageIgnored; |
| 99 GrColor fOverrideColor; | 101 GrColor fOverrideColor; |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; | 104 virtual void initBatchTracker(GrBatchTracker*, const InitBT&) const = 0; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr GeometryProcessor | 156 * 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 | 157 * 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 | 158 * 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 | 159 * coverage into the fragment shader. Where this color and coverage come from i s completely the |
| 158 * responsibility of the GrGeometryProcessor. | 160 * responsibility of the GrGeometryProcessor. |
| 159 */ | 161 */ |
| 160 class GrGeometryProcessor : public GrPrimitiveProcessor { | 162 class GrGeometryProcessor : public GrPrimitiveProcessor { |
| 161 public: | 163 public: |
| 162 // TODO the Hint can be handled in a much more clean way when we have deferr ed geometry or | 164 // TODO the Hint can be handled in a much more clean way when we have deferr ed geometry or |
| 163 // atleast bundles | 165 // atleast bundles |
| 164 GrGeometryProcessor(GrColor color, bool opaqueVertexColors = false) | 166 GrGeometryProcessor(GrColor color, |
| 167 bool opaqueVertexColors = false, | |
| 168 const SkMatrix& localMatrix = SkMatrix::I()) | |
| 165 : fVertexStride(0) | 169 : fVertexStride(0) |
| 166 , fColor(color) | 170 , fColor(color) |
| 167 , fOpaqueVertexColors(opaqueVertexColors) | 171 , fOpaqueVertexColors(opaqueVertexColors) |
| 168 , fWillUseGeoShader(false) | 172 , fWillUseGeoShader(false) |
| 169 , fHasVertexColor(false) | 173 , fHasVertexColor(false) |
| 170 , fHasLocalCoords(false) {} | 174 , fHasLocalCoords(false) |
| 175 , fLocalMatrix(localMatrix) {} | |
| 171 | 176 |
| 172 /* | 177 /* |
| 173 * This is a safeguard to prevent GPs from going beyond platform specific at tribute limits. | 178 * 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. | 179 * This number can almost certainly be raised if required. |
| 175 */ | 180 */ |
| 176 static const int kMaxVertexAttribs = 6; | 181 static const int kMaxVertexAttribs = 6; |
| 177 | 182 |
| 178 struct GrAttribute { | 183 struct GrAttribute { |
| 179 GrAttribute(const char* name, GrVertexAttribType type) | 184 GrAttribute(const char* name, GrVertexAttribType type) |
| 180 : fName(name) | 185 : fName(name) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 210 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t hat)) { | 215 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t hat)) { |
| 211 return false; | 216 return false; |
| 212 } | 217 } |
| 213 | 218 |
| 214 // TODO remove the hint | 219 // TODO remove the hint |
| 215 const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); | 220 const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); |
| 216 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors) { | 221 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors) { |
| 217 return false; | 222 return false; |
| 218 } | 223 } |
| 219 | 224 |
| 225 // TODO let the GP itself make this call | |
| 226 if (!fLocalMatrix.cheapEqualTo(other.localMatrix())) { | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 220 // TODO this equality test should really be broken up, some of this can live on the batch | 230 // 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 | 231 // tracker test and some of this should be in bundles |
| 222 if (!this->onIsEqual(other)) { | 232 if (!this->onIsEqual(other)) { |
| 223 return false; | 233 return false; |
| 224 } | 234 } |
| 225 | 235 |
| 226 return this->onCanMakeEqual(mine, theirs); | 236 return this->onCanMakeEqual(mine, theirs); |
| 227 } | 237 } |
| 228 | 238 |
| 229 | 239 |
| 230 // TODO we can remove color from the GrGeometryProcessor base class once we have bundles of | 240 // TODO we can remove color from the GrGeometryProcessor base class once we have bundles of |
| 231 // primitive data | 241 // primitive data |
| 232 GrColor color() const { return fColor; } | 242 GrColor color() const { return fColor; } |
| 243 const SkMatrix& localMatrix() const SK_OVERRIDE { return fLocalMatrix; } | |
| 233 | 244 |
| 234 // TODO this is a total hack until the gp can do deferred geometry | 245 // TODO this is a total hack until the gp can do deferred geometry |
| 235 bool hasVertexColor() const { return fHasVertexColor; } | 246 bool hasVertexColor() const { return fHasVertexColor; } |
| 236 | 247 |
| 237 // TODO this is a total hack until gp can setup and manage local coords | 248 // TODO this is a total hack until gp can setup and manage local coords |
| 238 bool hasLocalCoords() const { return fHasLocalCoords; } | 249 bool hasLocalCoords() const { return fHasLocalCoords; } |
| 239 | 250 |
| 240 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 251 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 241 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; | 252 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; |
| 242 | 253 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 // TODO delete this when we have more advanced equality testing via bundles and the BT | 308 // TODO delete this when we have more advanced equality testing via bundles and the BT |
| 298 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 309 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 299 | 310 |
| 300 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | 311 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
| 301 size_t fVertexStride; | 312 size_t fVertexStride; |
| 302 GrColor fColor; | 313 GrColor fColor; |
| 303 bool fOpaqueVertexColors; | 314 bool fOpaqueVertexColors; |
| 304 bool fWillUseGeoShader; | 315 bool fWillUseGeoShader; |
| 305 bool fHasVertexColor; | 316 bool fHasVertexColor; |
| 306 bool fHasLocalCoords; | 317 bool fHasLocalCoords; |
| 318 SkMatrix fLocalMatrix; | |
|
bsalomon
2014/12/19 14:15:53
move to primproc?
| |
| 307 | 319 |
| 308 typedef GrProcessor INHERITED; | 320 typedef GrProcessor INHERITED; |
| 309 }; | 321 }; |
| 310 | 322 |
| 311 /* | 323 /* |
| 312 * The path equivalent of the GP. For now this just manages color. In the long term we plan on | 324 * 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. | 325 * extending this class to handle all nvpr uniform / varying / program work. |
| 314 */ | 326 */ |
| 315 class GrPathProcessor : public GrPrimitiveProcessor { | 327 class GrPathProcessor : public GrPrimitiveProcessor { |
| 316 public: | 328 public: |
| 317 static GrPathProcessor* Create(GrColor color) { | 329 static GrPathProcessor* Create(GrColor color, const SkMatrix& localMatrix = SkMatrix::I()) { |
| 318 return SkNEW_ARGS(GrPathProcessor, (color)); | 330 return SkNEW_ARGS(GrPathProcessor, (color, localMatrix)); |
| 319 } | 331 } |
| 320 | 332 |
| 321 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; | 333 void initBatchTracker(GrBatchTracker*, const InitBT&) const SK_OVERRIDE; |
| 322 | 334 |
| 323 bool canMakeEqual(const GrBatchTracker& mine, | 335 bool canMakeEqual(const GrBatchTracker& mine, |
| 324 const GrPrimitiveProcessor& that, | 336 const GrPrimitiveProcessor& that, |
| 325 const GrBatchTracker& theirs) const SK_OVERRIDE; | 337 const GrBatchTracker& theirs) const SK_OVERRIDE; |
| 326 | 338 |
| 327 const char* name() const SK_OVERRIDE { return "PathProcessor"; } | 339 const char* name() const SK_OVERRIDE { return "PathProcessor"; } |
| 328 | 340 |
| 329 GrColor color() const { return fColor; } | 341 GrColor color() const { return fColor; } |
| 342 const SkMatrix& localMatrix() const SK_OVERRIDE { return fLocalMatrix; } | |
| 330 | 343 |
| 331 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; | 344 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE; |
| 332 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; | 345 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID E; |
| 333 | 346 |
| 334 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 347 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 335 const GrGLCaps& caps, | 348 const GrGLCaps& caps, |
| 336 GrProcessorKeyBuilder* b) const SK_OVERRIDE; | 349 GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
| 337 | 350 |
| 338 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co nst SK_OVERRIDE; | 351 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co nst SK_OVERRIDE; |
| 339 | 352 |
| 340 private: | 353 private: |
| 341 GrPathProcessor(GrColor color); | 354 GrPathProcessor(GrColor color, const SkMatrix& localMatrix); |
| 342 GrColor fColor; | 355 GrColor fColor; |
| 356 SkMatrix fLocalMatrix; | |
| 343 | 357 |
| 344 typedef GrProcessor INHERITED; | 358 typedef GrProcessor INHERITED; |
| 345 }; | 359 }; |
| 346 #endif | 360 #endif |
| OLD | NEW |