| OLD | NEW |
| 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 "glsl/GrGLSLFragmentShaderBuilder.h" |
| 16 #include "glsl/GrGLSLProgramBuilder.h" |
| 16 #include "glsl/GrGLSLProgramDataManager.h" | 17 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 // For brevity | 18 // For brevity |
| 18 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 19 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
| 19 | 20 |
| 20 static const SkScalar kErrorTol = 0.00001f; | 21 static const SkScalar kErrorTol = 0.00001f; |
| 21 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; | 22 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * We have three general cases for 2pt conical gradients. First we always assume
that | 25 * We have three general cases for 2pt conical gradients. First we always assume
that |
| 25 * the start radius <= end radius. Our first case (kInside_) is when the start c
ircle | 26 * the start radius <= end radius. Our first case (kInside_) is when the start c
ircle |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::onCreateGLInstance() const { | 177 GrGLFragmentProcessor* Edge2PtConicalEffect::onCreateGLInstance() const { |
| 177 return new GLEdge2PtConicalEffect(*this); | 178 return new GLEdge2PtConicalEffect(*this); |
| 178 } | 179 } |
| 179 | 180 |
| 180 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect); | 181 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect); |
| 181 | 182 |
| 182 /* | 183 /* |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 217 |
| 217 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) | 218 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) |
| 218 : fVSVaryingName(nullptr) | 219 : fVSVaryingName(nullptr) |
| 219 , fFSVaryingName(nullptr) | 220 , fFSVaryingName(nullptr) |
| 220 , fCachedRadius(-SK_ScalarMax) | 221 , fCachedRadius(-SK_ScalarMax) |
| 221 , fCachedDiffRadius(-SK_ScalarMax) {} | 222 , fCachedDiffRadius(-SK_ScalarMax) {} |
| 222 | 223 |
| 223 void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) { | 224 void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) { |
| 224 const Edge2PtConicalEffect& ge = args.fFp.cast<Edge2PtConicalEffect>(); | 225 const Edge2PtConicalEffect& ge = args.fFp.cast<Edge2PtConicalEffect>(); |
| 225 this->emitUniforms(args.fBuilder, ge); | 226 this->emitUniforms(args.fBuilder, ge); |
| 226 fParamUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vis
ibility, | 227 fParamUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_V
isibility, |
| 227 kFloat_GrSLType, kDefault_GrSLPrecision
, | 228 kFloat_GrSLType, kDefault_GrSLPrecision
, |
| 228 "Conical2FSParams", 3); | 229 "Conical2FSParams", 3); |
| 229 | 230 |
| 230 SkString cName("c"); | 231 SkString cName("c"); |
| 231 SkString tName("t"); | 232 SkString tName("t"); |
| 232 SkString p0; // start radius | 233 SkString p0; // start radius |
| 233 SkString p1; // start radius squared | 234 SkString p1; // start radius squared |
| 234 SkString p2; // difference in radii (r1 - r0) | 235 SkString p2; // difference in radii (r1 - r0) |
| 235 | 236 |
| 236 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 237 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); |
| 237 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 238 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); |
| 238 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); | 239 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); |
| 239 | 240 |
| 240 // We interpolate the linear component in coords[1]. | 241 // We interpolate the linear component in coords[1]. |
| 241 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType()); | 242 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType()); |
| 242 const char* coords2D; | 243 const char* coords2D; |
| 243 SkString bVar; | 244 SkString bVar; |
| 244 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 245 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 245 if (kVec3f_GrSLType == args.fCoords[0].getType()) { | 246 if (kVec3f_GrSLType == args.fCoords[0].getType()) { |
| 246 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x /
%s.z);\n", | 247 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x /
%s.z);\n", |
| 247 args.fCoords[0].c_str(), args.fCoords[0].c_str(), | 248 args.fCoords[0].c_str(), args.fCoords[0].c_str(), |
| 248 args.fCoords[1].c_str(), args.fCoords[1].c_str())
; | 249 args.fCoords[1].c_str(), args.fCoords[1].c_str())
; |
| 249 coords2D = "interpolants.xy"; | 250 coords2D = "interpolants.xy"; |
| 250 bVar = "interpolants.z"; | 251 bVar = "interpolants.z"; |
| 251 } else { | 252 } else { |
| 252 coords2D = args.fCoords[0].c_str(); | 253 coords2D = args.fCoords[0].c_str(); |
| 253 bVar.printf("%s.x", args.fCoords[1].c_str()); | 254 bVar.printf("%s.x", args.fCoords[1].c_str()); |
| 254 } | 255 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 SkScalar fCachedFocal; | 440 SkScalar fCachedFocal; |
| 440 | 441 |
| 441 // @} | 442 // @} |
| 442 | 443 |
| 443 private: | 444 private: |
| 444 typedef GrGLGradientEffect INHERITED; | 445 typedef GrGLGradientEffect INHERITED; |
| 445 | 446 |
| 446 }; | 447 }; |
| 447 | 448 |
| 448 void FocalOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 449 void FocalOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 449 GrProcessorKeyBuilder* b) c
onst { | 450 GrProcessorKeyBuilder* b)
const { |
| 450 GLFocalOutside2PtConicalEffect::GenKey(*this, caps, b); | 451 GLFocalOutside2PtConicalEffect::GenKey(*this, caps, b); |
| 451 } | 452 } |
| 452 | 453 |
| 453 GrGLFragmentProcessor* FocalOutside2PtConicalEffect::onCreateGLInstance() const
{ | 454 GrGLFragmentProcessor* FocalOutside2PtConicalEffect::onCreateGLInstance() const
{ |
| 454 return new GLFocalOutside2PtConicalEffect(*this); | 455 return new GLFocalOutside2PtConicalEffect(*this); |
| 455 } | 456 } |
| 456 | 457 |
| 457 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect); | 458 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect); |
| 458 | 459 |
| 459 /* | 460 /* |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 : fVSVaryingName(nullptr) | 493 : fVSVaryingName(nullptr) |
| 493 , fFSVaryingName(nullptr) | 494 , fFSVaryingName(nullptr) |
| 494 , fCachedFocal(SK_ScalarMax) { | 495 , fCachedFocal(SK_ScalarMax) { |
| 495 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); | 496 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); |
| 496 fIsFlipped = data.isFlipped(); | 497 fIsFlipped = data.isFlipped(); |
| 497 } | 498 } |
| 498 | 499 |
| 499 void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) { | 500 void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) { |
| 500 const FocalOutside2PtConicalEffect& ge = args.fFp.cast<FocalOutside2PtConica
lEffect>(); | 501 const FocalOutside2PtConicalEffect& ge = args.fFp.cast<FocalOutside2PtConica
lEffect>(); |
| 501 this->emitUniforms(args.fBuilder, ge); | 502 this->emitUniforms(args.fBuilder, ge); |
| 502 fParamUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vis
ibility, | 503 fParamUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_V
isibility, |
| 503 kFloat_GrSLType, kDefault_GrSLPrecision
, | 504 kFloat_GrSLType, kDefault_GrSLPrecision
, |
| 504 "Conical2FSParams", 2); | 505 "Conical2FSParams", 2); |
| 505 SkString tName("t"); | 506 SkString tName("t"); |
| 506 SkString p0; // focalX | 507 SkString p0; // focalX |
| 507 SkString p1; // 1 - focalX * focalX | 508 SkString p1; // 1 - focalX * focalX |
| 508 | 509 |
| 509 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 510 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); |
| 510 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 511 args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); |
| 511 | 512 |
| 512 // if we have a vec3 from being in perspective, convert it to a vec2 first | 513 // if we have a vec3 from being in perspective, convert it to a vec2 first |
| 513 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 514 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 514 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 515 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 515 const char* coords2D = coords2DString.c_str(); | 516 const char* coords2D = coords2DString.c_str(); |
| 516 | 517 |
| 517 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) | 518 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) |
| 518 | 519 |
| 519 // output will default to transparent black (we simply won't write anything | 520 // output will default to transparent black (we simply won't write anything |
| 520 // else to it if invalid, instead of discarding or returning prematurely) | 521 // else to it if invalid, instead of discarding or returning prematurely) |
| 521 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor)
; | 522 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor)
; |
| 522 | 523 |
| 523 fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); | 524 fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 SkScalar fCachedFocal; | 644 SkScalar fCachedFocal; |
| 644 | 645 |
| 645 // @} | 646 // @} |
| 646 | 647 |
| 647 private: | 648 private: |
| 648 typedef GrGLGradientEffect INHERITED; | 649 typedef GrGLGradientEffect INHERITED; |
| 649 | 650 |
| 650 }; | 651 }; |
| 651 | 652 |
| 652 void FocalInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 653 void FocalInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 653 GrProcessorKeyBuilder* b) const { | 654 GrProcessorKeyBuilder* b)
const { |
| 654 GLFocalInside2PtConicalEffect::GenKey(*this, caps, b); | 655 GLFocalInside2PtConicalEffect::GenKey(*this, caps, b); |
| 655 } | 656 } |
| 656 | 657 |
| 657 GrGLFragmentProcessor* FocalInside2PtConicalEffect::onCreateGLInstance() const { | 658 GrGLFragmentProcessor* FocalInside2PtConicalEffect::onCreateGLInstance() const { |
| 658 return new GLFocalInside2PtConicalEffect(*this); | 659 return new GLFocalInside2PtConicalEffect(*this); |
| 659 } | 660 } |
| 660 | 661 |
| 661 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect); | 662 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect); |
| 662 | 663 |
| 663 /* | 664 /* |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 } | 696 } |
| 696 | 697 |
| 697 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) | 698 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) |
| 698 : fVSVaryingName(nullptr) | 699 : fVSVaryingName(nullptr) |
| 699 , fFSVaryingName(nullptr) | 700 , fFSVaryingName(nullptr) |
| 700 , fCachedFocal(SK_ScalarMax) {} | 701 , fCachedFocal(SK_ScalarMax) {} |
| 701 | 702 |
| 702 void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) { | 703 void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) { |
| 703 const FocalInside2PtConicalEffect& ge = args.fFp.cast<FocalInside2PtConicalE
ffect>(); | 704 const FocalInside2PtConicalEffect& ge = args.fFp.cast<FocalInside2PtConicalE
ffect>(); |
| 704 this->emitUniforms(args.fBuilder, ge); | 705 this->emitUniforms(args.fBuilder, ge); |
| 705 fFocalUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | 706 fFocalUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibi
lity, |
| 706 kFloat_GrSLType, kDefault_GrSLPrecision, | 707 kFloat_GrSLType, kDefault_GrSLPrecisio
n, |
| 707 "Conical2FSParams"); | 708 "Conical2FSParams"); |
| 708 SkString tName("t"); | 709 SkString tName("t"); |
| 709 | 710 |
| 710 // this is the distance along x-axis from the end center to focal point in | 711 // this is the distance along x-axis from the end center to focal point in |
| 711 // transformed coordinates | 712 // transformed coordinates |
| 712 GrGLSLShaderVar focal = args.fBuilder->getUniformVariable(fFocalUni); | 713 GrGLSLShaderVar focal = args.fBuilder->getUniformVariable(fFocalUni); |
| 713 | 714 |
| 714 // if we have a vec3 from being in perspective, convert it to a vec2 first | 715 // if we have a vec3 from being in perspective, convert it to a vec2 first |
| 715 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 716 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 716 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 717 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 717 const char* coords2D = coords2DString.c_str(); | 718 const char* coords2D = coords2DString.c_str(); |
| 718 | 719 |
| 719 // t = p.x * focalX + length(p) | 720 // t = p.x * focalX + length(p) |
| 720 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st
r(), | 721 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st
r(), |
| 721 coords2D, focal.c_str(), coords2D); | 722 coords2D, focal.c_str(), coords2D); |
| 722 | 723 |
| 723 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI
nputColor, | 724 this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fI
nputColor, |
| 724 args.fSamplers); | 725 args.fSamplers); |
| 725 } | 726 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 SkScalar fCachedC; | 886 SkScalar fCachedC; |
| 886 | 887 |
| 887 // @} | 888 // @} |
| 888 | 889 |
| 889 private: | 890 private: |
| 890 typedef GrGLGradientEffect INHERITED; | 891 typedef GrGLGradientEffect INHERITED; |
| 891 | 892 |
| 892 }; | 893 }; |
| 893 | 894 |
| 894 void CircleInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 895 void CircleInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 895 GrProcessorKeyBuilder* b) c
onst { | 896 GrProcessorKeyBuilder* b)
const { |
| 896 GLCircleInside2PtConicalEffect::GenKey(*this, caps, b); | 897 GLCircleInside2PtConicalEffect::GenKey(*this, caps, b); |
| 897 } | 898 } |
| 898 | 899 |
| 899 GrGLFragmentProcessor* CircleInside2PtConicalEffect::onCreateGLInstance() const
{ | 900 GrGLFragmentProcessor* CircleInside2PtConicalEffect::onCreateGLInstance() const
{ |
| 900 return new GLCircleInside2PtConicalEffect(*this); | 901 return new GLCircleInside2PtConicalEffect(*this); |
| 901 } | 902 } |
| 902 | 903 |
| 903 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect); | 904 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect); |
| 904 | 905 |
| 905 /* | 906 /* |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 , fFSVaryingName(nullptr) | 941 , fFSVaryingName(nullptr) |
| 941 , fCachedCenterX(SK_ScalarMax) | 942 , fCachedCenterX(SK_ScalarMax) |
| 942 , fCachedCenterY(SK_ScalarMax) | 943 , fCachedCenterY(SK_ScalarMax) |
| 943 , fCachedA(SK_ScalarMax) | 944 , fCachedA(SK_ScalarMax) |
| 944 , fCachedB(SK_ScalarMax) | 945 , fCachedB(SK_ScalarMax) |
| 945 , fCachedC(SK_ScalarMax) {} | 946 , fCachedC(SK_ScalarMax) {} |
| 946 | 947 |
| 947 void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) { | 948 void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) { |
| 948 const CircleInside2PtConicalEffect& ge = args.fFp.cast<CircleInside2PtConica
lEffect>(); | 949 const CircleInside2PtConicalEffect& ge = args.fFp.cast<CircleInside2PtConica
lEffect>(); |
| 949 this->emitUniforms(args.fBuilder, ge); | 950 this->emitUniforms(args.fBuilder, ge); |
| 950 fCenterUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 951 fCenterUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visib
ility, |
| 951 kVec2f_GrSLType, kDefault_GrSLPrecision, | 952 kVec2f_GrSLType, kDefault_GrSLPrecisi
on, |
| 952 "Conical2FSCenter"); | 953 "Conical2FSCenter"); |
| 953 fParamUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | 954 fParamUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibi
lity, |
| 954 kVec3f_GrSLType, kDefault_GrSLPrecision, | 955 kVec3f_GrSLType, kDefault_GrSLPrecisio
n, |
| 955 "Conical2FSParams"); | 956 "Conical2FSParams"); |
| 956 SkString tName("t"); | 957 SkString tName("t"); |
| 957 | 958 |
| 958 GrGLSLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni); | 959 GrGLSLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni); |
| 959 // params.x = A | 960 // params.x = A |
| 960 // params.y = B | 961 // params.y = B |
| 961 // params.z = C | 962 // params.z = C |
| 962 GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni); | 963 GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni); |
| 963 | 964 |
| 964 // if we have a vec3 from being in perspective, convert it to a vec2 first | 965 // if we have a vec3 from being in perspective, convert it to a vec2 first |
| 965 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 966 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 966 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 967 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 967 const char* coords2D = coords2DString.c_str(); | 968 const char* coords2D = coords2DString.c_str(); |
| 968 | 969 |
| 969 // p = coords2D | 970 // p = coords2D |
| 970 // e = center end | 971 // e = center end |
| 971 // r = radius end | 972 // r = radius end |
| 972 // A = dot(e, e) - r^2 + 2 * r - 1 | 973 // A = dot(e, e) - r^2 + 2 * r - 1 |
| 973 // B = (r -1) / A | 974 // B = (r -1) / A |
| 974 // C = 1 / A | 975 // C = 1 / A |
| 975 // d = dot(e, p) + B | 976 // d = dot(e, p) + B |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 SkScalar fCachedTLimit; | 1111 SkScalar fCachedTLimit; |
| 1111 | 1112 |
| 1112 // @} | 1113 // @} |
| 1113 | 1114 |
| 1114 private: | 1115 private: |
| 1115 typedef GrGLGradientEffect INHERITED; | 1116 typedef GrGLGradientEffect INHERITED; |
| 1116 | 1117 |
| 1117 }; | 1118 }; |
| 1118 | 1119 |
| 1119 void CircleOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 1120 void CircleOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 1120 GrProcessorKeyBuilder* b)
const { | 1121 GrProcessorKeyBuilder* b
) const { |
| 1121 GLCircleOutside2PtConicalEffect::GenKey(*this, caps, b); | 1122 GLCircleOutside2PtConicalEffect::GenKey(*this, caps, b); |
| 1122 } | 1123 } |
| 1123 | 1124 |
| 1124 GrGLFragmentProcessor* CircleOutside2PtConicalEffect::onCreateGLInstance() const
{ | 1125 GrGLFragmentProcessor* CircleOutside2PtConicalEffect::onCreateGLInstance() const
{ |
| 1125 return new GLCircleOutside2PtConicalEffect(*this); | 1126 return new GLCircleOutside2PtConicalEffect(*this); |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect); | 1129 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect); |
| 1129 | 1130 |
| 1130 /* | 1131 /* |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 , fCachedB(SK_ScalarMax) | 1171 , fCachedB(SK_ScalarMax) |
| 1171 , fCachedC(SK_ScalarMax) | 1172 , fCachedC(SK_ScalarMax) |
| 1172 , fCachedTLimit(SK_ScalarMax) { | 1173 , fCachedTLimit(SK_ScalarMax) { |
| 1173 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC
onicalEffect>(); | 1174 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC
onicalEffect>(); |
| 1174 fIsFlipped = data.isFlipped(); | 1175 fIsFlipped = data.isFlipped(); |
| 1175 } | 1176 } |
| 1176 | 1177 |
| 1177 void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) { | 1178 void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) { |
| 1178 const CircleOutside2PtConicalEffect& ge = args.fFp.cast<CircleOutside2PtConi
calEffect>(); | 1179 const CircleOutside2PtConicalEffect& ge = args.fFp.cast<CircleOutside2PtConi
calEffect>(); |
| 1179 this->emitUniforms(args.fBuilder, ge); | 1180 this->emitUniforms(args.fBuilder, ge); |
| 1180 fCenterUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 1181 fCenterUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visib
ility, |
| 1181 kVec2f_GrSLType, kDefault_GrSLPrecision, | 1182 kVec2f_GrSLType, kDefault_GrSLPrecisi
on, |
| 1182 "Conical2FSCenter"); | 1183 "Conical2FSCenter"); |
| 1183 fParamUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | 1184 fParamUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibi
lity, |
| 1184 kVec4f_GrSLType, kDefault_GrSLPrecision, | 1185 kVec4f_GrSLType, kDefault_GrSLPrecisio
n, |
| 1185 "Conical2FSParams"); | 1186 "Conical2FSParams"); |
| 1186 SkString tName("t"); | 1187 SkString tName("t"); |
| 1187 | 1188 |
| 1188 GrGLSLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni); | 1189 GrGLSLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni); |
| 1189 // params.x = A | 1190 // params.x = A |
| 1190 // params.y = B | 1191 // params.y = B |
| 1191 // params.z = C | 1192 // params.z = C |
| 1192 GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni); | 1193 GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni); |
| 1193 | 1194 |
| 1194 // if we have a vec3 from being in perspective, convert it to a vec2 first | 1195 // if we have a vec3 from being in perspective, convert it to a vec2 first |
| 1195 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 1196 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 1196 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 1197 SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 1197 const char* coords2D = coords2DString.c_str(); | 1198 const char* coords2D = coords2DString.c_str(); |
| 1198 | 1199 |
| 1199 // output will default to transparent black (we simply won't write anything | 1200 // output will default to transparent black (we simply won't write anything |
| 1200 // else to it if invalid, instead of discarding or returning prematurely) | 1201 // else to it if invalid, instead of discarding or returning prematurely) |
| 1201 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor)
; | 1202 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor)
; |
| 1202 | 1203 |
| 1203 // p = coords2D | 1204 // p = coords2D |
| 1204 // e = center end | 1205 // e = center end |
| 1205 // r = radius end | 1206 // r = radius end |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1304 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
| 1304 } else if (type == kEdge_ConicalType) { | 1305 } else if (type == kEdge_ConicalType) { |
| 1305 set_matrix_edge_conical(shader, &matrix); | 1306 set_matrix_edge_conical(shader, &matrix); |
| 1306 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1307 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
| 1307 } else { | 1308 } else { |
| 1308 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1309 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
| 1309 } | 1310 } |
| 1310 } | 1311 } |
| 1311 | 1312 |
| 1312 #endif | 1313 #endif |
| OLD | NEW |