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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 return nullptr; | 617 return nullptr; |
618 } | 618 } |
619 | 619 |
620 SkAutoTUnref<GrTexture> blurProfile(CreateBlurProfileTexture(textureProv
ider, sigma)); | 620 SkAutoTUnref<GrTexture> blurProfile(CreateBlurProfileTexture(textureProv
ider, sigma)); |
621 if (!blurProfile) { | 621 if (!blurProfile) { |
622 return nullptr; | 622 return nullptr; |
623 } | 623 } |
624 // in OpenGL ES, mediump floats have a minimum range of 2^14. If we have
coordinates bigger | 624 // in OpenGL ES, mediump floats have a minimum range of 2^14. If we have
coordinates bigger |
625 // than that, the shader math will end up with infinities and result in
the blur effect not | 625 // than that, the shader math will end up with infinities and result in
the blur effect not |
626 // working correctly. To avoid this, we switch into highp when the coord
inates are too big. | 626 // working correctly. To avoid this, we switch into highp when the coord
inates are too big. |
627 // As 2^14 is the minimum range but the actual range can be bigger, we m
ight end up | 627 // As 2^14 is the minimum range but the actual range can be bigger, we m
ight end up |
628 // switching to highp sooner than strictly necessary, but most devices t
hat have a bigger | 628 // switching to highp sooner than strictly necessary, but most devices t
hat have a bigger |
629 // range for mediump also have mediump being exactly the same as highp (
e.g. all non-OpenGL | 629 // range for mediump also have mediump being exactly the same as highp (
e.g. all non-OpenGL |
630 // ES devices), and thus incur no additional penalty for the switch. | 630 // ES devices), and thus incur no additional penalty for the switch. |
631 static const SkScalar kMAX_BLUR_COORD = SkIntToScalar(16000); | 631 static const SkScalar kMAX_BLUR_COORD = SkIntToScalar(16000); |
632 GrSLPrecision precision; | 632 GrSLPrecision precision; |
633 if (SkScalarAbs(rect.top()) > kMAX_BLUR_COORD || | 633 if (SkScalarAbs(rect.top()) > kMAX_BLUR_COORD || |
634 SkScalarAbs(rect.left()) > kMAX_BLUR_COORD || | 634 SkScalarAbs(rect.left()) > kMAX_BLUR_COORD || |
635 SkScalarAbs(rect.bottom()) > kMAX_BLUR_COORD || | 635 SkScalarAbs(rect.bottom()) > kMAX_BLUR_COORD || |
636 SkScalarAbs(rect.right()) > kMAX_BLUR_COORD || | 636 SkScalarAbs(rect.right()) > kMAX_BLUR_COORD || |
637 SkScalarAbs(rect.width()) > kMAX_BLUR_COORD || | 637 SkScalarAbs(rect.width()) > kMAX_BLUR_COORD || |
638 SkScalarAbs(rect.height()) > kMAX_BLUR_COORD) { | 638 SkScalarAbs(rect.height()) > kMAX_BLUR_COORD) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 | 737 |
738 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 738 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
739 const char *fragmentPos = fragBuilder->fragmentPosition(); | 739 const char *fragmentPos = fragBuilder->fragmentPosition(); |
740 | 740 |
741 if (args.fInputColor) { | 741 if (args.fInputColor) { |
742 fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); | 742 fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); |
743 } else { | 743 } else { |
744 fragBuilder->codeAppendf("vec4 src=vec4(1);"); | 744 fragBuilder->codeAppendf("vec4 src=vec4(1);"); |
745 } | 745 } |
746 | 746 |
747 fragBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precision
String, fragmentPos, | 747 fragBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precision
String, fragmentPos, |
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.fSamplers[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.fSamplers[0], "vert_lookup", p
rofileSizeName, |
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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 if (!strokeRec.isFillStyle()) { | 1161 if (!strokeRec.isFillStyle()) { |
1162 return false; | 1162 return false; |
1163 } | 1163 } |
1164 | 1164 |
1165 SkScalar xformedSigma = this->computeXformedSigma(viewMatrix); | 1165 SkScalar xformedSigma = this->computeXformedSigma(viewMatrix); |
1166 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); | 1166 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); |
1167 | 1167 |
1168 SkRect proxyRect = rrect.rect(); | 1168 SkRect proxyRect = rrect.rect(); |
1169 proxyRect.outset(extra, extra); | 1169 proxyRect.outset(extra, extra); |
1170 | 1170 |
1171 SkAutoTUnref<const GrFragmentProcessor> fp(GrRRectBlurEffect::Create(texProv
ider, | 1171 SkAutoTUnref<const GrFragmentProcessor> fp(GrRRectBlurEffect::Create(texProv
ider, |
1172 xformed
Sigma, rrect)); | 1172 xformed
Sigma, rrect)); |
1173 if (!fp) { | 1173 if (!fp) { |
1174 return false; | 1174 return false; |
1175 } | 1175 } |
1176 | 1176 |
1177 grp->addCoverageFragmentProcessor(fp); | 1177 grp->addCoverageFragmentProcessor(fp); |
1178 | 1178 |
1179 SkMatrix inverse; | 1179 SkMatrix inverse; |
1180 if (!viewMatrix.invert(&inverse)) { | 1180 if (!viewMatrix.invert(&inverse)) { |
1181 return false; | 1181 return false; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 } else { | 1308 } else { |
1309 str->append("None"); | 1309 str->append("None"); |
1310 } | 1310 } |
1311 str->append("))"); | 1311 str->append("))"); |
1312 } | 1312 } |
1313 #endif | 1313 #endif |
1314 | 1314 |
1315 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1315 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1316 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1316 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1317 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1317 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |