| 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 #include "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
| 9 | 9 |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | |
| 11 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
| 12 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 13 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
| 14 #include "GrTBackendProcessorFactory.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 15 | 14 |
| 16 class GrGLConicEffect : public GrGLGeometryProcessor { | 15 class GrGLConicEffect : public GrGLGeometryProcessor { |
| 17 public: | 16 public: |
| 18 GrGLConicEffect(const GrBackendProcessorFactory&, | 17 GrGLConicEffect(const GrGeometryProcessor&, |
| 19 const GrGeometryProcessor&, | |
| 20 const GrBatchTracker&); | 18 const GrBatchTracker&); |
| 21 | 19 |
| 22 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 20 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 23 | 21 |
| 24 static inline void GenKey(const GrGeometryProcessor&, | 22 static inline void GenKey(const GrGeometryProcessor&, |
| 25 const GrBatchTracker&, | 23 const GrBatchTracker&, |
| 26 const GrGLCaps&, | 24 const GrGLCaps&, |
| 27 GrProcessorKeyBuilder*); | 25 GrProcessorKeyBuilder*); |
| 28 | 26 |
| 29 virtual void setData(const GrGLProgramDataManager&, | 27 virtual void setData(const GrGLProgramDataManager&, |
| 30 const GrGeometryProcessor&, | 28 const GrGeometryProcessor&, |
| 31 const GrBatchTracker&) SK_OVERRIDE {} | 29 const GrBatchTracker&) SK_OVERRIDE {} |
| 32 | 30 |
| 33 private: | 31 private: |
| 34 GrPrimitiveEdgeType fEdgeType; | 32 GrPrimitiveEdgeType fEdgeType; |
| 35 | 33 |
| 36 typedef GrGLGeometryProcessor INHERITED; | 34 typedef GrGLGeometryProcessor INHERITED; |
| 37 }; | 35 }; |
| 38 | 36 |
| 39 GrGLConicEffect::GrGLConicEffect(const GrBackendProcessorFactory& factory, | 37 GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor, |
| 40 const GrGeometryProcessor& processor, | 38 const GrBatchTracker& bt) { |
| 41 const GrBatchTracker& bt) | |
| 42 : INHERITED (factory) { | |
| 43 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 39 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 44 fEdgeType = ce.getEdgeType(); | 40 fEdgeType = ce.getEdgeType(); |
| 45 } | 41 } |
| 46 | 42 |
| 47 void GrGLConicEffect::emitCode(const EmitArgs& args) { | 43 void GrGLConicEffect::emitCode(const EmitArgs& args) { |
| 48 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 44 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 49 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); | 45 const GrConicEffect& gp = args.fGP.cast<GrConicEffect>(); |
| 50 | 46 |
| 51 GrGLVertToFrag v(kVec4f_GrSLType); | 47 GrGLVertToFrag v(kVec4f_GrSLType); |
| 52 args.fPB->addVarying("ConicCoeffs", &v); | 48 args.fPB->addVarying("ConicCoeffs", &v); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 GrProcessorKeyBuilder* b) { | 122 GrProcessorKeyBuilder* b) { |
| 127 const GrConicEffect& ce = processor.cast<GrConicEffect>(); | 123 const GrConicEffect& ce = processor.cast<GrConicEffect>(); |
| 128 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 124 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 129 b->add32(key); | 125 b->add32(key); |
| 130 } | 126 } |
| 131 | 127 |
| 132 ////////////////////////////////////////////////////////////////////////////// | 128 ////////////////////////////////////////////////////////////////////////////// |
| 133 | 129 |
| 134 GrConicEffect::~GrConicEffect() {} | 130 GrConicEffect::~GrConicEffect() {} |
| 135 | 131 |
| 136 const GrBackendGeometryProcessorFactory& GrConicEffect::getFactory() const { | 132 void GrConicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 137 return GrTBackendGeometryProcessorFactory<GrConicEffect>::getInstance(); | 133 const GrGLCaps& caps, |
| 134 GrProcessorKeyBuilder* b) const { |
| 135 GrGLConicEffect::GenKey(*this, bt, caps, b); |
| 136 } |
| 137 |
| 138 GrGLGeometryProcessor* GrConicEffect::createGLInstance(const GrBatchTracker& bt)
const { |
| 139 return SkNEW_ARGS(GrGLConicEffect, (*this, bt)); |
| 138 } | 140 } |
| 139 | 141 |
| 140 GrConicEffect::GrConicEffect(GrPrimitiveEdgeType edgeType) | 142 GrConicEffect::GrConicEffect(GrPrimitiveEdgeType edgeType) |
| 141 : fEdgeType(edgeType) { | 143 : fEdgeType(edgeType) { |
| 144 this->initClassID<GrConicEffect>(); |
| 142 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 145 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 143 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", | 146 fInConicCoeffs = &this->addVertexAttrib(GrAttribute("inConicCoeffs", |
| 144 kVec4f_GrVertexAttribTyp
e)); | 147 kVec4f_GrVertexAttribTyp
e)); |
| 145 } | 148 } |
| 146 | 149 |
| 147 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 150 bool GrConicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 148 const GrConicEffect& ce = other.cast<GrConicEffect>(); | 151 const GrConicEffect& ce = other.cast<GrConicEffect>(); |
| 149 return (ce.fEdgeType == fEdgeType); | 152 return (ce.fEdgeType == fEdgeType); |
| 150 } | 153 } |
| 151 | 154 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 165 } while (NULL == gp); | 168 } while (NULL == gp); |
| 166 return gp; | 169 return gp; |
| 167 } | 170 } |
| 168 | 171 |
| 169 ////////////////////////////////////////////////////////////////////////////// | 172 ////////////////////////////////////////////////////////////////////////////// |
| 170 // Quad | 173 // Quad |
| 171 ////////////////////////////////////////////////////////////////////////////// | 174 ////////////////////////////////////////////////////////////////////////////// |
| 172 | 175 |
| 173 class GrGLQuadEffect : public GrGLGeometryProcessor { | 176 class GrGLQuadEffect : public GrGLGeometryProcessor { |
| 174 public: | 177 public: |
| 175 GrGLQuadEffect(const GrBackendProcessorFactory&, | 178 GrGLQuadEffect(const GrGeometryProcessor&, |
| 176 const GrGeometryProcessor&, | |
| 177 const GrBatchTracker&); | 179 const GrBatchTracker&); |
| 178 | 180 |
| 179 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 181 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 180 | 182 |
| 181 static inline void GenKey(const GrGeometryProcessor&, | 183 static inline void GenKey(const GrGeometryProcessor&, |
| 182 const GrBatchTracker&, | 184 const GrBatchTracker&, |
| 183 const GrGLCaps&, | 185 const GrGLCaps&, |
| 184 GrProcessorKeyBuilder*); | 186 GrProcessorKeyBuilder*); |
| 185 | 187 |
| 186 virtual void setData(const GrGLProgramDataManager&, | 188 virtual void setData(const GrGLProgramDataManager&, |
| 187 const GrGeometryProcessor&, | 189 const GrGeometryProcessor&, |
| 188 const GrBatchTracker&) SK_OVERRIDE {} | 190 const GrBatchTracker&) SK_OVERRIDE {} |
| 189 | 191 |
| 190 private: | 192 private: |
| 191 GrPrimitiveEdgeType fEdgeType; | 193 GrPrimitiveEdgeType fEdgeType; |
| 192 | 194 |
| 193 typedef GrGLGeometryProcessor INHERITED; | 195 typedef GrGLGeometryProcessor INHERITED; |
| 194 }; | 196 }; |
| 195 | 197 |
| 196 GrGLQuadEffect::GrGLQuadEffect(const GrBackendProcessorFactory& factory, | 198 GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor, |
| 197 const GrGeometryProcessor& processor, | 199 const GrBatchTracker& bt) { |
| 198 const GrBatchTracker& bt) | |
| 199 : INHERITED (factory) { | |
| 200 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 200 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 201 fEdgeType = ce.getEdgeType(); | 201 fEdgeType = ce.getEdgeType(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void GrGLQuadEffect::emitCode(const EmitArgs& args) { | 204 void GrGLQuadEffect::emitCode(const EmitArgs& args) { |
| 205 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 205 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 206 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); | 206 const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>(); |
| 207 | 207 |
| 208 GrGLVertToFrag v(kVec4f_GrSLType); | 208 GrGLVertToFrag v(kVec4f_GrSLType); |
| 209 args.fPB->addVarying("HairQuadEdge", &v); | 209 args.fPB->addVarying("HairQuadEdge", &v); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 GrProcessorKeyBuilder* b) { | 269 GrProcessorKeyBuilder* b) { |
| 270 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); | 270 const GrQuadEffect& ce = processor.cast<GrQuadEffect>(); |
| 271 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 271 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 272 b->add32(key); | 272 b->add32(key); |
| 273 } | 273 } |
| 274 | 274 |
| 275 ////////////////////////////////////////////////////////////////////////////// | 275 ////////////////////////////////////////////////////////////////////////////// |
| 276 | 276 |
| 277 GrQuadEffect::~GrQuadEffect() {} | 277 GrQuadEffect::~GrQuadEffect() {} |
| 278 | 278 |
| 279 const GrBackendGeometryProcessorFactory& GrQuadEffect::getFactory() const { | 279 void GrQuadEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 280 return GrTBackendGeometryProcessorFactory<GrQuadEffect>::getInstance(); | 280 const GrGLCaps& caps, |
| 281 GrProcessorKeyBuilder* b) const { |
| 282 GrGLQuadEffect::GenKey(*this, bt, caps, b); |
| 283 } |
| 284 |
| 285 GrGLGeometryProcessor* GrQuadEffect::createGLInstance(const GrBatchTracker& bt)
const { |
| 286 return SkNEW_ARGS(GrGLQuadEffect, (*this, bt)); |
| 281 } | 287 } |
| 282 | 288 |
| 283 GrQuadEffect::GrQuadEffect(GrPrimitiveEdgeType edgeType) | 289 GrQuadEffect::GrQuadEffect(GrPrimitiveEdgeType edgeType) |
| 284 : fEdgeType(edgeType) { | 290 : fEdgeType(edgeType) { |
| 291 this->initClassID<GrQuadEffect>(); |
| 285 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 292 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 286 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", | 293 fInHairQuadEdge = &this->addVertexAttrib(GrAttribute("inHairQuadEdge", |
| 287 kVec4f_GrVertexAttribTyp
e)); | 294 kVec4f_GrVertexAttribTyp
e)); |
| 288 } | 295 } |
| 289 | 296 |
| 290 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { | 297 bool GrQuadEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 291 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); | 298 const GrQuadEffect& ce = other.cast<GrQuadEffect>(); |
| 292 return (ce.fEdgeType == fEdgeType); | 299 return (ce.fEdgeType == fEdgeType); |
| 293 } | 300 } |
| 294 | 301 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 308 } while (NULL == gp); | 315 } while (NULL == gp); |
| 309 return gp; | 316 return gp; |
| 310 } | 317 } |
| 311 | 318 |
| 312 ////////////////////////////////////////////////////////////////////////////// | 319 ////////////////////////////////////////////////////////////////////////////// |
| 313 // Cubic | 320 // Cubic |
| 314 ////////////////////////////////////////////////////////////////////////////// | 321 ////////////////////////////////////////////////////////////////////////////// |
| 315 | 322 |
| 316 class GrGLCubicEffect : public GrGLGeometryProcessor { | 323 class GrGLCubicEffect : public GrGLGeometryProcessor { |
| 317 public: | 324 public: |
| 318 GrGLCubicEffect(const GrBackendProcessorFactory&, | 325 GrGLCubicEffect(const GrGeometryProcessor&, |
| 319 const GrGeometryProcessor&, | |
| 320 const GrBatchTracker&); | 326 const GrBatchTracker&); |
| 321 | 327 |
| 322 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; | 328 virtual void emitCode(const EmitArgs&) SK_OVERRIDE; |
| 323 | 329 |
| 324 static inline void GenKey(const GrGeometryProcessor&, | 330 static inline void GenKey(const GrGeometryProcessor&, |
| 325 const GrBatchTracker&, | 331 const GrBatchTracker&, |
| 326 const GrGLCaps&, | 332 const GrGLCaps&, |
| 327 GrProcessorKeyBuilder*); | 333 GrProcessorKeyBuilder*); |
| 328 | 334 |
| 329 virtual void setData(const GrGLProgramDataManager&, | 335 virtual void setData(const GrGLProgramDataManager&, |
| 330 const GrGeometryProcessor&, | 336 const GrGeometryProcessor&, |
| 331 const GrBatchTracker&) SK_OVERRIDE {} | 337 const GrBatchTracker&) SK_OVERRIDE {} |
| 332 | 338 |
| 333 private: | 339 private: |
| 334 GrPrimitiveEdgeType fEdgeType; | 340 GrPrimitiveEdgeType fEdgeType; |
| 335 | 341 |
| 336 typedef GrGLGeometryProcessor INHERITED; | 342 typedef GrGLGeometryProcessor INHERITED; |
| 337 }; | 343 }; |
| 338 | 344 |
| 339 GrGLCubicEffect::GrGLCubicEffect(const GrBackendProcessorFactory& factory, | 345 GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor, |
| 340 const GrGeometryProcessor& processor, | 346 const GrBatchTracker&) { |
| 341 const GrBatchTracker&) | |
| 342 : INHERITED (factory) { | |
| 343 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 347 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 344 fEdgeType = ce.getEdgeType(); | 348 fEdgeType = ce.getEdgeType(); |
| 345 } | 349 } |
| 346 | 350 |
| 347 void GrGLCubicEffect::emitCode(const EmitArgs& args) { | 351 void GrGLCubicEffect::emitCode(const EmitArgs& args) { |
| 348 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 352 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 349 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); | 353 const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>(); |
| 350 | 354 |
| 351 GrGLVertToFrag v(kVec4f_GrSLType); | 355 GrGLVertToFrag v(kVec4f_GrSLType); |
| 352 args.fPB->addVarying("CubicCoeffs", &v, GrGLShaderVar::kHigh_Precision); | 356 args.fPB->addVarying("CubicCoeffs", &v, GrGLShaderVar::kHigh_Precision); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 GrProcessorKeyBuilder* b) { | 457 GrProcessorKeyBuilder* b) { |
| 454 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); | 458 const GrCubicEffect& ce = processor.cast<GrCubicEffect>(); |
| 455 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 459 uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 456 b->add32(key); | 460 b->add32(key); |
| 457 } | 461 } |
| 458 | 462 |
| 459 ////////////////////////////////////////////////////////////////////////////// | 463 ////////////////////////////////////////////////////////////////////////////// |
| 460 | 464 |
| 461 GrCubicEffect::~GrCubicEffect() {} | 465 GrCubicEffect::~GrCubicEffect() {} |
| 462 | 466 |
| 463 const GrBackendGeometryProcessorFactory& GrCubicEffect::getFactory() const { | 467 void GrCubicEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 464 return GrTBackendGeometryProcessorFactory<GrCubicEffect>::getInstance(); | 468 const GrGLCaps& caps, |
| 469 GrProcessorKeyBuilder* b) const { |
| 470 GrGLCubicEffect::GenKey(*this, bt, caps, b); |
| 471 } |
| 472 |
| 473 GrGLGeometryProcessor* GrCubicEffect::createGLInstance(const GrBatchTracker& bt)
const { |
| 474 return SkNEW_ARGS(GrGLCubicEffect, (*this, bt)); |
| 465 } | 475 } |
| 466 | 476 |
| 467 GrCubicEffect::GrCubicEffect(GrPrimitiveEdgeType edgeType) | 477 GrCubicEffect::GrCubicEffect(GrPrimitiveEdgeType edgeType) |
| 468 : fEdgeType(edgeType) { | 478 : fEdgeType(edgeType) { |
| 479 this->initClassID<GrCubicEffect>(); |
| 469 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 480 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 470 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", | 481 fInCubicCoeffs = &this->addVertexAttrib(GrAttribute("inCubicCoeffs", |
| 471 kVec4f_GrVertexAttribTyp
e)); | 482 kVec4f_GrVertexAttribTyp
e)); |
| 472 } | 483 } |
| 473 | 484 |
| 474 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { | 485 bool GrCubicEffect::onIsEqual(const GrGeometryProcessor& other) const { |
| 475 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); | 486 const GrCubicEffect& ce = other.cast<GrCubicEffect>(); |
| 476 return (ce.fEdgeType == fEdgeType); | 487 return (ce.fEdgeType == fEdgeType); |
| 477 } | 488 } |
| 478 | 489 |
| 479 ////////////////////////////////////////////////////////////////////////////// | 490 ////////////////////////////////////////////////////////////////////////////// |
| 480 | 491 |
| 481 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); | 492 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); |
| 482 | 493 |
| 483 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, | 494 GrGeometryProcessor* GrCubicEffect::TestCreate(SkRandom* random, |
| 484 GrContext*, | 495 GrContext*, |
| 485 const GrDrawTargetCaps& caps, | 496 const GrDrawTargetCaps& caps, |
| 486 GrTexture*[]) { | 497 GrTexture*[]) { |
| 487 GrGeometryProcessor* gp; | 498 GrGeometryProcessor* gp; |
| 488 do { | 499 do { |
| 489 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 500 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 490 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); | 501 random->nextULessThan(kGrPro
cessorEdgeTypeCnt)); |
| 491 gp = GrCubicEffect::Create(edgeType, caps); | 502 gp = GrCubicEffect::Create(edgeType, caps); |
| 492 } while (NULL == gp); | 503 } while (NULL == gp); |
| 493 return gp; | 504 return gp; |
| 494 } | 505 } |
| 495 | 506 |
| OLD | NEW |