OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "SkTwoPointConicalGradient.h" | 8 #include "SkTwoPointConicalGradient.h" |
10 | 9 |
11 static int valid_divide(float numer, float denom, float* ratio) { | 10 static int valid_divide(float numer, float denom, float* ratio) { |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 const GrDrawEffect&, | 487 const GrDrawEffect&, |
489 EffectKey key, | 488 EffectKey key, |
490 const char* outputColor, | 489 const char* outputColor, |
491 const char* inputColor, | 490 const char* inputColor, |
492 const TextureSamplerArray& samplers) { | 491 const TextureSamplerArray& samplers) { |
493 SkString fsCoords; | 492 SkString fsCoords; |
494 SkString vsCoordsVarying; | 493 SkString vsCoordsVarying; |
495 GrSLType coordsVaryingType; | 494 GrSLType coordsVaryingType; |
496 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); | 495 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT
ype); |
497 | 496 |
498 this->emitYCoordUniform(builder); | 497 this->emitUniforms(builder, key); |
499 // 2 copies of uniform array, 1 for each of vertex & fragment shader, | 498 // 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 | 499 // to work around Xoom bug. Doesn't seem to cause performance decrease |
501 // in test apps, but need to keep an eye on it. | 500 // in test apps, but need to keep an eye on it. |
502 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility
, | 501 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_Visibility
, |
503 kFloat_GrSLType, "Conical2VSParams",
6); | 502 kFloat_GrSLType, "Conical2VSParams",
6); |
504 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibili
ty, | 503 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibili
ty, |
505 kFloat_GrSLType, "Conical2FSParams",
6); | 504 kFloat_GrSLType, "Conical2FSParams",
6); |
506 | 505 |
507 // For radial gradients without perspective we can pass the linear | 506 // For radial gradients without perspective we can pass the linear |
508 // part of the quadratic as a varying. | 507 // part of the quadratic as a varying. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 609 |
611 // so we'll look at the larger one first: | 610 // so we'll look at the larger one first: |
612 builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str(
), | 611 builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str(
), |
613 r0Name.c_str(), r1Name.c_str()); | 612 r0Name.c_str(), r1Name.c_str()); |
614 | 613 |
615 // if r(t) > 0, then we're done; t will be our x coordinate | 614 // if r(t) > 0, then we're done; t will be our x coordinate |
616 builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_st
r(), | 615 builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_st
r(), |
617 p5.c_str(), p3.c_str()); | 616 p5.c_str(), p3.c_str()); |
618 | 617 |
619 builder->fsCodeAppend("\t\t"); | 618 builder->fsCodeAppend("\t\t"); |
620 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo
r, samplers[0]); | 619 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor
, samplers); |
621 | 620 |
622 // otherwise, if r(t) for the larger root was <= 0, try the other ro
ot | 621 // otherwise, if r(t) for the larger root was <= 0, try the other ro
ot |
623 builder->fsCodeAppend("\t\t} else {\n"); | 622 builder->fsCodeAppend("\t\t} else {\n"); |
624 builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(), | 623 builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(), |
625 r0Name.c_str(), r1Name.c_str()); | 624 r0Name.c_str(), r1Name.c_str()); |
626 | 625 |
627 // if r(t) > 0 for the smaller root, then t will be our x coordinate | 626 // if r(t) > 0 for the smaller root, then t will be our x coordinate |
628 builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n", | 627 builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n", |
629 tName.c_str(), p5.c_str(), p3.c_str()); | 628 tName.c_str(), p5.c_str(), p3.c_str()); |
630 | 629 |
631 builder->fsCodeAppend("\t\t\t"); | 630 builder->fsCodeAppend("\t\t\t"); |
632 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo
r, samplers[0]); | 631 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor
, samplers); |
633 | 632 |
634 // end if (r(t) > 0) for smaller root | 633 // end if (r(t) > 0) for smaller root |
635 builder->fsCodeAppend("\t\t\t}\n"); | 634 builder->fsCodeAppend("\t\t\t}\n"); |
636 // end if (r(t) > 0), else, for larger root | 635 // end if (r(t) > 0), else, for larger root |
637 builder->fsCodeAppend("\t\t}\n"); | 636 builder->fsCodeAppend("\t\t}\n"); |
638 // end if (discriminant >= 0) | 637 // end if (discriminant >= 0) |
639 builder->fsCodeAppend("\t}\n"); | 638 builder->fsCodeAppend("\t}\n"); |
640 } else { | 639 } else { |
641 | 640 |
642 // linear case: t = -c/b | 641 // linear case: t = -c/b |
643 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(), | 642 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(), |
644 cName.c_str(), bVar.c_str()); | 643 cName.c_str(), bVar.c_str()); |
645 | 644 |
646 // if r(t) > 0, then t will be the x coordinate | 645 // if r(t) > 0, then t will be the x coordinate |
647 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(
), | 646 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(
), |
648 p5.c_str(), p3.c_str()); | 647 p5.c_str(), p3.c_str()); |
649 builder->fsCodeAppend("\t"); | 648 builder->fsCodeAppend("\t"); |
650 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo
r, samplers[0]); | 649 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor
, samplers); |
651 builder->fsCodeAppend("\t}\n"); | 650 builder->fsCodeAppend("\t}\n"); |
652 } | 651 } |
653 } | 652 } |
654 } | 653 } |
655 | 654 |
656 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, | 655 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, |
657 const GrDrawEffect& drawEffect) { | 656 const GrDrawEffect& drawEffect) { |
658 INHERITED::setData(uman, drawEffect); | 657 INHERITED::setData(uman, drawEffect); |
659 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>()
; | 658 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>()
; |
660 SkASSERT(data.isDegenerate() == fIsDegenerate); | 659 SkASSERT(data.isDegenerate() == fIsDegenerate); |
(...skipping 25 matching lines...) Expand all Loading... |
686 uman.set1fv(fFSParamUni, 0, 6, values); | 685 uman.set1fv(fFSParamUni, 0, 6, values); |
687 fCachedCenter = centerX1; | 686 fCachedCenter = centerX1; |
688 fCachedRadius = radius0; | 687 fCachedRadius = radius0; |
689 fCachedDiffRadius = diffRadius; | 688 fCachedDiffRadius = diffRadius; |
690 } | 689 } |
691 } | 690 } |
692 | 691 |
693 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec
t, | 692 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec
t, |
694 const GrGLCaps&) { | 693 const GrGLCaps&) { |
695 enum { | 694 enum { |
696 kIsDegenerate = 1 << kMatrixKeyBitCnt, | 695 kIsDegenerate = 1 << kBaseKeyBitCnt, |
697 }; | 696 }; |
698 | 697 |
699 EffectKey key = GenMatrixKey(drawEffect); | 698 EffectKey key = GenBaseGradientKey(drawEffect); |
700 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) { | 699 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) { |
701 key |= kIsDegenerate; | 700 key |= kIsDegenerate; |
702 } | 701 } |
703 return key; | 702 return key; |
704 } | 703 } |
705 | 704 |
706 ///////////////////////////////////////////////////////////////////// | 705 ///////////////////////////////////////////////////////////////////// |
707 | 706 |
708 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk
Paint&) const { | 707 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk
Paint&) const { |
709 SkASSERT(NULL != context); | 708 SkASSERT(NULL != context); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 str->appendScalar(fCenter2.fY); | 754 str->appendScalar(fCenter2.fY); |
756 str->append(") radius2: "); | 755 str->append(") radius2: "); |
757 str->appendScalar(fRadius2); | 756 str->appendScalar(fRadius2); |
758 str->append(" "); | 757 str->append(" "); |
759 | 758 |
760 this->INHERITED::toString(str); | 759 this->INHERITED::toString(str); |
761 | 760 |
762 str->append(")"); | 761 str->append(")"); |
763 } | 762 } |
764 #endif | 763 #endif |
OLD | NEW |