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

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

Issue 22854005: GPU Gradients (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reverted defer flag to true 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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const char* fsCoords; 492 const char* fsCoords;
494 const char* vsCoordsVarying; 493 const char* 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_ShaderType , 501 fVSParamUni = builder->addUniformArray(GrGLShaderBuilder::kVertex_ShaderType ,
503 kFloat_GrSLType, "Conical2VSParams", 6); 502 kFloat_GrSLType, "Conical2VSParams", 6);
504 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy pe, 503 fFSParamUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderTy pe,
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 607
609 // so we'll look at the larger one first: 608 // so we'll look at the larger one first:
610 builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str( ), 609 builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str( ),
611 r0Name.c_str(), r1Name.c_str()); 610 r0Name.c_str(), r1Name.c_str());
612 611
613 // if r(t) > 0, then we're done; t will be our x coordinate 612 // if r(t) > 0, then we're done; t will be our x coordinate
614 builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_st r(), 613 builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_st r(),
615 p5.c_str(), p3.c_str()); 614 p5.c_str(), p3.c_str());
616 615
617 builder->fsCodeAppend("\t\t"); 616 builder->fsCodeAppend("\t\t");
618 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo r, samplers[0]); 617 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor , samplers);
619 618
620 // otherwise, if r(t) for the larger root was <= 0, try the other ro ot 619 // otherwise, if r(t) for the larger root was <= 0, try the other ro ot
621 builder->fsCodeAppend("\t\t} else {\n"); 620 builder->fsCodeAppend("\t\t} else {\n");
622 builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(), 621 builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(),
623 r0Name.c_str(), r1Name.c_str()); 622 r0Name.c_str(), r1Name.c_str());
624 623
625 // if r(t) > 0 for the smaller root, then t will be our x coordinate 624 // if r(t) > 0 for the smaller root, then t will be our x coordinate
626 builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n", 625 builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n",
627 tName.c_str(), p5.c_str(), p3.c_str()); 626 tName.c_str(), p5.c_str(), p3.c_str());
628 627
629 builder->fsCodeAppend("\t\t\t"); 628 builder->fsCodeAppend("\t\t\t");
630 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo r, samplers[0]); 629 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor , samplers);
631 630
632 // end if (r(t) > 0) for smaller root 631 // end if (r(t) > 0) for smaller root
633 builder->fsCodeAppend("\t\t\t}\n"); 632 builder->fsCodeAppend("\t\t\t}\n");
634 // end if (r(t) > 0), else, for larger root 633 // end if (r(t) > 0), else, for larger root
635 builder->fsCodeAppend("\t\t}\n"); 634 builder->fsCodeAppend("\t\t}\n");
636 // end if (discriminant >= 0) 635 // end if (discriminant >= 0)
637 builder->fsCodeAppend("\t}\n"); 636 builder->fsCodeAppend("\t}\n");
638 } else { 637 } else {
639 638
640 // linear case: t = -c/b 639 // linear case: t = -c/b
641 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(), 640 builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
642 cName.c_str(), bVar.c_str()); 641 cName.c_str(), bVar.c_str());
643 642
644 // if r(t) > 0, then t will be the x coordinate 643 // if r(t) > 0, then t will be the x coordinate
645 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str( ), 644 builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str( ),
646 p5.c_str(), p3.c_str()); 645 p5.c_str(), p3.c_str());
647 builder->fsCodeAppend("\t"); 646 builder->fsCodeAppend("\t");
648 this->emitColorLookup(builder, tName.c_str(), outputColor, inputColo r, samplers[0]); 647 this->emitColor(builder, tName.c_str(), key, outputColor, inputColor , samplers);
649 builder->fsCodeAppend("\t}\n"); 648 builder->fsCodeAppend("\t}\n");
650 } 649 }
651 } 650 }
652 } 651 }
653 652
654 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, 653 void GrGLConical2Gradient::setData(const GrGLUniformManager& uman,
655 const GrDrawEffect& drawEffect) { 654 const GrDrawEffect& drawEffect) {
656 INHERITED::setData(uman, drawEffect); 655 INHERITED::setData(uman, drawEffect);
657 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>() ; 656 const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>() ;
658 SkASSERT(data.isDegenerate() == fIsDegenerate); 657 SkASSERT(data.isDegenerate() == fIsDegenerate);
(...skipping 28 matching lines...) Expand all
687 fCachedDiffRadius = diffRadius; 686 fCachedDiffRadius = diffRadius;
688 } 687 }
689 } 688 }
690 689
691 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec t, 690 GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffec t,
692 const GrGLCaps&) { 691 const GrGLCaps&) {
693 enum { 692 enum {
694 kIsDegenerate = 1 << kMatrixKeyBitCnt, 693 kIsDegenerate = 1 << kMatrixKeyBitCnt,
695 }; 694 };
696 695
697 EffectKey key = GenMatrixKey(drawEffect); 696 EffectKey key = GenBaseGradientKey(drawEffect);
698 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) { 697 if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) {
699 key |= kIsDegenerate; 698 key |= kIsDegenerate;
700 } 699 }
701 return key; 700 return key;
702 } 701 }
703 702
704 ///////////////////////////////////////////////////////////////////// 703 /////////////////////////////////////////////////////////////////////
705 704
706 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk Paint&) const { 705 GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const Sk Paint&) const {
707 SkASSERT(NULL != context); 706 SkASSERT(NULL != context);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 str->appendScalar(fCenter2.fY); 752 str->appendScalar(fCenter2.fY);
754 str->append(") radius2: "); 753 str->append(") radius2: ");
755 str->appendScalar(fRadius2); 754 str->appendScalar(fRadius2);
756 str->append(" "); 755 str->append(" ");
757 756
758 this->INHERITED::toString(str); 757 this->INHERITED::toString(str);
759 758
760 str->append(")"); 759 str->append(")");
761 } 760 }
762 #endif 761 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698