| 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 "glsl/GrGLSLFragmentShaderBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 11 #include "glsl/GrGLSLGeometryProcessor.h" | 11 #include "glsl/GrGLSLGeometryProcessor.h" |
| 12 #include "glsl/GrGLSLProgramDataManager.h" | 12 #include "glsl/GrGLSLProgramDataManager.h" |
| 13 #include "glsl/GrGLSLUniformHandler.h" | 13 #include "glsl/GrGLSLUniformHandler.h" |
| 14 #include "glsl/GrGLSLUtil.h" | 14 #include "glsl/GrGLSLUtil.h" |
| 15 #include "glsl/GrGLSLVarying.h" | 15 #include "glsl/GrGLSLVarying.h" |
| 16 #include "glsl/GrGLSLVertexShaderBuilder.h" | 16 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 17 | 17 |
| 18 class GrGLConicEffect : public GrGLSLGeometryProcessor { | 18 class GrGLConicEffect : public GrGLSLGeometryProcessor { |
| 19 public: | 19 public: |
| 20 GrGLConicEffect(const GrGeometryProcessor&); | 20 GrGLConicEffect(const GrGeometryProcessor&); |
| 21 | 21 |
| 22 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 22 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
| 23 | 23 |
| 24 static inline void GenKey(const GrGeometryProcessor&, | 24 static inline void GenKey(const GrGeometryProcessor&, |
| 25 const GrGLSLCaps&, | 25 const GrGLSLCaps&, |
| 26 GrProcessorKeyBuilder*); | 26 GrProcessorKeyBuilder*); |
| 27 | 27 |
| 28 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& primProc, | 28 void setData(const GrGLSLProgramDataManager& pdman, |
| 29 FPCoordTransformIter&& transformIter) override { | 29 const GrPrimitiveProcessor& primProc) override { |
| 30 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); | 30 const GrConicEffect& ce = primProc.cast<GrConicEffect>(); |
| 31 | 31 |
| 32 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { | 32 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { |
| 33 fViewMatrix = ce.viewMatrix(); | 33 fViewMatrix = ce.viewMatrix(); |
| 34 float viewMatrix[3 * 3]; | 34 float viewMatrix[3 * 3]; |
| 35 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 35 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 36 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 36 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 37 } | 37 } |
| 38 | 38 |
| 39 if (ce.color() != fColor) { | 39 if (ce.color() != fColor) { |
| 40 float c[4]; | 40 float c[4]; |
| 41 GrColorToRGBAFloat(ce.color(), c); | 41 GrColorToRGBAFloat(ce.color(), c); |
| 42 pdman.set4fv(fColorUniform, 1, c); | 42 pdman.set4fv(fColorUniform, 1, c); |
| 43 fColor = ce.color(); | 43 fColor = ce.color(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale)
{ | 46 if (ce.coverageScale() != 0xff && ce.coverageScale() != fCoverageScale)
{ |
| 47 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverag
eScale())); | 47 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(ce.coverag
eScale())); |
| 48 fCoverageScale = ce.coverageScale(); | 48 fCoverageScale = ce.coverageScale(); |
| 49 } | 49 } |
| 50 this->setTransformDataHelper(ce.localMatrix(), pdman, &transformIter); | 50 } |
| 51 |
| 52 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 53 const GrGLSLProgramDataManager& pdman, |
| 54 int index, |
| 55 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
| 56 this->setTransformDataHelper(primProc.cast<GrConicEffect>().localMatrix(
), pdman, index, |
| 57 transforms); |
| 51 } | 58 } |
| 52 | 59 |
| 53 private: | 60 private: |
| 54 SkMatrix fViewMatrix; | 61 SkMatrix fViewMatrix; |
| 55 GrColor fColor; | 62 GrColor fColor; |
| 56 uint8_t fCoverageScale; | 63 uint8_t fCoverageScale; |
| 57 GrPrimitiveEdgeType fEdgeType; | 64 GrPrimitiveEdgeType fEdgeType; |
| 58 UniformHandle fColorUniform; | 65 UniformHandle fColorUniform; |
| 59 UniformHandle fCoverageScaleUniform; | 66 UniformHandle fCoverageScaleUniform; |
| 60 UniformHandle fViewMatrixUniform; | 67 UniformHandle fViewMatrixUniform; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 gp.viewMatrix(), | 102 gp.viewMatrix(), |
| 96 &fViewMatrixUniform); | 103 &fViewMatrixUniform); |
| 97 | 104 |
| 98 // emit transforms with position | 105 // emit transforms with position |
| 99 this->emitTransforms(vertBuilder, | 106 this->emitTransforms(vertBuilder, |
| 100 varyingHandler, | 107 varyingHandler, |
| 101 uniformHandler, | 108 uniformHandler, |
| 102 gpArgs->fPositionVar, | 109 gpArgs->fPositionVar, |
| 103 gp.inPosition()->fName, | 110 gp.inPosition()->fName, |
| 104 gp.localMatrix(), | 111 gp.localMatrix(), |
| 105 args.fFPCoordTransformHandler); | 112 args.fTransformsIn, |
| 113 args.fTransformsOut); |
| 106 | 114 |
| 107 // TODO: this precision check should actually be a check on the number of bi
ts | 115 // TODO: this precision check should actually be a check on the number of bi
ts |
| 108 // high and medium provide and the selection of the lowest level that suffic
es. | 116 // high and medium provide and the selection of the lowest level that suffic
es. |
| 109 // Additionally we should assert that the upstream code only lets us get her
e if | 117 // Additionally we should assert that the upstream code only lets us get her
e if |
| 110 // either high or medium provides the required number of bits. | 118 // either high or medium provides the required number of bits. |
| 111 GrSLPrecision precision = kHigh_GrSLPrecision; | 119 GrSLPrecision precision = kHigh_GrSLPrecision; |
| 112 const GrShaderCaps::PrecisionInfo& highP = args.fGLSLCaps->getFloatShaderPre
cisionInfo( | 120 const GrShaderCaps::PrecisionInfo& highP = args.fGLSLCaps->getFloatShaderPre
cisionInfo( |
| 113 kFragment_GrShaderT
ype, | 121 kFragment_GrShaderT
ype, |
| 114 kHigh_GrSLPrecision
); | 122 kHigh_GrSLPrecision
); |
| 115 if (!highP.supported()) { | 123 if (!highP.supported()) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 class GrGLQuadEffect : public GrGLSLGeometryProcessor { | 292 class GrGLQuadEffect : public GrGLSLGeometryProcessor { |
| 285 public: | 293 public: |
| 286 GrGLQuadEffect(const GrGeometryProcessor&); | 294 GrGLQuadEffect(const GrGeometryProcessor&); |
| 287 | 295 |
| 288 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 296 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
| 289 | 297 |
| 290 static inline void GenKey(const GrGeometryProcessor&, | 298 static inline void GenKey(const GrGeometryProcessor&, |
| 291 const GrGLSLCaps&, | 299 const GrGLSLCaps&, |
| 292 GrProcessorKeyBuilder*); | 300 GrProcessorKeyBuilder*); |
| 293 | 301 |
| 294 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& primProc, | 302 void setData(const GrGLSLProgramDataManager& pdman, |
| 295 FPCoordTransformIter&& transformIter) override { | 303 const GrPrimitiveProcessor& primProc) override { |
| 296 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); | 304 const GrQuadEffect& qe = primProc.cast<GrQuadEffect>(); |
| 297 | 305 |
| 298 if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMa
trix())) { | 306 if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMa
trix())) { |
| 299 fViewMatrix = qe.viewMatrix(); | 307 fViewMatrix = qe.viewMatrix(); |
| 300 float viewMatrix[3 * 3]; | 308 float viewMatrix[3 * 3]; |
| 301 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 309 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 302 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 310 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 303 } | 311 } |
| 304 | 312 |
| 305 if (qe.color() != fColor) { | 313 if (qe.color() != fColor) { |
| 306 float c[4]; | 314 float c[4]; |
| 307 GrColorToRGBAFloat(qe.color(), c); | 315 GrColorToRGBAFloat(qe.color(), c); |
| 308 pdman.set4fv(fColorUniform, 1, c); | 316 pdman.set4fv(fColorUniform, 1, c); |
| 309 fColor = qe.color(); | 317 fColor = qe.color(); |
| 310 } | 318 } |
| 311 | 319 |
| 312 if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale)
{ | 320 if (qe.coverageScale() != 0xff && qe.coverageScale() != fCoverageScale)
{ |
| 313 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverag
eScale())); | 321 pdman.set1f(fCoverageScaleUniform, GrNormalizeByteToFloat(qe.coverag
eScale())); |
| 314 fCoverageScale = qe.coverageScale(); | 322 fCoverageScale = qe.coverageScale(); |
| 315 } | 323 } |
| 316 this->setTransformDataHelper(qe.localMatrix(), pdman, &transformIter); | 324 } |
| 325 |
| 326 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 327 const GrGLSLProgramDataManager& pdman, |
| 328 int index, |
| 329 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
| 330 this->setTransformDataHelper(primProc.cast<GrQuadEffect>().localMatrix()
, pdman, index, |
| 331 transforms); |
| 317 } | 332 } |
| 318 | 333 |
| 319 private: | 334 private: |
| 320 SkMatrix fViewMatrix; | 335 SkMatrix fViewMatrix; |
| 321 GrColor fColor; | 336 GrColor fColor; |
| 322 uint8_t fCoverageScale; | 337 uint8_t fCoverageScale; |
| 323 GrPrimitiveEdgeType fEdgeType; | 338 GrPrimitiveEdgeType fEdgeType; |
| 324 UniformHandle fColorUniform; | 339 UniformHandle fColorUniform; |
| 325 UniformHandle fCoverageScaleUniform; | 340 UniformHandle fCoverageScaleUniform; |
| 326 UniformHandle fViewMatrixUniform; | 341 UniformHandle fViewMatrixUniform; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 gp.viewMatrix(), | 376 gp.viewMatrix(), |
| 362 &fViewMatrixUniform); | 377 &fViewMatrixUniform); |
| 363 | 378 |
| 364 // emit transforms with position | 379 // emit transforms with position |
| 365 this->emitTransforms(vertBuilder, | 380 this->emitTransforms(vertBuilder, |
| 366 varyingHandler, | 381 varyingHandler, |
| 367 uniformHandler, | 382 uniformHandler, |
| 368 gpArgs->fPositionVar, | 383 gpArgs->fPositionVar, |
| 369 gp.inPosition()->fName, | 384 gp.inPosition()->fName, |
| 370 gp.localMatrix(), | 385 gp.localMatrix(), |
| 371 args.fFPCoordTransformHandler); | 386 args.fTransformsIn, |
| 387 args.fTransformsOut); |
| 372 | 388 |
| 373 fragBuilder->codeAppendf("float edgeAlpha;"); | 389 fragBuilder->codeAppendf("float edgeAlpha;"); |
| 374 | 390 |
| 375 switch (fEdgeType) { | 391 switch (fEdgeType) { |
| 376 case kHairlineAA_GrProcessorEdgeType: { | 392 case kHairlineAA_GrProcessorEdgeType: { |
| 377 SkAssertResult(fragBuilder->enableFeature( | 393 SkAssertResult(fragBuilder->enableFeature( |
| 378 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | 394 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); |
| 379 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); | 395 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 380 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); | 396 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
| 381 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," | 397 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 class GrGLCubicEffect : public GrGLSLGeometryProcessor { | 509 class GrGLCubicEffect : public GrGLSLGeometryProcessor { |
| 494 public: | 510 public: |
| 495 GrGLCubicEffect(const GrGeometryProcessor&); | 511 GrGLCubicEffect(const GrGeometryProcessor&); |
| 496 | 512 |
| 497 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 513 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
| 498 | 514 |
| 499 static inline void GenKey(const GrGeometryProcessor&, | 515 static inline void GenKey(const GrGeometryProcessor&, |
| 500 const GrGLSLCaps&, | 516 const GrGLSLCaps&, |
| 501 GrProcessorKeyBuilder*); | 517 GrProcessorKeyBuilder*); |
| 502 | 518 |
| 503 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
or& primProc, | 519 void setData(const GrGLSLProgramDataManager& pdman, |
| 504 FPCoordTransformIter&& transformIter) override { | 520 const GrPrimitiveProcessor& primProc) override { |
| 505 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); | 521 const GrCubicEffect& ce = primProc.cast<GrCubicEffect>(); |
| 506 | 522 |
| 507 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { | 523 if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMa
trix())) { |
| 508 fViewMatrix = ce.viewMatrix(); | 524 fViewMatrix = ce.viewMatrix(); |
| 509 float viewMatrix[3 * 3]; | 525 float viewMatrix[3 * 3]; |
| 510 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 526 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 511 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 527 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 512 } | 528 } |
| 513 | 529 |
| 514 if (ce.color() != fColor) { | 530 if (ce.color() != fColor) { |
| 515 float c[4]; | 531 float c[4]; |
| 516 GrColorToRGBAFloat(ce.color(), c); | 532 GrColorToRGBAFloat(ce.color(), c); |
| 517 pdman.set4fv(fColorUniform, 1, c); | 533 pdman.set4fv(fColorUniform, 1, c); |
| 518 fColor = ce.color(); | 534 fColor = ce.color(); |
| 519 } | 535 } |
| 520 this->setTransformDataHelper(SkMatrix::I(), pdman, &transformIter); | |
| 521 } | 536 } |
| 522 | 537 |
| 523 private: | 538 private: |
| 524 SkMatrix fViewMatrix; | 539 SkMatrix fViewMatrix; |
| 525 GrColor fColor; | 540 GrColor fColor; |
| 526 GrPrimitiveEdgeType fEdgeType; | 541 GrPrimitiveEdgeType fEdgeType; |
| 527 UniformHandle fColorUniform; | 542 UniformHandle fColorUniform; |
| 528 UniformHandle fViewMatrixUniform; | 543 UniformHandle fViewMatrixUniform; |
| 529 | 544 |
| 530 typedef GrGLSLGeometryProcessor INHERITED; | 545 typedef GrGLSLGeometryProcessor INHERITED; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 gp.inPosition()->fName, | 577 gp.inPosition()->fName, |
| 563 gp.viewMatrix(), | 578 gp.viewMatrix(), |
| 564 &fViewMatrixUniform); | 579 &fViewMatrixUniform); |
| 565 | 580 |
| 566 // emit transforms with position | 581 // emit transforms with position |
| 567 this->emitTransforms(vertBuilder, | 582 this->emitTransforms(vertBuilder, |
| 568 varyingHandler, | 583 varyingHandler, |
| 569 uniformHandler, | 584 uniformHandler, |
| 570 gpArgs->fPositionVar, | 585 gpArgs->fPositionVar, |
| 571 gp.inPosition()->fName, | 586 gp.inPosition()->fName, |
| 572 args.fFPCoordTransformHandler); | 587 args.fTransformsIn, |
| 588 args.fTransformsOut); |
| 573 | 589 |
| 574 | 590 |
| 575 GrGLSLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecisi
on); | 591 GrGLSLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecisi
on); |
| 576 GrGLSLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); | 592 GrGLSLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); |
| 577 GrGLSLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); | 593 GrGLSLShaderVar dklmdy("dklmdy", kVec3f_GrSLType, 0, kHigh_GrSLPrecision); |
| 578 GrGLSLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 594 GrGLSLShaderVar dfdx("dfdx", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 579 GrGLSLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 595 GrGLSLShaderVar dfdy("dfdy", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 580 GrGLSLShaderVar gF("gF", kVec2f_GrSLType, 0, kHigh_GrSLPrecision); | 596 GrGLSLShaderVar gF("gF", kVec2f_GrSLType, 0, kHigh_GrSLPrecision); |
| 581 GrGLSLShaderVar gFM("gFM", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 597 GrGLSLShaderVar gFM("gFM", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| 582 GrGLSLShaderVar func("func", kFloat_GrSLType, 0, kHigh_GrSLPrecision); | 598 GrGLSLShaderVar func("func", kFloat_GrSLType, 0, kHigh_GrSLPrecision); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 sk_sp<GrGeometryProcessor> gp; | 719 sk_sp<GrGeometryProcessor> gp; |
| 704 do { | 720 do { |
| 705 GrPrimitiveEdgeType edgeType = | 721 GrPrimitiveEdgeType edgeType = |
| 706 static_cast<GrPrimitiveEdgeType>( | 722 static_cast<GrPrimitiveEdgeType>( |
| 707 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 723 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 708 gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), | 724 gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), |
| 709 GrTest::TestMatrix(d->fRandom), edgeType, *d->f
Caps); | 725 GrTest::TestMatrix(d->fRandom), edgeType, *d->f
Caps); |
| 710 } while (nullptr == gp); | 726 } while (nullptr == gp); |
| 711 return gp; | 727 return gp; |
| 712 } | 728 } |
| OLD | NEW |