Flutter Engine
The Flutter Engine
PaintOptions.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 Google LLC
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 skgpu_graphite_precompile_PaintOptions_DEFINED
9#define skgpu_graphite_precompile_PaintOptions_DEFINED
10
13#include "include/core/SkSpan.h"
16
17#include <functional>
18
19namespace skgpu::graphite {
20
21class PrecompileBlender;
22class PrecompileColorFilter;
23class PrecompileImageFilter;
24class PrecompileMaskFilter;
25class PrecompileShader;
26
27enum class Coverage;
28enum DrawTypeFlags : uint8_t;
29enum class PrecompileImageFilterFlags : uint32_t;
30
31class KeyContext;
32class PaintOptionsPriv;
33class PaintParamsKeyBuilder;
34class PipelineDataGatherer;
35class UniquePaintParamsID;
36
37/** \class PaintOptions
38 This is the Precompilation analog to SkPaint. It encapsulates a set of options for each
39 field of the SkPaint (e.g., colorFilters, imageFilters, etc). Many of the specific details
40 of an SkPaint that are irrelevant to the final compiled Pipelines are abstracted away
41 (e.g., the SkPaint's color field).
42
43 How Precompilation works in practice is a PaintOptions object is created and a set of options
44 for each slot (e.g., shader, blender) are added. When passed to the Precompile() function,
45 all the combinations specified by the PaintOptions will be created and precompiled.
46
47 To be concrete, if a PaintOptions object had two shader options and two blender options,
48 four combinations would be precompiled.
49*/
51public:
52 /** Constructs a PaintOptions object with default values. It is equivalent to a default
53 * initialized SkPaint.
54
55 @return default initialized PaintOptions
56 */
61
62 /** Sets the shader options used when generating precompilation combinations.
63
64 This corresponds to SkPaint's setShader() method
65
66 @param shaders The options used for shading when generating precompilation combinations.
67 */
68 void setShaders(SkSpan<const sk_sp<PrecompileShader>> shaders);
70 return SkSpan<const sk_sp<PrecompileShader>>(fShaderOptions);
71 }
72
73 /** Sets the image filter options used when generating precompilation combinations.
74
75 This corresponds to SkPaint's setImageFilter() method
76
77 @param imageFilters The options used for image filtering when generating precompilation
78 combinations.
79 */
80 void setImageFilters(SkSpan<const sk_sp<PrecompileImageFilter>> imageFilters);
82 return SkSpan<const sk_sp<PrecompileImageFilter>>(fImageFilterOptions);
83 }
84
85 /** Sets the mask filter options used when generating precompilation combinations.
86
87 This corresponds to SkPaint's setMaskFilter() method
88
89 @param maskFilters The options used for mask filtering when generating precompilation
90 combinations.
91 */
92 void setMaskFilters(SkSpan<const sk_sp<PrecompileMaskFilter>> maskFilters);
94 return SkSpan<const sk_sp<PrecompileMaskFilter>>(fMaskFilterOptions);
95 }
96
97 /** Sets the color filter options used when generating precompilation combinations.
98
99 This corresponds to SkPaint's setColorFilter() method
100
101 @param colorFilters The options used for color filtering when generating precompilation
102 combinations.
103 */
104 void setColorFilters(SkSpan<const sk_sp<PrecompileColorFilter>> colorFilters);
106 return SkSpan<const sk_sp<PrecompileColorFilter>>(fColorFilterOptions);
107 }
108
109 /** Sets the blend mode options used when generating precompilation combinations.
110
111 This corresponds to SkPaint's setBlendMode() method
112
113 @param blendModes The options used for blending when generating precompilation
114 combinations.
115 */
116 void setBlendModes(SkSpan<const SkBlendMode> blendModes);
118 return SkSpan<const SkBlendMode>(fBlendModeOptions.data(), fBlendModeOptions.size());
119 }
120
121 /** Sets the blender options used when generating precompilation combinations.
122
123 This corresponds to SkPaint's setBlender() method
124
125 @param blenders The options used for blending when generating precompilation combinations.
126 */
127 void setBlenders(SkSpan<const sk_sp<PrecompileBlender>> blenders);
129 return SkSpan<const sk_sp<PrecompileBlender>>(fBlenderOptions);
130 }
131
132 /** Sets the dither setting used when generating precompilation combinations
133
134 This corresponds to SkPaint's setDither() method
135
136 @param dither the dither setting used when generating precompilation combinations.
137 */
138 void setDither(bool dither) { fDither = dither; }
139 bool isDither() const { return fDither; }
140
141 // Provides access to functions that aren't part of the public API.
143 const PaintOptionsPriv priv() const; // NOLINT(readability-const-return-type)
144
145private:
146 friend class PaintOptionsPriv;
147
148 void addColorFilter(sk_sp<PrecompileColorFilter> cf);
149 void addBlendMode(SkBlendMode bm) {
150 fBlendModeOptions.push_back(bm);
151 }
152
153 void setClipShaders(SkSpan<const sk_sp<PrecompileShader>> clipShaders);
154
155 int numShaderCombinations() const;
156 int numColorFilterCombinations() const;
157 int numBlendCombinations() const;
158 int numClipShaderCombinations() const;
159
160 int numCombinations() const;
161 // 'desiredCombination' must be less than the result of the numCombinations call
162 void createKey(const KeyContext&,
165 int desiredCombination,
166 bool addPrimitiveBlender,
167 Coverage coverage) const;
168
169 typedef std::function<void(UniquePaintParamsID id,
171 bool withPrimitiveBlender,
172 Coverage)> ProcessCombination;
173
174 void buildCombinations(const KeyContext&,
176 DrawTypeFlags drawTypes,
177 bool addPrimitiveBlender,
179 const ProcessCombination& processCombination) const;
180
183 skia_private::TArray<SkBlendMode> fBlendModeOptions;
186
189
190 bool fDither = false;
191};
192
193} // namespace skgpu::graphite
194
195#endif // skgpu_graphite_precompile_PaintOptions_DEFINED
#define SK_API
Definition: SkAPI.h:35
SkBlendMode
Definition: SkBlendMode.h:38
void setDither(bool dither)
Definition: PaintOptions.h:138
SkSpan< const sk_sp< PrecompileColorFilter > > getColorFilters() const
Definition: PaintOptions.h:105
PaintOptions(const PaintOptions &)
SkSpan< const sk_sp< PrecompileShader > > getShaders() const
Definition: PaintOptions.h:69
SkSpan< const SkBlendMode > getBlendModes() const
Definition: PaintOptions.h:117
SkSpan< const sk_sp< PrecompileMaskFilter > > getMaskFilters() const
Definition: PaintOptions.h:93
SkSpan< const sk_sp< PrecompileBlender > > getBlenders() const
Definition: PaintOptions.h:128
SkSpan< const sk_sp< PrecompileImageFilter > > getImageFilters() const
Definition: PaintOptions.h:81
PaintOptions & operator=(const PaintOptions &)
FlPixelBufferTexturePrivate * priv
Dart_NativeFunction function
Definition: fuchsia.cc:51