Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
KeyHelpers.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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_KeyHelpers_DEFINED
9#define skgpu_graphite_KeyHelpers_DEFINED
10
13#include "include/core/SkM44.h"
17#include "include/core/SkSpan.h"
25
26class SkColorFilter;
27class SkData;
28class SkRuntimeEffect;
29
30namespace skgpu::graphite {
31
32class DrawContext;
33class KeyContext;
34class PaintParamsKeyBuilder;
35class PipelineDataGatherer;
36class UniquePaintParamsID;
37enum class ReadSwizzle;
38
39// Types of logical "destinations" that a blender might blend with.
40enum class DstColorType {
41 // A color read from the framebuffer.
43 // A color provided by geometry.
45 // A color evaluated by a child shader.
47};
48
49/**
50 * The KeyHelpers can be used to manually construct an SkPaintParamsKey.
51 *
52 * TODO: If we restructure how the keys are made, we can utilize a single block type for the
53 * different blend blocks outlined below. The different Src/Dst pairings could instead be encoded
54 * as parent-child relationships.
55 */
56
58 static void AddBlock(const KeyContext&,
62 SkIPoint dstOffset);
63};
64
66 static void AddBlock(const KeyContext&,
69 const SkPMColor4f&);
70};
71
77
83
85 struct GradientData {
86 // The number of stops stored internal to this data structure before falling back to
87 // bitmap storage.
88 static constexpr int kNumInternalStorageStops = 8;
89
90 // This ctor is used during pre-compilation when we don't have enough information to
91 // extract uniform data. However, we must be able to provide enough data to make all the
92 // relevant decisions about which code snippets to use.
94
95 // This ctor is used when extracting information from PaintParams. It must provide
96 // enough data to generate the uniform data the selected code snippet will require.
98 SkPoint point0, SkPoint point1,
99 float radius0, float radius1,
100 float bias, float scale,
102 int numStops,
103 const SkPMColor4f* colors,
104 const float* offsets,
105 sk_sp<TextureProxy> colorsAndOffsetsProxy,
107
108 bool operator==(const GradientData& rhs) const = delete;
109 bool operator!=(const GradientData& rhs) const = delete;
110
111 // Layout options.
114 float fRadii[2];
115
116 // Layout options for sweep gradient.
117 float fBias;
118 float fScale;
119
122
123 // For gradients w/ <= kNumInternalStorageStops stops we use fColors and fOffsets.
124 // The offsets are packed into a single float4 to save space when the layout is std140.
125 // Otherwise we use fColorsAndOffsetsProxy.
129
131 };
132
133 static void AddBlock(const KeyContext&,
136 const GradientData&);
137};
138
141 LMShaderData(const SkMatrix& localMatrix)
142 : fLocalMatrix(localMatrix) {
143 }
144
146 };
147
148 static void BeginBlock(const KeyContext&,
151 const LMShaderData&);
152};
153
155 struct ImageData {
156 ImageData(const SkSamplingOptions& sampling,
157 SkTileMode tileModeX,
158 SkTileMode tileModeY,
159 SkISize imgSize,
160 SkRect subset,
161 ReadSwizzle readSwizzle);
162
168
170
171 // TODO: Currently this is only filled in when we're generating the key from an actual
172 // SkImageShader. In the pre-compile case we will need to create a Graphite promise
173 // image which holds the appropriate data.
175 };
176
177 static void AddBlock(const KeyContext&,
180 const ImageData&);
181};
182
184 struct ImageData {
185 ImageData(const SkSamplingOptions& sampling,
186 SkTileMode tileModeX,
187 SkTileMode tileModeY,
188 SkISize imgSize,
189 SkRect subset);
190
195 SkISize fImgSizeUV; // Size of UV planes relative to Y's texel space
197 SkPoint fLinearFilterUVInset = { 0.50001f, 0.50001f };
201
202 // TODO: Currently these are only filled in when we're generating the key from an actual
203 // SkImageShader. In the pre-compile case we will need to create Graphite promise
204 // images which hold the appropriate data.
206 };
207
208 static void AddBlock(const KeyContext&,
211 const ImageData&);
212};
213
216 CoordClampData(SkRect subset) : fSubset(subset) {}
217
219 };
220
221 // The gatherer and data should be null or non-null together
222 static void BeginBlock(const KeyContext&,
225 const CoordClampData&);
226};
227
229 struct DitherData {
230 DitherData(float range, sk_sp<TextureProxy> proxy)
231 : fRange(range)
232 , fLUTProxy(std::move(proxy)) {}
233
234 float fRange;
236 };
237
238 static void AddBlock(const KeyContext&,
241 const DitherData&);
242};
243
245 enum class Type {
248 };
249
252 SkVector baseFrequency,
253 int numOctaves,
254 SkISize stitchData)
255 : fType(type)
256 , fBaseFrequency(baseFrequency)
257 , fNumOctaves(numOctaves)
258 , fStitchData{ SkIntToFloat(stitchData.fWidth), SkIntToFloat(stitchData.fHeight) } {
259 }
260
261 bool stitching() const { return !fStitchData.isZero(); }
262
267
270 };
271
272 // The gatherer and data should be null or non-null together
273 static void AddBlock(const KeyContext&,
276 const PerlinNoiseData&);
277};
278
282
289
291 static void AddBlock(const KeyContext&,
294 SkSpan<const float> coeffs);
295};
296
298 static void BeginBlock(const KeyContext&,
301};
302
304 static void BeginBlock(const KeyContext&,
307};
308
311 MatrixColorFilterData(const float matrix[20],
312 bool inHSLA)
313 : fMatrix(matrix[ 0], matrix[ 1], matrix[ 2], matrix[ 3],
314 matrix[ 5], matrix[ 6], matrix[ 7], matrix[ 8],
315 matrix[10], matrix[11], matrix[12], matrix[13],
316 matrix[15], matrix[16], matrix[17], matrix[18])
317 , fTranslate{matrix[4], matrix[9], matrix[14], matrix[19]}
318 , fInHSLA(inHSLA) {
319 }
320
324 };
325
326 // The gatherer and matrixCFData should be null or non-null together
327 static void AddBlock(const KeyContext&,
330 const MatrixColorFilterData&);
331};
332
345
361
362/**
363 * Blend mode color filters blend their input (as the dst color) with some given color (supplied
364 * via a uniform) as the src color.
365 */
370 const SkPMColor4f& srcColor);
371
373 struct ShaderData {
374 // This ctor is used during pre-compilation when we don't have enough information to
375 // extract uniform data.
377
378 // This ctor is used when extracting information from PaintParams.
380 sk_sp<const SkData> uniforms);
381
382 bool operator==(const ShaderData& rhs) const;
383 bool operator!=(const ShaderData& rhs) const { return !(*this == rhs); }
384
385 // Runtime shader data.
388 };
389
390 static void BeginBlock(const KeyContext&,
393 const ShaderData&);
394};
395
396void AddToKey(const KeyContext&,
399 const SkBlender*);
400
401/**
402 * Add implementation details, for the specified backend, of this SkColorFilter to the
403 * provided key.
404 *
405 * @param keyContext backend context for key creation
406 * @param builder builder for creating the key for this SkShader
407 * @param gatherer if non-null, storage for this colorFilter's data
408 * @param filter This function is a no-op if filter is null.
409 */
410void AddToKey(const KeyContext& keyContext,
411 PaintParamsKeyBuilder* builder,
412 PipelineDataGatherer* gatherer,
413 const SkColorFilter* filter);
414
415/**
416 * Add implementation details, for the specified backend, of this SkShader to the
417 * provided key.
418 *
419 * @param keyContext backend context for key creation
420 * @param builder builder for creating the key for this SkShader
421 * @param gatherer if non-null, storage for this colorFilter's data
422 * @param shader This function is a no-op if shader is null.
423 */
424void AddToKey(const KeyContext& keyContext,
425 PaintParamsKeyBuilder* builder,
426 PipelineDataGatherer* gatherer,
427 const SkShader* shader);
428
429// TODO(b/330864257) These visitation functions are redundant with AddToKey, except that they are
430// executed in the Device::drawGeometry() stack frame, whereas the keys are currently deferred until
431// DrawPass::Make. Image use needs to be detected in the draw frame to split tasks to match client
432// actions. Once paint keys are extracted in the draw frame, this can go away entirely.
436
437} // namespace skgpu::graphite
438
439#endif // skgpu_graphite_KeyHelpers_DEFINED
SkAlphaType
Definition SkAlphaType.h:26
SkBlendMode
Definition SkBlendMode.h:38
#define SkIntToFloat(x)
Definition SkScalar.h:58
SkTileMode
Definition SkTileMode.h:13
Definition SkM44.h:150
void AddToKey(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, const SkBlender *blender)
void AddBlendModeColorFilter(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkBlendMode bm, const SkPMColor4f &srcColor)
void NotifyImagesInUse(Recorder *recorder, DrawContext *drawContext, const SkBlender *blender)
Definition ref_ptr.h:256
const Scalar scale
bool isZero() const
Definition SkM44.h:98
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, SkBlendMode)
static void BeginBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *)
static void BeginBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, SkSpan< const float > coeffs)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const ColorSpaceTransformData &)
static void BeginBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *)
static void BeginBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const CoordClampData &)
DitherData(float range, sk_sp< TextureProxy > proxy)
Definition KeyHelpers.h:230
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const DitherData &)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, sk_sp< TextureProxy > dst, SkIPoint dstOffset)
bool operator!=(const GradientData &rhs) const =delete
SkPMColor4f fColors[kNumInternalStorageStops]
Definition KeyHelpers.h:126
SkGradientShader::Interpolation fInterpolation
Definition KeyHelpers.h:130
SkV4 fOffsets[kNumInternalStorageStops/4]
Definition KeyHelpers.h:127
bool operator==(const GradientData &rhs) const =delete
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const GradientData &)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const ImageData &)
static void BeginBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const LMShaderData &)
MatrixColorFilterData(const float matrix[20], bool inHSLA)
Definition KeyHelpers.h:311
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const MatrixColorFilterData &)
PerlinNoiseData(Type type, SkVector baseFrequency, int numOctaves, SkISize stitchData)
Definition KeyHelpers.h:251
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const PerlinNoiseData &)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *)
sk_sp< const SkRuntimeEffect > fEffect
Definition KeyHelpers.h:386
bool operator!=(const ShaderData &rhs) const
Definition KeyHelpers.h:383
bool operator==(const ShaderData &rhs) const
static void BeginBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const ShaderData &)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const SkPMColor4f &)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const TableColorFilterData &)
static void AddBlock(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *, const ImageData &)