OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkTwoPointConicalGradient.h" | 9 #include "SkTwoPointConicalGradient.h" |
10 | 10 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>()
; | 483 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>()
; |
484 fIsDegenerate = data.isDegenerate(); | 484 fIsDegenerate = data.isDegenerate(); |
485 } | 485 } |
486 | 486 |
487 void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder, | 487 void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder, |
488 const GrDrawEffect&, | 488 const GrDrawEffect&, |
489 EffectKey key, | 489 EffectKey key, |
490 const char* outputColor, | 490 const char* outputColor, |
491 const char* inputColor, | 491 const char* inputColor, |
492 const TextureSamplerArray& samplers) { | 492 const TextureSamplerArray& samplers) { |
493 const char* fsCoords; | 493 SkString fsCoords; |
494 const char* vsCoordsVarying; | 494 SkString vsCoordsVarying; |
495 GrSLType coordsVaryingType; | 495 GrSLType coordsVaryingType; |
496 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); | 496 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); |
497 | 497 |
498 this->emitYCoordUniform(builder); | 498 this->emitYCoordUniform(builder); |
499 // 2 copies of uniform array, 1 for each of vertex & fragment shader, | 499 // 2 copies of uniform array, 1 for each of vertex & fragment shader, |
500 // to work around Xoom bug. Doesn't seem to cause performance decrease | 500 // to work around Xoom bug. Doesn't seem to cause performance decrease |
501 // in test apps, but need to keep an eye on it. | 501 // in test apps, but need to keep an eye on it. |
502 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType
, | 502 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType
, |
503 kFloat_GrSLType, "Conical2VSParams",
6); | 503 kFloat_GrSLType, "Conical2VSParams",
6); |
504 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy
pe, | 504 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy
pe, |
(...skipping 14 matching lines...) Expand all Loading... |
519 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); | 519 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); |
520 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); | 520 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); |
521 builder->getUniformVariable(fVSParamUni).appendArrayAccess(5, &p5); | 521 builder->getUniformVariable(fVSParamUni).appendArrayAccess(5, &p5); |
522 | 522 |
523 // For radial gradients without perspective we can pass the linear | 523 // For radial gradients without perspective we can pass the linear |
524 // part of the quadratic as a varying. | 524 // part of the quadratic as a varying. |
525 if (kVec2f_GrSLType == coordsVaryingType) { | 525 if (kVec2f_GrSLType == coordsVaryingType) { |
526 // r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5]) | 526 // r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5]) |
527 builder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n", | 527 builder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n", |
528 fVSVaryingName, p2.c_str(), | 528 fVSVaryingName, p2.c_str(), |
529 vsCoordsVarying, p3.c_str(), p5.c_str()); | 529 vsCoordsVarying.c_str(), p3.c_str(), p5.c_str
()); |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 // FS | 533 // FS |
534 { | 534 { |
535 | 535 |
536 SkString cName("c"); | 536 SkString cName("c"); |
537 SkString ac4Name("ac4"); | 537 SkString ac4Name("ac4"); |
538 SkString dName("d"); | 538 SkString dName("d"); |
539 SkString qName("q"); | 539 SkString qName("q"); |
(...skipping 15 matching lines...) Expand all Loading... |
555 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); | 555 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); |
556 | 556 |
557 // If we we're able to interpolate the linear component, | 557 // If we we're able to interpolate the linear component, |
558 // bVar is the varying; otherwise compute it | 558 // bVar is the varying; otherwise compute it |
559 SkString bVar; | 559 SkString bVar; |
560 if (kVec2f_GrSLType == coordsVaryingType) { | 560 if (kVec2f_GrSLType == coordsVaryingType) { |
561 bVar = fFSVaryingName; | 561 bVar = fFSVaryingName; |
562 } else { | 562 } else { |
563 bVar = "b"; | 563 bVar = "b"; |
564 builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n
", | 564 builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n
", |
565 bVar.c_str(), p2.c_str(), fsCoords, | 565 bVar.c_str(), p2.c_str(), fsCoords.c_str(), |
566 p3.c_str(), p5.c_str()); | 566 p3.c_str(), p5.c_str()); |
567 } | 567 } |
568 | 568 |
569 // output will default to transparent black (we simply won't write anyth
ing | 569 // output will default to transparent black (we simply won't write anyth
ing |
570 // else to it if invalid, instead of discarding or returning prematurely
) | 570 // else to it if invalid, instead of discarding or returning prematurely
) |
571 builder->fsCodeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); | 571 builder->fsCodeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); |
572 | 572 |
573 // c = (x^2)+(y^2) - params[4] | 573 // c = (x^2)+(y^2) - params[4] |
574 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str()
, | 574 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str()
, |
575 fsCoords, fsCoords, | 575 fsCoords.c_str(), fsCoords.c_str(), |
576 p4.c_str()); | 576 p4.c_str()); |
577 | 577 |
578 // Non-degenerate case (quadratic) | 578 // Non-degenerate case (quadratic) |
579 if (!fIsDegenerate) { | 579 if (!fIsDegenerate) { |
580 | 580 |
581 // ac4 = params[0] * c | 581 // ac4 = params[0] * c |
582 builder->fsCodeAppendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p
0.c_str(), | 582 builder->fsCodeAppendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p
0.c_str(), |
583 cName.c_str()); | 583 cName.c_str()); |
584 | 584 |
585 // d = b^2 - ac4 | 585 // d = b^2 - ac4 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 str->appendScalar(fCenter2.fY); | 753 str->appendScalar(fCenter2.fY); |
754 str->append(") radius2: "); | 754 str->append(") radius2: "); |
755 str->appendScalar(fRadius2); | 755 str->appendScalar(fRadius2); |
756 str->append(" "); | 756 str->append(" "); |
757 | 757 |
758 this->INHERITED::toString(str); | 758 this->INHERITED::toString(str); |
759 | 759 |
760 str->append(")"); | 760 str->append(")"); |
761 } | 761 } |
762 #endif | 762 #endif |
OLD | NEW |