Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: src/effects/gradients/SkTwoPointConicalGradient.cpp

Issue 22854005: GPU Gradients (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixes from code reviews Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 const GrDrawEffect&, 490 const GrDrawEffect&,
492 EffectKey key, 491 EffectKey key,
493 const char* outputColor, 492 const char* outputColor,
494 const char* inputColor, 493 const char* inputColor,
495 const TextureSamplerArray& samplers) { 494 const TextureSamplerArray& samplers) {
496 const char* fsCoords; 495 const char* fsCoords;
497 const char* vsCoordsVarying; 496 const char* vsCoordsVarying;
498 GrSLType coordsVaryingType; 497 GrSLType coordsVaryingType;
499 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT ype); 498 this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingT ype);
500 499
501 this->emitYCoordUniform(builder); 500 this->emitUniforms(builder, key);
502 // 2 copies of uniform array, 1 for each of vertex & fragment shader, 501 // 2 copies of uniform array, 1 for each of vertex & fragment shader,
503 // to work around Xoom bug. Doesn't seem to cause performance decrease 502 // to work around Xoom bug. Doesn't seem to cause performance decrease
504 // in test apps, but need to keep an eye on it. 503 // in test apps, but need to keep an eye on it.
505 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType , 504 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType ,
506 kFloat_GrSLType, "Conical2VSParams", 6); 505 kFloat_GrSLType, "Conical2VSParams", 6);
507 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy pe, 506 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy pe,
508 kFloat_GrSLType, "Conical2FSParams", 6); 507 kFloat_GrSLType, "Conical2FSParams", 6);
509 508
510 // For radial gradients without perspective we can pass the linear 509 // For radial gradients without perspective we can pass the linear
511 // part of the quadratic as a varying. 510 // part of the quadratic as a varying.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 610
612 // so we'll look at the larger one first: 611 // so we'll look at the larger one first:
613 builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str( ), 612 builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str( ),
614 r0Name.c_str(), r1Name.c_str()); 613 r0Name.c_str(), r1Name.c_str());
615 614
616 // if r(t) > 0, then we're done; t will be our x coordinate 615 // if r(t) > 0, then we're done; t will be our x coordinate
617 builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_st r(), 616 builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_st r(),
618 p5.c_str(), p3.c_str()); 617 p5.c_str(), p3.c_str());
619 618
620 builder->fsCodeAppend("\t\t"); 619 builder->fsCodeAppend("\t\t");
621 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo r, samplers[0]); 620 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor , samplers);
622 621
623 // otherwise, if r(t) for the larger root was <= 0, try the other ro ot 622 // otherwise, if r(t) for the larger root was <= 0, try the other ro ot
624 builder->fsCodeAppend("\t\t} else {\n"); 623 builder->fsCodeAppend("\t\t} else {\n");
625 builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(), 624 builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(),
626 r0Name.c_str(), r1Name.c_str()); 625 r0Name.c_str(), r1Name.c_str());
627 626
628 // if r(t) > 0 for the smaller root, then t will be our x coordinate 627 // if r(t) > 0 for the smaller root, then t will be our x coordinate
629 builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n", 628 builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n",
630 tName.c_str(), p5.c_str(), p3.c_str()); 629 tName.c_str(), p5.c_str(), p3.c_str());
631 630
632 builder->fsCodeAppend("\t\t\t"); 631 builder->fsCodeAppend("\t\t\t");
633 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo r, samplers[0]); 632 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor , samplers);
634 633
635 // end if (r(t) > 0) for smaller root 634 // end if (r(t) > 0) for smaller root
636 builder->fsCodeAppend("\t\t\t}\n"); 635 builder->fsCodeAppend("\t\t\t}\n");
637 // end if (r(t) > 0), else, for larger root 636 // end if (r(t) > 0), else, for larger root
638 builder->fsCodeAppend("\t\t}\n"); 637 builder->fsCodeAppend("\t\t}\n");
639 // end if (discriminant >= 0) 638 // end if (discriminant >= 0)
640 builder->fsCodeAppend("\t}\n"); 639 builder->fsCodeAppend("\t}\n");
641 } else { 640 } else {
642 641
643 // linear case: t = -c/b 642 // linear case: t = -c/b
644 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(), 643 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
645 cName.c_str(), bVar.c_str()); 644 cName.c_str(), bVar.c_str());
646 645
647 // if r(t) > 0, then t will be the x coordinate 646 // if r(t) > 0, then t will be the x coordinate
648 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str( ), 647 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str( ),
649 p5.c_str(), p3.c_str()); 648 p5.c_str(), p3.c_str());
650 builder->fsCodeAppend("\t"); 649 builder->fsCodeAppend("\t");
651 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo r, samplers[0]); 650 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor , samplers);
652 builder->fsCodeAppend("\t}\n"); 651 builder->fsCodeAppend("\t}\n");
653 } 652 }
654 } 653 }
655 } 654 }
656 655
657 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, 656 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman,
658 const GrDrawEffect& drawEffect) { 657 const GrDrawEffect& drawEffect) {
659 INHERITED::setData(uman, drawEffect); 658 INHERITED::setData(uman, drawEffect);
660 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>() ; 659 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>() ;
661 GrAssert(data.isDegenerate() == fIsDegenerate); 660 GrAssert(data.isDegenerate() == fIsDegenerate);
(...skipping 28 matching lines...) Expand all
690 fCachedDiffRadius = diffRadius; 689 fCachedDiffRadius = diffRadius;
691 } 690 }
692 } 691 }
693 692
694 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec t, 693 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec t,
695 const GrGLCaps&) { 694 const GrGLCaps&) {
696 enum { 695 enum {
697 kIsDegenerate = 1 << kMatrixKeyBitCnt, 696 kIsDegenerate = 1 << kMatrixKeyBitCnt,
698 }; 697 };
699 698
700 EffectKey key = GenMatrixKey(drawEffect); 699 EffectKey key = GenBaseGradientKey(drawEffect);
701 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) { 700 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) {
702 key |= kIsDegenerate; 701 key |= kIsDegenerate;
703 } 702 }
704 return key; 703 return key;
705 } 704 }
706 705
707 ///////////////////////////////////////////////////////////////////// 706 /////////////////////////////////////////////////////////////////////
708 707
709 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk Paint&) const { 708 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk Paint&) const {
710 SkASSERT(NULL != context); 709 SkASSERT(NULL != context);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 str->appendScalar(fCenter2.fY); 755 str->appendScalar(fCenter2.fY);
757 str->append(") radius2: "); 756 str->append(") radius2: ");
758 str->appendScalar(fRadius2); 757 str->appendScalar(fRadius2);
759 str->append(" "); 758 str->append(" ");
760 759
761 this->INHERITED::toString(str); 760 this->INHERITED::toString(str);
762 761
763 str->append(")"); 762 str->append(")");
764 } 763 }
765 #endif 764 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698