• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "include/core/SkColor.h"
12 #include "include/core/SkPaint.h"
13 
14 class SkColorInfo;
15 class SkShader;
16 
17 namespace skgpu::graphite {
18 
19 class KeyContext;
20 class PaintParamsKeyBuilder;
21 class PipelineDataGatherer;
22 
23 // TBD: If occlusion culling is eliminated as a phase, we can easily move the paint conversion
24 // back to Device when the command is recorded (similar to SkPaint -> GrPaint), and then
25 // PaintParams is not required as an intermediate representation.
26 // NOTE: Only represents the shading state of an SkPaint. Style and complex effects (mask filters,
27 // image filters, path effects) must be handled higher up. AA is not tracked since everything is
28 // assumed to be anti-aliased.
29 class PaintParams {
30 public:
31     PaintParams(const SkColor4f& color,
32                 sk_sp<SkBlender> finalBlender,
33                 sk_sp<SkShader>,
34                 sk_sp<SkColorFilter>,
35                 sk_sp<SkBlender> primitiveBlender,
36                 bool skipColorXform);
37     explicit PaintParams(const SkPaint&,
38                          sk_sp<SkBlender> primitiveBlender,
39                          bool skipColorXform);
40 
41     PaintParams(const PaintParams&);
42     ~PaintParams();
43 
44     PaintParams& operator=(const PaintParams&);
45 
color()46     SkColor4f color() const { return fColor; }
47 
48     std::optional<SkBlendMode> asFinalBlendMode() const;
finalBlender()49     SkBlender* finalBlender() const { return fFinalBlender.get(); }
50     sk_sp<SkBlender> refFinalBlender() const;
51 
shader()52     SkShader* shader() const { return fShader.get(); }
53     sk_sp<SkShader> refShader() const;
54 
colorFilter()55     SkColorFilter* colorFilter() const { return fColorFilter.get(); }
56     sk_sp<SkColorFilter> refColorFilter() const;
57 
primitiveBlender()58     SkBlender* primitiveBlender() const { return fPrimitiveBlender.get(); }
59     sk_sp<SkBlender> refPrimitiveBlender() const;
60 
skipColorXform()61     bool skipColorXform() const { return fSkipColorXform; }
62 
63     /** Converts an SkColor4f to the destination color space. */
64     static SkColor4f Color4fPrepForDst(SkColor4f srgb, const SkColorInfo& dstColorInfo);
65 
66     void toKey(const KeyContext&,
67                PaintParamsKeyBuilder*,
68                PipelineDataGatherer*) const;
69 
70 private:
71     SkColor4f            fColor;
72     sk_sp<SkBlender>     fFinalBlender; // A nullptr here means SrcOver blending
73     sk_sp<SkShader>      fShader;
74     sk_sp<SkColorFilter> fColorFilter;
75     // A nullptr fPrimitiveBlender means there's no primitive color blending and it is skipped.
76     // In the case where there is primitive blending, the primitive color is the source color and
77     // the dest is the paint's color (or the paint's shader's computed color).
78     sk_sp<SkBlender>     fPrimitiveBlender;
79     bool                 fSkipColorXform;
80 
81     // TODO: Will also store ColorFilter, dither, and any extra shader from an
82     // active clipShader().
83 };
84 
85 } // namespace skgpu::graphite
86 
87 #endif // skgpu_PaintParams_DEFINED
88