Flutter Engine
The Flutter Engine
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
91 struct BlurRec {
94 };
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
109 return kSkMaskFilter_Type;
110 }
111
113 return kSkMaskFilter_Type;
114 }
115
116protected:
118
123 };
124
126 public:
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
Definition: FontMgrTest.cpp:50
SkBlurStyle
Definition: SkBlurTypes.h:11
void sk_register_blur_maskfilter_createproc()
SkMaskFilterBase * as_MFB(SkMaskFilter *mf)
static SkScalar center(float pos0, float pos1)
Definition: GrClip.h:29
Definition: SkDraw.h:38
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
Definition: SkMaskFilter.h:50
Definition: SkPath.h:59
T * get() const
Definition: SkRefCnt.h:303
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
dst
Definition: cp.py:12
Definition: GpuTools.h:21
dest
Definition: zip.py:79
Definition: SkRect.h:32
Definition: SkMask.h:25
Format
Definition: SkMask.h:26