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

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

Issue 1251173002: Added GrGLFragmentProcessor::EmitArgs struct for use with emitCode() (Closed) Base URL: https://skia.googlesource.com/skia@composeshader_gpu
Patch Set: Created 5 years, 5 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
« no previous file with comments | « src/effects/gradients/SkSweepGradient.cpp ('k') | src/gpu/effects/GrBicubicEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 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_gpu.h" 9 #include "SkTwoPointConicalGradient_gpu.h"
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // @} 137 // @}
138 138
139 typedef GrGradientEffect INHERITED; 139 typedef GrGradientEffect INHERITED;
140 }; 140 };
141 141
142 class GLEdge2PtConicalEffect : public GrGLGradientEffect { 142 class GLEdge2PtConicalEffect : public GrGLGradientEffect {
143 public: 143 public:
144 GLEdge2PtConicalEffect(const GrProcessor&); 144 GLEdge2PtConicalEffect(const GrProcessor&);
145 virtual ~GLEdge2PtConicalEffect() { } 145 virtual ~GLEdge2PtConicalEffect() { }
146 146
147 virtual void emitCode(GrGLFPBuilder*, 147 virtual void emitCode(EmitArgs&) override;
148 const GrFragmentProcessor&,
149 const char* outputColor,
150 const char* inputColor,
151 const TransformedCoordsArray&,
152 const TextureSamplerArray&) override;
153 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 148 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
154 149
155 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 150 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
156 151
157 protected: 152 protected:
158 UniformHandle fParamUni; 153 UniformHandle fParamUni;
159 154
160 const char* fVSVaryingName; 155 const char* fVSVaryingName;
161 const char* fFSVaryingName; 156 const char* fFSVaryingName;
162 157
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 &paintColor, d->fProcDataManager, &fp)); 216 &paintColor, d->fProcDataManager, &fp));
222 return fp; 217 return fp;
223 } 218 }
224 219
225 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) 220 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&)
226 : fVSVaryingName(NULL) 221 : fVSVaryingName(NULL)
227 , fFSVaryingName(NULL) 222 , fFSVaryingName(NULL)
228 , fCachedRadius(-SK_ScalarMax) 223 , fCachedRadius(-SK_ScalarMax)
229 , fCachedDiffRadius(-SK_ScalarMax) {} 224 , fCachedDiffRadius(-SK_ScalarMax) {}
230 225
231 void GLEdge2PtConicalEffect::emitCode(GrGLFPBuilder* builder, 226 void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) {
232 const GrFragmentProcessor& fp, 227 const Edge2PtConicalEffect& ge = args.fFp.cast<Edge2PtConicalEffect>();
233 const char* outputColor, 228 this->emitUniforms(args.fBuilder, ge);
234 const char* inputColor, 229 fParamUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vis ibility,
235 const TransformedCoordsArray& coords,
236 const TextureSamplerArray& samplers) {
237 const Edge2PtConicalEffect& ge = fp.cast<Edge2PtConicalEffect>();
238 this->emitUniforms(builder, ge);
239 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit y,
240 kFloat_GrSLType, kDefault_GrSLPrecision , 230 kFloat_GrSLType, kDefault_GrSLPrecision ,
241 "Conical2FSParams", 3); 231 "Conical2FSParams", 3);
242 232
243 SkString cName("c"); 233 SkString cName("c");
244 SkString tName("t"); 234 SkString tName("t");
245 SkString p0; // start radius 235 SkString p0; // start radius
246 SkString p1; // start radius squared 236 SkString p1; // start radius squared
247 SkString p2; // difference in radii (r1 - r0) 237 SkString p2; // difference in radii (r1 - r0)
248 238
249 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); 239 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0);
250 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); 240 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
251 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); 241 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2);
252 242
253 // We interpolate the linear component in coords[1]. 243 // We interpolate the linear component in coords[1].
254 SkASSERT(coords[0].getType() == coords[1].getType()); 244 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType());
255 const char* coords2D; 245 const char* coords2D;
256 SkString bVar; 246 SkString bVar;
257 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 247 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
258 if (kVec3f_GrSLType == coords[0].getType()) { 248 if (kVec3f_GrSLType == args.fCoords[0].getType()) {
259 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n", 249 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n",
260 coords[0].c_str(), coords[0].c_str(), coords[1].c _str(), 250 args.fCoords[0].c_str(), args.fCoords[0].c_str(),
261 coords[1].c_str()); 251 args.fCoords[1].c_str(), args.fCoords[1].c_str()) ;
262 coords2D = "interpolants.xy"; 252 coords2D = "interpolants.xy";
263 bVar = "interpolants.z"; 253 bVar = "interpolants.z";
264 } else { 254 } else {
265 coords2D = coords[0].c_str(); 255 coords2D = args.fCoords[0].c_str();
266 bVar.printf("%s.x", coords[1].c_str()); 256 bVar.printf("%s.x", args.fCoords[1].c_str());
267 } 257 }
268 258
269 // output will default to transparent black (we simply won't write anything 259 // output will default to transparent black (we simply won't write anything
270 // else to it if invalid, instead of discarding or returning prematurely) 260 // else to it if invalid, instead of discarding or returning prematurely)
271 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); 261 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor) ;
272 262
273 // c = (x^2)+(y^2) - params[1] 263 // c = (x^2)+(y^2) - params[1]
274 fsBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", 264 fsBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
275 cName.c_str(), coords2D, coords2D, p1.c_str()); 265 cName.c_str(), coords2D, coords2D, p1.c_str());
276 266
277 // linear case: t = -c/b 267 // linear case: t = -c/b
278 fsBuilder->codeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(), 268 fsBuilder->codeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
279 cName.c_str(), bVar.c_str()); 269 cName.c_str(), bVar.c_str());
280 270
281 // if r(t) > 0, then t will be the x coordinate 271 // if r(t) > 0, then t will be the x coordinate
282 fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(), 272 fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
283 p2.c_str(), p0.c_str()); 273 p2.c_str(), p0.c_str());
284 fsBuilder->codeAppend("\t"); 274 fsBuilder->codeAppend("\t");
285 this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, sampler s); 275 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
276 args.fSamplers);
286 fsBuilder->codeAppend("\t}\n"); 277 fsBuilder->codeAppend("\t}\n");
287 } 278 }
288 279
289 void GLEdge2PtConicalEffect::setData(const GrGLProgramDataManager& pdman, 280 void GLEdge2PtConicalEffect::setData(const GrGLProgramDataManager& pdman,
290 const GrProcessor& processor) { 281 const GrProcessor& processor) {
291 INHERITED::setData(pdman, processor); 282 INHERITED::setData(pdman, processor);
292 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>(); 283 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>();
293 SkScalar radius0 = data.radius(); 284 SkScalar radius0 = data.radius();
294 SkScalar diffRadius = data.diffRadius(); 285 SkScalar diffRadius = data.diffRadius();
295 286
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 bool fIsFlipped; 418 bool fIsFlipped;
428 419
429 typedef GrGradientEffect INHERITED; 420 typedef GrGradientEffect INHERITED;
430 }; 421 };
431 422
432 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect { 423 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect {
433 public: 424 public:
434 GLFocalOutside2PtConicalEffect(const GrProcessor&); 425 GLFocalOutside2PtConicalEffect(const GrProcessor&);
435 virtual ~GLFocalOutside2PtConicalEffect() { } 426 virtual ~GLFocalOutside2PtConicalEffect() { }
436 427
437 virtual void emitCode(GrGLFPBuilder*, 428 virtual void emitCode(EmitArgs&) override;
438 const GrFragmentProcessor&,
439 const char* outputColor,
440 const char* inputColor,
441 const TransformedCoordsArray&,
442 const TextureSamplerArray&) override;
443 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 429 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
444 430
445 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 431 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
446 432
447 protected: 433 protected:
448 UniformHandle fParamUni; 434 UniformHandle fParamUni;
449 435
450 const char* fVSVaryingName; 436 const char* fVSVaryingName;
451 const char* fFSVaryingName; 437 const char* fFSVaryingName;
452 438
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 499 }
514 500
515 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor & processor) 501 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor & processor)
516 : fVSVaryingName(NULL) 502 : fVSVaryingName(NULL)
517 , fFSVaryingName(NULL) 503 , fFSVaryingName(NULL)
518 , fCachedFocal(SK_ScalarMax) { 504 , fCachedFocal(SK_ScalarMax) {
519 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>(); 505 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>();
520 fIsFlipped = data.isFlipped(); 506 fIsFlipped = data.isFlipped();
521 } 507 }
522 508
523 void GLFocalOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, 509 void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) {
524 const GrFragmentProcessor& fp, 510 const FocalOutside2PtConicalEffect& ge = args.fFp.cast<FocalOutside2PtConica lEffect>();
525 const char* outputColor, 511 this->emitUniforms(args.fBuilder, ge);
526 const char* inputColor, 512 fParamUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vis ibility,
527 const TransformedCoordsArray& coor ds,
528 const TextureSamplerArray& sampler s) {
529 const FocalOutside2PtConicalEffect& ge = fp.cast<FocalOutside2PtConicalEffec t>();
530 this->emitUniforms(builder, ge);
531 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit y,
532 kFloat_GrSLType, kDefault_GrSLPrecision , 513 kFloat_GrSLType, kDefault_GrSLPrecision ,
533 "Conical2FSParams", 2); 514 "Conical2FSParams", 2);
534 SkString tName("t"); 515 SkString tName("t");
535 SkString p0; // focalX 516 SkString p0; // focalX
536 SkString p1; // 1 - focalX * focalX 517 SkString p1; // 1 - focalX * focalX
537 518
538 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); 519 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0);
539 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); 520 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
540 521
541 // if we have a vec3 from being in perspective, convert it to a vec2 first 522 // if we have a vec3 from being in perspective, convert it to a vec2 first
542 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 523 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
543 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); 524 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
544 const char* coords2D = coords2DString.c_str(); 525 const char* coords2D = coords2DString.c_str();
545 526
546 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) 527 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2)
547 528
548 // output will default to transparent black (we simply won't write anything 529 // output will default to transparent black (we simply won't write anything
549 // else to it if invalid, instead of discarding or returning prematurely) 530 // else to it if invalid, instead of discarding or returning prematurely)
550 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); 531 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor) ;
551 532
552 fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); 533 fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D);
553 fsBuilder->codeAppendf("\tfloat ys = %s.y * %s.y;\n", coords2D, coords2D); 534 fsBuilder->codeAppendf("\tfloat ys = %s.y * %s.y;\n", coords2D, coords2D);
554 fsBuilder->codeAppendf("\tfloat d = xs + %s * ys;\n", p1.c_str()); 535 fsBuilder->codeAppendf("\tfloat d = xs + %s * ys;\n", p1.c_str());
555 536
556 // Must check to see if we flipped the circle order (to make sure start radi us < end radius) 537 // Must check to see if we flipped the circle order (to make sure start radi us < end radius)
557 // If so we must also flip sign on sqrt 538 // If so we must also flip sign on sqrt
558 if (!fIsFlipped) { 539 if (!fIsFlipped) {
559 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + sqrt(d);\n", tName.c_s tr(), 540 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + sqrt(d);\n", tName.c_s tr(),
560 coords2D, p0.c_str()); 541 coords2D, p0.c_str());
561 } else { 542 } else {
562 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s - sqrt(d);\n", tName.c_s tr(), 543 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s - sqrt(d);\n", tName.c_s tr(),
563 coords2D, p0.c_str()); 544 coords2D, p0.c_str());
564 } 545 }
565 546
566 fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str()); 547 fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
567 fsBuilder->codeAppend("\t\t"); 548 fsBuilder->codeAppend("\t\t");
568 this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, sampler s); 549 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
550 args.fSamplers);
569 fsBuilder->codeAppend("\t}\n"); 551 fsBuilder->codeAppend("\t}\n");
570 } 552 }
571 553
572 void GLFocalOutside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman , 554 void GLFocalOutside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman ,
573 const GrProcessor& processor) { 555 const GrProcessor& processor) {
574 INHERITED::setData(pdman, processor); 556 INHERITED::setData(pdman, processor);
575 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>(); 557 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>();
576 SkASSERT(data.isFlipped() == fIsFlipped); 558 SkASSERT(data.isFlipped() == fIsFlipped);
577 SkScalar focal = data.focal(); 559 SkScalar focal = data.focal();
578 560
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 SkScalar fFocalX; 631 SkScalar fFocalX;
650 632
651 typedef GrGradientEffect INHERITED; 633 typedef GrGradientEffect INHERITED;
652 }; 634 };
653 635
654 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect { 636 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect {
655 public: 637 public:
656 GLFocalInside2PtConicalEffect(const GrProcessor&); 638 GLFocalInside2PtConicalEffect(const GrProcessor&);
657 virtual ~GLFocalInside2PtConicalEffect() {} 639 virtual ~GLFocalInside2PtConicalEffect() {}
658 640
659 virtual void emitCode(GrGLFPBuilder*, 641 virtual void emitCode(EmitArgs&) override;
660 const GrFragmentProcessor&,
661 const char* outputColor,
662 const char* inputColor,
663 const TransformedCoordsArray&,
664 const TextureSamplerArray&) override;
665 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 642 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
666 643
667 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 644 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
668 645
669 protected: 646 protected:
670 UniformHandle fFocalUni; 647 UniformHandle fFocalUni;
671 648
672 const char* fVSVaryingName; 649 const char* fVSVaryingName;
673 const char* fFSVaryingName; 650 const char* fFSVaryingName;
674 651
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 GrTest::TestMatrix(d->fRandom), N ULL, 707 GrTest::TestMatrix(d->fRandom), N ULL,
731 &paintColor, d->fProcDataManager, &fp)); 708 &paintColor, d->fProcDataManager, &fp));
732 return fp; 709 return fp;
733 } 710 }
734 711
735 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) 712 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&)
736 : fVSVaryingName(NULL) 713 : fVSVaryingName(NULL)
737 , fFSVaryingName(NULL) 714 , fFSVaryingName(NULL)
738 , fCachedFocal(SK_ScalarMax) {} 715 , fCachedFocal(SK_ScalarMax) {}
739 716
740 void GLFocalInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, 717 void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) {
741 const GrFragmentProcessor& fp, 718 const FocalInside2PtConicalEffect& ge = args.fFp.cast<FocalInside2PtConicalE ffect>();
742 const char* outputColor, 719 this->emitUniforms(args.fBuilder, ge);
743 const char* inputColor, 720 fFocalUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili ty,
744 const TransformedCoordsArray& coord s,
745 const TextureSamplerArray& samplers ) {
746 const FocalInside2PtConicalEffect& ge = fp.cast<FocalInside2PtConicalEffect> ();
747 this->emitUniforms(builder, ge);
748 fFocalUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
749 kFloat_GrSLType, kDefault_GrSLPrecision, 721 kFloat_GrSLType, kDefault_GrSLPrecision,
750 "Conical2FSParams"); 722 "Conical2FSParams");
751 SkString tName("t"); 723 SkString tName("t");
752 724
753 // this is the distance along x-axis from the end center to focal point in 725 // this is the distance along x-axis from the end center to focal point in
754 // transformed coordinates 726 // transformed coordinates
755 GrGLShaderVar focal = builder->getUniformVariable(fFocalUni); 727 GrGLShaderVar focal = args.fBuilder->getUniformVariable(fFocalUni);
756 728
757 // if we have a vec3 from being in perspective, convert it to a vec2 first 729 // if we have a vec3 from being in perspective, convert it to a vec2 first
758 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 730 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
759 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); 731 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
760 const char* coords2D = coords2DString.c_str(); 732 const char* coords2D = coords2DString.c_str();
761 733
762 // t = p.x * focalX + length(p) 734 // t = p.x * focalX + length(p)
763 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(), 735 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(),
764 coords2D, focal.c_str(), coords2D); 736 coords2D, focal.c_str(), coords2D);
765 737
766 this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, sampler s); 738 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
739 args.fSamplers);
767 } 740 }
768 741
769 void GLFocalInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman, 742 void GLFocalInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman,
770 const GrProcessor& processor) { 743 const GrProcessor& processor) {
771 INHERITED::setData(pdman, processor); 744 INHERITED::setData(pdman, processor);
772 const FocalInside2PtConicalEffect& data = processor.cast<FocalInside2PtConic alEffect>(); 745 const FocalInside2PtConicalEffect& data = processor.cast<FocalInside2PtConic alEffect>();
773 SkScalar focal = data.focal(); 746 SkScalar focal = data.focal();
774 747
775 if (fCachedFocal != focal) { 748 if (fCachedFocal != focal) {
776 pdman.set1f(fFocalUni, SkScalarToFloat(focal)); 749 pdman.set1f(fFocalUni, SkScalarToFloat(focal));
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 const CircleConicalInfo fInfo; 873 const CircleConicalInfo fInfo;
901 874
902 typedef GrGradientEffect INHERITED; 875 typedef GrGradientEffect INHERITED;
903 }; 876 };
904 877
905 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect { 878 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect {
906 public: 879 public:
907 GLCircleInside2PtConicalEffect(const GrProcessor&); 880 GLCircleInside2PtConicalEffect(const GrProcessor&);
908 virtual ~GLCircleInside2PtConicalEffect() {} 881 virtual ~GLCircleInside2PtConicalEffect() {}
909 882
910 virtual void emitCode(GrGLFPBuilder*, 883 virtual void emitCode(EmitArgs&) override;
911 const GrFragmentProcessor&,
912 const char* outputColor,
913 const char* inputColor,
914 const TransformedCoordsArray&,
915 const TextureSamplerArray&) override;
916 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 884 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
917 885
918 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 886 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
919 887
920 protected: 888 protected:
921 UniformHandle fCenterUni; 889 UniformHandle fCenterUni;
922 UniformHandle fParamUni; 890 UniformHandle fParamUni;
923 891
924 const char* fVSVaryingName; 892 const char* fVSVaryingName;
925 const char* fFSVaryingName; 893 const char* fFSVaryingName;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 958
991 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor & processor) 959 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor & processor)
992 : fVSVaryingName(NULL) 960 : fVSVaryingName(NULL)
993 , fFSVaryingName(NULL) 961 , fFSVaryingName(NULL)
994 , fCachedCenterX(SK_ScalarMax) 962 , fCachedCenterX(SK_ScalarMax)
995 , fCachedCenterY(SK_ScalarMax) 963 , fCachedCenterY(SK_ScalarMax)
996 , fCachedA(SK_ScalarMax) 964 , fCachedA(SK_ScalarMax)
997 , fCachedB(SK_ScalarMax) 965 , fCachedB(SK_ScalarMax)
998 , fCachedC(SK_ScalarMax) {} 966 , fCachedC(SK_ScalarMax) {}
999 967
1000 void GLCircleInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, 968 void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) {
1001 const GrFragmentProcessor& fp, 969 const CircleInside2PtConicalEffect& ge = args.fFp.cast<CircleInside2PtConica lEffect>();
1002 const char* outputColor, 970 this->emitUniforms(args.fBuilder, ge);
1003 const char* inputColor, 971 fCenterUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity,
1004 const TransformedCoordsArray& coor ds,
1005 const TextureSamplerArray& sampler s) {
1006 const CircleInside2PtConicalEffect& ge = fp.cast<CircleInside2PtConicalEffec t>();
1007 this->emitUniforms(builder, ge);
1008 fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1009 kVec2f_GrSLType, kDefault_GrSLPrecision, 972 kVec2f_GrSLType, kDefault_GrSLPrecision,
1010 "Conical2FSCenter"); 973 "Conical2FSCenter");
1011 fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 974 fParamUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili ty,
1012 kVec3f_GrSLType, kDefault_GrSLPrecision, 975 kVec3f_GrSLType, kDefault_GrSLPrecision,
1013 "Conical2FSParams"); 976 "Conical2FSParams");
1014 SkString tName("t"); 977 SkString tName("t");
1015 978
1016 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); 979 GrGLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni);
1017 // params.x = A 980 // params.x = A
1018 // params.y = B 981 // params.y = B
1019 // params.z = C 982 // params.z = C
1020 GrGLShaderVar params = builder->getUniformVariable(fParamUni); 983 GrGLShaderVar params = args.fBuilder->getUniformVariable(fParamUni);
1021 984
1022 // if we have a vec3 from being in perspective, convert it to a vec2 first 985 // if we have a vec3 from being in perspective, convert it to a vec2 first
1023 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 986 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
1024 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); 987 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
1025 const char* coords2D = coords2DString.c_str(); 988 const char* coords2D = coords2DString.c_str();
1026 989
1027 // p = coords2D 990 // p = coords2D
1028 // e = center end 991 // e = center end
1029 // r = radius end 992 // r = radius end
1030 // A = dot(e, e) - r^2 + 2 * r - 1 993 // A = dot(e, e) - r^2 + 2 * r - 1
1031 // B = (r -1) / A 994 // B = (r -1) / A
1032 // C = 1 / A 995 // C = 1 / A
1033 // d = dot(e, p) + B 996 // d = dot(e, p) + B
1034 // t = d +/- sqrt(d^2 - A * dot(p, p) + C) 997 // t = d +/- sqrt(d^2 - A * dot(p, p) + C)
1035 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D ); 998 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D );
1036 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(), 999 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(),
1037 params.c_str()); 1000 params.c_str());
1038 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n", 1001 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n",
1039 tName.c_str(), params.c_str(), params.c_str()); 1002 tName.c_str(), params.c_str(), params.c_str());
1040 1003
1041 this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, sampler s); 1004 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
1005 args.fSamplers);
1042 } 1006 }
1043 1007
1044 void GLCircleInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman , 1008 void GLCircleInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman ,
1045 const GrProcessor& processor) { 1009 const GrProcessor& processor) {
1046 INHERITED::setData(pdman, processor); 1010 INHERITED::setData(pdman, processor);
1047 const CircleInside2PtConicalEffect& data = processor.cast<CircleInside2PtCon icalEffect>(); 1011 const CircleInside2PtConicalEffect& data = processor.cast<CircleInside2PtCon icalEffect>();
1048 SkScalar centerX = data.centerX(); 1012 SkScalar centerX = data.centerX();
1049 SkScalar centerY = data.centerY(); 1013 SkScalar centerY = data.centerY();
1050 SkScalar A = data.A(); 1014 SkScalar A = data.A();
1051 SkScalar B = data.B(); 1015 SkScalar B = data.B();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 bool fIsFlipped; 1101 bool fIsFlipped;
1138 1102
1139 typedef GrGradientEffect INHERITED; 1103 typedef GrGradientEffect INHERITED;
1140 }; 1104 };
1141 1105
1142 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect { 1106 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect {
1143 public: 1107 public:
1144 GLCircleOutside2PtConicalEffect(const GrProcessor&); 1108 GLCircleOutside2PtConicalEffect(const GrProcessor&);
1145 virtual ~GLCircleOutside2PtConicalEffect() {} 1109 virtual ~GLCircleOutside2PtConicalEffect() {}
1146 1110
1147 virtual void emitCode(GrGLFPBuilder*, 1111 virtual void emitCode(EmitArgs&) override;
1148 const GrFragmentProcessor&,
1149 const char* outputColor,
1150 const char* inputColor,
1151 const TransformedCoordsArray&,
1152 const TextureSamplerArray&) override;
1153 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1112 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
1154 1113
1155 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 1114 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
1156 1115
1157 protected: 1116 protected:
1158 UniformHandle fCenterUni; 1117 UniformHandle fCenterUni;
1159 UniformHandle fParamUni; 1118 UniformHandle fParamUni;
1160 1119
1161 const char* fVSVaryingName; 1120 const char* fVSVaryingName;
1162 const char* fFSVaryingName; 1121 const char* fFSVaryingName;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 , fCachedCenterX(SK_ScalarMax) 1193 , fCachedCenterX(SK_ScalarMax)
1235 , fCachedCenterY(SK_ScalarMax) 1194 , fCachedCenterY(SK_ScalarMax)
1236 , fCachedA(SK_ScalarMax) 1195 , fCachedA(SK_ScalarMax)
1237 , fCachedB(SK_ScalarMax) 1196 , fCachedB(SK_ScalarMax)
1238 , fCachedC(SK_ScalarMax) 1197 , fCachedC(SK_ScalarMax)
1239 , fCachedTLimit(SK_ScalarMax) { 1198 , fCachedTLimit(SK_ScalarMax) {
1240 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>(); 1199 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>();
1241 fIsFlipped = data.isFlipped(); 1200 fIsFlipped = data.isFlipped();
1242 } 1201 }
1243 1202
1244 void GLCircleOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, 1203 void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) {
1245 const GrFragmentProcessor& fp, 1204 const CircleOutside2PtConicalEffect& ge = args.fFp.cast<CircleOutside2PtConi calEffect>();
1246 const char* outputColor, 1205 this->emitUniforms(args.fBuilder, ge);
1247 const char* inputColor, 1206 fCenterUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibil ity,
1248 const TransformedCoordsArray& coo rds,
1249 const TextureSamplerArray& sample rs) {
1250 const CircleOutside2PtConicalEffect& ge = fp.cast<CircleOutside2PtConicalEff ect>();
1251 this->emitUniforms(builder, ge);
1252 fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
1253 kVec2f_GrSLType, kDefault_GrSLPrecision, 1207 kVec2f_GrSLType, kDefault_GrSLPrecision,
1254 "Conical2FSCenter"); 1208 "Conical2FSCenter");
1255 fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 1209 fParamUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili ty,
1256 kVec4f_GrSLType, kDefault_GrSLPrecision, 1210 kVec4f_GrSLType, kDefault_GrSLPrecision,
1257 "Conical2FSParams"); 1211 "Conical2FSParams");
1258 SkString tName("t"); 1212 SkString tName("t");
1259 1213
1260 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); 1214 GrGLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni);
1261 // params.x = A 1215 // params.x = A
1262 // params.y = B 1216 // params.y = B
1263 // params.z = C 1217 // params.z = C
1264 GrGLShaderVar params = builder->getUniformVariable(fParamUni); 1218 GrGLShaderVar params = args.fBuilder->getUniformVariable(fParamUni);
1265 1219
1266 // if we have a vec3 from being in perspective, convert it to a vec2 first 1220 // if we have a vec3 from being in perspective, convert it to a vec2 first
1267 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 1221 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
1268 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); 1222 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
1269 const char* coords2D = coords2DString.c_str(); 1223 const char* coords2D = coords2DString.c_str();
1270 1224
1271 // output will default to transparent black (we simply won't write anything 1225 // output will default to transparent black (we simply won't write anything
1272 // else to it if invalid, instead of discarding or returning prematurely) 1226 // else to it if invalid, instead of discarding or returning prematurely)
1273 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); 1227 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor) ;
1274 1228
1275 // p = coords2D 1229 // p = coords2D
1276 // e = center end 1230 // e = center end
1277 // r = radius end 1231 // r = radius end
1278 // A = dot(e, e) - r^2 + 2 * r - 1 1232 // A = dot(e, e) - r^2 + 2 * r - 1
1279 // B = (r -1) / A 1233 // B = (r -1) / A
1280 // C = 1 / A 1234 // C = 1 / A
1281 // d = dot(e, p) + B 1235 // d = dot(e, p) + B
1282 // t = d +/- sqrt(d^2 - A * dot(p, p) + C) 1236 // t = d +/- sqrt(d^2 - A * dot(p, p) + C)
1283 1237
1284 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D ); 1238 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D );
1285 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(), 1239 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(),
1286 params.c_str()); 1240 params.c_str());
1287 fsBuilder->codeAppendf("\tfloat deter = d * d - %s.x * pDotp + %s.z;\n", par ams.c_str(), 1241 fsBuilder->codeAppendf("\tfloat deter = d * d - %s.x * pDotp + %s.z;\n", par ams.c_str(),
1288 params.c_str()); 1242 params.c_str());
1289 1243
1290 // Must check to see if we flipped the circle order (to make sure start radi us < end radius) 1244 // Must check to see if we flipped the circle order (to make sure start radi us < end radius)
1291 // If so we must also flip sign on sqrt 1245 // If so we must also flip sign on sqrt
1292 if (!fIsFlipped) { 1246 if (!fIsFlipped) {
1293 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(deter);\n", tName.c_str()) ; 1247 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(deter);\n", tName.c_str()) ;
1294 } else { 1248 } else {
1295 fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ; 1249 fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ;
1296 } 1250 }
1297 1251
1298 fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str()); 1252 fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str());
1299 fsBuilder->codeAppend("\t\t"); 1253 fsBuilder->codeAppend("\t\t");
1300 this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, sampler s); 1254 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
1255 args.fSamplers);
1301 fsBuilder->codeAppend("\t}\n"); 1256 fsBuilder->codeAppend("\t}\n");
1302 } 1257 }
1303 1258
1304 void GLCircleOutside2PtConicalEffect::setData(const GrGLProgramDataManager& pdma n, 1259 void GLCircleOutside2PtConicalEffect::setData(const GrGLProgramDataManager& pdma n,
1305 const GrProcessor& processor) { 1260 const GrProcessor& processor) {
1306 INHERITED::setData(pdman, processor); 1261 INHERITED::setData(pdman, processor);
1307 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>(); 1262 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>();
1308 SkASSERT(data.isFlipped() == fIsFlipped); 1263 SkASSERT(data.isFlipped() == fIsFlipped);
1309 SkScalar centerX = data.centerX(); 1264 SkScalar centerX = data.centerX();
1310 SkScalar centerY = data.centerY(); 1265 SkScalar centerY = data.centerY();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } else if (type == kEdge_ConicalType) { 1334 } else if (type == kEdge_ConicalType) {
1380 set_matrix_edge_conical(shader, &matrix); 1335 set_matrix_edge_conical(shader, &matrix);
1381 return Edge2PtConicalEffect::Create(ctx, procDataManager, shader, matrix , tm); 1336 return Edge2PtConicalEffect::Create(ctx, procDataManager, shader, matrix , tm);
1382 } else { 1337 } else {
1383 return CircleOutside2PtConicalEffect::Create(ctx, procDataManager, shade r, matrix, tm, 1338 return CircleOutside2PtConicalEffect::Create(ctx, procDataManager, shade r, matrix, tm,
1384 info); 1339 info);
1385 } 1340 }
1386 } 1341 }
1387 1342
1388 #endif 1343 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkSweepGradient.cpp ('k') | src/gpu/effects/GrBicubicEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698