Debian Codegraph @

src/gpu/graphite/compute/VelloRenderer.h

raw
1 /*
2 * Copyright 2023 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_compute_VelloRenderer_DEFINED
9 #define skgpu_graphite_compute_VelloRenderer_DEFINED
10
11 #include "include/core/SkColor.h"
12 #include "include/core/SkPath.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkStrokeRec.h"
15 #include "src/gpu/graphite/compute/VelloComputeSteps.h"
16 #include "third_party/vello/cpp/vello.h"
17
18 #include <memory>
19
20 namespace skgpu::graphite {
21
22 class Caps;
23 class DispatchGroup;
24 class Recorder;
25 class TextureProxy;
26 class Transform;
27
28 // Encodes Bezier path fills, shapes, and clips. Once populated, this data structure can be used
29 // with the full compositing and coverage mask generating pipelines. The latter only uses the red
30 // color channel information.
31 //
32 // All color type parameters are expected to be unpremultiplied and in the sRGB color space.
33 class VelloScene final {
34 public:
35 VelloScene();
36
37 void reset();
38
39 void solidFill(const SkPath&,
40 const SkColor4f&,
41 const SkPathFillType,
42 const Transform& transform);
43
44 void solidStroke(const SkPath&,
45 const SkColor4f&,
46 const SkStrokeRec&,
47 const Transform& transform);
48
49 void pushClipLayer(const SkPath& shape, const Transform& transform);
50 void popClipLayer();
51
52 void append(const VelloScene& other);
53
54 private:
55 friend class VelloRenderer;
56
57 // Disallow copy
58 VelloScene(const VelloScene&) = delete;
59 VelloScene& operator=(const VelloScene&) = delete;
60
61 ::rust::Box<::vello_cpp::Encoding> fEncoding;
62 SkDEBUGCODE(int fLayers = 0;)
63 };
64
65 enum class VelloAaConfig {
66 kAnalyticArea,
67 kMSAA16,
68 kMSAA8,
69 };
70
71 // A VelloRenderer that is specialized for rendering coverage masks. The renderer only supports
72 // paths and clipping and omits the full vello imaging model (e.g. gradients and images).
73 //
74 // VelloRenderer requires `kAlpha_8_SkColorType` as the target color type on platforms that
75 // support the `R8Unorm` storage texture view format. Otherwise, the texture format must be
76 // `kRGBA_8888_SkColorType`.
77 class VelloRenderer final {
78 public:
79 explicit VelloRenderer(const Caps*);
80 ~VelloRenderer();
81
82 struct RenderParams {
83 // Dimensions of the fine rasterization target
84 uint32_t fWidth;
85 uint32_t fHeight;
86
87 // The background color used during blending.
88 SkColor4f fBaseColor;
89
90 // The antialiasing method.
91 VelloAaConfig fAaConfig;
92 };
93
94 // Run the full pipeline which supports compositing colors with different blend styles. Does
95 // nothing if `scene` or target render dimensions are empty.
96 //
97 // The color type of `target` must be `kAlpha_8_SkColorType` on platforms that support R8Unorm
98 // storage textures. Otherwise, it must be `kRGBA_8888_SkColorType`.
99 std::unique_ptr<DispatchGroup> renderScene(const RenderParams&,
100 const VelloScene&,
101 sk_sp<TextureProxy> target,
102 Recorder*) const;
103
104 private:
105 // Pipelines
106 VelloBackdropDynStep fBackdrop;
107 VelloBboxClearStep fBboxClear;
108 VelloBinningStep fBinning;
109 VelloClipLeafStep fClipLeaf;
110 VelloClipReduceStep fClipReduce;
111 VelloCoarseStep fCoarse;
112 VelloDrawLeafStep fDrawLeaf;
113 VelloDrawReduceStep fDrawReduce;
114 VelloFlattenStep fFlatten;
115 VelloPathCountStep fPathCount;
116 VelloPathCountSetupStep fPathCountSetup;
117 VelloPathTilingStep fPathTiling;
118 VelloPathTilingSetupStep fPathTilingSetup;
119 VelloPathtagReduceStep fPathtagReduce;
120 VelloPathtagReduce2Step fPathtagReduce2;
121 VelloPathtagScan1Step fPathtagScan1;
122 VelloPathtagScanLargeStep fPathtagScanLarge;
123 VelloPathtagScanSmallStep fPathtagScanSmall;
124 VelloTileAllocStep fTileAlloc;
125
126 // Fine rasterization stage variants:
127 std::unique_ptr<ComputeStep> fFineArea;
128 std::unique_ptr<ComputeStep> fFineMsaa16;
129 std::unique_ptr<ComputeStep> fFineMsaa8;
130 };
131
132 } // namespace skgpu::graphite
133
134 #endif // skgpu_graphite_compute_VelloRenderer_DEFINED