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

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

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 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
« no previous file with comments | « src/effects/gradients/SkSweepGradient.cpp ('k') | src/gpu/GrProcessor.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 SkShader::TileMode tm) { 65 SkShader::TileMode tm) {
66 return SkNEW_ARGS(Edge2PtConicalEffect, (ctx, procDataManager, shader, m atrix, tm)); 66 return SkNEW_ARGS(Edge2PtConicalEffect, (ctx, procDataManager, shader, m atrix, tm));
67 } 67 }
68 68
69 virtual ~Edge2PtConicalEffect() {} 69 virtual ~Edge2PtConicalEffect() {}
70 70
71 const char* name() const override { 71 const char* name() const override {
72 return "Two-Point Conical Gradient Edge Touching"; 72 return "Two-Point Conical Gradient Edge Touching";
73 } 73 }
74 74
75 GrGLFragmentProcessor* createGLInstance() const override;
76
77 // The radial gradient parameters can collapse to a linear (instead of quadr atic) equation. 75 // The radial gradient parameters can collapse to a linear (instead of quadr atic) equation.
78 SkScalar center() const { return fCenterX1; } 76 SkScalar center() const { return fCenterX1; }
79 SkScalar diffRadius() const { return fDiffRadius; } 77 SkScalar diffRadius() const { return fDiffRadius; }
80 SkScalar radius() const { return fRadius0; } 78 SkScalar radius() const { return fRadius0; }
81 79
82 private: 80 private:
81 GrGLFragmentProcessor* onCreateGLInstance() const override;
82
83 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 83 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
84 84
85 bool onIsEqual(const GrFragmentProcessor& sBase) const override { 85 bool onIsEqual(const GrFragmentProcessor& sBase) const override {
86 const Edge2PtConicalEffect& s = sBase.cast<Edge2PtConicalEffect>(); 86 const Edge2PtConicalEffect& s = sBase.cast<Edge2PtConicalEffect>();
87 return (INHERITED::onIsEqual(sBase) && 87 return (INHERITED::onIsEqual(sBase) &&
88 this->fCenterX1 == s.fCenterX1 && 88 this->fCenterX1 == s.fCenterX1 &&
89 this->fRadius0 == s.fRadius0 && 89 this->fRadius0 == s.fRadius0 &&
90 this->fDiffRadius == s.fDiffRadius); 90 this->fDiffRadius == s.fDiffRadius);
91 } 91 }
92 92
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(EmitArgs&) override; 147 virtual void emitCode(EmitArgs&) override;
148 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
149 148
150 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 149 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
151 150
152 protected: 151 protected:
152 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
153
153 UniformHandle fParamUni; 154 UniformHandle fParamUni;
154 155
155 const char* fVSVaryingName; 156 const char* fVSVaryingName;
156 const char* fFSVaryingName; 157 const char* fFSVaryingName;
157 158
158 // @{ 159 // @{
159 /// Values last uploaded as uniforms 160 /// Values last uploaded as uniforms
160 161
161 SkScalar fCachedRadius; 162 SkScalar fCachedRadius;
162 SkScalar fCachedDiffRadius; 163 SkScalar fCachedDiffRadius;
163 164
164 // @} 165 // @}
165 166
166 private: 167 private:
167 typedef GrGLGradientEffect INHERITED; 168 typedef GrGLGradientEffect INHERITED;
168 169
169 }; 170 };
170 171
171 void Edge2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 172 void Edge2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
172 GrProcessorKeyBuilder* b) const { 173 GrProcessorKeyBuilder* b) const {
173 GLEdge2PtConicalEffect::GenKey(*this, caps, b); 174 GLEdge2PtConicalEffect::GenKey(*this, caps, b);
174 } 175 }
175 176
176 GrGLFragmentProcessor* Edge2PtConicalEffect::createGLInstance() const { 177 GrGLFragmentProcessor* Edge2PtConicalEffect::onCreateGLInstance() const {
177 return SkNEW_ARGS(GLEdge2PtConicalEffect, (*this)); 178 return SkNEW_ARGS(GLEdge2PtConicalEffect, (*this));
178 } 179 }
179 180
180 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect); 181 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect);
181 182
182 /* 183 /*
183 * All Two point conical gradient test create functions may occasionally create edge case shaders 184 * All Two point conical gradient test create functions may occasionally create edge case shaders
184 */ 185 */
185 GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData* d) { 186 GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData* d) {
186 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 187 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 271
271 // if r(t) > 0, then t will be the x coordinate 272 // if r(t) > 0, then t will be the x coordinate
272 fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(), 273 fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
273 p2.c_str(), p0.c_str()); 274 p2.c_str(), p0.c_str());
274 fsBuilder->codeAppend("\t"); 275 fsBuilder->codeAppend("\t");
275 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 276 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
276 args.fSamplers); 277 args.fSamplers);
277 fsBuilder->codeAppend("\t}\n"); 278 fsBuilder->codeAppend("\t}\n");
278 } 279 }
279 280
280 void GLEdge2PtConicalEffect::setData(const GrGLProgramDataManager& pdman, 281 void GLEdge2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman,
281 const GrProcessor& processor) { 282 const GrProcessor& processor) {
282 INHERITED::setData(pdman, processor); 283 INHERITED::onSetData(pdman, processor);
283 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>(); 284 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>();
284 SkScalar radius0 = data.radius(); 285 SkScalar radius0 = data.radius();
285 SkScalar diffRadius = data.diffRadius(); 286 SkScalar diffRadius = data.diffRadius();
286 287
287 if (fCachedRadius != radius0 || 288 if (fCachedRadius != radius0 ||
288 fCachedDiffRadius != diffRadius) { 289 fCachedDiffRadius != diffRadius) {
289 290
290 float values[3] = { 291 float values[3] = {
291 SkScalarToFloat(radius0), 292 SkScalarToFloat(radius0),
292 SkScalarToFloat(SkScalarMul(radius0, radius0)), 293 SkScalarToFloat(SkScalarMul(radius0, radius0)),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return SkNEW_ARGS(FocalOutside2PtConicalEffect, (ctx, procDataManager, s hader, matrix, tm, 379 return SkNEW_ARGS(FocalOutside2PtConicalEffect, (ctx, procDataManager, s hader, matrix, tm,
379 focalX)); 380 focalX));
380 } 381 }
381 382
382 virtual ~FocalOutside2PtConicalEffect() { } 383 virtual ~FocalOutside2PtConicalEffect() { }
383 384
384 const char* name() const override { 385 const char* name() const override {
385 return "Two-Point Conical Gradient Focal Outside"; 386 return "Two-Point Conical Gradient Focal Outside";
386 } 387 }
387 388
388 GrGLFragmentProcessor* createGLInstance() const override;
389
390 bool isFlipped() const { return fIsFlipped; } 389 bool isFlipped() const { return fIsFlipped; }
391 SkScalar focal() const { return fFocalX; } 390 SkScalar focal() const { return fFocalX; }
392 391
393 private: 392 private:
393 GrGLFragmentProcessor* onCreateGLInstance() const override;
394
394 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 395 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
395 396
396 bool onIsEqual(const GrFragmentProcessor& sBase) const override { 397 bool onIsEqual(const GrFragmentProcessor& sBase) const override {
397 const FocalOutside2PtConicalEffect& s = sBase.cast<FocalOutside2PtConica lEffect>(); 398 const FocalOutside2PtConicalEffect& s = sBase.cast<FocalOutside2PtConica lEffect>();
398 return (INHERITED::onIsEqual(sBase) && 399 return (INHERITED::onIsEqual(sBase) &&
399 this->fFocalX == s.fFocalX && 400 this->fFocalX == s.fFocalX &&
400 this->fIsFlipped == s.fIsFlipped); 401 this->fIsFlipped == s.fIsFlipped);
401 } 402 }
402 403
403 FocalOutside2PtConicalEffect(GrContext* ctx, 404 FocalOutside2PtConicalEffect(GrContext* ctx,
(...skipping 15 matching lines...) Expand all
419 420
420 typedef GrGradientEffect INHERITED; 421 typedef GrGradientEffect INHERITED;
421 }; 422 };
422 423
423 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect { 424 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect {
424 public: 425 public:
425 GLFocalOutside2PtConicalEffect(const GrProcessor&); 426 GLFocalOutside2PtConicalEffect(const GrProcessor&);
426 virtual ~GLFocalOutside2PtConicalEffect() { } 427 virtual ~GLFocalOutside2PtConicalEffect() { }
427 428
428 virtual void emitCode(EmitArgs&) override; 429 virtual void emitCode(EmitArgs&) override;
429 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
430 430
431 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 431 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
432 432
433 protected: 433 protected:
434 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
435
434 UniformHandle fParamUni; 436 UniformHandle fParamUni;
435 437
436 const char* fVSVaryingName; 438 const char* fVSVaryingName;
437 const char* fFSVaryingName; 439 const char* fFSVaryingName;
438 440
439 bool fIsFlipped; 441 bool fIsFlipped;
440 442
441 // @{ 443 // @{
442 /// Values last uploaded as uniforms 444 /// Values last uploaded as uniforms
443 445
444 SkScalar fCachedFocal; 446 SkScalar fCachedFocal;
445 447
446 // @} 448 // @}
447 449
448 private: 450 private:
449 typedef GrGLGradientEffect INHERITED; 451 typedef GrGLGradientEffect INHERITED;
450 452
451 }; 453 };
452 454
453 void FocalOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 455 void FocalOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
454 GrProcessorKeyBuilder* b) c onst { 456 GrProcessorKeyBuilder* b) c onst {
455 GLFocalOutside2PtConicalEffect::GenKey(*this, caps, b); 457 GLFocalOutside2PtConicalEffect::GenKey(*this, caps, b);
456 } 458 }
457 459
458 GrGLFragmentProcessor* FocalOutside2PtConicalEffect::createGLInstance() const { 460 GrGLFragmentProcessor* FocalOutside2PtConicalEffect::onCreateGLInstance() const {
459 return SkNEW_ARGS(GLFocalOutside2PtConicalEffect, (*this)); 461 return SkNEW_ARGS(GLFocalOutside2PtConicalEffect, (*this));
460 } 462 }
461 463
462 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect); 464 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect);
463 465
464 /* 466 /*
465 * All Two point conical gradient test create functions may occasionally create edge case shaders 467 * All Two point conical gradient test create functions may occasionally create edge case shaders
466 */ 468 */
467 GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorTestDat a* d) { 469 GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorTestDat a* d) {
468 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 470 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 coords2D, p0.c_str()); 546 coords2D, p0.c_str());
545 } 547 }
546 548
547 fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str()); 549 fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
548 fsBuilder->codeAppend("\t\t"); 550 fsBuilder->codeAppend("\t\t");
549 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 551 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
550 args.fSamplers); 552 args.fSamplers);
551 fsBuilder->codeAppend("\t}\n"); 553 fsBuilder->codeAppend("\t}\n");
552 } 554 }
553 555
554 void GLFocalOutside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman , 556 void GLFocalOutside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdm an,
555 const GrProcessor& processor) { 557 const GrProcessor& processor) {
556 INHERITED::setData(pdman, processor); 558 INHERITED::onSetData(pdman, processor);
557 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>(); 559 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>();
558 SkASSERT(data.isFlipped() == fIsFlipped); 560 SkASSERT(data.isFlipped() == fIsFlipped);
559 SkScalar focal = data.focal(); 561 SkScalar focal = data.focal();
560 562
561 if (fCachedFocal != focal) { 563 if (fCachedFocal != focal) {
562 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal); 564 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal);
563 565
564 float values[2] = { 566 float values[2] = {
565 SkScalarToFloat(focal), 567 SkScalarToFloat(focal),
566 SkScalarToFloat(oneMinus2F), 568 SkScalarToFloat(oneMinus2F),
(...skipping 27 matching lines...) Expand all
594 return SkNEW_ARGS(FocalInside2PtConicalEffect, (ctx, procDataManager, sh ader, matrix, tm, 596 return SkNEW_ARGS(FocalInside2PtConicalEffect, (ctx, procDataManager, sh ader, matrix, tm,
595 focalX)); 597 focalX));
596 } 598 }
597 599
598 virtual ~FocalInside2PtConicalEffect() {} 600 virtual ~FocalInside2PtConicalEffect() {}
599 601
600 const char* name() const override { 602 const char* name() const override {
601 return "Two-Point Conical Gradient Focal Inside"; 603 return "Two-Point Conical Gradient Focal Inside";
602 } 604 }
603 605
604 GrGLFragmentProcessor* createGLInstance() const override;
605
606 SkScalar focal() const { return fFocalX; } 606 SkScalar focal() const { return fFocalX; }
607 607
608 typedef GLFocalInside2PtConicalEffect GLProcessor; 608 typedef GLFocalInside2PtConicalEffect GLProcessor;
609 609
610 private: 610 private:
611 GrGLFragmentProcessor* onCreateGLInstance() const override;
612
611 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 613 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
612 614
613 bool onIsEqual(const GrFragmentProcessor& sBase) const override { 615 bool onIsEqual(const GrFragmentProcessor& sBase) const override {
614 const FocalInside2PtConicalEffect& s = sBase.cast<FocalInside2PtConicalE ffect>(); 616 const FocalInside2PtConicalEffect& s = sBase.cast<FocalInside2PtConicalE ffect>();
615 return (INHERITED::onIsEqual(sBase) && 617 return (INHERITED::onIsEqual(sBase) &&
616 this->fFocalX == s.fFocalX); 618 this->fFocalX == s.fFocalX);
617 } 619 }
618 620
619 FocalInside2PtConicalEffect(GrContext* ctx, 621 FocalInside2PtConicalEffect(GrContext* ctx,
620 GrProcessorDataManager* procDataManager, 622 GrProcessorDataManager* procDataManager,
(...skipping 11 matching lines...) Expand all
632 634
633 typedef GrGradientEffect INHERITED; 635 typedef GrGradientEffect INHERITED;
634 }; 636 };
635 637
636 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect { 638 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect {
637 public: 639 public:
638 GLFocalInside2PtConicalEffect(const GrProcessor&); 640 GLFocalInside2PtConicalEffect(const GrProcessor&);
639 virtual ~GLFocalInside2PtConicalEffect() {} 641 virtual ~GLFocalInside2PtConicalEffect() {}
640 642
641 virtual void emitCode(EmitArgs&) override; 643 virtual void emitCode(EmitArgs&) override;
642 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
643 644
644 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 645 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
645 646
646 protected: 647 protected:
648 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
649
647 UniformHandle fFocalUni; 650 UniformHandle fFocalUni;
648 651
649 const char* fVSVaryingName; 652 const char* fVSVaryingName;
650 const char* fFSVaryingName; 653 const char* fFSVaryingName;
651 654
652 // @{ 655 // @{
653 /// Values last uploaded as uniforms 656 /// Values last uploaded as uniforms
654 657
655 SkScalar fCachedFocal; 658 SkScalar fCachedFocal;
656 659
657 // @} 660 // @}
658 661
659 private: 662 private:
660 typedef GrGLGradientEffect INHERITED; 663 typedef GrGLGradientEffect INHERITED;
661 664
662 }; 665 };
663 666
664 void FocalInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 667 void FocalInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
665 GrProcessorKeyBuilder* b) const { 668 GrProcessorKeyBuilder* b) const {
666 GLFocalInside2PtConicalEffect::GenKey(*this, caps, b); 669 GLFocalInside2PtConicalEffect::GenKey(*this, caps, b);
667 } 670 }
668 671
669 GrGLFragmentProcessor* FocalInside2PtConicalEffect::createGLInstance() const { 672 GrGLFragmentProcessor* FocalInside2PtConicalEffect::onCreateGLInstance() const {
670 return SkNEW_ARGS(GLFocalInside2PtConicalEffect, (*this)); 673 return SkNEW_ARGS(GLFocalInside2PtConicalEffect, (*this));
671 } 674 }
672 675
673 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect); 676 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect);
674 677
675 /* 678 /*
676 * All Two point conical gradient test create functions may occasionally create edge case shaders 679 * All Two point conical gradient test create functions may occasionally create edge case shaders
677 */ 680 */
678 GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTestData * d) { 681 GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTestData * d) {
679 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 682 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 const char* coords2D = coords2DString.c_str(); 735 const char* coords2D = coords2DString.c_str();
733 736
734 // t = p.x * focalX + length(p) 737 // t = p.x * focalX + length(p)
735 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(), 738 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(),
736 coords2D, focal.c_str(), coords2D); 739 coords2D, focal.c_str(), coords2D);
737 740
738 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 741 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
739 args.fSamplers); 742 args.fSamplers);
740 } 743 }
741 744
742 void GLFocalInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman, 745 void GLFocalInside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdma n,
743 const GrProcessor& processor) { 746 const GrProcessor& processor) {
744 INHERITED::setData(pdman, processor); 747 INHERITED::onSetData(pdman, processor);
745 const FocalInside2PtConicalEffect& data = processor.cast<FocalInside2PtConic alEffect>(); 748 const FocalInside2PtConicalEffect& data = processor.cast<FocalInside2PtConic alEffect>();
746 SkScalar focal = data.focal(); 749 SkScalar focal = data.focal();
747 750
748 if (fCachedFocal != focal) { 751 if (fCachedFocal != focal) {
749 pdman.set1f(fFocalUni, SkScalarToFloat(focal)); 752 pdman.set1f(fFocalUni, SkScalarToFloat(focal));
750 fCachedFocal = focal; 753 fCachedFocal = focal;
751 } 754 }
752 } 755 }
753 756
754 void GLFocalInside2PtConicalEffect::GenKey(const GrProcessor& processor, 757 void GLFocalInside2PtConicalEffect::GenKey(const GrProcessor& processor,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 SkShader::TileMode tm, 833 SkShader::TileMode tm,
831 const CircleConicalInfo& info) { 834 const CircleConicalInfo& info) {
832 return SkNEW_ARGS(CircleInside2PtConicalEffect, (ctx, procDataManager, s hader, matrix, tm, 835 return SkNEW_ARGS(CircleInside2PtConicalEffect, (ctx, procDataManager, s hader, matrix, tm,
833 info)); 836 info));
834 } 837 }
835 838
836 virtual ~CircleInside2PtConicalEffect() {} 839 virtual ~CircleInside2PtConicalEffect() {}
837 840
838 const char* name() const override { return "Two-Point Conical Gradient Insid e"; } 841 const char* name() const override { return "Two-Point Conical Gradient Insid e"; }
839 842
840 GrGLFragmentProcessor* createGLInstance() const override;
841
842 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } 843 SkScalar centerX() const { return fInfo.fCenterEnd.fX; }
843 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } 844 SkScalar centerY() const { return fInfo.fCenterEnd.fY; }
844 SkScalar A() const { return fInfo.fA; } 845 SkScalar A() const { return fInfo.fA; }
845 SkScalar B() const { return fInfo.fB; } 846 SkScalar B() const { return fInfo.fB; }
846 SkScalar C() const { return fInfo.fC; } 847 SkScalar C() const { return fInfo.fC; }
847 848
848 private: 849 private:
850 GrGLFragmentProcessor* onCreateGLInstance() const override;
851
849 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, 852 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
850 GrProcessorKeyBuilder* b) const override; 853 GrProcessorKeyBuilder* b) const override;
851 854
852 bool onIsEqual(const GrFragmentProcessor& sBase) const override { 855 bool onIsEqual(const GrFragmentProcessor& sBase) const override {
853 const CircleInside2PtConicalEffect& s = sBase.cast<CircleInside2PtConica lEffect>(); 856 const CircleInside2PtConicalEffect& s = sBase.cast<CircleInside2PtConica lEffect>();
854 return (INHERITED::onIsEqual(sBase) && 857 return (INHERITED::onIsEqual(sBase) &&
855 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && 858 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd &&
856 this->fInfo.fA == s.fInfo.fA && 859 this->fInfo.fA == s.fInfo.fA &&
857 this->fInfo.fB == s.fInfo.fB && 860 this->fInfo.fB == s.fInfo.fB &&
858 this->fInfo.fC == s.fInfo.fC); 861 this->fInfo.fC == s.fInfo.fC);
(...skipping 15 matching lines...) Expand all
874 877
875 typedef GrGradientEffect INHERITED; 878 typedef GrGradientEffect INHERITED;
876 }; 879 };
877 880
878 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect { 881 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect {
879 public: 882 public:
880 GLCircleInside2PtConicalEffect(const GrProcessor&); 883 GLCircleInside2PtConicalEffect(const GrProcessor&);
881 virtual ~GLCircleInside2PtConicalEffect() {} 884 virtual ~GLCircleInside2PtConicalEffect() {}
882 885
883 virtual void emitCode(EmitArgs&) override; 886 virtual void emitCode(EmitArgs&) override;
884 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
885 887
886 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 888 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
887 889
888 protected: 890 protected:
891 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
892
889 UniformHandle fCenterUni; 893 UniformHandle fCenterUni;
890 UniformHandle fParamUni; 894 UniformHandle fParamUni;
891 895
892 const char* fVSVaryingName; 896 const char* fVSVaryingName;
893 const char* fFSVaryingName; 897 const char* fFSVaryingName;
894 898
895 // @{ 899 // @{
896 /// Values last uploaded as uniforms 900 /// Values last uploaded as uniforms
897 901
898 SkScalar fCachedCenterX; 902 SkScalar fCachedCenterX;
899 SkScalar fCachedCenterY; 903 SkScalar fCachedCenterY;
900 SkScalar fCachedA; 904 SkScalar fCachedA;
901 SkScalar fCachedB; 905 SkScalar fCachedB;
902 SkScalar fCachedC; 906 SkScalar fCachedC;
903 907
904 // @} 908 // @}
905 909
906 private: 910 private:
907 typedef GrGLGradientEffect INHERITED; 911 typedef GrGLGradientEffect INHERITED;
908 912
909 }; 913 };
910 914
911 void CircleInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 915 void CircleInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
912 GrProcessorKeyBuilder* b) c onst { 916 GrProcessorKeyBuilder* b) c onst {
913 GLCircleInside2PtConicalEffect::GenKey(*this, caps, b); 917 GLCircleInside2PtConicalEffect::GenKey(*this, caps, b);
914 } 918 }
915 919
916 GrGLFragmentProcessor* CircleInside2PtConicalEffect::createGLInstance() const { 920 GrGLFragmentProcessor* CircleInside2PtConicalEffect::onCreateGLInstance() const {
917 return SkNEW_ARGS(GLCircleInside2PtConicalEffect, (*this)); 921 return SkNEW_ARGS(GLCircleInside2PtConicalEffect, (*this));
918 } 922 }
919 923
920 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect); 924 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect);
921 925
922 /* 926 /*
923 * All Two point conical gradient test create functions may occasionally create edge case shaders 927 * All Two point conical gradient test create functions may occasionally create edge case shaders
924 */ 928 */
925 GrFragmentProcessor* 929 GrFragmentProcessor*
926 CircleInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { 930 CircleInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D ); 1002 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D );
999 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(), 1003 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(),
1000 params.c_str()); 1004 params.c_str());
1001 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n", 1005 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n",
1002 tName.c_str(), params.c_str(), params.c_str()); 1006 tName.c_str(), params.c_str(), params.c_str());
1003 1007
1004 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 1008 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
1005 args.fSamplers); 1009 args.fSamplers);
1006 } 1010 }
1007 1011
1008 void GLCircleInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman , 1012 void GLCircleInside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdm an,
1009 const GrProcessor& processor) { 1013 const GrProcessor& processor) {
1010 INHERITED::setData(pdman, processor); 1014 INHERITED::onSetData(pdman, processor);
1011 const CircleInside2PtConicalEffect& data = processor.cast<CircleInside2PtCon icalEffect>(); 1015 const CircleInside2PtConicalEffect& data = processor.cast<CircleInside2PtCon icalEffect>();
1012 SkScalar centerX = data.centerX(); 1016 SkScalar centerX = data.centerX();
1013 SkScalar centerY = data.centerY(); 1017 SkScalar centerY = data.centerY();
1014 SkScalar A = data.A(); 1018 SkScalar A = data.A();
1015 SkScalar B = data.B(); 1019 SkScalar B = data.B();
1016 SkScalar C = data.C(); 1020 SkScalar C = data.C();
1017 1021
1018 if (fCachedCenterX != centerX || fCachedCenterY != centerY || 1022 if (fCachedCenterX != centerX || fCachedCenterY != centerY ||
1019 fCachedA != A || fCachedB != B || fCachedC != C) { 1023 fCachedA != A || fCachedB != B || fCachedC != C) {
1020 1024
(...skipping 25 matching lines...) Expand all
1046 SkShader::TileMode tm, 1050 SkShader::TileMode tm,
1047 const CircleConicalInfo& info) { 1051 const CircleConicalInfo& info) {
1048 return SkNEW_ARGS(CircleOutside2PtConicalEffect, (ctx, procDataManager, shader, matrix, 1052 return SkNEW_ARGS(CircleOutside2PtConicalEffect, (ctx, procDataManager, shader, matrix,
1049 tm, info)); 1053 tm, info));
1050 } 1054 }
1051 1055
1052 virtual ~CircleOutside2PtConicalEffect() {} 1056 virtual ~CircleOutside2PtConicalEffect() {}
1053 1057
1054 const char* name() const override { return "Two-Point Conical Gradient Outsi de"; } 1058 const char* name() const override { return "Two-Point Conical Gradient Outsi de"; }
1055 1059
1056 GrGLFragmentProcessor* createGLInstance() const override;
1057
1058 SkScalar centerX() const { return fInfo.fCenterEnd.fX; } 1060 SkScalar centerX() const { return fInfo.fCenterEnd.fX; }
1059 SkScalar centerY() const { return fInfo.fCenterEnd.fY; } 1061 SkScalar centerY() const { return fInfo.fCenterEnd.fY; }
1060 SkScalar A() const { return fInfo.fA; } 1062 SkScalar A() const { return fInfo.fA; }
1061 SkScalar B() const { return fInfo.fB; } 1063 SkScalar B() const { return fInfo.fB; }
1062 SkScalar C() const { return fInfo.fC; } 1064 SkScalar C() const { return fInfo.fC; }
1063 SkScalar tLimit() const { return fTLimit; } 1065 SkScalar tLimit() const { return fTLimit; }
1064 bool isFlipped() const { return fIsFlipped; } 1066 bool isFlipped() const { return fIsFlipped; }
1065 1067
1066 private: 1068 private:
1069 GrGLFragmentProcessor* onCreateGLInstance() const override;
1070
1067 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride; 1071 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov erride;
1068 1072
1069 bool onIsEqual(const GrFragmentProcessor& sBase) const override { 1073 bool onIsEqual(const GrFragmentProcessor& sBase) const override {
1070 const CircleOutside2PtConicalEffect& s = sBase.cast<CircleOutside2PtConi calEffect>(); 1074 const CircleOutside2PtConicalEffect& s = sBase.cast<CircleOutside2PtConi calEffect>();
1071 return (INHERITED::onIsEqual(sBase) && 1075 return (INHERITED::onIsEqual(sBase) &&
1072 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd && 1076 this->fInfo.fCenterEnd == s.fInfo.fCenterEnd &&
1073 this->fInfo.fA == s.fInfo.fA && 1077 this->fInfo.fA == s.fInfo.fA &&
1074 this->fInfo.fB == s.fInfo.fB && 1078 this->fInfo.fB == s.fInfo.fB &&
1075 this->fInfo.fC == s.fInfo.fC && 1079 this->fInfo.fC == s.fInfo.fC &&
1076 this->fTLimit == s.fTLimit && 1080 this->fTLimit == s.fTLimit &&
(...skipping 25 matching lines...) Expand all
1102 1106
1103 typedef GrGradientEffect INHERITED; 1107 typedef GrGradientEffect INHERITED;
1104 }; 1108 };
1105 1109
1106 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect { 1110 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect {
1107 public: 1111 public:
1108 GLCircleOutside2PtConicalEffect(const GrProcessor&); 1112 GLCircleOutside2PtConicalEffect(const GrProcessor&);
1109 virtual ~GLCircleOutside2PtConicalEffect() {} 1113 virtual ~GLCircleOutside2PtConicalEffect() {}
1110 1114
1111 virtual void emitCode(EmitArgs&) override; 1115 virtual void emitCode(EmitArgs&) override;
1112 void setData(const GrGLProgramDataManager&, const GrProcessor&) override;
1113 1116
1114 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 1117 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
1115 1118
1116 protected: 1119 protected:
1120 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
1121
1117 UniformHandle fCenterUni; 1122 UniformHandle fCenterUni;
1118 UniformHandle fParamUni; 1123 UniformHandle fParamUni;
1119 1124
1120 const char* fVSVaryingName; 1125 const char* fVSVaryingName;
1121 const char* fFSVaryingName; 1126 const char* fFSVaryingName;
1122 1127
1123 bool fIsFlipped; 1128 bool fIsFlipped;
1124 1129
1125 // @{ 1130 // @{
1126 /// Values last uploaded as uniforms 1131 /// Values last uploaded as uniforms
(...skipping 10 matching lines...) Expand all
1137 private: 1142 private:
1138 typedef GrGLGradientEffect INHERITED; 1143 typedef GrGLGradientEffect INHERITED;
1139 1144
1140 }; 1145 };
1141 1146
1142 void CircleOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 1147 void CircleOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
1143 GrProcessorKeyBuilder* b) const { 1148 GrProcessorKeyBuilder* b) const {
1144 GLCircleOutside2PtConicalEffect::GenKey(*this, caps, b); 1149 GLCircleOutside2PtConicalEffect::GenKey(*this, caps, b);
1145 } 1150 }
1146 1151
1147 GrGLFragmentProcessor* CircleOutside2PtConicalEffect::createGLInstance() const { 1152 GrGLFragmentProcessor* CircleOutside2PtConicalEffect::onCreateGLInstance() const {
1148 return SkNEW_ARGS(GLCircleOutside2PtConicalEffect, (*this)); 1153 return SkNEW_ARGS(GLCircleOutside2PtConicalEffect, (*this));
1149 } 1154 }
1150 1155
1151 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect); 1156 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect);
1152 1157
1153 /* 1158 /*
1154 * All Two point conical gradient test create functions may occasionally create edge case shaders 1159 * All Two point conical gradient test create functions may occasionally create edge case shaders
1155 */ 1160 */
1156 GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessorTestDa ta* d) { 1161 GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessorTestDa ta* d) {
1157 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 1162 SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ; 1254 fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ;
1250 } 1255 }
1251 1256
1252 fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str()); 1257 fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str());
1253 fsBuilder->codeAppend("\t\t"); 1258 fsBuilder->codeAppend("\t\t");
1254 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 1259 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
1255 args.fSamplers); 1260 args.fSamplers);
1256 fsBuilder->codeAppend("\t}\n"); 1261 fsBuilder->codeAppend("\t}\n");
1257 } 1262 }
1258 1263
1259 void GLCircleOutside2PtConicalEffect::setData(const GrGLProgramDataManager& pdma n, 1264 void GLCircleOutside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pd man,
1260 const GrProcessor& processor) { 1265 const GrProcessor& processor) {
1261 INHERITED::setData(pdman, processor); 1266 INHERITED::onSetData(pdman, processor);
1262 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>(); 1267 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>();
1263 SkASSERT(data.isFlipped() == fIsFlipped); 1268 SkASSERT(data.isFlipped() == fIsFlipped);
1264 SkScalar centerX = data.centerX(); 1269 SkScalar centerX = data.centerX();
1265 SkScalar centerY = data.centerY(); 1270 SkScalar centerY = data.centerY();
1266 SkScalar A = data.A(); 1271 SkScalar A = data.A();
1267 SkScalar B = data.B(); 1272 SkScalar B = data.B();
1268 SkScalar C = data.C(); 1273 SkScalar C = data.C();
1269 SkScalar tLimit = data.tLimit(); 1274 SkScalar tLimit = data.tLimit();
1270 1275
1271 if (fCachedCenterX != centerX || fCachedCenterY != centerY || 1276 if (fCachedCenterX != centerX || fCachedCenterY != centerY ||
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 } else if (type == kEdge_ConicalType) { 1339 } else if (type == kEdge_ConicalType) {
1335 set_matrix_edge_conical(shader, &matrix); 1340 set_matrix_edge_conical(shader, &matrix);
1336 return Edge2PtConicalEffect::Create(ctx, procDataManager, shader, matrix , tm); 1341 return Edge2PtConicalEffect::Create(ctx, procDataManager, shader, matrix , tm);
1337 } else { 1342 } else {
1338 return CircleOutside2PtConicalEffect::Create(ctx, procDataManager, shade r, matrix, tm, 1343 return CircleOutside2PtConicalEffect::Create(ctx, procDataManager, shade r, matrix, tm,
1339 info); 1344 info);
1340 } 1345 }
1341 } 1346 }
1342 1347
1343 #endif 1348 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkSweepGradient.cpp ('k') | src/gpu/GrProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698