Flutter Engine
The Flutter Engine
RendererProvider.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_RendererProvider_DEFINED
9#define skgpu_graphite_RendererProvider_DEFINED
10
14
15#include <vector>
16
17namespace skgpu::graphite {
18
19class Caps;
20class StaticBufferManager;
21
22#ifdef SK_ENABLE_VELLO_SHADERS
23class VelloRenderer;
24#endif
25
26/**
27 * Graphite defines a limited set of renderers in order to increase the likelihood of batching
28 * across draw calls, and reducing the number of shader permutations required. These Renderers are
29 * stateless singletons and remain alive for the life of the Context and its Recorders.
30 *
31 * Because Renderers are immutable and the defined Renderers are created at context initialization,
32 * RendererProvider is trivially thread-safe.
33 */
35public:
36 static bool IsVelloRendererSupported(const Caps*);
37
39
40 // TODO: Add configuration options to disable "optimization" renderers in favor of the more
41 // general case, or renderers that won't be used by the application. When that's added, these
42 // functions could return null.
43
44 // Path rendering for fills and strokes
46 return &fStencilTessellatedCurves[(int) type];
47 }
49 return &fStencilTessellatedWedges[(int) type];
50 }
51 const Renderer* convexTessellatedWedges() const { return &fConvexTessellatedWedges; }
52 const Renderer* tessellatedStrokes() const { return &fTessellatedStrokes; }
53
54 // Coverage mask rendering
55 const Renderer* coverageMask() const { return &fCoverageMask; }
56
57 // Atlas'ed text rendering
58 const Renderer* bitmapText(bool useLCDText) const { return &fBitmapText[useLCDText]; }
59 const Renderer* sdfText(bool useLCDText) const { return &fSDFText[useLCDText]; }
60
61 // Mesh rendering
62 const Renderer* vertices(SkVertices::VertexMode mode, bool hasColors, bool hasTexCoords) const {
63 SkASSERT(mode != SkVertices::kTriangleFan_VertexMode); // Should be converted to kTriangles
65 return &fVertices[4*triStrip + 2*hasColors + hasTexCoords];
66 }
67
68 // Filled and stroked [r]rects
69 const Renderer* analyticRRect() const { return &fAnalyticRRect; }
70
71 // Per-edge AA quadrilaterals
72 const Renderer* perEdgeAAQuad() const { return &fPerEdgeAAQuad; }
73
74 const Renderer* analyticBlur() const { return &fAnalyticBlur; }
75
76 // TODO: May need to add support for inverse filled strokes (need to check SVG spec if this is a
77 // real thing).
78
79 // Iterate over all available Renderers to combine with specified paint combinations when
80 // pre-compiling pipelines.
82 return {fRenderers.data(), fRenderers.size()};
83 }
84
85 const RenderStep* lookup(uint32_t uniqueID) const;
86
87#ifdef SK_ENABLE_VELLO_SHADERS
88 // Compute shader-based path renderer and compositor.
89 const VelloRenderer* velloRenderer() const { return fVelloRenderer.get(); }
90#endif
91
92private:
93 static constexpr int kPathTypeCount = 4;
94 static constexpr int kVerticesCount = 8; // 2 modes * 2 color configs * 2 tex coord configs
95
96 friend class Context; // for ctor
97
98 // TODO: Take in caps that determines which Renderers to use for each category
99 RendererProvider(const Caps*, StaticBufferManager* bufferManager);
100
101 // Cannot be moved or copied
102 RendererProvider(const RendererProvider&) = delete;
104
105 // Renderers are composed of 1+ steps, and some steps can be shared by multiple Renderers.
106 // Renderers don't keep their RenderSteps alive so RendererProvider holds them here.
107 std::vector<std::unique_ptr<RenderStep>> fRenderSteps;
108
109 // NOTE: Keep all Renderers dense to support automatically completing 'fRenderers'.
110 Renderer fStencilTessellatedCurves[kPathTypeCount];
111 Renderer fStencilTessellatedWedges[kPathTypeCount];
112 Renderer fConvexTessellatedWedges;
113 Renderer fTessellatedStrokes;
114
115 Renderer fCoverageMask;
116
117 Renderer fBitmapText[2]; // bool isLCD
118 Renderer fSDFText[2]; // bool isLCD
119
120 Renderer fAnalyticRRect;
121 Renderer fPerEdgeAAQuad;
122
123 Renderer fAnalyticBlur;
124
125 Renderer fVertices[kVerticesCount];
126
127 // Aggregate of all enabled Renderers for convenient iteration when pre-compiling
128 std::vector<const Renderer*> fRenderers;
129
130#ifdef SK_ENABLE_VELLO_SHADERS
131 std::unique_ptr<VelloRenderer> fVelloRenderer;
132#endif
133};
134
135} // namespace skgpu::graphite
136
137#endif // skgpu_graphite_RendererProvider_DEFINED
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkPathFillType
Definition: SkPathTypes.h:11
GLenum type
@ kTriangleStrip_VertexMode
Definition: SkVertices.h:32
@ kTriangleFan_VertexMode
Definition: SkVertices.h:33
SkSpan< const Renderer *const > renderers() const
const Renderer * tessellatedStrokes() const
const Renderer * convexTessellatedWedges() const
const Renderer * stencilTessellatedCurvesAndTris(SkPathFillType type) const
const Renderer * perEdgeAAQuad() const
const Renderer * analyticBlur() const
const Renderer * stencilTessellatedWedges(SkPathFillType type) const
const Renderer * vertices(SkVertices::VertexMode mode, bool hasColors, bool hasTexCoords) const
const Renderer * bitmapText(bool useLCDText) const
const RenderStep * lookup(uint32_t uniqueID) const
static bool IsVelloRendererSupported(const Caps *)
const Renderer * analyticRRect() const
const Renderer * sdfText(bool useLCDText) const
const Renderer * coverageMask() const
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228