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

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

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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/SkGradientShaderPriv.h ('k') | src/gpu/GrDefaultGeoProcFactory.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
11 #include "SkTwoPointConicalGradient.h" 11 #include "SkTwoPointConicalGradient.h"
12 12
13 #if SK_SUPPORT_GPU 13 #if SK_SUPPORT_GPU
14 #include "GrPaint.h" 14 #include "GrPaint.h"
15 #include "gl/builders/GrGLProgramBuilder.h" 15 #include "gl/builders/GrGLProgramBuilder.h"
16 #include "glsl/GrGLSLProgramDataManager.h"
16 // For brevity 17 // For brevity
17 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 18 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
18 19
19 static const SkScalar kErrorTol = 0.00001f; 20 static const SkScalar kErrorTol = 0.00001f;
20 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; 21 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol;
21 22
22 /** 23 /**
23 * We have three general cases for 2pt conical gradients. First we always assume that 24 * We have three general cases for 2pt conical gradients. First we always assume that
24 * the start radius <= end radius. Our first case (kInside_) is when the start c ircle 25 * the start radius <= end radius. Our first case (kInside_) is when the start c ircle
25 * is completely enclosed by the end circle. The second case (kOutside_) is the case 26 * is completely enclosed by the end circle. The second case (kOutside_) is the case
26 * when the start circle is either completely outside the end circle or the circ les 27 * when the start circle is either completely outside the end circle or the circ les
27 * overlap. The final case (kEdge_) is when the start circle is inside the end o ne, 28 * overlap. The final case (kEdge_) is when the start circle is inside the end o ne,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 class GLEdge2PtConicalEffect : public GrGLGradientEffect { 141 class GLEdge2PtConicalEffect : public GrGLGradientEffect {
141 public: 142 public:
142 GLEdge2PtConicalEffect(const GrProcessor&); 143 GLEdge2PtConicalEffect(const GrProcessor&);
143 virtual ~GLEdge2PtConicalEffect() { } 144 virtual ~GLEdge2PtConicalEffect() { }
144 145
145 virtual void emitCode(EmitArgs&) override; 146 virtual void emitCode(EmitArgs&) override;
146 147
147 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 148 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
148 149
149 protected: 150 protected:
150 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 151 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
151 152
152 UniformHandle fParamUni; 153 UniformHandle fParamUni;
153 154
154 const char* fVSVaryingName; 155 const char* fVSVaryingName;
155 const char* fFSVaryingName; 156 const char* fFSVaryingName;
156 157
157 // @{ 158 // @{
158 /// Values last uploaded as uniforms 159 /// Values last uploaded as uniforms
159 160
160 SkScalar fCachedRadius; 161 SkScalar fCachedRadius;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 267
267 // if r(t) > 0, then t will be the x coordinate 268 // if r(t) > 0, then t will be the x coordinate
268 fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(), 269 fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
269 p2.c_str(), p0.c_str()); 270 p2.c_str(), p0.c_str());
270 fsBuilder->codeAppend("\t"); 271 fsBuilder->codeAppend("\t");
271 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 272 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
272 args.fSamplers); 273 args.fSamplers);
273 fsBuilder->codeAppend("\t}\n"); 274 fsBuilder->codeAppend("\t}\n");
274 } 275 }
275 276
276 void GLEdge2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman, 277 void GLEdge2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman,
277 const GrProcessor& processor) { 278 const GrProcessor& processor) {
278 INHERITED::onSetData(pdman, processor); 279 INHERITED::onSetData(pdman, processor);
279 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>(); 280 const Edge2PtConicalEffect& data = processor.cast<Edge2PtConicalEffect>();
280 SkScalar radius0 = data.radius(); 281 SkScalar radius0 = data.radius();
281 SkScalar diffRadius = data.diffRadius(); 282 SkScalar diffRadius = data.diffRadius();
282 283
283 if (fCachedRadius != radius0 || 284 if (fCachedRadius != radius0 ||
284 fCachedDiffRadius != diffRadius) { 285 fCachedDiffRadius != diffRadius) {
285 286
286 float values[3] = { 287 float values[3] = {
287 SkScalarToFloat(radius0), 288 SkScalarToFloat(radius0),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect { 417 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect {
417 public: 418 public:
418 GLFocalOutside2PtConicalEffect(const GrProcessor&); 419 GLFocalOutside2PtConicalEffect(const GrProcessor&);
419 virtual ~GLFocalOutside2PtConicalEffect() { } 420 virtual ~GLFocalOutside2PtConicalEffect() { }
420 421
421 virtual void emitCode(EmitArgs&) override; 422 virtual void emitCode(EmitArgs&) override;
422 423
423 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 424 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
424 425
425 protected: 426 protected:
426 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 427 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
427 428
428 UniformHandle fParamUni; 429 UniformHandle fParamUni;
429 430
430 const char* fVSVaryingName; 431 const char* fVSVaryingName;
431 const char* fFSVaryingName; 432 const char* fFSVaryingName;
432 433
433 bool fIsFlipped; 434 bool fIsFlipped;
434 435
435 // @{ 436 // @{
436 /// Values last uploaded as uniforms 437 /// Values last uploaded as uniforms
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 coords2D, p0.c_str()); 534 coords2D, p0.c_str());
534 } 535 }
535 536
536 fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str()); 537 fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
537 fsBuilder->codeAppend("\t\t"); 538 fsBuilder->codeAppend("\t\t");
538 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 539 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
539 args.fSamplers); 540 args.fSamplers);
540 fsBuilder->codeAppend("\t}\n"); 541 fsBuilder->codeAppend("\t}\n");
541 } 542 }
542 543
543 void GLFocalOutside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdm an, 544 void GLFocalOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& p dman,
544 const GrProcessor& processor) { 545 const GrProcessor& processor) {
545 INHERITED::onSetData(pdman, processor); 546 INHERITED::onSetData(pdman, processor);
546 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>(); 547 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon icalEffect>();
547 SkASSERT(data.isFlipped() == fIsFlipped); 548 SkASSERT(data.isFlipped() == fIsFlipped);
548 SkScalar focal = data.focal(); 549 SkScalar focal = data.focal();
549 550
550 if (fCachedFocal != focal) { 551 if (fCachedFocal != focal) {
551 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal); 552 SkScalar oneMinus2F = 1.f - SkScalarMul(focal, focal);
552 553
553 float values[2] = { 554 float values[2] = {
554 SkScalarToFloat(focal), 555 SkScalarToFloat(focal),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect { 623 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect {
623 public: 624 public:
624 GLFocalInside2PtConicalEffect(const GrProcessor&); 625 GLFocalInside2PtConicalEffect(const GrProcessor&);
625 virtual ~GLFocalInside2PtConicalEffect() {} 626 virtual ~GLFocalInside2PtConicalEffect() {}
626 627
627 virtual void emitCode(EmitArgs&) override; 628 virtual void emitCode(EmitArgs&) override;
628 629
629 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 630 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
630 631
631 protected: 632 protected:
632 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 633 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
633 634
634 UniformHandle fFocalUni; 635 UniformHandle fFocalUni;
635 636
636 const char* fVSVaryingName; 637 const char* fVSVaryingName;
637 const char* fFSVaryingName; 638 const char* fFSVaryingName;
638 639
639 // @{ 640 // @{
640 /// Values last uploaded as uniforms 641 /// Values last uploaded as uniforms
641 642
642 SkScalar fCachedFocal; 643 SkScalar fCachedFocal;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 const char* coords2D = coords2DString.c_str(); 717 const char* coords2D = coords2DString.c_str();
717 718
718 // t = p.x * focalX + length(p) 719 // t = p.x * focalX + length(p)
719 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(), 720 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st r(),
720 coords2D, focal.c_str(), coords2D); 721 coords2D, focal.c_str(), coords2D);
721 722
722 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 723 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
723 args.fSamplers); 724 args.fSamplers);
724 } 725 }
725 726
726 void GLFocalInside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdma n, 727 void GLFocalInside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pd man,
727 const GrProcessor& processor) { 728 const GrProcessor& processor) {
728 INHERITED::onSetData(pdman, processor); 729 INHERITED::onSetData(pdman, processor);
729 const FocalInside2PtConicalEffect& data = processor.cast<FocalInside2PtConic alEffect>(); 730 const FocalInside2PtConicalEffect& data = processor.cast<FocalInside2PtConic alEffect>();
730 SkScalar focal = data.focal(); 731 SkScalar focal = data.focal();
731 732
732 if (fCachedFocal != focal) { 733 if (fCachedFocal != focal) {
733 pdman.set1f(fFocalUni, SkScalarToFloat(focal)); 734 pdman.set1f(fFocalUni, SkScalarToFloat(focal));
734 fCachedFocal = focal; 735 fCachedFocal = focal;
735 } 736 }
736 } 737 }
737 738
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect { 860 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect {
860 public: 861 public:
861 GLCircleInside2PtConicalEffect(const GrProcessor&); 862 GLCircleInside2PtConicalEffect(const GrProcessor&);
862 virtual ~GLCircleInside2PtConicalEffect() {} 863 virtual ~GLCircleInside2PtConicalEffect() {}
863 864
864 virtual void emitCode(EmitArgs&) override; 865 virtual void emitCode(EmitArgs&) override;
865 866
866 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 867 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
867 868
868 protected: 869 protected:
869 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 870 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
870 871
871 UniformHandle fCenterUni; 872 UniformHandle fCenterUni;
872 UniformHandle fParamUni; 873 UniformHandle fParamUni;
873 874
874 const char* fVSVaryingName; 875 const char* fVSVaryingName;
875 const char* fFSVaryingName; 876 const char* fFSVaryingName;
876 877
877 // @{ 878 // @{
878 /// Values last uploaded as uniforms 879 /// Values last uploaded as uniforms
879 880
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D ); 977 fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D );
977 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(), 978 fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, cente r.c_str(),
978 params.c_str()); 979 params.c_str());
979 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n", 980 fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\ n",
980 tName.c_str(), params.c_str(), params.c_str()); 981 tName.c_str(), params.c_str(), params.c_str());
981 982
982 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 983 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
983 args.fSamplers); 984 args.fSamplers);
984 } 985 }
985 986
986 void GLCircleInside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdm an, 987 void GLCircleInside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& p dman,
987 const GrProcessor& processor) { 988 const GrProcessor& processor) {
988 INHERITED::onSetData(pdman, processor); 989 INHERITED::onSetData(pdman, processor);
989 const CircleInside2PtConicalEffect& data = processor.cast<CircleInside2PtCon icalEffect>(); 990 const CircleInside2PtConicalEffect& data = processor.cast<CircleInside2PtCon icalEffect>();
990 SkScalar centerX = data.centerX(); 991 SkScalar centerX = data.centerX();
991 SkScalar centerY = data.centerY(); 992 SkScalar centerY = data.centerY();
992 SkScalar A = data.A(); 993 SkScalar A = data.A();
993 SkScalar B = data.B(); 994 SkScalar B = data.B();
994 SkScalar C = data.C(); 995 SkScalar C = data.C();
995 996
996 if (fCachedCenterX != centerX || fCachedCenterY != centerY || 997 if (fCachedCenterX != centerX || fCachedCenterY != centerY ||
997 fCachedA != A || fCachedB != B || fCachedC != C) { 998 fCachedA != A || fCachedB != B || fCachedC != C) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect { 1082 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect {
1082 public: 1083 public:
1083 GLCircleOutside2PtConicalEffect(const GrProcessor&); 1084 GLCircleOutside2PtConicalEffect(const GrProcessor&);
1084 virtual ~GLCircleOutside2PtConicalEffect() {} 1085 virtual ~GLCircleOutside2PtConicalEffect() {}
1085 1086
1086 virtual void emitCode(EmitArgs&) override; 1087 virtual void emitCode(EmitArgs&) override;
1087 1088
1088 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b); 1089 static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKe yBuilder* b);
1089 1090
1090 protected: 1091 protected:
1091 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 1092 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
1092 1093
1093 UniformHandle fCenterUni; 1094 UniformHandle fCenterUni;
1094 UniformHandle fParamUni; 1095 UniformHandle fParamUni;
1095 1096
1096 const char* fVSVaryingName; 1097 const char* fVSVaryingName;
1097 const char* fFSVaryingName; 1098 const char* fFSVaryingName;
1098 1099
1099 bool fIsFlipped; 1100 bool fIsFlipped;
1100 1101
1101 // @{ 1102 // @{
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ; 1223 fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str()) ;
1223 } 1224 }
1224 1225
1225 fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str()); 1226 fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str( ), params.c_str());
1226 fsBuilder->codeAppend("\t\t"); 1227 fsBuilder->codeAppend("\t\t");
1227 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor, 1228 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI nputColor,
1228 args.fSamplers); 1229 args.fSamplers);
1229 fsBuilder->codeAppend("\t}\n"); 1230 fsBuilder->codeAppend("\t}\n");
1230 } 1231 }
1231 1232
1232 void GLCircleOutside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pd man, 1233 void GLCircleOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman,
1233 const GrProcessor& processor) { 1234 const GrProcessor& processor) {
1234 INHERITED::onSetData(pdman, processor); 1235 INHERITED::onSetData(pdman, processor);
1235 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>(); 1236 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC onicalEffect>();
1236 SkASSERT(data.isFlipped() == fIsFlipped); 1237 SkASSERT(data.isFlipped() == fIsFlipped);
1237 SkScalar centerX = data.centerX(); 1238 SkScalar centerX = data.centerX();
1238 SkScalar centerY = data.centerY(); 1239 SkScalar centerY = data.centerY();
1239 SkScalar A = data.A(); 1240 SkScalar A = data.A();
1240 SkScalar B = data.B(); 1241 SkScalar B = data.B();
1241 SkScalar C = data.C(); 1242 SkScalar C = data.C();
1242 SkScalar tLimit = data.tLimit(); 1243 SkScalar tLimit = data.tLimit();
1243 1244
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o); 1303 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o);
1303 } else if (type == kEdge_ConicalType) { 1304 } else if (type == kEdge_ConicalType) {
1304 set_matrix_edge_conical(shader, &matrix); 1305 set_matrix_edge_conical(shader, &matrix);
1305 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); 1306 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm);
1306 } else { 1307 } else {
1307 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo); 1308 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo);
1308 } 1309 }
1309 } 1310 }
1310 1311
1311 #endif 1312 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShaderPriv.h ('k') | src/gpu/GrDefaultGeoProcFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698