Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
SkBlurMaskFilterImpl Class Reference

#include <SkBlurMaskFilterImpl.h>

Inheritance diagram for SkBlurMaskFilterImpl:
SkMaskFilterBase SkMaskFilter SkFlattenable SkRefCnt SkRefCntBase

Public Member Functions

 SkBlurMaskFilterImpl (SkScalar sigma, SkBlurStyle, bool respectCTM)
 
SkMask::Format getFormat () const override
 
bool filterMask (SkMaskBuilder *dst, const SkMask &src, const SkMatrix &, SkIPoint *margin) const override
 
SkMaskFilterBase::Type type () const override
 
void computeFastBounds (const SkRect &, SkRect *) const override
 
bool asABlur (BlurRec *) const override
 
sk_sp< SkImageFilterasImageFilter (const SkMatrix &ctm) const override
 
SkScalar computeXformedSigma (const SkMatrix &ctm) const
 
SkBlurStyle blurStyle () const
 
SkScalar sigma () const
 
bool ignoreXform () const
 
- Public Member Functions inherited from SkMaskFilterBase
virtual SkMask::Format getFormat () const =0
 
virtual bool filterMask (SkMaskBuilder *dst, const SkMask &src, const SkMatrix &, SkIPoint *margin) const =0
 
virtual Type type () const =0
 
virtual void computeFastBounds (const SkRect &src, SkRect *dest) const
 
virtual bool asABlur (BlurRec *) const
 
virtual sk_sp< SkImageFilterasImageFilter (const SkMatrix &ctm) const
 
SkFlattenable::Type getFlattenableType () const override
 
- Public Member Functions inherited from SkMaskFilter
SkRect approximateFilteredBounds (const SkRect &src) const
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual Factory getFactory () const =0
 
virtual const char * getTypeName () const =0
 
virtual void flatten (SkWriteBuffer &) const
 
virtual Type getFlattenableType () const =0
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Friends

class SkBlurMaskFilter
 
void sk_register_blur_maskfilter_createproc ()
 

Additional Inherited Members

- Public Types inherited from SkMaskFilterBase
enum class  Type {
  kBlur , kEmboss , kSDF , kShader ,
  kTable
}
 
- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type , kSkBlender_Type , kSkDrawable_Type , kSkDrawLooper_Type ,
  kSkImageFilter_Type , kSkMaskFilter_Type , kSkPathEffect_Type , kSkShader_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 
- Static Public Member Functions inherited from SkMaskFilterBase
static SkFlattenable::Type GetFlattenableType ()
 
- Static Public Member Functions inherited from SkMaskFilter
static sk_sp< SkMaskFilterMakeBlur (SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
 
static sk_sp< SkMaskFilterDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static void Register (const char name[], Factory)
 
static sk_sp< SkFlattenableDeserialize (Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
 
- Protected Types inherited from SkMaskFilterBase
enum  FilterReturn { kFalse_FilterReturn , kTrue_FilterReturn , kUnimplemented_FilterReturn }
 
- Protected Member Functions inherited from SkMaskFilterBase
 SkMaskFilterBase ()
 
virtual FilterReturn filterRectsToNine (const SkRect[], int count, const SkMatrix &, const SkIRect &clipBounds, SkTLazy< NinePatch > *) const
 
virtual FilterReturn filterRRectToNine (const SkRRect &, const SkMatrix &, const SkIRect &clipBounds, SkTLazy< NinePatch > *) const
 

Detailed Description

Definition at line 28 of file SkBlurMaskFilterImpl.h.

Constructor & Destructor Documentation

◆ SkBlurMaskFilterImpl()

SkBlurMaskFilterImpl::SkBlurMaskFilterImpl ( SkScalar  sigma,
SkBlurStyle  style,
bool  respectCTM 
)

Definition at line 50 of file SkBlurMaskFilterImpl.cpp.

51 : fSigma(sigma)
52 , fBlurStyle(style)
53 , fRespectCTM(respectCTM) {
54 SkASSERT(fSigma > 0);
55 SkASSERT((unsigned)style <= kLastEnum_SkBlurStyle);
56}
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kLastEnum_SkBlurStyle
Definition: SkBlurTypes.h:17

Member Function Documentation

◆ asABlur()

bool SkBlurMaskFilterImpl::asABlur ( BlurRec ) const
overridevirtual

If this filter can be represented by a BlurRec, return true and (if not null) fill in the provided BlurRec parameter. If this effect cannot be represented as a BlurRec, return false and ignore the BlurRec parameter.

Reimplemented from SkMaskFilterBase.

Definition at line 62 of file SkBlurMaskFilterImpl.cpp.

62 {
63 if (this->ignoreXform()) {
64 return false;
65 }
66
67 if (rec) {
68 rec->fSigma = fSigma;
69 rec->fStyle = fBlurStyle;
70 }
71 return true;
72}

◆ asImageFilter()

sk_sp< SkImageFilter > SkBlurMaskFilterImpl::asImageFilter ( const SkMatrix ctm) const
overridevirtual

Return an SkImageFilter representation of this mask filter that SkCanvas can apply to an alpha-only image to produce an equivalent effect to running the mask filter directly.

Reimplemented from SkMaskFilterBase.

Definition at line 74 of file SkBlurMaskFilterImpl.cpp.

74 {
75 float sigma = fSigma;
76 if (this->ignoreXform()) {
77 // This is analogous to computeXformedSigma(), but it might be more correct to wrap the
78 // blur image filter in a local matrix with ctm^-1, or to control the skif::Mapping when
79 // the mask filter layer is restored. This is inaccurate when 'ctm' has skew or perspective
80 const float ctmScaleFactor = fSigma / ctm.mapRadius(fSigma);
81 sigma *= ctmScaleFactor;
82 }
83
84 // The null input image filter will be bound to the original coverage mask.
86 // Combine the original coverage mask (src) and the blurred coverage mask (dst)
87 switch(fBlurStyle) {
88 case kInner_SkBlurStyle: // dst = dst * src
89 // = 0 * src + src * dst
90 return SkImageFilters::Blend(SkBlendMode::kDstIn, std::move(filter), nullptr);
91 case kSolid_SkBlurStyle: // dst = src + dst - src * dst
92 // = 1 * src + (1 - src) * dst
93 return SkImageFilters::Blend(SkBlendMode::kSrcOver, std::move(filter), nullptr);
94 case kOuter_SkBlurStyle: // dst = dst * (1 - src)
95 // = 0 * src + (1 - src) * dst
96 return SkImageFilters::Blend(SkBlendMode::kDstOut, std::move(filter), nullptr);
98 return filter;
99 }
101}
#define SkUNREACHABLE
Definition: SkAssert.h:135
@ kDstIn
r = d * sa
@ kSrcOver
r = s + (1-sa)*d
@ kDstOut
r = d * (1-sa)
@ kOuter_SkBlurStyle
nothing inside, fuzzy outside
Definition: SkBlurTypes.h:14
@ kSolid_SkBlurStyle
solid inside, fuzzy outside
Definition: SkBlurTypes.h:13
@ kInner_SkBlurStyle
fuzzy inside, nothing outside
Definition: SkBlurTypes.h:15
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
SkScalar mapRadius(SkScalar radius) const
Definition: SkMatrix.cpp:1170

◆ blurStyle()

SkBlurStyle SkBlurMaskFilterImpl::blurStyle ( ) const
inline

Definition at line 44 of file SkBlurMaskFilterImpl.h.

44{return fBlurStyle;}

◆ computeFastBounds()

void SkBlurMaskFilterImpl::computeFastBounds ( const SkRect src,
SkRect dest 
) const
overridevirtual

The fast bounds function is used to enable the paint to be culled early in the drawing pipeline. This function accepts the current bounds of the paint as its src param and the filter adjust those bounds using its current mask and returns the result using the dest param. Callers are allowed to provide the same struct for both src and dest so each implementation must accommodate that behavior.

The default impl calls filterMask with the src mask having no image, but subclasses may override this if they can compute the rect faster.

Reimplemented from SkMaskFilterBase.

Definition at line 506 of file SkBlurMaskFilterImpl.cpp.

507 {
508 // TODO: if we're doing kInner blur, should we return a different outset?
509 // i.e. pad == 0 ?
510
511 SkScalar pad = 3.0f * fSigma;
512
513 dst->setLTRB(src.fLeft - pad, src.fTop - pad,
514 src.fRight + pad, src.fBottom + pad);
515}
float SkScalar
Definition: extension.cpp:12
dst
Definition: cp.py:12

◆ computeXformedSigma()

SkScalar SkBlurMaskFilterImpl::computeXformedSigma ( const SkMatrix ctm) const

Definition at line 103 of file SkBlurMaskFilterImpl.cpp.

103 {
104 constexpr SkScalar kMaxBlurSigma = SkIntToScalar(128);
105 SkScalar xformedSigma = this->ignoreXform() ? fSigma : ctm.mapRadius(fSigma);
106 return std::min(xformedSigma, kMaxBlurSigma);
107}
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ filterMask()

bool SkBlurMaskFilterImpl::filterMask ( SkMaskBuilder dst,
const SkMask src,
const SkMatrix ,
SkIPoint margin 
) const
overridevirtual

Create a new mask by filter the src mask. If src.fImage == null, then do not allocate or create the dst image but do fill out the other fields in dstMask. If you do allocate a dst image, use SkMask::AllocImage() If this returns false, dst mask is ignored.

Parameters
dstthe result of the filter. If src.fImage == null, dst should not allocate its image
srcthe original image to be filtered.
matrixthe CTM
marginif not null, return the buffer dx/dy need when calculating the effect. Used when drawing a clipped object to know how much larger to allocate the src before applying the filter. If returning false, ignore this parameter.
Returns
true if the dst mask was correctly created.

Implements SkMaskFilterBase.

Definition at line 109 of file SkBlurMaskFilterImpl.cpp.

111 {
113 return SkBlurMask::BoxBlur(dst, src, sigma, fBlurStyle, margin);
114}
SkScalar computeXformedSigma(const SkMatrix &ctm) const
static bool BoxBlur(SkMaskBuilder *dst, const SkMask &src, SkScalar sigma, SkBlurStyle style, SkIPoint *margin=nullptr)
Definition: SkBlurMask.cpp:116
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ getFormat()

SkMask::Format SkBlurMaskFilterImpl::getFormat ( ) const
overridevirtual

Returns the format of the resulting mask that this subclass will return when its filterMask() method is called.

Implements SkMaskFilterBase.

Definition at line 58 of file SkBlurMaskFilterImpl.cpp.

58 {
59 return SkMask::kA8_Format;
60}
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28

◆ ignoreXform()

bool SkBlurMaskFilterImpl::ignoreXform ( ) const
inline

Definition at line 46 of file SkBlurMaskFilterImpl.h.

46{ return !fRespectCTM; }

◆ sigma()

SkScalar SkBlurMaskFilterImpl::sigma ( ) const
inline

Definition at line 45 of file SkBlurMaskFilterImpl.h.

45{return fSigma;}

◆ type()

SkMaskFilterBase::Type SkBlurMaskFilterImpl::type ( ) const
inlineoverridevirtual

Implements SkMaskFilterBase.

Definition at line 36 of file SkBlurMaskFilterImpl.h.

Friends And Related Function Documentation

◆ sk_register_blur_maskfilter_createproc

void sk_register_blur_maskfilter_createproc ( )
friend

Definition at line 533 of file SkBlurMaskFilterImpl.cpp.

◆ SkBlurMaskFilter

friend class SkBlurMaskFilter
friend

Definition at line 71 of file SkBlurMaskFilterImpl.h.


The documentation for this class was generated from the following files: