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" |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 556 |
557 class GrRectBlurEffect : public GrFragmentProcessor { | 557 class GrRectBlurEffect : public GrFragmentProcessor { |
558 public: | 558 public: |
559 virtual ~GrRectBlurEffect(); | 559 virtual ~GrRectBlurEffect(); |
560 | 560 |
561 static const char* Name() { return "RectBlur"; } | 561 static const char* Name() { return "RectBlur"; } |
562 | 562 |
563 typedef GrGLRectBlurEffect GLProcessor; | 563 typedef GrGLRectBlurEffect GLProcessor; |
564 | 564 |
565 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 565 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
566 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | |
567 | |
568 /** | 566 /** |
569 * Create a simple filter effect with custom bicubic coefficients. | 567 * Create a simple filter effect with custom bicubic coefficients. |
570 */ | 568 */ |
571 static GrFragmentProcessor* Create(GrContext *context, const SkRect& rect, f
loat sigma) { | 569 static GrFragmentProcessor* Create(GrContext *context, const SkRect& rect, f
loat sigma) { |
572 GrTexture *blurProfileTexture = NULL; | 570 GrTexture *blurProfileTexture = NULL; |
573 int doubleProfileSize = SkScalarCeilToInt(12*sigma); | 571 int doubleProfileSize = SkScalarCeilToInt(12*sigma); |
574 | 572 |
575 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.heigh
t()) { | 573 if (doubleProfileSize >= rect.width() || doubleProfileSize >= rect.heigh
t()) { |
576 // if the blur sigma is too large so the gaussian overlaps the whole | 574 // if the blur sigma is too large so the gaussian overlaps the whole |
577 // rect in either direction, fall back to CPU path for now. | 575 // rect in either direction, fall back to CPU path for now. |
578 | 576 |
579 return NULL; | 577 return NULL; |
580 } | 578 } |
581 | 579 |
582 bool createdBlurProfileTexture = CreateBlurProfileTexture(context, sigma
, &blurProfileTexture); | 580 bool createdBlurProfileTexture = CreateBlurProfileTexture(context, sigma
, &blurProfileTexture); |
583 SkAutoTUnref<GrTexture> hunref(blurProfileTexture); | 581 SkAutoTUnref<GrTexture> hunref(blurProfileTexture); |
584 if (!createdBlurProfileTexture) { | 582 if (!createdBlurProfileTexture) { |
585 return NULL; | 583 return NULL; |
586 } | 584 } |
587 return SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture)); | 585 return SkNEW_ARGS(GrRectBlurEffect, (rect, sigma, blurProfileTexture)); |
588 } | 586 } |
589 | 587 |
590 const SkRect& getRect() const { return fRect; } | 588 const SkRect& getRect() const { return fRect; } |
591 float getSigma() const { return fSigma; } | 589 float getSigma() const { return fSigma; } |
592 | 590 |
593 private: | 591 private: |
594 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile); | 592 GrRectBlurEffect(const SkRect& rect, float sigma, GrTexture *blur_profile); |
595 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; | 593 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
596 | 594 |
| 595 virtual void onGetConstantColorComponents(GrColor* color, uint32_t* validFla
gs, |
| 596 bool* isSingleComponent) const SK_
OVERRIDE; |
| 597 |
597 static bool CreateBlurProfileTexture(GrContext *context, float sigma, | 598 static bool CreateBlurProfileTexture(GrContext *context, float sigma, |
598 GrTexture **blurProfileTexture); | 599 GrTexture **blurProfileTexture); |
599 | 600 |
600 SkRect fRect; | 601 SkRect fRect; |
601 float fSigma; | 602 float fSigma; |
602 GrTextureAccess fBlurProfileAccess; | 603 GrTextureAccess fBlurProfileAccess; |
603 | 604 |
604 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 605 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
605 | 606 |
606 typedef GrFragmentProcessor INHERITED; | 607 typedef GrFragmentProcessor INHERITED; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 759 |
759 const GrBackendFragmentProcessorFactory& GrRectBlurEffect::getFactory() const { | 760 const GrBackendFragmentProcessorFactory& GrRectBlurEffect::getFactory() const { |
760 return GrTBackendFragmentProcessorFactory<GrRectBlurEffect>::getInstance(); | 761 return GrTBackendFragmentProcessorFactory<GrRectBlurEffect>::getInstance(); |
761 } | 762 } |
762 | 763 |
763 bool GrRectBlurEffect::onIsEqual(const GrProcessor& sBase) const { | 764 bool GrRectBlurEffect::onIsEqual(const GrProcessor& sBase) const { |
764 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); | 765 const GrRectBlurEffect& s = sBase.cast<GrRectBlurEffect>(); |
765 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); | 766 return this->getSigma() == s.getSigma() && this->getRect() == s.getRect(); |
766 } | 767 } |
767 | 768 |
768 void GrRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* vali
dFlags) const { | 769 void GrRectBlurEffect::onGetConstantColorComponents(GrColor* color, uint32_t* va
lidFlags, |
| 770 bool* isSingleComponent) con
st { |
769 *validFlags = 0; | 771 *validFlags = 0; |
770 return; | |
771 } | 772 } |
772 | 773 |
773 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); | 774 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); |
774 | 775 |
775 GrFragmentProcessor* GrRectBlurEffect::TestCreate(SkRandom* random, | 776 GrFragmentProcessor* GrRectBlurEffect::TestCreate(SkRandom* random, |
776 GrContext* context, | 777 GrContext* context, |
777 const GrDrawTargetCaps&, | 778 const GrDrawTargetCaps&, |
778 GrTexture**) { | 779 GrTexture**) { |
779 float sigma = random->nextRangeF(3,8); | 780 float sigma = random->nextRangeF(3,8); |
780 float width = random->nextRangeF(200,300); | 781 float width = random->nextRangeF(200,300); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); | 831 static GrFragmentProcessor* Create(GrContext* context, float sigma, const Sk
RRect&); |
831 | 832 |
832 virtual ~GrRRectBlurEffect() {}; | 833 virtual ~GrRRectBlurEffect() {}; |
833 static const char* Name() { return "GrRRectBlur"; } | 834 static const char* Name() { return "GrRRectBlur"; } |
834 | 835 |
835 const SkRRect& getRRect() const { return fRRect; } | 836 const SkRRect& getRRect() const { return fRRect; } |
836 float getSigma() const { return fSigma; } | 837 float getSigma() const { return fSigma; } |
837 | 838 |
838 typedef GrGLRRectBlurEffect GLProcessor; | 839 typedef GrGLRRectBlurEffect GLProcessor; |
839 | 840 |
840 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | |
841 | |
842 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 841 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
843 | 842 |
844 private: | 843 private: |
845 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); | 844 GrRRectBlurEffect(float sigma, const SkRRect&, GrTexture* profileTexture); |
846 | 845 |
847 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; | 846 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
848 | 847 |
| 848 virtual void onGetConstantColorComponents(GrColor* color, uint32_t* validFla
gs, |
| 849 bool* isSingleComponent) const SK_
OVERRIDE; |
| 850 |
849 SkRRect fRRect; | 851 SkRRect fRRect; |
850 float fSigma; | 852 float fSigma; |
851 GrTextureAccess fNinePatchAccess; | 853 GrTextureAccess fNinePatchAccess; |
852 | 854 |
853 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 855 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
854 | 856 |
855 typedef GrFragmentProcessor INHERITED; | 857 typedef GrFragmentProcessor INHERITED; |
856 }; | 858 }; |
857 | 859 |
858 | 860 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 } | 924 } |
923 | 925 |
924 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); | 926 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); |
925 if (NULL == blurNinePatchTexture) { | 927 if (NULL == blurNinePatchTexture) { |
926 return NULL; | 928 return NULL; |
927 } | 929 } |
928 | 930 |
929 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); | 931 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); |
930 } | 932 } |
931 | 933 |
932 void GrRRectBlurEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { | 934 void GrRRectBlurEffect::onGetConstantColorComponents(GrColor* color, uint32_t* v
alidFlags, |
| 935 bool* isSingleComponent) co
nst { |
933 *validFlags = 0; | 936 *validFlags = 0; |
934 } | 937 } |
935 | 938 |
936 const GrBackendFragmentProcessorFactory& GrRRectBlurEffect::getFactory() const { | 939 const GrBackendFragmentProcessorFactory& GrRRectBlurEffect::getFactory() const { |
937 return GrTBackendFragmentProcessorFactory<GrRRectBlurEffect>::getInstance(); | 940 return GrTBackendFragmentProcessorFactory<GrRRectBlurEffect>::getInstance(); |
938 } | 941 } |
939 | 942 |
940 GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTextur
e *ninePatchTexture) | 943 GrRRectBlurEffect::GrRRectBlurEffect(float sigma, const SkRRect& rrect, GrTextur
e *ninePatchTexture) |
941 : fRRect(rrect), | 944 : fRRect(rrect), |
942 fSigma(sigma), | 945 fSigma(sigma), |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 } else { | 1222 } else { |
1220 str->append("None"); | 1223 str->append("None"); |
1221 } | 1224 } |
1222 str->append("))"); | 1225 str->append("))"); |
1223 } | 1226 } |
1224 #endif | 1227 #endif |
1225 | 1228 |
1226 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) | 1229 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) |
1227 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) | 1230 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) |
1228 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1231 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |