Flutter Engine
The Flutter Engine
VelloRenderer.h
Go to the documentation of this file.
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
12#include "include/core/SkPath.h"
17
18#include <memory>
19
20namespace skgpu::graphite {
21
22class Caps;
23class DispatchGroup;
24class Recorder;
25class TextureProxy;
26class 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.
33class VelloScene final {
34public:
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
54private:
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
65enum class VelloAaConfig {
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`.
77class VelloRenderer final {
78public:
79 explicit VelloRenderer(const Caps*);
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.
89
90 // The antialiasing method.
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&,
102 Recorder*) const;
103
104private:
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
SkPathFillType
Definition: SkPathTypes.h:11
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
Definition: SkPath.h:59
std::unique_ptr< DispatchGroup > renderScene(const RenderParams &, const VelloScene &, sk_sp< TextureProxy > target, Recorder *) const
void pushClipLayer(const SkPath &shape, const Transform &transform)
void append(const VelloScene &other)
void solidStroke(const SkPath &, const SkColor4f &, const SkStrokeRec &, const Transform &transform)
void solidFill(const SkPath &, const SkColor4f &, const SkPathFillType, const Transform &transform)
uint32_t * target
skgpu::graphite::Transform Transform
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47