OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
10 #include "SkBlurMask.h" | 10 #include "SkBlurMask.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "GrCircleBlurFragmentProcessor.h" | 21 #include "GrCircleBlurFragmentProcessor.h" |
22 #include "GrContext.h" | 22 #include "GrContext.h" |
23 #include "GrDrawContext.h" | 23 #include "GrDrawContext.h" |
24 #include "GrTexture.h" | 24 #include "GrTexture.h" |
25 #include "GrFragmentProcessor.h" | 25 #include "GrFragmentProcessor.h" |
26 #include "GrInvariantOutput.h" | 26 #include "GrInvariantOutput.h" |
27 #include "SkGrPixelRef.h" | 27 #include "SkGrPixelRef.h" |
28 #include "SkDraw.h" | 28 #include "SkDraw.h" |
29 #include "effects/GrSimpleTextureEffect.h" | 29 #include "effects/GrSimpleTextureEffect.h" |
30 #include "gl/GrGLFragmentProcessor.h" | 30 #include "gl/GrGLFragmentProcessor.h" |
31 #include "gl/builders/GrGLProgramBuilder.h" | 31 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 32 #include "glsl/GrGLSLProgramBuilder.h" |
32 #include "glsl/GrGLSLProgramDataManager.h" | 33 #include "glsl/GrGLSLProgramDataManager.h" |
33 #include "glsl/GrGLSLTextureSampler.h" | 34 #include "glsl/GrGLSLTextureSampler.h" |
34 #endif | 35 #endif |
35 | 36 |
36 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { | 37 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { |
37 return SkBlurMask::ConvertRadiusToSigma(radius); | 38 return SkBlurMask::ConvertRadiusToSigma(radius); |
38 } | 39 } |
39 | 40 |
40 class SkBlurMaskFilterImpl : public SkMaskFilter { | 41 class SkBlurMaskFilterImpl : public SkMaskFilter { |
41 public: | 42 public: |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 private: | 690 private: |
690 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 691 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
691 | 692 |
692 UniformHandle fProxyRectUniform; | 693 UniformHandle fProxyRectUniform; |
693 UniformHandle fProfileSizeUniform; | 694 UniformHandle fProfileSizeUniform; |
694 GrSLPrecision fPrecision; | 695 GrSLPrecision fPrecision; |
695 | 696 |
696 typedef GrGLFragmentProcessor INHERITED; | 697 typedef GrGLFragmentProcessor INHERITED; |
697 }; | 698 }; |
698 | 699 |
699 void OutputRectBlurProfileLookup(GrGLFragmentBuilder* fsBuilder, | 700 void OutputRectBlurProfileLookup(GrGLSLFragmentBuilder* fsBuilder, |
700 const GrGLSLTextureSampler& sampler, | 701 const GrGLSLTextureSampler& sampler, |
701 const char *output, | 702 const char *output, |
702 const char *profileSize, const char *loc, | 703 const char *profileSize, const char *loc, |
703 const char *blurred_width, | 704 const char *blurred_width, |
704 const char *sharp_width) { | 705 const char *sharp_width) { |
705 fsBuilder->codeAppendf("float %s;", output); | 706 fsBuilder->codeAppendf("float %s;", output); |
706 fsBuilder->codeAppendf("{"); | 707 fsBuilder->codeAppendf("{"); |
707 fsBuilder->codeAppendf("float coord = ((abs(%s - 0.5 * %s) - 0.5 * %s)) / %s
;", | 708 fsBuilder->codeAppendf("float coord = ((abs(%s - 0.5 * %s) - 0.5 * %s)) / %s
;", |
708 loc, blurred_width, sharp_width, profileSize); | 709 loc, blurred_width, sharp_width, profileSize); |
709 fsBuilder->codeAppendf("%s = ", output); | 710 fsBuilder->codeAppendf("%s = ", output); |
710 fsBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)"); | 711 fsBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)"); |
711 fsBuilder->codeAppend(".a;"); | 712 fsBuilder->codeAppend(".a;"); |
712 fsBuilder->codeAppendf("}"); | 713 fsBuilder->codeAppendf("}"); |
713 } | 714 } |
714 | 715 |
715 | 716 |
716 void GrGLRectBlurEffect::GenKey(GrSLPrecision precision, GrProcessorKeyBuilder*
b) { | 717 void GrGLRectBlurEffect::GenKey(GrSLPrecision precision, GrProcessorKeyBuilder*
b) { |
717 b->add32(precision); | 718 b->add32(precision); |
718 } | 719 } |
719 | 720 |
720 | 721 |
721 void GrGLRectBlurEffect::emitCode(EmitArgs& args) { | 722 void GrGLRectBlurEffect::emitCode(EmitArgs& args) { |
722 | 723 |
723 const char *rectName; | 724 const char *rectName; |
724 const char *profileSizeName; | 725 const char *profileSizeName; |
725 | 726 |
726 const char* precisionString = GrGLSLShaderVar::PrecisionString(args.fBuilder
->glslCaps(), | 727 const char* precisionString = GrGLSLShaderVar::PrecisionString(args.fBuilder
->glslCaps(), |
727 fPrecision); | 728 fPrecision); |
728 fProxyRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 729 fProxyRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, |
729 kVec4f_GrSLType, | 730 kVec4f_GrSLType, |
730 fPrecision, | 731 fPrecision, |
731 "proxyRect", | 732 "proxyRect", |
732 &rectName); | 733 &rectName); |
733 fProfileSizeUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragmen
t_Visibility, | 734 fProfileSizeUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragm
ent_Visibility, |
734 kFloat_GrSLType, | 735 kFloat_GrSLType, |
735 kDefault_GrSLPrecision, | 736 kDefault_GrSLPrecision, |
736 "profileSize", | 737 "profileSize", |
737 &profileSizeName); | 738 &profileSizeName); |
738 | 739 |
739 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 740 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
740 const char *fragmentPos = fsBuilder->fragmentPosition(); | 741 const char *fragmentPos = fsBuilder->fragmentPosition(); |
741 | 742 |
742 if (args.fInputColor) { | 743 if (args.fInputColor) { |
743 fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); | 744 fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); |
744 } else { | 745 } else { |
745 fsBuilder->codeAppendf("vec4 src=vec4(1);"); | 746 fsBuilder->codeAppendf("vec4 src=vec4(1);"); |
746 } | 747 } |
747 | 748 |
748 fsBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precisionSt
ring, fragmentPos, | 749 fsBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precisionSt
ring, fragmentPos, |
749 rectName); | 750 rectName); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 : fRect(rect) | 810 : fRect(rect) |
810 , fSigma(sigma) | 811 , fSigma(sigma) |
811 , fBlurProfileAccess(blurProfile) | 812 , fBlurProfileAccess(blurProfile) |
812 , fPrecision(precision) { | 813 , fPrecision(precision) { |
813 this->initClassID<GrRectBlurEffect>(); | 814 this->initClassID<GrRectBlurEffect>(); |
814 this->addTextureAccess(&fBlurProfileAccess); | 815 this->addTextureAccess(&fBlurProfileAccess); |
815 this->setWillReadFragmentPosition(); | 816 this->setWillReadFragmentPosition(); |
816 } | 817 } |
817 | 818 |
818 void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 819 void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
819 GrProcessorKeyBuilder* b) const { | 820 GrProcessorKeyBuilder* b) const { |
820 GrGLRectBlurEffect::GenKey(fPrecision, b); | 821 GrGLRectBlurEffect::GenKey(fPrecision, b); |
821 } | 822 } |
822 | 823 |
823 GrGLFragmentProcessor* GrRectBlurEffect::onCreateGLInstance() const { | 824 GrGLFragmentProcessor* GrRectBlurEffect::onCreateGLInstance() const { |
824 return new GrGLRectBlurEffect(*this, fPrecision); | 825 return new GrGLRectBlurEffect(*this, fPrecision); |
825 } | 826 } |
826 | 827 |
827 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 828 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
828 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); | 829 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); |
829 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); | 830 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 }; | 1060 }; |
1060 | 1061 |
1061 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { | 1062 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { |
1062 const char *rectName; | 1063 const char *rectName; |
1063 const char *cornerRadiusName; | 1064 const char *cornerRadiusName; |
1064 const char *blurRadiusName; | 1065 const char *blurRadiusName; |
1065 | 1066 |
1066 // The proxy rect has left, top, right, and bottom edges correspond to | 1067 // The proxy rect has left, top, right, and bottom edges correspond to |
1067 // components x, y, z, and w, respectively. | 1068 // components x, y, z, and w, respectively. |
1068 | 1069 |
1069 fProxyRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 1070 fProxyRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, |
1070 kVec4f_GrSLType, | 1071 kVec4f_GrSLType, |
1071 kDefault_GrSLPrecision, | 1072 kDefault_GrSLPrecision, |
1072 "proxyRect", | 1073 "proxyRect", |
1073 &rectName); | 1074 &rectName); |
1074 fCornerRadiusUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragme
nt_Visibility, | 1075 fCornerRadiusUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFrag
ment_Visibility, |
1075 kFloat_GrSLType, | 1076 kFloat_GrSLType, |
1076 kDefault_GrSLPrecision, | 1077 kDefault_GrSLPrecision, |
1077 "cornerRadius", | 1078 "cornerRadius", |
1078 &cornerRadiusName); | 1079 &cornerRadiusName); |
1079 fBlurRadiusUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 1080 fBlurRadiusUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
1080 kFloat_GrSLType, | 1081 kFloat_GrSLType, |
1081 kDefault_GrSLPrecision, | 1082 kDefault_GrSLPrecision, |
1082 "blurRadius", | 1083 "blurRadius", |
1083 &blurRadiusName); | 1084 &blurRadiusName); |
1084 | 1085 |
1085 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 1086 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
1086 const char* fragmentPos = fsBuilder->fragmentPosition(); | 1087 const char* fragmentPos = fsBuilder->fragmentPosition(); |
1087 | 1088 |
1088 // warp the fragment position to the appropriate part of the 9patch blur tex
ture | 1089 // warp the fragment position to the appropriate part of the 9patch blur tex
ture |
1089 | 1090 |
1090 fsBuilder->codeAppendf("vec2 rectCenter = (%s.xy + %s.zw)/2.0;", rectName, r
ectName); | 1091 fsBuilder->codeAppendf("vec2 rectCenter = (%s.xy + %s.zw)/2.0;", rectName, r
ectName); |
1091 fsBuilder->codeAppendf("vec2 translatedFragPos = %s.xy - %s.xy;", fragmentPo
s, rectName); | 1092 fsBuilder->codeAppendf("vec2 translatedFragPos = %s.xy - %s.xy;", fragmentPo
s, rectName); |
1092 fsBuilder->codeAppendf("float threshold = %s + 2.0*%s;", cornerRadiusName, b
lurRadiusName); | 1093 fsBuilder->codeAppendf("float threshold = %s + 2.0*%s;", cornerRadiusName, b
lurRadiusName); |
1093 fsBuilder->codeAppendf("vec2 middle = %s.zw - %s.xy - 2.0*threshold;", rectN
ame, rectName); | 1094 fsBuilder->codeAppendf("vec2 middle = %s.zw - %s.xy - 2.0*threshold;", rectN
ame, rectName); |
1094 | 1095 |
1095 fsBuilder->codeAppendf("if (translatedFragPos.x >= threshold && translatedFr
agPos.x < (middle.x+threshold)) {"); | 1096 fsBuilder->codeAppendf("if (translatedFragPos.x >= threshold && translatedFr
agPos.x < (middle.x+threshold)) {"); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 } else { | 1301 } else { |
1301 str->append("None"); | 1302 str->append("None"); |
1302 } | 1303 } |
1303 str->append("))"); | 1304 str->append("))"); |
1304 } | 1305 } |
1305 #endif | 1306 #endif |
1306 | 1307 |
1307 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1308 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1308 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1309 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1309 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1310 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |