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

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

Issue 12547012: Make GrGLEffects use an interface to append their code. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 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 "SkTwoPointRadialGradient.h" 9 #include "SkTwoPointRadialGradient.h"
10 10
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 kFloat_GrSLType, "Radial2FSParams", 6 ); 553 kFloat_GrSLType, "Radial2FSParams", 6 );
554 554
555 // For radial gradients without perspective we can pass the linear 555 // For radial gradients without perspective we can pass the linear
556 // part of the quadratic as a varying. 556 // part of the quadratic as a varying.
557 if (kVec2f_GrSLType == coordsVaryingType) { 557 if (kVec2f_GrSLType == coordsVaryingType) {
558 builder->addVarying(kFloat_GrSLType, "Radial2BCoeff", &fVSVaryingName, & fFSVaryingName); 558 builder->addVarying(kFloat_GrSLType, "Radial2BCoeff", &fVSVaryingName, & fFSVaryingName);
559 } 559 }
560 560
561 // VS 561 // VS
562 { 562 {
563 SkString* code = &builder->fVSCode;
564 SkString p2; 563 SkString p2;
565 SkString p3; 564 SkString p3;
566 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2); 565 builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
567 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3); 566 builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
568 567
569 // For radial gradients without perspective we can pass the linear 568 // For radial gradients without perspective we can pass the linear
570 // part of the quadratic as a varying. 569 // part of the quadratic as a varying.
571 if (kVec2f_GrSLType == coordsVaryingType) { 570 if (kVec2f_GrSLType == coordsVaryingType) {
572 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3]) 571 // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
573 code->appendf("\t%s = 2.0 *(%s * %s.x - %s);\n", 572 builder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
574 fVSVaryingName, p2.c_str(), 573 fVSVaryingName, p2.c_str(),
575 vsCoordsVarying, p3.c_str()); 574 vsCoordsVarying, p3.c_str());
576 } 575 }
577 } 576 }
578 577
579 // FS 578 // FS
580 { 579 {
581 SkString* code = &builder->fFSCode;
582 SkString cName("c"); 580 SkString cName("c");
583 SkString ac4Name("ac4"); 581 SkString ac4Name("ac4");
584 SkString rootName("root"); 582 SkString rootName("root");
585 SkString t; 583 SkString t;
586 SkString p0; 584 SkString p0;
587 SkString p1; 585 SkString p1;
588 SkString p2; 586 SkString p2;
589 SkString p3; 587 SkString p3;
590 SkString p4; 588 SkString p4;
591 SkString p5; 589 SkString p5;
592 builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0); 590 builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0);
593 builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1); 591 builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1);
594 builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2); 592 builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2);
595 builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3); 593 builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3);
596 builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4); 594 builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4);
597 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5); 595 builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
598 596
599 // If we we're able to interpolate the linear component, 597 // If we we're able to interpolate the linear component,
600 // bVar is the varying; otherwise compute it 598 // bVar is the varying; otherwise compute it
601 SkString bVar; 599 SkString bVar;
602 if (kVec2f_GrSLType == coordsVaryingType) { 600 if (kVec2f_GrSLType == coordsVaryingType) {
603 bVar = fFSVaryingName; 601 bVar = fFSVaryingName;
604 } else { 602 } else {
605 bVar = "b"; 603 bVar = "b";
606 code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n", 604 builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
607 bVar.c_str(), p2.c_str(), fsCoords, p3.c_str()); 605 bVar.c_str(), p2.c_str(), fsCoords, p3.c_str( ));
608 } 606 }
609 607
610 // c = (x^2)+(y^2) - params[4] 608 // c = (x^2)+(y^2) - params[4]
611 code->appendf("\tfloat %s = dot(%s, %s) - %s;\n", 609 builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
612 cName.c_str(), 610 cName.c_str(),
613 fsCoords, 611 fsCoords,
614 fsCoords, 612 fsCoords,
615 p4.c_str()); 613 p4.c_str());
616 614
617 // If we aren't degenerate, emit some extra code, and accept a slightly 615 // If we aren't degenerate, emit some extra code, and accept a slightly
618 // more complex coord. 616 // more complex coord.
619 if (!fIsDegenerate) { 617 if (!fIsDegenerate) {
620 618
621 // ac4 = 4.0 * params[0] * c 619 // ac4 = 4.0 * params[0] * c
622 code->appendf("\tfloat %s = %s * 4.0 * %s;\n", 620 builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n",
623 ac4Name.c_str(), p0.c_str(), 621 ac4Name.c_str(), p0.c_str(),
624 cName.c_str()); 622 cName.c_str());
625 623
626 // root = sqrt(b^2-4ac) 624 // root = sqrt(b^2-4ac)
627 // (abs to avoid exception due to fp precision) 625 // (abs to avoid exception due to fp precision)
628 code->appendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n", 626 builder->fsCodeAppendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n",
629 rootName.c_str(), bVar.c_str(), bVar.c_str(), 627 rootName.c_str(), bVar.c_str(), bVar.c_str(),
630 ac4Name.c_str()); 628 ac4Name.c_str());
631 629
632 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1] 630 // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
633 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(), 631 t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(),
634 rootName.c_str(), p1.c_str()); 632 rootName.c_str(), p1.c_str());
635 } else { 633 } else {
636 // t is: -c/b 634 // t is: -c/b
637 t.printf("-%s / %s", cName.c_str(), bVar.c_str()); 635 t.printf("-%s / %s", cName.c_str(), bVar.c_str());
638 } 636 }
639 637
640 this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, sampl ers[0]); 638 this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, sampl ers[0]);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 } 709 }
712 710
713 #else 711 #else
714 712
715 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c onst { 713 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c onst {
716 SkDEBUGFAIL("Should not call in GPU-less build"); 714 SkDEBUGFAIL("Should not call in GPU-less build");
717 return NULL; 715 return NULL;
718 } 716 }
719 717
720 #endif 718 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkTwoPointConicalGradient.cpp ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698