OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBlurMaskFilter.h" | 8 #include "SkBlurMaskFilter.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkGpuBlurUtils.h" | 10 #include "SkGpuBlurUtils.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "GrContext.h" | 21 #include "GrContext.h" |
22 #include "GrDrawContext.h" | 22 #include "GrDrawContext.h" |
23 #include "GrTexture.h" | 23 #include "GrTexture.h" |
24 #include "GrFragmentProcessor.h" | 24 #include "GrFragmentProcessor.h" |
25 #include "GrInvariantOutput.h" | 25 #include "GrInvariantOutput.h" |
26 #include "SkDraw.h" | 26 #include "SkDraw.h" |
27 #include "effects/GrSimpleTextureEffect.h" | 27 #include "effects/GrSimpleTextureEffect.h" |
28 #include "glsl/GrGLSLFragmentProcessor.h" | 28 #include "glsl/GrGLSLFragmentProcessor.h" |
29 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 29 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
30 #include "glsl/GrGLSLProgramDataManager.h" | 30 #include "glsl/GrGLSLProgramDataManager.h" |
31 #include "glsl/GrGLSLTextureSampler.h" | 31 #include "glsl/GrGLSLSampler.h" |
32 #include "glsl/GrGLSLUniformHandler.h" | 32 #include "glsl/GrGLSLUniformHandler.h" |
33 #endif | 33 #endif |
34 | 34 |
35 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { | 35 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { |
36 return SkBlurMask::ConvertRadiusToSigma(radius); | 36 return SkBlurMask::ConvertRadiusToSigma(radius); |
37 } | 37 } |
38 | 38 |
39 class SkBlurMaskFilterImpl : public SkMaskFilter { | 39 class SkBlurMaskFilterImpl : public SkMaskFilter { |
40 public: | 40 public: |
41 SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags); | 41 SkBlurMaskFilterImpl(SkScalar sigma, SkBlurStyle, uint32_t flags); |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 private: | 684 private: |
685 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 685 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
686 | 686 |
687 UniformHandle fProxyRectUniform; | 687 UniformHandle fProxyRectUniform; |
688 UniformHandle fProfileSizeUniform; | 688 UniformHandle fProfileSizeUniform; |
689 | 689 |
690 typedef GrGLSLFragmentProcessor INHERITED; | 690 typedef GrGLSLFragmentProcessor INHERITED; |
691 }; | 691 }; |
692 | 692 |
693 void OutputRectBlurProfileLookup(GrGLSLFPFragmentBuilder* fragBuilder, | 693 void OutputRectBlurProfileLookup(GrGLSLFPFragmentBuilder* fragBuilder, |
694 const GrGLSLTextureSampler& sampler, | 694 const GrGLSLSampler& sampler, |
695 const char *output, | 695 const char *output, |
696 const char *profileSize, const char *loc, | 696 const char *profileSize, const char *loc, |
697 const char *blurred_width, | 697 const char *blurred_width, |
698 const char *sharp_width) { | 698 const char *sharp_width) { |
699 fragBuilder->codeAppendf("float %s;", output); | 699 fragBuilder->codeAppendf("float %s;", output); |
700 fragBuilder->codeAppendf("{"); | 700 fragBuilder->codeAppendf("{"); |
701 fragBuilder->codeAppendf("float coord = ((abs(%s - 0.5 * %s) - 0.5 * %s)) /
%s;", | 701 fragBuilder->codeAppendf("float coord = ((abs(%s - 0.5 * %s) - 0.5 * %s)) /
%s;", |
702 loc, blurred_width, sharp_width, profileSize); | 702 loc, blurred_width, sharp_width, profileSize); |
703 fragBuilder->codeAppendf("%s = ", output); | 703 fragBuilder->codeAppendf("%s = ", output); |
704 fragBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)"); | 704 fragBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)"); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 rectName); | 748 rectName); |
749 fragBuilder->codeAppendf("%s float width = %s.z - %s.x;", precisionString, r
ectName, rectName); | 749 fragBuilder->codeAppendf("%s float width = %s.z - %s.x;", precisionString, r
ectName, rectName); |
750 fragBuilder->codeAppendf("%s float height = %s.w - %s.y;", precisionString,
rectName, rectName); | 750 fragBuilder->codeAppendf("%s float height = %s.w - %s.y;", precisionString,
rectName, rectName); |
751 | 751 |
752 fragBuilder->codeAppendf("%s vec2 smallDims = vec2(width - %s, height - %s);
", precisionString, | 752 fragBuilder->codeAppendf("%s vec2 smallDims = vec2(width - %s, height - %s);
", precisionString, |
753 profileSizeName, profileSizeName); | 753 profileSizeName, profileSizeName); |
754 fragBuilder->codeAppendf("%s float center = 2.0 * floor(%s/2.0 + .25) - 1.0;
", precisionString, | 754 fragBuilder->codeAppendf("%s float center = 2.0 * floor(%s/2.0 + .25) - 1.0;
", precisionString, |
755 profileSizeName); | 755 profileSizeName); |
756 fragBuilder->codeAppendf("%s vec2 wh = smallDims - vec2(center,center);", pr
ecisionString); | 756 fragBuilder->codeAppendf("%s vec2 wh = smallDims - vec2(center,center);", pr
ecisionString); |
757 | 757 |
758 OutputRectBlurProfileLookup(fragBuilder, args.fSamplers[0], "horiz_lookup",
profileSizeName, | 758 OutputRectBlurProfileLookup(fragBuilder, args.fTexSamplers[0], "horiz_lookup
", profileSizeName, |
759 "translatedPos.x", "width", "wh.x"); | 759 "translatedPos.x", "width", "wh.x"); |
760 OutputRectBlurProfileLookup(fragBuilder, args.fSamplers[0], "vert_lookup", p
rofileSizeName, | 760 OutputRectBlurProfileLookup(fragBuilder, args.fTexSamplers[0], "vert_lookup"
, profileSizeName, |
761 "translatedPos.y", "height", "wh.y"); | 761 "translatedPos.y", "height", "wh.y"); |
762 | 762 |
763 fragBuilder->codeAppendf("float final = horiz_lookup * vert_lookup;"); | 763 fragBuilder->codeAppendf("float final = horiz_lookup * vert_lookup;"); |
764 fragBuilder->codeAppendf("%s = src * final;", args.fOutputColor); | 764 fragBuilder->codeAppendf("%s = src * final;", args.fOutputColor); |
765 } | 765 } |
766 | 766 |
767 void GrGLRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 767 void GrGLRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
768 const GrProcessor& proc) { | 768 const GrProcessor& proc) { |
769 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); | 769 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); |
770 SkRect rect = rbe.getRect(); | 770 SkRect rect = rbe.getRect(); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 "if (translatedFragPos.y > threshold && translatedFragPos.y < (middl
e.y+threshold)) {"); | 1107 "if (translatedFragPos.y > threshold && translatedFragPos.y < (middl
e.y+threshold)) {"); |
1108 fragBuilder->codeAppendf("translatedFragPos.y = threshold;"); | 1108 fragBuilder->codeAppendf("translatedFragPos.y = threshold;"); |
1109 fragBuilder->codeAppendf("} else if (translatedFragPos.y >= (middle.y + thre
shold)) {"); | 1109 fragBuilder->codeAppendf("} else if (translatedFragPos.y >= (middle.y + thre
shold)) {"); |
1110 fragBuilder->codeAppendf("translatedFragPos.y -= middle.y - 1.0;"); | 1110 fragBuilder->codeAppendf("translatedFragPos.y -= middle.y - 1.0;"); |
1111 fragBuilder->codeAppendf("}"); | 1111 fragBuilder->codeAppendf("}"); |
1112 | 1112 |
1113 fragBuilder->codeAppendf("vec2 proxyDims = vec2(2.0*threshold+1.0);"); | 1113 fragBuilder->codeAppendf("vec2 proxyDims = vec2(2.0*threshold+1.0);"); |
1114 fragBuilder->codeAppendf("vec2 texCoord = translatedFragPos / proxyDims;"); | 1114 fragBuilder->codeAppendf("vec2 texCoord = translatedFragPos / proxyDims;"); |
1115 | 1115 |
1116 fragBuilder->codeAppendf("%s = ", args.fOutputColor); | 1116 fragBuilder->codeAppendf("%s = ", args.fOutputColor); |
1117 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers
[0], "texCoord"); | 1117 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fTexSampl
ers[0], "texCoord"); |
1118 fragBuilder->codeAppend(";"); | 1118 fragBuilder->codeAppend(";"); |
1119 } | 1119 } |
1120 | 1120 |
1121 void GrGLRRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 1121 void GrGLRRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
1122 const GrProcessor& proc) { | 1122 const GrProcessor& proc) { |
1123 const GrRRectBlurEffect& brre = proc.cast<GrRRectBlurEffect>(); | 1123 const GrRRectBlurEffect& brre = proc.cast<GrRRectBlurEffect>(); |
1124 const SkRRect& rrect = brre.getRRect(); | 1124 const SkRRect& rrect = brre.getRRect(); |
1125 | 1125 |
1126 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f); | 1126 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f); |
1127 pdman.set1f(fBlurRadiusUniform, blurRadius); | 1127 pdman.set1f(fBlurRadiusUniform, blurRadius); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 } else { | 1309 } else { |
1310 str->append("None"); | 1310 str->append("None"); |
1311 } | 1311 } |
1312 str->append("))"); | 1312 str->append("))"); |
1313 } | 1313 } |
1314 #endif | 1314 #endif |
1315 | 1315 |
1316 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1316 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1317 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1317 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1318 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1318 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |