Debian Codegraph @

include/gpu/graphite/precompile/PaintOptions.h

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