Generates triangles from the path. If the data needs to be synchronized back to the CPU, e.g. because one of the buffer views are host visible and will be used without creating a blit pass to copy them back, the callback is used to determine when the GPU calculation is complete and its status. On Metal, no additional synchronization is needed as long as the buffers are not heap allocated, so no additional synchronization mechanism is provided.
70 {
72 using PS = PathPolylineComputeShader;
73 using SS = StrokeComputeShader;
74
77 (cubic_count * 6);
78 auto line_count =
83 }
84 PS::Cubics<kMaxCubicCount> cubics{.count = 0};
85 PS::Quads<kMaxQuadCount> quads{.count = 0};
86 PS::Lines<kMaxLineCount>
lines{.count = 0};
87 PS::Components<kMaxComponentCount> components{.count = 0};
88 PS::Config config{.cubic_accuracy = cubic_accuracy_,
89 .quad_tolerance = quad_tolerance_};
90
91 path.EnumerateComponents(
92 [&lines, &components](
size_t index,
const LinearPathComponent&
linear) {
94 sizeof(LinearPathComponent));
95 components.data[components.count++] = {
lines.count++, 2};
96 },
97 [&quads, &components](size_t index, const QuadraticPathComponent& quad) {
98 ::memcpy(&quads.data[quads.count], &quad,
99 sizeof(QuadraticPathComponent));
100 components.data[components.count++] = {quads.count++, 3};
101 },
102 [&cubics, &components](
size_t index,
const CubicPathComponent&
cubic) {
103 ::memcpy(&cubics.data[cubics.count], &cubic,
104 sizeof(CubicPathComponent));
105 components.data[components.count++] = {cubics.count++, 4};
106 },
107 [](
size_t index,
const ContourComponent&
contour) {});
108
109 auto polyline_buffer =
110 CreateDeviceBuffer<PS::Polyline<2048>>(context, "Polyline");
111
112 auto cmd_buffer = context->CreateCommandBuffer();
113 auto pass = cmd_buffer->CreateComputePass();
115
116 {
117 using PathPolylinePipelineBuilder = ComputePipelineBuilder<PS>;
118 auto pipeline_desc =
119 PathPolylinePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
121 auto compute_pipeline =
122 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
124
125 pass->SetPipeline(compute_pipeline);
126 pass->SetCommandLabel("Generate Polyline");
127
128 PS::BindConfig(*pass, host_buffer.EmplaceUniform(config));
129 PS::BindCubics(*pass, host_buffer.EmplaceStorageBuffer(cubics));
130 PS::BindQuads(*pass, host_buffer.EmplaceStorageBuffer(quads));
131 PS::BindLines(*pass, host_buffer.EmplaceStorageBuffer(lines));
132 PS::BindComponents(*pass, host_buffer.EmplaceStorageBuffer(components));
134
135 if (!pass->Compute(
ISize(line_count, 1)).
ok()) {
137 }
138 }
139
140 {
141 using StrokePipelineBuilder = ComputePipelineBuilder<SS>;
142 auto pipeline_desc =
143 StrokePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
145 auto compute_pipeline =
146 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
148
149 pass->AddBufferMemoryBarrier();
150 pass->SetPipeline(compute_pipeline);
151 pass->SetCommandLabel("Compute Stroke");
152
153 SS::Config config{
154 .width = stroke_width_,
155 .cap = static_cast<uint32_t>(stroke_cap_),
156 .join = static_cast<uint32_t>(stroke_join_),
157 .miter_limit = miter_limit_,
158 };
159 SS::BindConfig(*pass, host_buffer.EmplaceUniform(config));
160
162 SS::BindVertexBufferCount(*pass, std::move(vertex_buffer_count));
163 SS::BindVertexBuffer(*pass, std::move(vertex_buffer));
164
165 if (!pass->Compute(
ISize(line_count, 1)).
ok()) {
167 }
168 }
169
170 if (!pass->EncodeCommands()) {
172 }
173
174 if (!context->GetCommandQueue()->Submit({cmd_buffer},
callback).ok()) {
176 }
177
179}
static bool ok(int result)
static constexpr size_t kMaxCubicCount
static constexpr size_t kMaxQuadCount
static constexpr size_t kMaxLineCount
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DCHECK(condition)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)