Flutter Engine
The Flutter Engine
PaintParams.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_PaintParams_DEFINED
9#define skgpu_graphite_PaintParams_DEFINED
10
14#include <functional> // std::function
15
16class SkColorInfo;
17class SkShader;
18
19namespace skgpu::graphite {
20
21class DrawContext;
22class KeyContext;
23class PaintParamsKeyBuilder;
24class PipelineDataGatherer;
25class Recorder;
26class TextureProxy;
27
28// TBD: If occlusion culling is eliminated as a phase, we can easily move the paint conversion
29// back to Device when the command is recorded (similar to SkPaint -> GrPaint), and then
30// PaintParams is not required as an intermediate representation.
31// NOTE: Only represents the shading state of an SkPaint. Style and complex effects (mask filters,
32// image filters, path effects) must be handled higher up. AA is not tracked since everything is
33// assumed to be anti-aliased.
35public:
36 explicit PaintParams(const SkPaint&,
38 sk_sp<SkShader> clipShader,
39 DstReadRequirement dstReadReq,
40 bool skipColorXform);
41
44
46
47 SkColor4f color() const { return fColor; }
48
49 std::optional<SkBlendMode> asFinalBlendMode() const;
50 SkBlender* finalBlender() const { return fFinalBlender.get(); }
52
53 SkShader* shader() const { return fShader.get(); }
55
56 SkColorFilter* colorFilter() const { return fColorFilter.get(); }
58
59 SkBlender* primitiveBlender() const { return fPrimitiveBlender.get(); }
61
62 DstReadRequirement dstReadRequirement() const { return fDstReadReq; }
63 bool skipColorXform() const { return fSkipColorXform; }
64 bool dither() const { return fDither; }
65
66 /** Converts an SkColor4f to the destination color space. */
67 static SkColor4f Color4fPrepForDst(SkColor4f srgb, const SkColorInfo& dstColorInfo);
68
70
72
73private:
74 void addPaintColorToKey(const KeyContext&, PaintParamsKeyBuilder*, PipelineDataGatherer*) const;
75 void handlePrimitiveColor(const KeyContext&,
78 void handlePaintAlpha(const KeyContext&, PaintParamsKeyBuilder*, PipelineDataGatherer*) const;
79 void handleColorFilter(const KeyContext&, PaintParamsKeyBuilder*, PipelineDataGatherer*) const;
80 void handleDithering(const KeyContext&, PaintParamsKeyBuilder*, PipelineDataGatherer*) const;
81 void handleDstRead(const KeyContext&, PaintParamsKeyBuilder*, PipelineDataGatherer*) const;
82
83 SkColor4f fColor;
84 sk_sp<SkBlender> fFinalBlender; // A nullptr here means SrcOver blending
85 sk_sp<SkShader> fShader;
86 sk_sp<SkColorFilter> fColorFilter;
87 // A nullptr fPrimitiveBlender means there's no primitive color blending and it is skipped.
88 // In the case where there is primitive blending, the primitive color is the source color and
89 // the dest is the paint's color (or the paint's shader's computed color).
90 sk_sp<SkBlender> fPrimitiveBlender;
91 sk_sp<SkShader> fClipShader;
92 DstReadRequirement fDstReadReq;
93 bool fSkipColorXform;
94 bool fDither;
95};
96
97using AddToKeyFn = std::function<void()>;
98
100 AddToKeyFn addBlendToKey, AddToKeyFn addSrcToKey, AddToKeyFn addDstToKey);
102 AddToKeyFn addInnerToKey, AddToKeyFn addOuterToKey);
103// Add a blend mode node for a specific SkBlendMode.
104void AddKnownModeBlend(const KeyContext&,
108// Add a blend mode node for an SkBlendMode that can vary
110void AddDstReadBlock(const KeyContext&,
115
116} // namespace skgpu::graphite
117
118#endif // skgpu_PaintParams_DEFINED
SkBlendMode
Definition: SkBlendMode.h:38
SkColorType
Definition: SkColorType.h:19
T * get() const
Definition: SkRefCnt.h:303
PaintParams & operator=(const PaintParams &)
sk_sp< SkBlender > refFinalBlender() const
Definition: PaintParams.cpp:77
sk_sp< SkBlender > refPrimitiveBlender() const
Definition: PaintParams.cpp:83
SkBlender * finalBlender() const
Definition: PaintParams.h:50
SkColor4f color() const
Definition: PaintParams.h:47
DstReadRequirement dstReadRequirement() const
Definition: PaintParams.h:62
void toKey(const KeyContext &, PaintParamsKeyBuilder *, PipelineDataGatherer *) const
PaintParams(const SkPaint &, sk_sp< SkBlender > primitiveBlender, sk_sp< SkShader > clipShader, DstReadRequirement dstReadReq, bool skipColorXform)
Definition: PaintParams.cpp:53
std::optional< SkBlendMode > asFinalBlendMode() const
Definition: PaintParams.cpp:72
static SkColor4f Color4fPrepForDst(SkColor4f srgb, const SkColorInfo &dstColorInfo)
Definition: PaintParams.cpp:85
sk_sp< SkColorFilter > refColorFilter() const
Definition: PaintParams.cpp:81
SkBlender * primitiveBlender() const
Definition: PaintParams.h:59
void notifyImagesInUse(Recorder *, DrawContext *) const
SkColorFilter * colorFilter() const
Definition: PaintParams.h:56
sk_sp< SkShader > refShader() const
Definition: PaintParams.cpp:79
PaintParams(const PaintParams &)
SkShader * shader() const
Definition: PaintParams.h:53
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::function< void()> AddToKeyFn
Definition: PaintParams.h:97
void AddKnownModeBlend(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkBlendMode bm)
void Compose(const KeyContext &keyContext, PaintParamsKeyBuilder *keyBuilder, PipelineDataGatherer *gatherer, AddToKeyFn addInnerToKey, AddToKeyFn addOuterToKey)
void AddDitherBlock(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkColorType ct)
void AddDstReadBlock(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, DstReadRequirement dstReadReq)
void Blend(const KeyContext &keyContext, PaintParamsKeyBuilder *keyBuilder, PipelineDataGatherer *gatherer, AddToKeyFn addBlendToKey, AddToKeyFn addSrcToKey, AddToKeyFn addDstToKey)
Definition: PaintParams.cpp:95
DstReadRequirement
Definition: Caps.h:64
void AddModeBlend(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkBlendMode bm)