/src/skia/include/gpu/graphite/precompile/PaintOptions.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
31 | | class KeyContext; |
32 | | class PaintOptionsPriv; |
33 | | class PaintParamsKeyBuilder; |
34 | | class PipelineDataGatherer; |
35 | | class 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 | | */ |
50 | | class SK_API PaintOptions { |
51 | | public: |
52 | | /** Constructs a PaintOptions object with default values. It is equivalent to a default |
53 | | * initialized SkPaint. |
54 | | |
55 | | @return default initialized PaintOptions |
56 | | */ |
57 | | PaintOptions(); |
58 | | PaintOptions(const PaintOptions&); |
59 | | ~PaintOptions(); |
60 | | PaintOptions& operator=(const PaintOptions&); |
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); |
69 | 0 | SkSpan<const sk_sp<PrecompileShader>> getShaders() const { |
70 | 0 | return SkSpan<const sk_sp<PrecompileShader>>(fShaderOptions); |
71 | 0 | } |
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); |
81 | 0 | SkSpan<const sk_sp<PrecompileImageFilter>> getImageFilters() const { |
82 | 0 | return SkSpan<const sk_sp<PrecompileImageFilter>>(fImageFilterOptions); |
83 | 0 | } |
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); |
93 | 0 | SkSpan<const sk_sp<PrecompileMaskFilter>> getMaskFilters() const { |
94 | 0 | return SkSpan<const sk_sp<PrecompileMaskFilter>>(fMaskFilterOptions); |
95 | 0 | } |
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); |
105 | 0 | SkSpan<const sk_sp<PrecompileColorFilter>> getColorFilters() const { |
106 | 0 | return SkSpan<const sk_sp<PrecompileColorFilter>>(fColorFilterOptions); |
107 | 0 | } |
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); |
117 | 0 | SkSpan<const SkBlendMode> getBlendModes() const { |
118 | 0 | return SkSpan<const SkBlendMode>(fBlendModeOptions.data(), fBlendModeOptions.size()); |
119 | 0 | } |
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); |
128 | 0 | SkSpan<const sk_sp<PrecompileBlender>> getBlenders() const { |
129 | 0 | return SkSpan<const sk_sp<PrecompileBlender>>(fBlenderOptions); |
130 | 0 | } |
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 | 0 | void setDither(bool dither) { fDither = dither; } |
139 | 0 | bool isDither() const { return fDither; } |
140 | | |
141 | | // Provides access to functions that aren't part of the public API. |
142 | | PaintOptionsPriv priv(); |
143 | | const PaintOptionsPriv priv() const; // NOLINT(readability-const-return-type) |
144 | | |
145 | | private: |
146 | | friend class PaintOptionsPriv; |
147 | | friend class PrecompileImageFilter; // for ProcessCombination access |
148 | | friend class PrecompileMaskFilter; // for ProcessCombination access |
149 | | |
150 | | void addColorFilter(sk_sp<PrecompileColorFilter> cf); |
151 | 0 | void addBlendMode(SkBlendMode bm) { |
152 | 0 | fBlendModeOptions.push_back(bm); |
153 | 0 | } |
154 | | |
155 | | void setClipShaders(SkSpan<const sk_sp<PrecompileShader>> clipShaders); |
156 | | |
157 | | int numShaderCombinations() const; |
158 | | int numColorFilterCombinations() const; |
159 | | int numBlendCombinations() const; |
160 | | int numClipShaderCombinations() const; |
161 | | |
162 | | int numCombinations() const; |
163 | | // 'desiredCombination' must be less than the result of the numCombinations call |
164 | | void createKey(const KeyContext&, |
165 | | PaintParamsKeyBuilder*, |
166 | | PipelineDataGatherer*, |
167 | | int desiredCombination, |
168 | | bool addPrimitiveBlender, |
169 | | Coverage coverage) const; |
170 | | |
171 | | typedef std::function<void(UniquePaintParamsID id, |
172 | | DrawTypeFlags, |
173 | | bool withPrimitiveBlender, |
174 | | Coverage)> ProcessCombination; |
175 | | |
176 | | void buildCombinations(const KeyContext&, |
177 | | PipelineDataGatherer*, |
178 | | DrawTypeFlags drawTypes, |
179 | | bool addPrimitiveBlender, |
180 | | Coverage coverage, |
181 | | const ProcessCombination& processCombination) const; |
182 | | |
183 | | skia_private::TArray<sk_sp<PrecompileShader>> fShaderOptions; |
184 | | skia_private::TArray<sk_sp<PrecompileColorFilter>> fColorFilterOptions; |
185 | | skia_private::TArray<SkBlendMode> fBlendModeOptions; |
186 | | skia_private::TArray<sk_sp<PrecompileBlender>> fBlenderOptions; |
187 | | skia_private::TArray<sk_sp<PrecompileShader>> fClipShaderOptions; |
188 | | |
189 | | skia_private::TArray<sk_sp<PrecompileImageFilter>> fImageFilterOptions; |
190 | | skia_private::TArray<sk_sp<PrecompileMaskFilter>> fMaskFilterOptions; |
191 | | |
192 | | bool fDither = false; |
193 | | }; |
194 | | |
195 | | } // namespace skgpu::graphite |
196 | | |
197 | | #endif // skgpu_graphite_precompile_PaintOptions_DEFINED |