Flutter Engine
The Flutter Engine
RendererProvider.cpp
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
9
27#include "src/sksl/SkSLUtil.h"
28
29#ifdef SK_ENABLE_VELLO_SHADERS
31#endif
32
33namespace skgpu::graphite {
34
36#ifdef SK_ENABLE_VELLO_SHADERS
37 return caps->computeSupport();
38#else
39 return false;
40#endif
41}
42
43// The destructor is intentionally defined here and not in the header file to allow forward
44// declared types (such as `VelloRenderer`) to be defined as a `std::unique_ptr` parameter type
45// in members.
47
48RendererProvider::RendererProvider(const Caps* caps, StaticBufferManager* bufferManager) {
49 // This constructor requires all Renderers be densely packed so that it can simply iterate over
50 // the fields directly and fill 'fRenderers' with every one that was initialized with a
51 // non-empty renderer. While this is a little magical, it simplifies the rest of the logic
52 // and can be enforced statically.
53 static constexpr size_t kRendererSize = offsetof(RendererProvider, fRenderers) -
54 offsetof(RendererProvider, fStencilTessellatedCurves);
55 static_assert(kRendererSize % sizeof(Renderer) == 0, "Renderer declarations are not dense");
56
57 const bool infinitySupport = caps->shaderCaps()->fInfinitySupport;
58
59 // Single-step renderers don't share RenderSteps
60 auto makeFromStep = [&](std::unique_ptr<RenderStep> singleStep, DrawTypeFlags drawTypes) {
61 std::string name = "SingleStep[";
62 name += singleStep->name();
63 name += "]";
64 fRenderSteps.push_back(std::move(singleStep));
65 return Renderer(name, drawTypes, fRenderSteps.back().get());
66 };
67
68 fConvexTessellatedWedges =
69 makeFromStep(std::make_unique<TessellateWedgesRenderStep>(
70 "convex", infinitySupport, kDirectDepthGreaterPass, bufferManager),
72 fTessellatedStrokes = makeFromStep(
73 std::make_unique<TessellateStrokesRenderStep>(infinitySupport), DrawTypeFlags::kShape);
74 fCoverageMask = makeFromStep(std::make_unique<CoverageMaskRenderStep>(), DrawTypeFlags::kShape);
75 for (bool lcd : {false, true}) {
76 fBitmapText[lcd] = makeFromStep(std::make_unique<BitmapTextRenderStep>(lcd),
78 fSDFText[lcd] = lcd ? makeFromStep(std::make_unique<SDFTextLCDRenderStep>(),
80 : makeFromStep(std::make_unique<SDFTextRenderStep>(),
82 }
83 fAnalyticRRect = makeFromStep(std::make_unique<AnalyticRRectRenderStep>(bufferManager),
85 fPerEdgeAAQuad = makeFromStep(std::make_unique<PerEdgeAAQuadRenderStep>(bufferManager),
87 fAnalyticBlur = makeFromStep(std::make_unique<AnalyticBlurRenderStep>(),
90 for (bool color : {false, true}) {
91 for (bool texCoords : {false, true}) {
92 int index = 4*(primType == PrimitiveType::kTriangleStrip) + 2*color + texCoords;
93 fVertices[index] = makeFromStep(
94 std::make_unique<VerticesRenderStep>(primType, color, texCoords),
96 }
97 }
98 }
99
100 // The tessellating path renderers that use stencil can share the cover steps.
101 auto coverFill = std::make_unique<CoverBoundsRenderStep>(false);
102 auto coverInverse = std::make_unique<CoverBoundsRenderStep>(true);
103
104 for (bool evenOdd : {false, true}) {
105 // These steps can be shared by regular and inverse fills
106 auto stencilFan = std::make_unique<MiddleOutFanRenderStep>(evenOdd);
107 auto stencilCurve = std::make_unique<TessellateCurvesRenderStep>(
108 evenOdd, infinitySupport, bufferManager);
109 auto stencilWedge =
110 evenOdd ? std::make_unique<TessellateWedgesRenderStep>(
111 "evenodd", infinitySupport, kEvenOddStencilPass, bufferManager)
112 : std::make_unique<TessellateWedgesRenderStep>(
113 "winding", infinitySupport, kWindingStencilPass, bufferManager);
114
115 for (bool inverse : {false, true}) {
116 static const char* kTessVariants[4] =
117 {"[winding]", "[evenodd]", "[inverse-winding]", "[inverse-evenodd]"};
118
119 int index = 2*inverse + evenOdd; // matches SkPathFillType
120 std::string variant = kTessVariants[index];
121
122 constexpr DrawTypeFlags kTextAndShape =
124
125 const RenderStep* coverStep = inverse ? coverInverse.get() : coverFill.get();
126 fStencilTessellatedCurves[index] = Renderer("StencilTessellatedCurvesAndTris" + variant,
127 kTextAndShape,
128 stencilFan.get(),
129 stencilCurve.get(),
130 coverStep);
131
132 fStencilTessellatedWedges[index] = Renderer("StencilTessellatedWedges" + variant,
133 kTextAndShape,
134 stencilWedge.get(),
135 coverStep);
136 }
137
138 fRenderSteps.push_back(std::move(stencilFan));
139 fRenderSteps.push_back(std::move(stencilCurve));
140 fRenderSteps.push_back(std::move(stencilWedge));
141 }
142
143 fRenderSteps.push_back(std::move(coverInverse));
144 fRenderSteps.push_back(std::move(coverFill));
145
146 // Fill out 'fRenderers' by iterating the "span" from fStencilTessellatedCurves to fRenderers
147 // and checking if they've been skipped or not.
148 SkSpan<Renderer> allRenderers = {fStencilTessellatedCurves, kRendererSize / sizeof(Renderer)};
149 for (const Renderer& r : allRenderers) {
150 if (r.numRenderSteps() > 0) {
151 fRenderers.push_back(&r);
152 }
153 }
154
155#ifdef SK_ENABLE_VELLO_SHADERS
156 fVelloRenderer = std::make_unique<VelloRenderer>(caps);
157#endif
158}
159
160const RenderStep* RendererProvider::lookup(uint32_t uniqueID) const {
161 for (auto&& rs : fRenderSteps) {
162 if (rs->uniqueID() == uniqueID) {
163 return rs.get();
164 }
165 }
166 return nullptr;
167}
168
169} // namespace skgpu::graphite
bool computeSupport() const
Definition: Caps.h:257
const SkSL::ShaderCaps * shaderCaps() const
Definition: Caps.h:75
const RenderStep * lookup(uint32_t uniqueID) const
static bool IsVelloRendererSupported(const Caps *)
DlColor color
constexpr char kText[]
Definition: glyph_pos.cpp:28
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
constexpr DepthStencilSettings kWindingStencilPass
static constexpr DepthStencilSettings kDirectDepthGreaterPass
constexpr DepthStencilSettings kEvenOddStencilPass
Definition: ref_ptr.h:256
bool fInfinitySupport
Definition: SkSLUtil.h:103