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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 603 |
604 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 604 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
605 | 605 |
606 typedef GrFragmentProcessor INHERITED; | 606 typedef GrFragmentProcessor INHERITED; |
607 }; | 607 }; |
608 | 608 |
609 class GrGLRectBlurEffect : public GrGLFragmentProcessor { | 609 class GrGLRectBlurEffect : public GrGLFragmentProcessor { |
610 public: | 610 public: |
611 GrGLRectBlurEffect(const GrBackendProcessorFactory& factory, | 611 GrGLRectBlurEffect(const GrBackendProcessorFactory& factory, |
612 const GrProcessor&); | 612 const GrProcessor&); |
613 virtual void emitCode(GrGLProgramBuilder*, | 613 virtual void emitCode(GrGLFPBuilder*, |
614 const GrFragmentProcessor&, | 614 const GrFragmentProcessor&, |
615 const GrProcessorKey&, | 615 const GrProcessorKey&, |
616 const char* outputColor, | 616 const char* outputColor, |
617 const char* inputColor, | 617 const char* inputColor, |
618 const TransformedCoordsArray&, | 618 const TransformedCoordsArray&, |
619 const TextureSamplerArray&) SK_OVERRIDE; | 619 const TextureSamplerArray&) SK_OVERRIDE; |
620 | 620 |
621 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 621 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
622 | 622 |
623 private: | 623 private: |
624 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 624 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
625 | 625 |
626 UniformHandle fProxyRectUniform; | 626 UniformHandle fProxyRectUniform; |
627 UniformHandle fProfileSizeUniform; | 627 UniformHandle fProfileSizeUniform; |
628 | 628 |
629 typedef GrGLFragmentProcessor INHERITED; | 629 typedef GrGLFragmentProcessor INHERITED; |
630 }; | 630 }; |
631 | 631 |
632 | 632 |
633 | 633 |
634 GrGLRectBlurEffect::GrGLRectBlurEffect(const GrBackendProcessorFactory& factory,
const GrProcessor&) | 634 GrGLRectBlurEffect::GrGLRectBlurEffect(const GrBackendProcessorFactory& factory,
const GrProcessor&) |
635 : INHERITED(factory) { | 635 : INHERITED(factory) { |
636 } | 636 } |
637 | 637 |
638 void OutputRectBlurProfileLookup(GrGLFragmentShaderBuilder* fsBuilder, | 638 void OutputRectBlurProfileLookup(GrGLFPFragmentBuilder* fsBuilder, |
639 const GrGLShaderBuilder::TextureSampler& sample
r, | 639 const GrGLShaderBuilder::TextureSampler& sample
r, |
640 const char *output, | 640 const char *output, |
641 const char *profileSize, const char *loc, | 641 const char *profileSize, const char *loc, |
642 const char *blurred_width, | 642 const char *blurred_width, |
643 const char *sharp_width) { | 643 const char *sharp_width) { |
644 fsBuilder->codeAppendf("\tfloat %s;\n", output); | 644 fsBuilder->codeAppendf("\tfloat %s;\n", output); |
645 fsBuilder->codeAppendf("\t\t{\n"); | 645 fsBuilder->codeAppendf("\t\t{\n"); |
646 fsBuilder->codeAppendf("\t\t\tfloat coord = (0.5 * (abs(2.0*%s - %s) - %s))/
%s;\n", | 646 fsBuilder->codeAppendf("\t\t\tfloat coord = (0.5 * (abs(2.0*%s - %s) - %s))/
%s;\n", |
647 loc, blurred_width, sharp_width, profileSize); | 647 loc, blurred_width, sharp_width, profileSize); |
648 fsBuilder->codeAppendf("\t\t\t%s = ", output); | 648 fsBuilder->codeAppendf("\t\t\t%s = ", output); |
649 fsBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)"); | 649 fsBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)"); |
650 fsBuilder->codeAppend(".a;\n"); | 650 fsBuilder->codeAppend(".a;\n"); |
651 fsBuilder->codeAppendf("\t\t}\n"); | 651 fsBuilder->codeAppendf("\t\t}\n"); |
652 } | 652 } |
653 | 653 |
654 void GrGLRectBlurEffect::emitCode(GrGLProgramBuilder* builder, | 654 void GrGLRectBlurEffect::emitCode(GrGLFPBuilder* builder, |
655 const GrFragmentProcessor&, | 655 const GrFragmentProcessor&, |
656 const GrProcessorKey& key, | 656 const GrProcessorKey& key, |
657 const char* outputColor, | 657 const char* outputColor, |
658 const char* inputColor, | 658 const char* inputColor, |
659 const TransformedCoordsArray& coords, | 659 const TransformedCoordsArray& coords, |
660 const TextureSamplerArray& samplers) { | 660 const TextureSamplerArray& samplers) { |
661 | 661 |
662 const char *rectName; | 662 const char *rectName; |
663 const char *profileSizeName; | 663 const char *profileSizeName; |
664 | 664 |
665 fProxyRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 665 fProxyRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
666 kVec4f_GrSLType, | 666 kVec4f_GrSLType, |
667 "proxyRect", | 667 "proxyRect", |
668 &rectName); | 668 &rectName); |
669 fProfileSizeUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visi
bility, | 669 fProfileSizeUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visi
bility, |
670 kFloat_GrSLType, | 670 kFloat_GrSLType, |
671 "profileSize", | 671 "profileSize", |
672 &profileSizeName); | 672 &profileSizeName); |
673 | 673 |
674 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 674 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
675 const char *fragmentPos = fsBuilder->fragmentPosition(); | 675 const char *fragmentPos = fsBuilder->fragmentPosition(); |
676 | 676 |
677 if (inputColor) { | 677 if (inputColor) { |
678 fsBuilder->codeAppendf("\tvec4 src=%s;\n", inputColor); | 678 fsBuilder->codeAppendf("\tvec4 src=%s;\n", inputColor); |
679 } else { | 679 } else { |
680 fsBuilder->codeAppendf("\tvec4 src=vec4(1)\n;"); | 680 fsBuilder->codeAppendf("\tvec4 src=vec4(1)\n;"); |
681 } | 681 } |
682 | 682 |
683 fsBuilder->codeAppendf("\tvec2 translatedPos = %s.xy - %s.xy;\n", fragmentPo
s, rectName ); | 683 fsBuilder->codeAppendf("\tvec2 translatedPos = %s.xy - %s.xy;\n", fragmentPo
s, rectName ); |
684 fsBuilder->codeAppendf("\tfloat width = %s.z - %s.x;\n", rectName, rectName)
; | 684 fsBuilder->codeAppendf("\tfloat width = %s.z - %s.x;\n", rectName, rectName)
; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); | 967 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); |
968 return GrRRectBlurEffect::Create(context, sigma, rrect); | 968 return GrRRectBlurEffect::Create(context, sigma, rrect); |
969 } | 969 } |
970 | 970 |
971 ////////////////////////////////////////////////////////////////////////////// | 971 ////////////////////////////////////////////////////////////////////////////// |
972 | 972 |
973 class GrGLRRectBlurEffect : public GrGLFragmentProcessor { | 973 class GrGLRRectBlurEffect : public GrGLFragmentProcessor { |
974 public: | 974 public: |
975 GrGLRRectBlurEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 975 GrGLRRectBlurEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
976 | 976 |
977 virtual void emitCode(GrGLProgramBuilder*, | 977 virtual void emitCode(GrGLFPBuilder*, |
978 const GrFragmentProcessor&, | 978 const GrFragmentProcessor&, |
979 const GrProcessorKey&, | 979 const GrProcessorKey&, |
980 const char* outputColor, | 980 const char* outputColor, |
981 const char* inputColor, | 981 const char* inputColor, |
982 const TransformedCoordsArray&, | 982 const TransformedCoordsArray&, |
983 const TextureSamplerArray&) SK_OVERRIDE; | 983 const TextureSamplerArray&) SK_OVERRIDE; |
984 | 984 |
985 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 985 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
986 | 986 |
987 private: | 987 private: |
988 GrGLProgramDataManager::UniformHandle fProxyRectUniform; | 988 GrGLProgramDataManager::UniformHandle fProxyRectUniform; |
989 GrGLProgramDataManager::UniformHandle fCornerRadiusUniform; | 989 GrGLProgramDataManager::UniformHandle fCornerRadiusUniform; |
990 GrGLProgramDataManager::UniformHandle fBlurRadiusUniform; | 990 GrGLProgramDataManager::UniformHandle fBlurRadiusUniform; |
991 typedef GrGLFragmentProcessor INHERITED; | 991 typedef GrGLFragmentProcessor INHERITED; |
992 }; | 992 }; |
993 | 993 |
994 GrGLRRectBlurEffect::GrGLRRectBlurEffect(const GrBackendProcessorFactory& factor
y, | 994 GrGLRRectBlurEffect::GrGLRRectBlurEffect(const GrBackendProcessorFactory& factor
y, |
995 const GrProcessor&) | 995 const GrProcessor&) |
996 : INHERITED (factory) { | 996 : INHERITED (factory) { |
997 } | 997 } |
998 | 998 |
999 void GrGLRRectBlurEffect::emitCode(GrGLProgramBuilder* builder, | 999 void GrGLRRectBlurEffect::emitCode(GrGLFPBuilder* builder, |
1000 const GrFragmentProcessor&, | 1000 const GrFragmentProcessor&, |
1001 const GrProcessorKey&, | 1001 const GrProcessorKey&, |
1002 const char* outputColor, | 1002 const char* outputColor, |
1003 const char* inputColor, | 1003 const char* inputColor, |
1004 const TransformedCoordsArray&, | 1004 const TransformedCoordsArray&, |
1005 const TextureSamplerArray& samplers) { | 1005 const TextureSamplerArray& samplers) { |
1006 const char *rectName; | 1006 const char *rectName; |
1007 const char *cornerRadiusName; | 1007 const char *cornerRadiusName; |
1008 const char *blurRadiusName; | 1008 const char *blurRadiusName; |
1009 | 1009 |
1010 // The proxy rect has left, top, right, and bottom edges correspond to | 1010 // The proxy rect has left, top, right, and bottom edges correspond to |
1011 // components x, y, z, and w, respectively. | 1011 // components x, y, z, and w, respectively. |
1012 | 1012 |
1013 fProxyRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 1013 fProxyRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
1014 kVec4f_GrSLType, | 1014 kVec4f_GrSLType, |
1015 "proxyRect", | 1015 "proxyRect", |
1016 &rectName); | 1016 &rectName); |
1017 fCornerRadiusUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 1017 fCornerRadiusUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
1018 kFloat_GrSLType, | 1018 kFloat_GrSLType, |
1019 "cornerRadius", | 1019 "cornerRadius", |
1020 &cornerRadiusName); | 1020 &cornerRadiusName); |
1021 fBlurRadiusUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 1021 fBlurRadiusUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
1022 kFloat_GrSLType, | 1022 kFloat_GrSLType, |
1023 "blurRadius", | 1023 "blurRadius", |
1024 &blurRadiusName); | 1024 &blurRadiusName); |
1025 | 1025 |
1026 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1026 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1027 const char* fragmentPos = fsBuilder->fragmentPosition(); | 1027 const char* fragmentPos = fsBuilder->fragmentPosition(); |
1028 | 1028 |
1029 // warp the fragment position to the appropriate part of the 9patch blur tex
ture | 1029 // warp the fragment position to the appropriate part of the 9patch blur tex
ture |
1030 | 1030 |
1031 fsBuilder->codeAppendf("\t\tvec2 rectCenter = (%s.xy + %s.zw)/2.0;\n", rectN
ame, rectName); | 1031 fsBuilder->codeAppendf("\t\tvec2 rectCenter = (%s.xy + %s.zw)/2.0;\n", rectN
ame, rectName); |
1032 fsBuilder->codeAppendf("\t\tvec2 translatedFragPos = %s.xy - %s.xy;\n", frag
mentPos, rectName); | 1032 fsBuilder->codeAppendf("\t\tvec2 translatedFragPos = %s.xy - %s.xy;\n", frag
mentPos, rectName); |
1033 fsBuilder->codeAppendf("\t\tfloat threshold = %s + 2.0*%s;\n", cornerRadiusN
ame, blurRadiusName ); | 1033 fsBuilder->codeAppendf("\t\tfloat threshold = %s + 2.0*%s;\n", cornerRadiusN
ame, blurRadiusName ); |
1034 fsBuilder->codeAppendf("\t\tvec2 middle = %s.zw - %s.xy - 2.0*threshold;\n",
rectName, rectName ); | 1034 fsBuilder->codeAppendf("\t\tvec2 middle = %s.zw - %s.xy - 2.0*threshold;\n",
rectName, rectName ); |
1035 | 1035 |
1036 fsBuilder->codeAppendf("\t\tif (translatedFragPos.x >= threshold && translat
edFragPos.x < (middle.x+threshold)) {\n" ); | 1036 fsBuilder->codeAppendf("\t\tif (translatedFragPos.x >= threshold && translat
edFragPos.x < (middle.x+threshold)) {\n" ); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 } else { | 1220 } else { |
1221 str->append("None"); | 1221 str->append("None"); |
1222 } | 1222 } |
1223 str->append("))"); | 1223 str->append("))"); |
1224 } | 1224 } |
1225 #endif | 1225 #endif |
1226 | 1226 |
1227 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1227 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1228 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1228 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1229 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1229 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |