| 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" |
| 11 #include "SkGpuBlurUtils.h" | 11 #include "SkGpuBlurUtils.h" |
| 12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
| 14 #include "SkMaskFilter.h" | 14 #include "SkMaskFilter.h" |
| 15 #include "SkRRect.h" | 15 #include "SkRRect.h" |
| 16 #include "SkRTConf.h" | 16 #include "SkRTConf.h" |
| 17 #include "SkStringUtils.h" | 17 #include "SkStringUtils.h" |
| 18 #include "SkStrokeRec.h" | 18 #include "SkStrokeRec.h" |
| 19 | 19 |
| 20 #if SK_SUPPORT_GPU | 20 #if SK_SUPPORT_GPU |
| 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 "glsl/GrGLSLFragmentProcessor.h" |
| 31 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 31 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 32 #include "glsl/GrGLSLProgramBuilder.h" | 32 #include "glsl/GrGLSLProgramBuilder.h" |
| 33 #include "glsl/GrGLSLProgramDataManager.h" | 33 #include "glsl/GrGLSLProgramDataManager.h" |
| 34 #include "glsl/GrGLSLTextureSampler.h" | 34 #include "glsl/GrGLSLTextureSampler.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { | 37 SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { |
| 38 return SkBlurMask::ConvertRadiusToSigma(radius); | 38 return SkBlurMask::ConvertRadiusToSigma(radius); |
| 39 } | 39 } |
| 40 | 40 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 return new GrRectBlurEffect(rect, sigma, blurProfile, precision); | 648 return new GrRectBlurEffect(rect, sigma, blurProfile, precision); |
| 649 } | 649 } |
| 650 | 650 |
| 651 const SkRect& getRect() const { return fRect; } | 651 const SkRect& getRect() const { return fRect; } |
| 652 float getSigma() const { return fSigma; } | 652 float getSigma() const { return fSigma; } |
| 653 | 653 |
| 654 private: | 654 private: |
| 655 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blurProfile, | 655 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blurProfile, |
| 656 GrSLPrecision fPrecision); | 656 GrSLPrecision fPrecision); |
| 657 | 657 |
| 658 GrGLFragmentProcessor* onCreateGLInstance() const override; | 658 GrGLSLFragmentProcessor* onCreateGLInstance() const override; |
| 659 | 659 |
| 660 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 660 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
| 661 | 661 |
| 662 bool onIsEqual(const GrFragmentProcessor&) const override; | 662 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 663 | 663 |
| 664 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 664 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 665 | 665 |
| 666 static GrTexture* CreateBlurProfileTexture(GrTextureProvider*, float sigma); | 666 static GrTexture* CreateBlurProfileTexture(GrTextureProvider*, float sigma); |
| 667 | 667 |
| 668 SkRect fRect; | 668 SkRect fRect; |
| 669 float fSigma; | 669 float fSigma; |
| 670 GrTextureAccess fBlurProfileAccess; | 670 GrTextureAccess fBlurProfileAccess; |
| 671 GrSLPrecision fPrecision; | 671 GrSLPrecision fPrecision; |
| 672 | 672 |
| 673 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 673 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 674 | 674 |
| 675 typedef GrFragmentProcessor INHERITED; | 675 typedef GrFragmentProcessor INHERITED; |
| 676 }; | 676 }; |
| 677 | 677 |
| 678 class GrGLRectBlurEffect : public GrGLFragmentProcessor { | 678 class GrGLRectBlurEffect : public GrGLSLFragmentProcessor { |
| 679 public: | 679 public: |
| 680 GrGLRectBlurEffect(const GrProcessor&, GrSLPrecision precision) | 680 GrGLRectBlurEffect(const GrProcessor&, GrSLPrecision precision) |
| 681 : fPrecision(precision) { | 681 : fPrecision(precision) { |
| 682 } | 682 } |
| 683 void emitCode(EmitArgs&) override; | 683 void emitCode(EmitArgs&) override; |
| 684 | 684 |
| 685 static void GenKey(GrSLPrecision precision, GrProcessorKeyBuilder* b); | 685 static void GenKey(GrSLPrecision precision, GrProcessorKeyBuilder* b); |
| 686 | 686 |
| 687 protected: | 687 protected: |
| 688 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 688 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 689 | 689 |
| 690 private: | 690 private: |
| 691 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 691 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
| 692 | 692 |
| 693 UniformHandle fProxyRectUniform; | 693 UniformHandle fProxyRectUniform; |
| 694 UniformHandle fProfileSizeUniform; | 694 UniformHandle fProfileSizeUniform; |
| 695 GrSLPrecision fPrecision; | 695 GrSLPrecision fPrecision; |
| 696 | 696 |
| 697 typedef GrGLFragmentProcessor INHERITED; | 697 typedef GrGLSLFragmentProcessor INHERITED; |
| 698 }; | 698 }; |
| 699 | 699 |
| 700 void OutputRectBlurProfileLookup(GrGLSLFragmentBuilder* fsBuilder, | 700 void OutputRectBlurProfileLookup(GrGLSLFragmentBuilder* fsBuilder, |
| 701 const GrGLSLTextureSampler& sampler, | 701 const GrGLSLTextureSampler& sampler, |
| 702 const char *output, | 702 const char *output, |
| 703 const char *profileSize, const char *loc, | 703 const char *profileSize, const char *loc, |
| 704 const char *blurred_width, | 704 const char *blurred_width, |
| 705 const char *sharp_width) { | 705 const char *sharp_width) { |
| 706 fsBuilder->codeAppendf("float %s;", output); | 706 fsBuilder->codeAppendf("float %s;", output); |
| 707 fsBuilder->codeAppendf("{"); | 707 fsBuilder->codeAppendf("{"); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 this->initClassID<GrRectBlurEffect>(); | 814 this->initClassID<GrRectBlurEffect>(); |
| 815 this->addTextureAccess(&fBlurProfileAccess); | 815 this->addTextureAccess(&fBlurProfileAccess); |
| 816 this->setWillReadFragmentPosition(); | 816 this->setWillReadFragmentPosition(); |
| 817 } | 817 } |
| 818 | 818 |
| 819 void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 819 void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 820 GrProcessorKeyBuilder* b) const { | 820 GrProcessorKeyBuilder* b) const { |
| 821 GrGLRectBlurEffect::GenKey(fPrecision, b); | 821 GrGLRectBlurEffect::GenKey(fPrecision, b); |
| 822 } | 822 } |
| 823 | 823 |
| 824 GrGLFragmentProcessor* GrRectBlurEffect::onCreateGLInstance() const { | 824 GrGLSLFragmentProcessor* GrRectBlurEffect::onCreateGLInstance() const { |
| 825 return new GrGLRectBlurEffect(*this, fPrecision); | 825 return new GrGLRectBlurEffect(*this, fPrecision); |
| 826 } | 826 } |
| 827 | 827 |
| 828 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 828 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
| 829 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); | 829 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); |
| 830 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); | 830 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); |
| 831 } | 831 } |
| 832 | 832 |
| 833 void GrRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
{ | 833 void GrRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const
{ |
| 834 inout->mulByUnknownSingleComponent(); | 834 inout->mulByUnknownSingleComponent(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 | 905 |
| 906 static const GrFragmentProcessor* Create(GrTextureProvider*, float sigma, co
nst SkRRect&); | 906 static const GrFragmentProcessor* Create(GrTextureProvider*, float sigma, co
nst SkRRect&); |
| 907 | 907 |
| 908 virtual ~GrRRectBlurEffect() {}; | 908 virtual ~GrRRectBlurEffect() {}; |
| 909 const char* name() const override { return "GrRRectBlur"; } | 909 const char* name() const override { return "GrRRectBlur"; } |
| 910 | 910 |
| 911 const SkRRect& getRRect() const { return fRRect; } | 911 const SkRRect& getRRect() const { return fRRect; } |
| 912 float getSigma() const { return fSigma; } | 912 float getSigma() const { return fSigma; } |
| 913 | 913 |
| 914 private: | 914 private: |
| 915 GrGLFragmentProcessor* onCreateGLInstance() const override; | 915 GrGLSLFragmentProcessor* onCreateGLInstance() const override; |
| 916 | 916 |
| 917 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); | 917 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); |
| 918 | 918 |
| 919 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 919 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 920 GrProcessorKeyBuilder* b) const override; | 920 GrProcessorKeyBuilder* b) const override; |
| 921 | 921 |
| 922 bool onIsEqual(const GrFragmentProcessor& other) const override; | 922 bool onIsEqual(const GrFragmentProcessor& other) const override; |
| 923 | 923 |
| 924 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 924 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 925 | 925 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 SkScalar h = d->fRandom->nextRangeScalar(100.f, 1000.f); | 1036 SkScalar h = d->fRandom->nextRangeScalar(100.f, 1000.f); |
| 1037 SkScalar r = d->fRandom->nextRangeF(1.f, 9.f); | 1037 SkScalar r = d->fRandom->nextRangeF(1.f, 9.f); |
| 1038 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); | 1038 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); |
| 1039 SkRRect rrect; | 1039 SkRRect rrect; |
| 1040 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); | 1040 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); |
| 1041 return GrRRectBlurEffect::Create(d->fContext->textureProvider(), sigma, rrec
t); | 1041 return GrRRectBlurEffect::Create(d->fContext->textureProvider(), sigma, rrec
t); |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 ////////////////////////////////////////////////////////////////////////////// | 1044 ////////////////////////////////////////////////////////////////////////////// |
| 1045 | 1045 |
| 1046 class GrGLRRectBlurEffect : public GrGLFragmentProcessor { | 1046 class GrGLRRectBlurEffect : public GrGLSLFragmentProcessor { |
| 1047 public: | 1047 public: |
| 1048 GrGLRRectBlurEffect(const GrProcessor&) {} | 1048 GrGLRRectBlurEffect(const GrProcessor&) {} |
| 1049 | 1049 |
| 1050 virtual void emitCode(EmitArgs&) override; | 1050 virtual void emitCode(EmitArgs&) override; |
| 1051 | 1051 |
| 1052 protected: | 1052 protected: |
| 1053 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 1053 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 1054 | 1054 |
| 1055 private: | 1055 private: |
| 1056 GrGLSLProgramDataManager::UniformHandle fProxyRectUniform; | 1056 GrGLSLProgramDataManager::UniformHandle fProxyRectUniform; |
| 1057 GrGLSLProgramDataManager::UniformHandle fCornerRadiusUniform; | 1057 GrGLSLProgramDataManager::UniformHandle fCornerRadiusUniform; |
| 1058 GrGLSLProgramDataManager::UniformHandle fBlurRadiusUniform; | 1058 GrGLSLProgramDataManager::UniformHandle fBlurRadiusUniform; |
| 1059 typedef GrGLFragmentProcessor INHERITED; | 1059 typedef GrGLSLFragmentProcessor INHERITED; |
| 1060 }; | 1060 }; |
| 1061 | 1061 |
| 1062 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { | 1062 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { |
| 1063 const char *rectName; | 1063 const char *rectName; |
| 1064 const char *cornerRadiusName; | 1064 const char *cornerRadiusName; |
| 1065 const char *blurRadiusName; | 1065 const char *blurRadiusName; |
| 1066 | 1066 |
| 1067 // 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 |
| 1068 // components x, y, z, and w, respectively. | 1068 // components x, y, z, and w, respectively. |
| 1069 | 1069 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 SkScalar radius = 0; | 1128 SkScalar radius = 0; |
| 1129 SkASSERT(rrect.isSimpleCircular() || rrect.isRect()); | 1129 SkASSERT(rrect.isSimpleCircular() || rrect.isRect()); |
| 1130 radius = rrect.getSimpleRadii().fX; | 1130 radius = rrect.getSimpleRadii().fX; |
| 1131 pdman.set1f(fCornerRadiusUniform, radius); | 1131 pdman.set1f(fCornerRadiusUniform, radius); |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 void GrRRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorK
eyBuilder* b) const { | 1134 void GrRRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorK
eyBuilder* b) const { |
| 1135 GrGLRRectBlurEffect::GenKey(*this, caps, b); | 1135 GrGLRRectBlurEffect::GenKey(*this, caps, b); |
| 1136 } | 1136 } |
| 1137 | 1137 |
| 1138 GrGLFragmentProcessor* GrRRectBlurEffect::onCreateGLInstance() const { | 1138 GrGLSLFragmentProcessor* GrRRectBlurEffect::onCreateGLInstance() const { |
| 1139 return new GrGLRRectBlurEffect(*this); | 1139 return new GrGLRRectBlurEffect(*this); |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid
er, | 1142 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid
er, |
| 1143 GrDrawContext* drawContext, | 1143 GrDrawContext* drawContext, |
| 1144 GrPaint* grp, | 1144 GrPaint* grp, |
| 1145 const GrClip& clip, | 1145 const GrClip& clip, |
| 1146 const SkMatrix& viewMatrix, | 1146 const SkMatrix& viewMatrix, |
| 1147 const SkStrokeRec& strokeRec
, | 1147 const SkStrokeRec& strokeRec
, |
| 1148 const SkRRect& rrect) const
{ | 1148 const SkRRect& rrect) const
{ |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 } else { | 1301 } else { |
| 1302 str->append("None"); | 1302 str->append("None"); |
| 1303 } | 1303 } |
| 1304 str->append("))"); | 1304 str->append("))"); |
| 1305 } | 1305 } |
| 1306 #endif | 1306 #endif |
| 1307 | 1307 |
| 1308 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1308 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
| 1309 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1309 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
| 1310 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1310 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |