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 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // @} | 133 // @} |
134 | 134 |
135 typedef GrGradientEffect INHERITED; | 135 typedef GrGradientEffect INHERITED; |
136 }; | 136 }; |
137 | 137 |
138 class GLEdge2PtConicalEffect : public GrGLGradientEffect { | 138 class GLEdge2PtConicalEffect : public GrGLGradientEffect { |
139 public: | 139 public: |
140 GLEdge2PtConicalEffect(const GrBackendProcessorFactory& factory, const GrPro
cessor&); | 140 GLEdge2PtConicalEffect(const GrBackendProcessorFactory& factory, const GrPro
cessor&); |
141 virtual ~GLEdge2PtConicalEffect() { } | 141 virtual ~GLEdge2PtConicalEffect() { } |
142 | 142 |
143 virtual void emitCode(GrGLProgramBuilder*, | 143 virtual void emitCode(GrGLFPBuilder*, |
144 const GrFragmentProcessor&, | 144 const GrFragmentProcessor&, |
145 const GrProcessorKey&, | 145 const GrProcessorKey&, |
146 const char* outputColor, | 146 const char* outputColor, |
147 const char* inputColor, | 147 const char* inputColor, |
148 const TransformedCoordsArray&, | 148 const TransformedCoordsArray&, |
149 const TextureSamplerArray&) SK_OVERRIDE; | 149 const TextureSamplerArray&) SK_OVERRIDE; |
150 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 150 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
151 | 151 |
152 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); | 152 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); |
153 | 153 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 | 217 |
218 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendProcessorFactory&
factory, | 218 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendProcessorFactory&
factory, |
219 const GrProcessor&) | 219 const GrProcessor&) |
220 : INHERITED(factory) | 220 : INHERITED(factory) |
221 , fVSVaryingName(NULL) | 221 , fVSVaryingName(NULL) |
222 , fFSVaryingName(NULL) | 222 , fFSVaryingName(NULL) |
223 , fCachedRadius(-SK_ScalarMax) | 223 , fCachedRadius(-SK_ScalarMax) |
224 , fCachedDiffRadius(-SK_ScalarMax) {} | 224 , fCachedDiffRadius(-SK_ScalarMax) {} |
225 | 225 |
226 void GLEdge2PtConicalEffect::emitCode(GrGLProgramBuilder* builder, | 226 void GLEdge2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
227 const GrFragmentProcessor&, | 227 const GrFragmentProcessor&, |
228 const GrProcessorKey& key, | 228 const GrProcessorKey& key, |
229 const char* outputColor, | 229 const char* outputColor, |
230 const char* inputColor, | 230 const char* inputColor, |
231 const TransformedCoordsArray& coords, | 231 const TransformedCoordsArray& coords, |
232 const TextureSamplerArray& samplers) { | 232 const TextureSamplerArray& samplers) { |
233 uint32_t baseKey = key.get32(0); | 233 uint32_t baseKey = key.get32(0); |
234 this->emitUniforms(builder, baseKey); | 234 this->emitUniforms(builder, baseKey); |
235 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, | 235 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, |
236 kFloat_GrSLType, "Conical2FSParams", 3)
; | 236 kFloat_GrSLType, "Conical2FSParams", 3)
; |
237 | 237 |
238 SkString cName("c"); | 238 SkString cName("c"); |
239 SkString tName("t"); | 239 SkString tName("t"); |
240 SkString p0; // start radius | 240 SkString p0; // start radius |
241 SkString p1; // start radius squared | 241 SkString p1; // start radius squared |
242 SkString p2; // difference in radii (r1 - r0) | 242 SkString p2; // difference in radii (r1 - r0) |
243 | 243 |
244 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 244 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); |
245 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 245 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); |
246 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); | 246 builder->getUniformVariable(fParamUni).appendArrayAccess(2, &p2); |
247 | 247 |
248 // We interpolate the linear component in coords[1]. | 248 // We interpolate the linear component in coords[1]. |
249 SkASSERT(coords[0].getType() == coords[1].getType()); | 249 SkASSERT(coords[0].getType() == coords[1].getType()); |
250 const char* coords2D; | 250 const char* coords2D; |
251 SkString bVar; | 251 SkString bVar; |
252 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 252 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
253 if (kVec3f_GrSLType == coords[0].getType()) { | 253 if (kVec3f_GrSLType == coords[0].getType()) { |
254 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x /
%s.z);\n", | 254 fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x /
%s.z);\n", |
255 coords[0].c_str(), coords[0].c_str(), coords[1].c
_str(), | 255 coords[0].c_str(), coords[0].c_str(), coords[1].c
_str(), |
256 coords[1].c_str()); | 256 coords[1].c_str()); |
257 coords2D = "interpolants.xy"; | 257 coords2D = "interpolants.xy"; |
258 bVar = "interpolants.z"; | 258 bVar = "interpolants.z"; |
259 } else { | 259 } else { |
260 coords2D = coords[0].c_str(); | 260 coords2D = coords[0].c_str(); |
261 bVar.printf("%s.x", coords[1].c_str()); | 261 bVar.printf("%s.x", coords[1].c_str()); |
262 } | 262 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 bool fIsFlipped; | 414 bool fIsFlipped; |
415 | 415 |
416 typedef GrGradientEffect INHERITED; | 416 typedef GrGradientEffect INHERITED; |
417 }; | 417 }; |
418 | 418 |
419 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect { | 419 class GLFocalOutside2PtConicalEffect : public GrGLGradientEffect { |
420 public: | 420 public: |
421 GLFocalOutside2PtConicalEffect(const GrBackendProcessorFactory& factory, con
st GrProcessor&); | 421 GLFocalOutside2PtConicalEffect(const GrBackendProcessorFactory& factory, con
st GrProcessor&); |
422 virtual ~GLFocalOutside2PtConicalEffect() { } | 422 virtual ~GLFocalOutside2PtConicalEffect() { } |
423 | 423 |
424 virtual void emitCode(GrGLProgramBuilder*, | 424 virtual void emitCode(GrGLFPBuilder*, |
425 const GrFragmentProcessor&, | 425 const GrFragmentProcessor&, |
426 const GrProcessorKey&, | 426 const GrProcessorKey&, |
427 const char* outputColor, | 427 const char* outputColor, |
428 const char* inputColor, | 428 const char* inputColor, |
429 const TransformedCoordsArray&, | 429 const TransformedCoordsArray&, |
430 const TextureSamplerArray&) SK_OVERRIDE; | 430 const TextureSamplerArray&) SK_OVERRIDE; |
431 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 431 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
432 | 432 |
433 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); | 433 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); |
434 | 434 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendPr
ocessorFactory& factory, | 497 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendPr
ocessorFactory& factory, |
498 const GrProcessor
& processor) | 498 const GrProcessor
& processor) |
499 : INHERITED(factory) | 499 : INHERITED(factory) |
500 , fVSVaryingName(NULL) | 500 , fVSVaryingName(NULL) |
501 , fFSVaryingName(NULL) | 501 , fFSVaryingName(NULL) |
502 , fCachedFocal(SK_ScalarMax) { | 502 , fCachedFocal(SK_ScalarMax) { |
503 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); | 503 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); |
504 fIsFlipped = data.isFlipped(); | 504 fIsFlipped = data.isFlipped(); |
505 } | 505 } |
506 | 506 |
507 void GLFocalOutside2PtConicalEffect::emitCode(GrGLProgramBuilder* builder, | 507 void GLFocalOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
508 const GrFragmentProcessor&, | 508 const GrFragmentProcessor&, |
509 const GrProcessorKey& key, | 509 const GrProcessorKey& key, |
510 const char* outputColor, | 510 const char* outputColor, |
511 const char* inputColor, | 511 const char* inputColor, |
512 const TransformedCoordsArray& coor
ds, | 512 const TransformedCoordsArray& coor
ds, |
513 const TextureSamplerArray& sampler
s) { | 513 const TextureSamplerArray& sampler
s) { |
514 uint32_t baseKey = key.get32(0); | 514 uint32_t baseKey = key.get32(0); |
515 this->emitUniforms(builder, baseKey); | 515 this->emitUniforms(builder, baseKey); |
516 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, | 516 fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibilit
y, |
517 kFloat_GrSLType, "Conical2FSParams", 2)
; | 517 kFloat_GrSLType, "Conical2FSParams", 2)
; |
518 SkString tName("t"); | 518 SkString tName("t"); |
519 SkString p0; // focalX | 519 SkString p0; // focalX |
520 SkString p1; // 1 - focalX * focalX | 520 SkString p1; // 1 - focalX * focalX |
521 | 521 |
522 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); | 522 builder->getUniformVariable(fParamUni).appendArrayAccess(0, &p0); |
523 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); | 523 builder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1); |
524 | 524 |
525 // if we have a vec3 from being in perspective, convert it to a vec2 first | 525 // if we have a vec3 from being in perspective, convert it to a vec2 first |
526 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 526 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
527 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); | 527 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); |
528 const char* coords2D = coords2DString.c_str(); | 528 const char* coords2D = coords2DString.c_str(); |
529 | 529 |
530 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) | 530 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) |
531 | 531 |
532 // output will default to transparent black (we simply won't write anything | 532 // output will default to transparent black (we simply won't write anything |
533 // else to it if invalid, instead of discarding or returning prematurely) | 533 // else to it if invalid, instead of discarding or returning prematurely) |
534 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); | 534 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); |
535 | 535 |
536 fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); | 536 fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 SkScalar fFocalX; | 623 SkScalar fFocalX; |
624 | 624 |
625 typedef GrGradientEffect INHERITED; | 625 typedef GrGradientEffect INHERITED; |
626 }; | 626 }; |
627 | 627 |
628 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect { | 628 class GLFocalInside2PtConicalEffect : public GrGLGradientEffect { |
629 public: | 629 public: |
630 GLFocalInside2PtConicalEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor&); | 630 GLFocalInside2PtConicalEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor&); |
631 virtual ~GLFocalInside2PtConicalEffect() {} | 631 virtual ~GLFocalInside2PtConicalEffect() {} |
632 | 632 |
633 virtual void emitCode(GrGLProgramBuilder*, | 633 virtual void emitCode(GrGLFPBuilder*, |
634 const GrFragmentProcessor&, | 634 const GrFragmentProcessor&, |
635 const GrProcessorKey&, | 635 const GrProcessorKey&, |
636 const char* outputColor, | 636 const char* outputColor, |
637 const char* inputColor, | 637 const char* inputColor, |
638 const TransformedCoordsArray&, | 638 const TransformedCoordsArray&, |
639 const TextureSamplerArray&) SK_OVERRIDE; | 639 const TextureSamplerArray&) SK_OVERRIDE; |
640 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 640 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
641 | 641 |
642 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); | 642 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); |
643 | 643 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 return fp; | 703 return fp; |
704 } | 704 } |
705 | 705 |
706 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendProc
essorFactory& factory, | 706 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendProc
essorFactory& factory, |
707 const GrProcessor&) | 707 const GrProcessor&) |
708 : INHERITED(factory) | 708 : INHERITED(factory) |
709 , fVSVaryingName(NULL) | 709 , fVSVaryingName(NULL) |
710 , fFSVaryingName(NULL) | 710 , fFSVaryingName(NULL) |
711 , fCachedFocal(SK_ScalarMax) {} | 711 , fCachedFocal(SK_ScalarMax) {} |
712 | 712 |
713 void GLFocalInside2PtConicalEffect::emitCode(GrGLProgramBuilder* builder, | 713 void GLFocalInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
714 const GrFragmentProcessor&, | 714 const GrFragmentProcessor&, |
715 const GrProcessorKey& key, | 715 const GrProcessorKey& key, |
716 const char* outputColor, | 716 const char* outputColor, |
717 const char* inputColor, | 717 const char* inputColor, |
718 const TransformedCoordsArray& coord
s, | 718 const TransformedCoordsArray& coord
s, |
719 const TextureSamplerArray& samplers
) { | 719 const TextureSamplerArray& samplers
) { |
720 uint32_t baseKey = key.get32(0); | 720 uint32_t baseKey = key.get32(0); |
721 this->emitUniforms(builder, baseKey); | 721 this->emitUniforms(builder, baseKey); |
722 fFocalUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 722 fFocalUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
723 kFloat_GrSLType, "Conical2FSParams"); | 723 kFloat_GrSLType, "Conical2FSParams"); |
724 SkString tName("t"); | 724 SkString tName("t"); |
725 | 725 |
726 // this is the distance along x-axis from the end center to focal point in | 726 // this is the distance along x-axis from the end center to focal point in |
727 // transformed coordinates | 727 // transformed coordinates |
728 GrGLShaderVar focal = builder->getUniformVariable(fFocalUni); | 728 GrGLShaderVar focal = builder->getUniformVariable(fFocalUni); |
729 | 729 |
730 // if we have a vec3 from being in perspective, convert it to a vec2 first | 730 // if we have a vec3 from being in perspective, convert it to a vec2 first |
731 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 731 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
732 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); | 732 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); |
733 const char* coords2D = coords2DString.c_str(); | 733 const char* coords2D = coords2DString.c_str(); |
734 | 734 |
735 // t = p.x * focalX + length(p) | 735 // t = p.x * focalX + length(p) |
736 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st
r(), | 736 fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_st
r(), |
737 coords2D, focal.c_str(), coords2D); | 737 coords2D, focal.c_str(), coords2D); |
738 | 738 |
739 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa
mplers); | 739 this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, sa
mplers); |
740 } | 740 } |
741 | 741 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 const CircleConicalInfo fInfo; | 868 const CircleConicalInfo fInfo; |
869 | 869 |
870 typedef GrGradientEffect INHERITED; | 870 typedef GrGradientEffect INHERITED; |
871 }; | 871 }; |
872 | 872 |
873 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect { | 873 class GLCircleInside2PtConicalEffect : public GrGLGradientEffect { |
874 public: | 874 public: |
875 GLCircleInside2PtConicalEffect(const GrBackendProcessorFactory& factory, con
st GrProcessor&); | 875 GLCircleInside2PtConicalEffect(const GrBackendProcessorFactory& factory, con
st GrProcessor&); |
876 virtual ~GLCircleInside2PtConicalEffect() {} | 876 virtual ~GLCircleInside2PtConicalEffect() {} |
877 | 877 |
878 virtual void emitCode(GrGLProgramBuilder*, | 878 virtual void emitCode(GrGLFPBuilder*, |
879 const GrFragmentProcessor&, | 879 const GrFragmentProcessor&, |
880 const GrProcessorKey&, | 880 const GrProcessorKey&, |
881 const char* outputColor, | 881 const char* outputColor, |
882 const char* inputColor, | 882 const char* inputColor, |
883 const TransformedCoordsArray&, | 883 const TransformedCoordsArray&, |
884 const TextureSamplerArray&) SK_OVERRIDE; | 884 const TextureSamplerArray&) SK_OVERRIDE; |
885 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 885 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
886 | 886 |
887 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); | 887 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); |
888 | 888 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 const GrProcessor
& processor) | 956 const GrProcessor
& processor) |
957 : INHERITED(factory) | 957 : INHERITED(factory) |
958 , fVSVaryingName(NULL) | 958 , fVSVaryingName(NULL) |
959 , fFSVaryingName(NULL) | 959 , fFSVaryingName(NULL) |
960 , fCachedCenterX(SK_ScalarMax) | 960 , fCachedCenterX(SK_ScalarMax) |
961 , fCachedCenterY(SK_ScalarMax) | 961 , fCachedCenterY(SK_ScalarMax) |
962 , fCachedA(SK_ScalarMax) | 962 , fCachedA(SK_ScalarMax) |
963 , fCachedB(SK_ScalarMax) | 963 , fCachedB(SK_ScalarMax) |
964 , fCachedC(SK_ScalarMax) {} | 964 , fCachedC(SK_ScalarMax) {} |
965 | 965 |
966 void GLCircleInside2PtConicalEffect::emitCode(GrGLProgramBuilder* builder, | 966 void GLCircleInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
967 const GrFragmentProcessor&, | 967 const GrFragmentProcessor&, |
968 const GrProcessorKey& key, | 968 const GrProcessorKey& key, |
969 const char* outputColor, | 969 const char* outputColor, |
970 const char* inputColor, | 970 const char* inputColor, |
971 const TransformedCoordsArray& coor
ds, | 971 const TransformedCoordsArray& coor
ds, |
972 const TextureSamplerArray& sampler
s) { | 972 const TextureSamplerArray& sampler
s) { |
973 uint32_t baseKey = key.get32(0); | 973 uint32_t baseKey = key.get32(0); |
974 this->emitUniforms(builder, baseKey); | 974 this->emitUniforms(builder, baseKey); |
975 fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 975 fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
976 kVec2f_GrSLType, "Conical2FSCenter"); | 976 kVec2f_GrSLType, "Conical2FSCenter"); |
977 fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 977 fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
978 kVec3f_GrSLType, "Conical2FSParams"); | 978 kVec3f_GrSLType, "Conical2FSParams"); |
979 SkString tName("t"); | 979 SkString tName("t"); |
980 | 980 |
981 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); | 981 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); |
982 // params.x = A | 982 // params.x = A |
983 // params.y = B | 983 // params.y = B |
984 // params.z = C | 984 // params.z = C |
985 GrGLShaderVar params = builder->getUniformVariable(fParamUni); | 985 GrGLShaderVar params = builder->getUniformVariable(fParamUni); |
986 | 986 |
987 // if we have a vec3 from being in perspective, convert it to a vec2 first | 987 // if we have a vec3 from being in perspective, convert it to a vec2 first |
988 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 988 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
989 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); | 989 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); |
990 const char* coords2D = coords2DString.c_str(); | 990 const char* coords2D = coords2DString.c_str(); |
991 | 991 |
992 // p = coords2D | 992 // p = coords2D |
993 // e = center end | 993 // e = center end |
994 // r = radius end | 994 // r = radius end |
995 // A = dot(e, e) - r^2 + 2 * r - 1 | 995 // A = dot(e, e) - r^2 + 2 * r - 1 |
996 // B = (r -1) / A | 996 // B = (r -1) / A |
997 // C = 1 / A | 997 // C = 1 / A |
998 // d = dot(e, p) + B | 998 // d = dot(e, p) + B |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 bool fIsFlipped; | 1100 bool fIsFlipped; |
1101 | 1101 |
1102 typedef GrGradientEffect INHERITED; | 1102 typedef GrGradientEffect INHERITED; |
1103 }; | 1103 }; |
1104 | 1104 |
1105 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect { | 1105 class GLCircleOutside2PtConicalEffect : public GrGLGradientEffect { |
1106 public: | 1106 public: |
1107 GLCircleOutside2PtConicalEffect(const GrBackendProcessorFactory&, const GrPr
ocessor&); | 1107 GLCircleOutside2PtConicalEffect(const GrBackendProcessorFactory&, const GrPr
ocessor&); |
1108 virtual ~GLCircleOutside2PtConicalEffect() {} | 1108 virtual ~GLCircleOutside2PtConicalEffect() {} |
1109 | 1109 |
1110 virtual void emitCode(GrGLProgramBuilder*, | 1110 virtual void emitCode(GrGLFPBuilder*, |
1111 const GrFragmentProcessor&, | 1111 const GrFragmentProcessor&, |
1112 const GrProcessorKey&, | 1112 const GrProcessorKey&, |
1113 const char* outputColor, | 1113 const char* outputColor, |
1114 const char* inputColor, | 1114 const char* inputColor, |
1115 const TransformedCoordsArray&, | 1115 const TransformedCoordsArray&, |
1116 const TextureSamplerArray&) SK_OVERRIDE; | 1116 const TextureSamplerArray&) SK_OVERRIDE; |
1117 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1117 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
1118 | 1118 |
1119 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); | 1119 static void GenKey(const GrProcessor&, const GrGLCaps& caps, GrProcessorKeyB
uilder* b); |
1120 | 1120 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 , fCachedCenterX(SK_ScalarMax) | 1196 , fCachedCenterX(SK_ScalarMax) |
1197 , fCachedCenterY(SK_ScalarMax) | 1197 , fCachedCenterY(SK_ScalarMax) |
1198 , fCachedA(SK_ScalarMax) | 1198 , fCachedA(SK_ScalarMax) |
1199 , fCachedB(SK_ScalarMax) | 1199 , fCachedB(SK_ScalarMax) |
1200 , fCachedC(SK_ScalarMax) | 1200 , fCachedC(SK_ScalarMax) |
1201 , fCachedTLimit(SK_ScalarMax) { | 1201 , fCachedTLimit(SK_ScalarMax) { |
1202 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC
onicalEffect>(); | 1202 const CircleOutside2PtConicalEffect& data = processor.cast<CircleOutside2PtC
onicalEffect>(); |
1203 fIsFlipped = data.isFlipped(); | 1203 fIsFlipped = data.isFlipped(); |
1204 } | 1204 } |
1205 | 1205 |
1206 void GLCircleOutside2PtConicalEffect::emitCode(GrGLProgramBuilder* builder, | 1206 void GLCircleOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
1207 const GrFragmentProcessor&, | 1207 const GrFragmentProcessor&, |
1208 const GrProcessorKey& key, | 1208 const GrProcessorKey& key, |
1209 const char* outputColor, | 1209 const char* outputColor, |
1210 const char* inputColor, | 1210 const char* inputColor, |
1211 const TransformedCoordsArray& coo
rds, | 1211 const TransformedCoordsArray& coo
rds, |
1212 const TextureSamplerArray& sample
rs) { | 1212 const TextureSamplerArray& sample
rs) { |
1213 uint32_t baseKey = key.get32(0); | 1213 uint32_t baseKey = key.get32(0); |
1214 this->emitUniforms(builder, baseKey); | 1214 this->emitUniforms(builder, baseKey); |
1215 fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1215 fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1216 kVec2f_GrSLType, "Conical2FSCenter"); | 1216 kVec2f_GrSLType, "Conical2FSCenter"); |
1217 fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1217 fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1218 kVec4f_GrSLType, "Conical2FSParams"); | 1218 kVec4f_GrSLType, "Conical2FSParams"); |
1219 SkString tName("t"); | 1219 SkString tName("t"); |
1220 | 1220 |
1221 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); | 1221 GrGLShaderVar center = builder->getUniformVariable(fCenterUni); |
1222 // params.x = A | 1222 // params.x = A |
1223 // params.y = B | 1223 // params.y = B |
1224 // params.z = C | 1224 // params.z = C |
1225 GrGLShaderVar params = builder->getUniformVariable(fParamUni); | 1225 GrGLShaderVar params = builder->getUniformVariable(fParamUni); |
1226 | 1226 |
1227 // if we have a vec3 from being in perspective, convert it to a vec2 first | 1227 // if we have a vec3 from being in perspective, convert it to a vec2 first |
1228 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1228 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1229 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); | 1229 SkString coords2DString = fsBuilder->ensureFSCoords2D(coords, 0); |
1230 const char* coords2D = coords2DString.c_str(); | 1230 const char* coords2D = coords2DString.c_str(); |
1231 | 1231 |
1232 // output will default to transparent black (we simply won't write anything | 1232 // output will default to transparent black (we simply won't write anything |
1233 // else to it if invalid, instead of discarding or returning prematurely) | 1233 // else to it if invalid, instead of discarding or returning prematurely) |
1234 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); | 1234 fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor); |
1235 | 1235 |
1236 // p = coords2D | 1236 // p = coords2D |
1237 // e = center end | 1237 // e = center end |
1238 // r = radius end | 1238 // r = radius end |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1335 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
1336 } else if (type == kEdge_ConicalType) { | 1336 } else if (type == kEdge_ConicalType) { |
1337 set_matrix_edge_conical(shader, &matrix); | 1337 set_matrix_edge_conical(shader, &matrix); |
1338 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1338 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
1339 } else { | 1339 } else { |
1340 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1340 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
1341 } | 1341 } |
1342 } | 1342 } |
1343 | 1343 |
1344 #endif | 1344 #endif |
OLD | NEW |