Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/effects/SkBlurMaskFilter.cpp

Issue 1287023009: Added tree structure to GrGLFragmentProcessor, i.e. GL instances (Closed) Base URL: https://skia.googlesource.com/skia@cs3_isequal_nonrecursive
Patch Set: moved onSetData from public to protected, onCreateGLInstance from public to private in subclasses Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkArithmeticMode_gpu.cpp ('k') | src/effects/SkColorCubeFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 #if SK_SUPPORT_GPU 604 #if SK_SUPPORT_GPU
605 605
606 class GrGLRectBlurEffect; 606 class GrGLRectBlurEffect;
607 607
608 class GrRectBlurEffect : public GrFragmentProcessor { 608 class GrRectBlurEffect : public GrFragmentProcessor {
609 public: 609 public:
610 virtual ~GrRectBlurEffect(); 610 virtual ~GrRectBlurEffect();
611 611
612 const char* name() const override { return "RectBlur"; } 612 const char* name() const override { return "RectBlur"; }
613 613
614 GrGLFragmentProcessor* createGLInstance() const override;
615
616 /** 614 /**
617 * Create a simple filter effect with custom bicubic coefficients. 615 * Create a simple filter effect with custom bicubic coefficients.
618 */ 616 */
619 static GrFragmentProcessor* Create(GrTextureProvider *textureProvider, const SkRect& rect, 617 static GrFragmentProcessor* Create(GrTextureProvider *textureProvider, const SkRect& rect,
620 float sigma) { 618 float sigma) {
621 GrTexture *blurProfileTexture = NULL; 619 GrTexture *blurProfileTexture = NULL;
622 int doubleProfileSize = SkScalarCeilToInt(12*sigma); 620 int doubleProfileSize = SkScalarCeilToInt(12*sigma);
623 621
624 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.heigh t()) { 622 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.heigh t()) {
625 // if the blur sigma is too large so the gaussian overlaps the whole 623 // if the blur sigma is too large so the gaussian overlaps the whole
626 // rect in either direction, fall back to CPU path for now. 624 // rect in either direction, fall back to CPU path for now.
627 625
628 return NULL; 626 return NULL;
629 } 627 }
630 628
631 bool createdBlurProfileTexture = CreateBlurProfileTexture( 629 bool createdBlurProfileTexture = CreateBlurProfileTexture(
632 textureProvider, sigma, &blurProfileTexture); 630 textureProvider, sigma, &blurProfileTexture);
633 SkAutoTUnref<GrTexture> hunref(blurProfileTexture); 631 SkAutoTUnref<GrTexture> hunref(blurProfileTexture);
634 if (!createdBlurProfileTexture) { 632 if (!createdBlurProfileTexture) {
635 return NULL; 633 return NULL;
636 } 634 }
637 return SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture)); 635 return SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture));
638 } 636 }
639 637
640 const SkRect& getRect() const { return fRect; } 638 const SkRect& getRect() const { return fRect; }
641 float getSigma() const { return fSigma; } 639 float getSigma() const { return fSigma; }
642 640
643 private: 641 private:
642 GrGLFragmentProcessor* onCreateGLInstance() const override;
643
644 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile); 644 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile);
645 645
646 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, 646 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
647 GrProcessorKeyBuilder* b) const override; 647 GrProcessorKeyBuilder* b) const override;
648 648
649 bool onIsEqual(const GrFragmentProcessor&) const override; 649 bool onIsEqual(const GrFragmentProcessor&) const override;
650 650
651 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 651 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
652 652
653 static bool CreateBlurProfileTexture(GrTextureProvider*, float sigma, 653 static bool CreateBlurProfileTexture(GrTextureProvider*, float sigma,
654 GrTexture **blurProfileTexture); 654 GrTexture **blurProfileTexture);
655 655
656 SkRect fRect; 656 SkRect fRect;
657 float fSigma; 657 float fSigma;
658 GrTextureAccess fBlurProfileAccess; 658 GrTextureAccess fBlurProfileAccess;
659 659
660 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 660 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
661 661
662 typedef GrFragmentProcessor INHERITED; 662 typedef GrFragmentProcessor INHERITED;
663 }; 663 };
664 664
665 class GrGLRectBlurEffect : public GrGLFragmentProcessor { 665 class GrGLRectBlurEffect : public GrGLFragmentProcessor {
666 public: 666 public:
667 GrGLRectBlurEffect(const GrProcessor&) {} 667 GrGLRectBlurEffect(const GrProcessor&) {}
668 virtual void emitCode(EmitArgs&) override; 668 virtual void emitCode(EmitArgs&) override;
669 669
670 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 670 protected:
671 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
671 672
672 private: 673 private:
673 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 674 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
674 675
675 UniformHandle fProxyRectUniform; 676 UniformHandle fProxyRectUniform;
676 UniformHandle fProfileSizeUniform; 677 UniformHandle fProfileSizeUniform;
677 678
678 typedef GrGLFragmentProcessor INHERITED; 679 typedef GrGLFragmentProcessor INHERITED;
679 }; 680 };
680 681
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 730
730 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "horiz_lookup", pr ofileSizeName, 731 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "horiz_lookup", pr ofileSizeName,
731 "translatedPos.x", "width", "wh.x"); 732 "translatedPos.x", "width", "wh.x");
732 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "vert_lookup", pro fileSizeName, 733 OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "vert_lookup", pro fileSizeName,
733 "translatedPos.y", "height", "wh.y"); 734 "translatedPos.y", "height", "wh.y");
734 735
735 fsBuilder->codeAppendf("\tfloat final = horiz_lookup * vert_lookup;\n"); 736 fsBuilder->codeAppendf("\tfloat final = horiz_lookup * vert_lookup;\n");
736 fsBuilder->codeAppendf("\t%s = src * final;\n", args.fOutputColor ); 737 fsBuilder->codeAppendf("\t%s = src * final;\n", args.fOutputColor );
737 } 738 }
738 739
739 void GrGLRectBlurEffect::setData(const GrGLProgramDataManager& pdman, 740 void GrGLRectBlurEffect::onSetData(const GrGLProgramDataManager& pdman,
740 const GrProcessor& proc) { 741 const GrProcessor& proc) {
741 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>(); 742 const GrRectBlurEffect& rbe = proc.cast<GrRectBlurEffect>();
742 SkRect rect = rbe.getRect(); 743 SkRect rect = rbe.getRect();
743 744
744 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot tom); 745 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot tom);
745 pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); 746 pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma()));
746 } 747 }
747 748
748 bool GrRectBlurEffect::CreateBlurProfileTexture(GrTextureProvider* textureProvid er, float sigma, 749 bool GrRectBlurEffect::CreateBlurProfileTexture(GrTextureProvider* textureProvid er, float sigma,
749 GrTexture **blurProfileTexture) { 750 GrTexture **blurProfileTexture) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 } 794 }
794 795
795 GrRectBlurEffect::~GrRectBlurEffect() { 796 GrRectBlurEffect::~GrRectBlurEffect() {
796 } 797 }
797 798
798 void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, 799 void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
799 GrProcessorKeyBuilder* b) const { 800 GrProcessorKeyBuilder* b) const {
800 GrGLRectBlurEffect::GenKey(*this, caps, b); 801 GrGLRectBlurEffect::GenKey(*this, caps, b);
801 } 802 }
802 803
803 GrGLFragmentProcessor* GrRectBlurEffect::createGLInstance() const { 804 GrGLFragmentProcessor* GrRectBlurEffect::onCreateGLInstance() const {
804 return SkNEW_ARGS(GrGLRectBlurEffect, (*this)); 805 return SkNEW_ARGS(GrGLRectBlurEffect, (*this));
805 } 806 }
806 807
807 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 808 bool GrRectBlurEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
808 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); 809 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>();
809 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); 810 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect();
810 } 811 }
811 812
812 void GrRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { 813 void GrRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
813 inout->mulByUnknownSingleComponent(); 814 inout->mulByUnknownSingleComponent();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 public: 874 public:
874 875
875 static GrFragmentProcessor* Create(GrTextureProvider*, float sigma, const Sk RRect&); 876 static GrFragmentProcessor* Create(GrTextureProvider*, float sigma, const Sk RRect&);
876 877
877 virtual ~GrRRectBlurEffect() {}; 878 virtual ~GrRRectBlurEffect() {};
878 const char* name() const override { return "GrRRectBlur"; } 879 const char* name() const override { return "GrRRectBlur"; }
879 880
880 const SkRRect& getRRect() const { return fRRect; } 881 const SkRRect& getRRect() const { return fRRect; }
881 float getSigma() const { return fSigma; } 882 float getSigma() const { return fSigma; }
882 883
883 GrGLFragmentProcessor* createGLInstance() const override; 884 private:
885 GrGLFragmentProcessor* onCreateGLInstance() const override;
884 886
885 private:
886 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); 887 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture);
887 888
888 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, 889 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
889 GrProcessorKeyBuilder* b) const override; 890 GrProcessorKeyBuilder* b) const override;
890 891
891 bool onIsEqual(const GrFragmentProcessor& other) const override; 892 bool onIsEqual(const GrFragmentProcessor& other) const override;
892 893
893 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 894 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
894 895
895 SkRRect fRRect; 896 SkRRect fRRect;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 } 1008 }
1008 1009
1009 ////////////////////////////////////////////////////////////////////////////// 1010 //////////////////////////////////////////////////////////////////////////////
1010 1011
1011 class GrGLRRectBlurEffect : public GrGLFragmentProcessor { 1012 class GrGLRRectBlurEffect : public GrGLFragmentProcessor {
1012 public: 1013 public:
1013 GrGLRRectBlurEffect(const GrProcessor&) {} 1014 GrGLRRectBlurEffect(const GrProcessor&) {}
1014 1015
1015 virtual void emitCode(EmitArgs&) override; 1016 virtual void emitCode(EmitArgs&) override;
1016 1017
1017 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; 1018 protected:
1019 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
1018 1020
1019 private: 1021 private:
1020 GrGLProgramDataManager::UniformHandle fProxyRectUniform; 1022 GrGLProgramDataManager::UniformHandle fProxyRectUniform;
1021 GrGLProgramDataManager::UniformHandle fCornerRadiusUniform; 1023 GrGLProgramDataManager::UniformHandle fCornerRadiusUniform;
1022 GrGLProgramDataManager::UniformHandle fBlurRadiusUniform; 1024 GrGLProgramDataManager::UniformHandle fBlurRadiusUniform;
1023 typedef GrGLFragmentProcessor INHERITED; 1025 typedef GrGLFragmentProcessor INHERITED;
1024 }; 1026 };
1025 1027
1026 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { 1028 void GrGLRRectBlurEffect::emitCode(EmitArgs& args) {
1027 const char *rectName; 1029 const char *rectName;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 fsBuilder->codeAppendf("\t\t}\n"); 1072 fsBuilder->codeAppendf("\t\t}\n");
1071 1073
1072 fsBuilder->codeAppendf("\t\tvec2 proxyDims = vec2(2.0*threshold+1.0);\n"); 1074 fsBuilder->codeAppendf("\t\tvec2 proxyDims = vec2(2.0*threshold+1.0);\n");
1073 fsBuilder->codeAppendf("\t\tvec2 texCoord = translatedFragPos / proxyDims;\n "); 1075 fsBuilder->codeAppendf("\t\tvec2 texCoord = translatedFragPos / proxyDims;\n ");
1074 1076
1075 fsBuilder->codeAppendf("\t%s = ", args.fOutputColor); 1077 fsBuilder->codeAppendf("\t%s = ", args.fOutputColor);
1076 fsBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers[0 ], "texCoord"); 1078 fsBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers[0 ], "texCoord");
1077 fsBuilder->codeAppend(";\n"); 1079 fsBuilder->codeAppend(";\n");
1078 } 1080 }
1079 1081
1080 void GrGLRRectBlurEffect::setData(const GrGLProgramDataManager& pdman, 1082 void GrGLRRectBlurEffect::onSetData(const GrGLProgramDataManager& pdman,
1081 const GrProcessor& proc) { 1083 const GrProcessor& proc) {
1082 const GrRRectBlurEffect& brre = proc.cast<GrRRectBlurEffect>(); 1084 const GrRRectBlurEffect& brre = proc.cast<GrRRectBlurEffect>();
1083 SkRRect rrect = brre.getRRect(); 1085 SkRRect rrect = brre.getRRect();
1084 1086
1085 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f); 1087 float blurRadius = 3.f*SkScalarCeilToScalar(brre.getSigma()-1/6.0f);
1086 pdman.set1f(fBlurRadiusUniform, blurRadius); 1088 pdman.set1f(fBlurRadiusUniform, blurRadius);
1087 1089
1088 SkRect rect = rrect.getBounds(); 1090 SkRect rect = rrect.getBounds();
1089 rect.outset(blurRadius, blurRadius); 1091 rect.outset(blurRadius, blurRadius);
1090 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot tom); 1092 pdman.set4f(fProxyRectUniform, rect.fLeft, rect.fTop, rect.fRight, rect.fBot tom);
1091 1093
1092 SkScalar radius = 0; 1094 SkScalar radius = 0;
1093 SkASSERT(rrect.isSimpleCircular() || rrect.isRect()); 1095 SkASSERT(rrect.isSimpleCircular() || rrect.isRect());
1094 radius = rrect.getSimpleRadii().fX; 1096 radius = rrect.getSimpleRadii().fX;
1095 pdman.set1f(fCornerRadiusUniform, radius); 1097 pdman.set1f(fCornerRadiusUniform, radius);
1096 } 1098 }
1097 1099
1098 void GrRRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorK eyBuilder* b) const { 1100 void GrRRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorK eyBuilder* b) const {
1099 GrGLRRectBlurEffect::GenKey(*this, caps, b); 1101 GrGLRRectBlurEffect::GenKey(*this, caps, b);
1100 } 1102 }
1101 1103
1102 GrGLFragmentProcessor* GrRRectBlurEffect::createGLInstance() const { 1104 GrGLFragmentProcessor* GrRRectBlurEffect::onCreateGLInstance() const {
1103 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this)); 1105 return SkNEW_ARGS(GrGLRRectBlurEffect, (*this));
1104 } 1106 }
1105 1107
1106 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid er, 1108 bool SkBlurMaskFilterImpl::directFilterRRectMaskGPU(GrTextureProvider* texProvid er,
1107 GrDrawContext* drawContext, 1109 GrDrawContext* drawContext,
1108 GrRenderTarget* rt, 1110 GrRenderTarget* rt,
1109 GrPaint* grp, 1111 GrPaint* grp,
1110 const GrClip& clip, 1112 const GrClip& clip,
1111 const SkMatrix& viewMatrix, 1113 const SkMatrix& viewMatrix,
1112 const SkStrokeRec& strokeRec , 1114 const SkStrokeRec& strokeRec ,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 } else { 1266 } else {
1265 str->append("None"); 1267 str->append("None");
1266 } 1268 }
1267 str->append("))"); 1269 str->append("))");
1268 } 1270 }
1269 #endif 1271 #endif
1270 1272
1271 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) 1273 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1272 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) 1274 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1273 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1275 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode_gpu.cpp ('k') | src/effects/SkColorCubeFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698