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

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

Issue 374923002: Goodbye GrEffectRef. (Closed) Base URL: https://skia.googlesource.com/skia.git@noref3
Patch Set: Address comments Created 6 years, 5 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.cpp ('k') | src/effects/SkColorFilters.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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 static const char* Name() { return "RectBlur"; } 548 static const char* Name() { return "RectBlur"; }
549 549
550 typedef GrGLRectBlurEffect GLEffect; 550 typedef GrGLRectBlurEffect GLEffect;
551 551
552 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 552 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
553 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 553 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
554 554
555 /** 555 /**
556 * Create a simple filter effect with custom bicubic coefficients. 556 * Create a simple filter effect with custom bicubic coefficients.
557 */ 557 */
558 static GrEffectRef* Create(GrContext *context, const SkRect& rect, 558 static GrEffect* Create(GrContext *context, const SkRect& rect, float sigma) {
559 float sigma) {
560 GrTexture *blurProfileTexture = NULL; 559 GrTexture *blurProfileTexture = NULL;
561 int doubleProfileSize = SkScalarCeilToInt(12*sigma); 560 int doubleProfileSize = SkScalarCeilToInt(12*sigma);
562 561
563 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.heigh t()) { 562 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.heigh t()) {
564 // if the blur sigma is too large so the gaussian overlaps the whole 563 // if the blur sigma is too large so the gaussian overlaps the whole
565 // rect in either direction, fall back to CPU path for now. 564 // rect in either direction, fall back to CPU path for now.
566 565
567 return NULL; 566 return NULL;
568 } 567 }
569 568
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); 751 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect();
753 } 752 }
754 753
755 void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* vali dFlags) const { 754 void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* vali dFlags) const {
756 *validFlags = 0; 755 *validFlags = 0;
757 return; 756 return;
758 } 757 }
759 758
760 GR_DEFINE_EFFECT_TEST(GrRectBlurEffect); 759 GR_DEFINE_EFFECT_TEST(GrRectBlurEffect);
761 760
762 GrEffectRef* GrRectBlurEffect::TestCreate(SkRandom* random, 761 GrEffect* GrRectBlurEffect::TestCreate(SkRandom* random,
763 GrContext* context, 762 GrContext* context,
764 const GrDrawTargetCaps&, 763 const GrDrawTargetCaps&,
765 GrTexture**) { 764 GrTexture**) {
766 float sigma = random->nextRangeF(3,8); 765 float sigma = random->nextRangeF(3,8);
767 float width = random->nextRangeF(200,300); 766 float width = random->nextRangeF(200,300);
768 float height = random->nextRangeF(200,300); 767 float height = random->nextRangeF(200,300);
769 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm a); 768 return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigm a);
770 } 769 }
771 770
772 771
773 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context, 772 bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
774 GrPaint* grp, 773 GrPaint* grp,
775 const SkStrokeRec& strokeRec, 774 const SkStrokeRec& strokeRec,
(...skipping 10 matching lines...) Expand all
786 if (!strokeRec.isFillStyle()) { 785 if (!strokeRec.isFillStyle()) {
787 return false; 786 return false;
788 } 787 }
789 788
790 SkMatrix ctm = context->getMatrix(); 789 SkMatrix ctm = context->getMatrix();
791 SkScalar xformedSigma = this->computeXformedSigma(ctm); 790 SkScalar xformedSigma = this->computeXformedSigma(ctm);
792 791
793 int pad=SkScalarCeilToInt(6*xformedSigma)/2; 792 int pad=SkScalarCeilToInt(6*xformedSigma)/2;
794 rect.outset(SkIntToScalar(pad), SkIntToScalar(pad)); 793 rect.outset(SkIntToScalar(pad), SkIntToScalar(pad));
795 794
796 SkAutoTUnref<GrEffectRef> effect(GrRectBlurEffect::Create( 795 SkAutoTUnref<GrEffect> effect(GrRectBlurEffect::Create(context, rect, xforme dSigma));
797 context, rect, xformedSigma));
798 if (!effect) { 796 if (!effect) {
799 return false; 797 return false;
800 } 798 }
801 799
802 GrContext::AutoMatrix am; 800 GrContext::AutoMatrix am;
803 if (!am.setIdentity(context, grp)) { 801 if (!am.setIdentity(context, grp)) {
804 return false; 802 return false;
805 } 803 }
806 804
807 grp->addCoverageEffect(effect); 805 grp->addCoverageEffect(effect);
808 806
809 context->drawRect(*grp, rect); 807 context->drawRect(*grp, rect);
810 return true; 808 return true;
811 } 809 }
812 810
813 class GrGLRRectBlurEffect; 811 class GrGLRRectBlurEffect;
814 812
815 class GrRRectBlurEffect : public GrEffect { 813 class GrRRectBlurEffect : public GrEffect {
816 public: 814 public:
817 815
818 static GrEffectRef* Create(GrContext* context, float sigma, const SkRRect&); 816 static GrEffect* Create(GrContext* context, float sigma, const SkRRect&);
819 817
820 virtual ~GrRRectBlurEffect() {}; 818 virtual ~GrRRectBlurEffect() {};
821 static const char* Name() { return "GrRRectBlur"; } 819 static const char* Name() { return "GrRRectBlur"; }
822 820
823 const SkRRect& getRRect() const { return fRRect; } 821 const SkRRect& getRRect() const { return fRRect; }
824 float getSigma() const { return fSigma; } 822 float getSigma() const { return fSigma; }
825 823
826 typedef GrGLRRectBlurEffect GLEffect; 824 typedef GrGLRRectBlurEffect GLEffect;
827 825
828 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 826 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
829 827
830 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 828 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
831 829
832 private: 830 private:
833 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); 831 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture);
834 832
835 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; 833 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
836 834
837 SkRRect fRRect; 835 SkRRect fRRect;
838 float fSigma; 836 float fSigma;
839 GrTextureAccess fNinePatchAccess; 837 GrTextureAccess fNinePatchAccess;
840 838
841 GR_DECLARE_EFFECT_TEST; 839 GR_DECLARE_EFFECT_TEST;
842 840
843 typedef GrEffect INHERITED; 841 typedef GrEffect INHERITED;
844 }; 842 };
845 843
846 844
847 GrEffectRef* GrRRectBlurEffect::Create(GrContext* context, float sigma, const Sk RRect& rrect) { 845 GrEffect* GrRRectBlurEffect::Create(GrContext* context, float sigma, const SkRRe ct& rrect) {
848 if (!rrect.isSimpleCircular()) { 846 if (!rrect.isSimpleCircular()) {
849 return NULL; 847 return NULL;
850 } 848 }
851 849
852 // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be 850 // Make sure we can successfully ninepatch this rrect -- the blur sigma has to be
853 // sufficiently small relative to both the size of the corner radius and the 851 // sufficiently small relative to both the size of the corner radius and the
854 // width (and height) of the rrect. 852 // width (and height) of the rrect.
855 853
856 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f); 854 unsigned int blurRadius = 3*SkScalarCeilToInt(sigma-1/6.0f);
857 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x()); 855 unsigned int cornerRadius = SkScalarCeilToInt(rrect.getSimpleRadii().x());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 932
935 bool GrRRectBlurEffect::onIsEqual(const GrEffect& other) const { 933 bool GrRRectBlurEffect::onIsEqual(const GrEffect& other) const {
936 const GrRRectBlurEffect& rrbe = CastEffect<GrRRectBlurEffect>(other); 934 const GrRRectBlurEffect& rrbe = CastEffect<GrRRectBlurEffect>(other);
937 return fRRect.getSimpleRadii().fX == rrbe.fRRect.getSimpleRadii().fX && fSig ma == rrbe.fSigma; 935 return fRRect.getSimpleRadii().fX == rrbe.fRRect.getSimpleRadii().fX && fSig ma == rrbe.fSigma;
938 } 936 }
939 937
940 ////////////////////////////////////////////////////////////////////////////// 938 //////////////////////////////////////////////////////////////////////////////
941 939
942 GR_DEFINE_EFFECT_TEST(GrRRectBlurEffect); 940 GR_DEFINE_EFFECT_TEST(GrRRectBlurEffect);
943 941
944 GrEffectRef* GrRRectBlurEffect::TestCreate(SkRandom* random, 942 GrEffect* GrRRectBlurEffect::TestCreate(SkRandom* random,
945 GrContext* context, 943 GrContext* context,
946 const GrDrawTargetCaps& caps, 944 const GrDrawTargetCaps& caps,
947 GrTexture*[]) { 945 GrTexture*[]) {
948 SkScalar w = random->nextRangeScalar(100.f, 1000.f); 946 SkScalar w = random->nextRangeScalar(100.f, 1000.f);
949 SkScalar h = random->nextRangeScalar(100.f, 1000.f); 947 SkScalar h = random->nextRangeScalar(100.f, 1000.f);
950 SkScalar r = random->nextRangeF(1.f, 9.f); 948 SkScalar r = random->nextRangeF(1.f, 9.f);
951 SkScalar sigma = random->nextRangeF(1.f,10.f); 949 SkScalar sigma = random->nextRangeF(1.f,10.f);
952 SkRRect rrect; 950 SkRRect rrect;
953 rrect.setRectXY(SkRect::MakeWH(w, h), r, r); 951 rrect.setRectXY(SkRect::MakeWH(w, h), r, r);
954 return GrRRectBlurEffect::Create(context, sigma, rrect); 952 return GrRRectBlurEffect::Create(context, sigma, rrect);
955 } 953 }
956 954
957 ////////////////////////////////////////////////////////////////////////////// 955 //////////////////////////////////////////////////////////////////////////////
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 if (!strokeRec.isFillStyle()) { 1065 if (!strokeRec.isFillStyle()) {
1068 return false; 1066 return false;
1069 } 1067 }
1070 1068
1071 SkRect proxy_rect = rrect.rect(); 1069 SkRect proxy_rect = rrect.rect();
1072 SkMatrix ctm = context->getMatrix(); 1070 SkMatrix ctm = context->getMatrix();
1073 SkScalar xformedSigma = this->computeXformedSigma(ctm); 1071 SkScalar xformedSigma = this->computeXformedSigma(ctm);
1074 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f); 1072 float extra=3.f*SkScalarCeilToScalar(xformedSigma-1/6.0f);
1075 proxy_rect.outset(extra, extra); 1073 proxy_rect.outset(extra, extra);
1076 1074
1077 SkAutoTUnref<GrEffectRef> effect(GrRRectBlurEffect::Create( 1075 SkAutoTUnref<GrEffect> effect(GrRRectBlurEffect::Create(
1078 context, xformedSigma, rrect)); 1076 context, xformedSigma, rrect));
1079 if (!effect) { 1077 if (!effect) {
1080 return false; 1078 return false;
1081 } 1079 }
1082 1080
1083 GrContext::AutoMatrix am; 1081 GrContext::AutoMatrix am;
1084 if (!am.setIdentity(context, grp)) { 1082 if (!am.setIdentity(context, grp)) {
1085 return false; 1083 return false;
1086 } 1084 }
1087 1085
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } else { 1203 } else {
1206 str->append("None"); 1204 str->append("None");
1207 } 1205 }
1208 str->append("))"); 1206 str->append("))");
1209 } 1207 }
1210 #endif 1208 #endif
1211 1209
1212 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) 1210 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1213 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) 1211 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1214 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1212 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode.cpp ('k') | src/effects/SkColorFilters.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698