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 11 matching lines...) Expand all Loading... |
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 "gl/builders/GrGLProgramBuilder.h" |
| 32 #include "glsl/GrGLSLProgramDataManager.h" |
32 #endif | 33 #endif |
33 | 34 |
34 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { | 35 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { |
35 return SkBlurMask::ConvertRadiusToSigma(radius); | 36 return SkBlurMask::ConvertRadiusToSigma(radius); |
36 } | 37 } |
37 | 38 |
38 class SkBlurMaskFilterImpl : public SkMaskFilter { | 39 class SkBlurMaskFilterImpl : public SkMaskFilter { |
39 public: | 40 public: |
40 SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags); | 41 SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags); |
41 | 42 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 class GrGLRectBlurEffect : public GrGLFragmentProcessor { | 676 class GrGLRectBlurEffect : public GrGLFragmentProcessor { |
676 public: | 677 public: |
677 GrGLRectBlurEffect(const GrProcessor&, GrSLPrecision precision) | 678 GrGLRectBlurEffect(const GrProcessor&, GrSLPrecision precision) |
678 : fPrecision(precision) { | 679 : fPrecision(precision) { |
679 } | 680 } |
680 void emitCode(EmitArgs&) override; | 681 void emitCode(EmitArgs&) override; |
681 | 682 |
682 static void GenKey(GrSLPrecision precision, GrProcessorKeyBuilder* b); | 683 static void GenKey(GrSLPrecision precision, GrProcessorKeyBuilder* b); |
683 | 684 |
684 protected: | 685 protected: |
685 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 686 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
686 | 687 |
687 private: | 688 private: |
688 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 689 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
689 | 690 |
690 UniformHandle fProxyRectUniform; | 691 UniformHandle fProxyRectUniform; |
691 UniformHandle fProfileSizeUniform; | 692 UniformHandle fProfileSizeUniform; |
692 GrSLPrecision fPrecision; | 693 GrSLPrecision fPrecision; |
693 | 694 |
694 typedef GrGLFragmentProcessor INHERITED; | 695 typedef GrGLFragmentProcessor INHERITED; |
695 }; | 696 }; |
696 | 697 |
697 void OutputRectBlurProfileLookup(GrGLFragmentBuilder* fsBuilder, | 698 void OutputRectBlurProfileLookup(GrGLFragmentBuilder* fsBuilder, |
698 const GrGLShaderBuilder::TextureSampler& sample
r, | 699 const GrGLShaderBuilder::TextureSampler& sample
r, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 | 757 |
757 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "horiz_lookup", pr
ofileSizeName, | 758 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "horiz_lookup", pr
ofileSizeName, |
758 "translatedPos.x", "width", "wh.x"); | 759 "translatedPos.x", "width", "wh.x"); |
759 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "vert_lookup", pro
fileSizeName, | 760 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "vert_lookup", pro
fileSizeName, |
760 "translatedPos.y", "height", "wh.y"); | 761 "translatedPos.y", "height", "wh.y"); |
761 | 762 |
762 fsBuilder->codeAppendf("float final = horiz_lookup * vert_lookup;"); | 763 fsBuilder->codeAppendf("float final = horiz_lookup * vert_lookup;"); |
763 fsBuilder->codeAppendf("%s = src * final;", args.fOutputColor); | 764 fsBuilder->codeAppendf("%s = src * final;", args.fOutputColor); |
764 } | 765 } |
765 | 766 |
766 void GrGLRectBlurEffect::onSetData(const GrGLProgramDataManager& pdman, | 767 void GrGLRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
767 const GrProcessor& proc) { | 768 const GrProcessor& proc) { |
768 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); | 769 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); |
769 SkRect rect = rbe.getRect(); | 770 SkRect rect = rbe.getRect(); |
770 | 771 |
771 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot
tom); | 772 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot
tom); |
772 pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); | 773 pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); |
773 } | 774 } |
774 | 775 |
775 GrTexture* GrRectBlurEffect::CreateBlurProfileTexture(GrTextureProvider* texture
Provider, | 776 GrTexture* GrRectBlurEffect::CreateBlurProfileTexture(GrTextureProvider* texture
Provider, |
776 float sigma) { | 777 float sigma) { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 | 1041 |
1041 ////////////////////////////////////////////////////////////////////////////// | 1042 ////////////////////////////////////////////////////////////////////////////// |
1042 | 1043 |
1043 class GrGLRRectBlurEffect : public GrGLFragmentProcessor { | 1044 class GrGLRRectBlurEffect : public GrGLFragmentProcessor { |
1044 public: | 1045 public: |
1045 GrGLRRectBlurEffect(const GrProcessor&) {} | 1046 GrGLRRectBlurEffect(const GrProcessor&) {} |
1046 | 1047 |
1047 virtual void emitCode(EmitArgs&) override; | 1048 virtual void emitCode(EmitArgs&) override; |
1048 | 1049 |
1049 protected: | 1050 protected: |
1050 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 1051 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
1051 | 1052 |
1052 private: | 1053 private: |
1053 GrGLProgramDataManager::UniformHandle fProxyRectUniform; | 1054 GrGLSLProgramDataManager::UniformHandle fProxyRectUniform; |
1054 GrGLProgramDataManager::UniformHandle fCornerRadiusUniform; | 1055 GrGLSLProgramDataManager::UniformHandle fCornerRadiusUniform; |
1055 GrGLProgramDataManager::UniformHandle fBlurRadiusUniform; | 1056 GrGLSLProgramDataManager::UniformHandle fBlurRadiusUniform; |
1056 typedef GrGLFragmentProcessor INHERITED; | 1057 typedef GrGLFragmentProcessor INHERITED; |
1057 }; | 1058 }; |
1058 | 1059 |
1059 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { | 1060 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { |
1060 const char *rectName; | 1061 const char *rectName; |
1061 const char *cornerRadiusName; | 1062 const char *cornerRadiusName; |
1062 const char *blurRadiusName; | 1063 const char *blurRadiusName; |
1063 | 1064 |
1064 // The proxy rect has left, top, right, and bottom edges correspond to | 1065 // The proxy rect has left, top, right, and bottom edges correspond to |
1065 // components x, y, z, and w, respectively. | 1066 // components x, y, z, and w, respectively. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 fsBuilder->codeAppendf("}"); | 1104 fsBuilder->codeAppendf("}"); |
1104 | 1105 |
1105 fsBuilder->codeAppendf("vec2 proxyDims = vec2(2.0*threshold+1.0);"); | 1106 fsBuilder->codeAppendf("vec2 proxyDims = vec2(2.0*threshold+1.0);"); |
1106 fsBuilder->codeAppendf("vec2 texCoord = translatedFragPos / proxyDims;"); | 1107 fsBuilder->codeAppendf("vec2 texCoord = translatedFragPos / proxyDims;"); |
1107 | 1108 |
1108 fsBuilder->codeAppendf("%s = ", args.fOutputColor); | 1109 fsBuilder->codeAppendf("%s = ", args.fOutputColor); |
1109 fsBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers[0
], "texCoord"); | 1110 fsBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers[0
], "texCoord"); |
1110 fsBuilder->codeAppend(";"); | 1111 fsBuilder->codeAppend(";"); |
1111 } | 1112 } |
1112 | 1113 |
1113 void GrGLRRectBlurEffect::onSetData(const GrGLProgramDataManager& pdman, | 1114 void GrGLRRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
1114 const GrProcessor& proc) { | 1115 const GrProcessor& proc) { |
1115 const GrRRectBlurEffect& brre = proc.cast<GrRRectBlurEffect>(); | 1116 const GrRRectBlurEffect& brre = proc.cast<GrRRectBlurEffect>(); |
1116 SkRRect rrect = brre.getRRect(); | 1117 SkRRect rrect = brre.getRRect(); |
1117 | 1118 |
1118 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f); | 1119 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f); |
1119 pdman.set1f(fBlurRadiusUniform, blurRadius); | 1120 pdman.set1f(fBlurRadiusUniform, blurRadius); |
1120 | 1121 |
1121 SkRect rect = rrect.getBounds(); | 1122 SkRect rect = rrect.getBounds(); |
1122 rect.outset(blurRadius, blurRadius); | 1123 rect.outset(blurRadius, blurRadius); |
1123 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot
tom); | 1124 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot
tom); |
1124 | 1125 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 } else { | 1299 } else { |
1299 str->append("None"); | 1300 str->append("None"); |
1300 } | 1301 } |
1301 str->append("))"); | 1302 str->append("))"); |
1302 } | 1303 } |
1303 #endif | 1304 #endif |
1304 | 1305 |
1305 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1306 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1306 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1307 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1307 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1308 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |