Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkMaskFilterBase.h
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkMaskFilterBase_DEFINED
9#define SkMaskFilterBase_DEFINED
10
17#include "src/base/SkTLazy.h"
18#include "src/core/SkMask.h"
19
20class GrClip;
21struct GrFPArgs;
23class GrPaint;
25class GrRenderTarget;
26namespace skgpu {
27namespace ganesh {
29}
30} // namespace skgpu
32class GrStyledShape;
34class GrTexture;
35class GrTextureProxy;
36
37class SkBitmap;
38class SkBlitter;
39class SkCachedData;
40class SkMatrix;
41class SkPath;
42class SkRasterClip;
43class SkRRect;
44
46public:
47 /** Returns the format of the resulting mask that this subclass will return
48 when its filterMask() method is called.
49 */
50 virtual SkMask::Format getFormat() const = 0;
51
52 /** Create a new mask by filter the src mask.
53 If src.fImage == null, then do not allocate or create the dst image
54 but do fill out the other fields in dstMask.
55 If you do allocate a dst image, use SkMask::AllocImage()
56 If this returns false, dst mask is ignored.
57 @param dst the result of the filter. If src.fImage == null, dst should not allocate its image
58 @param src the original image to be filtered.
59 @param matrix the CTM
60 @param margin if not null, return the buffer dx/dy need when calculating the effect. Used when
61 drawing a clipped object to know how much larger to allocate the src before
62 applying the filter. If returning false, ignore this parameter.
63 @return true if the dst mask was correctly created.
64 */
65 virtual bool filterMask(SkMaskBuilder* dst, const SkMask& src, const SkMatrix&,
66 SkIPoint* margin) const = 0;
67
68 enum class Type {
69 kBlur,
70 kEmboss,
71 kSDF,
72 kShader,
73 kTable,
74 };
75
76 virtual Type type() const = 0;
77
78 /**
79 * The fast bounds function is used to enable the paint to be culled early
80 * in the drawing pipeline. This function accepts the current bounds of the
81 * paint as its src param and the filter adjust those bounds using its
82 * current mask and returns the result using the dest param. Callers are
83 * allowed to provide the same struct for both src and dest so each
84 * implementation must accommodate that behavior.
85 *
86 * The default impl calls filterMask with the src mask having no image,
87 * but subclasses may override this if they can compute the rect faster.
88 */
89 virtual void computeFastBounds(const SkRect& src, SkRect* dest) const;
90
95 /**
96 * If this filter can be represented by a BlurRec, return true and (if not null) fill in the
97 * provided BlurRec parameter. If this effect cannot be represented as a BlurRec, return false
98 * and ignore the BlurRec parameter.
99 */
100 virtual bool asABlur(BlurRec*) const;
101
102 /**
103 * Return an SkImageFilter representation of this mask filter that SkCanvas can apply to an
104 * alpha-only image to produce an equivalent effect to running the mask filter directly.
105 */
106 virtual sk_sp<SkImageFilter> asImageFilter(const SkMatrix& ctm) const;
107
111
113 return kSkMaskFilter_Type;
114 }
115
116protected:
118
124
126 public:
127 NinePatch(const SkMask& mask, SkIRect outerRect, SkIPoint center, SkCachedData* cache)
128 : fMask(mask), fOuterRect(outerRect), fCenter(center), fCache(cache) {}
129 ~NinePatch();
130
131 SkMask fMask; // fBounds must have [0,0] in its top-left
132 SkIRect fOuterRect; // width/height must be >= fMask.fBounds'
133 SkIPoint fCenter; // identifies center row/col for stretching
135 };
136
137 /**
138 * Override if your subclass can filter a rect, and return the answer as
139 * a ninepatch mask to be stretched over the returned outerRect. On success
140 * return kTrue_FilterReturn. On failure (e.g. out of memory) return
141 * kFalse_FilterReturn. If the normal filterMask() entry-point should be
142 * called (the default) return kUnimplemented_FilterReturn.
143 *
144 * By convention, the caller will take the center rol/col from the returned
145 * mask as the slice it can replicate horizontally and vertically as we
146 * stretch the mask to fit inside outerRect. It is an error for outerRect
147 * to be smaller than the mask's bounds. This would imply that the width
148 * and height of the mask should be odd. This is not required, just that
149 * the caller will call mask.fBounds.centerX() and centerY() to find the
150 * strips that will be replicated.
151 */
152 virtual FilterReturn filterRectsToNine(const SkRect[], int count,
153 const SkMatrix&,
154 const SkIRect& clipBounds,
155 SkTLazy<NinePatch>*) const;
156 /**
157 * Similar to filterRectsToNine, except it performs the work on a round rect.
158 */
159 virtual FilterReturn filterRRectToNine(const SkRRect&, const SkMatrix&,
160 const SkIRect& clipBounds,
161 SkTLazy<NinePatch>*) const;
162
163private:
164 friend class SkDraw;
165 friend class SkDrawBase;
166
167 /** Helper method that, given a path in device space, will rasterize it into a kA8_Format mask
168 and then call filterMask(). If this returns true, the specified blitter will be called
169 to render that mask. Returns false if filterMask() returned false.
170 This method is not exported to java.
171 */
172 bool filterPath(const SkPath& devPath, const SkMatrix& ctm, const SkRasterClip&, SkBlitter*,
174
175 /** Helper method that, given a roundRect in device space, will rasterize it into a kA8_Format
176 mask and then call filterMask(). If this returns true, the specified blitter will be called
177 to render that mask. Returns false if filterMask() returned false.
178 */
179 bool filterRRect(const SkRRect& devRRect, const SkMatrix& ctm, const SkRasterClip&,
180 SkBlitter*) const;
181
182 using INHERITED = SkFlattenable;
183};
184
186 return static_cast<SkMaskFilterBase*>(mf);
187}
188
189inline const SkMaskFilterBase* as_MFB(const SkMaskFilter* mf) {
190 return static_cast<const SkMaskFilterBase*>(mf);
191}
192
194 return static_cast<SkMaskFilterBase*>(mf.get());
195}
196
197// For RegisterFlattenables access to the blur mask filter implementation
199
200#endif
int count
SkBlurStyle
Definition SkBlurTypes.h:11
void sk_register_blur_maskfilter_createproc()
SkMaskFilterBase * as_MFB(SkMaskFilter *mf)
static SkScalar center(float pos0, float pos1)
NinePatch(const SkMask &mask, SkIRect outerRect, SkIPoint center, SkCachedData *cache)
SkFlattenable::Type getFlattenableType() const override
virtual sk_sp< SkImageFilter > asImageFilter(const SkMatrix &ctm) const
static SkFlattenable::Type GetFlattenableType()
virtual bool filterMask(SkMaskBuilder *dst, const SkMask &src, const SkMatrix &, SkIPoint *margin) const =0
virtual SkMask::Format getFormat() const =0
virtual bool asABlur(BlurRec *) const
virtual FilterReturn filterRRectToNine(const SkRRect &, const SkMatrix &, const SkIRect &clipBounds, SkTLazy< NinePatch > *) const
virtual Type type() const =0
virtual FilterReturn filterRectsToNine(const SkRect[], int count, const SkMatrix &, const SkIRect &clipBounds, SkTLazy< NinePatch > *) const
virtual void computeFastBounds(const SkRect &src, SkRect *dest) const
friend class SkFlattenable
T * get() const
Definition SkRefCnt.h:303
float SkScalar
Definition extension.cpp:12
Format
Definition SkMask.h:26