Debian Codegraph @

src/gpu/graphite/render/MiddleOutFanRenderStep.cpp

raw
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 #include "src/gpu/graphite/render/MiddleOutFanRenderStep.h"
9
10 #include "include/core/SkPath.h"
11 #include "include/private/base/SkDebug.h"
12 #include "src/core/SkSLTypeShared.h"
13 #include "src/gpu/BufferWriter.h"
14 #include "src/gpu/graphite/Attribute.h"
15 #include "src/gpu/graphite/DrawOrder.h"
16 #include "src/gpu/graphite/DrawParams.h"
17 #include "src/gpu/graphite/DrawTypes.h"
18 #include "src/gpu/graphite/DrawWriter.h"
19 #include "src/gpu/graphite/PipelineData.h"
20 #include "src/gpu/graphite/geom/Geometry.h"
21 #include "src/gpu/graphite/geom/Shape.h"
22 #include "src/gpu/graphite/geom/Transform.h"
23 #include "src/gpu/graphite/render/CommonDepthStencilSettings.h"
24 #include "src/gpu/tessellate/MiddleOutPolygonTriangulator.h"
25
26 #include <algorithm>
27
28 namespace skgpu::graphite {
29
30 MiddleOutFanRenderStep::MiddleOutFanRenderStep(Layout layout, bool evenOdd)
31 : RenderStep(layout,
32 evenOdd ? RenderStepID::kMiddleOutFan_EvenOdd
33 : RenderStepID::kMiddleOutFan_Winding,
34 Flags::kRequiresMSAA | Flags::kAppendVertices,
35 /*uniforms=*/{{"localToDevice", SkSLType::kFloat4x4}},
36 PrimitiveType::kTriangles,
37 evenOdd ? kEvenOddStencilPass : kWindingStencilPass,
38 /*staticAttrs=*/ {},
39 /*appendAttrs=*/
40 {{{"position", VertexAttribType::kFloat2, SkSLType::kFloat2},
41 {"depth", VertexAttribType::kFloat, SkSLType::kFloat},
42 {"ssboIndex", VertexAttribType::kUInt, SkSLType::kUInt}}}) {}
43
44 MiddleOutFanRenderStep::~MiddleOutFanRenderStep() {}
45
46 std::string MiddleOutFanRenderStep::vertexSkSL() const {
47 return
48 "float4 devPosition = localToDevice * float4(position, 0.0, 1.0);\n"
49 "devPosition.z = depth;\n"
50 "stepLocalCoords = position;\n";
51 }
52
53 void MiddleOutFanRenderStep::writeVertices(DrawWriter* writer,
54 const DrawParams& params,
55 uint32_t ssboIndex) const {
56 // TODO: Have Shape provide a path-like iterator so we don't actually have to convert non
57 // paths to SkPath just to iterate their pts/verbs
58 SkPath path = params.geometry().shape().asPath();
59
60 const int maxTrianglesInFans = std::max(path.countVerbs() - 2, 0);
61
62 float depth = params.order().depthAsFloat();
63
64 DrawWriter::Vertices verts{*writer};
65 verts.reserve(maxTrianglesInFans * 3);
66 for (tess::PathMiddleOutFanIter it(path); !it.done();) {
67 for (auto [p0, p1, p2] : it.nextStack()) {
68 verts.append(3) << p0 << depth << ssboIndex
69 << p1 << depth << ssboIndex
70 << p2 << depth << ssboIndex;
71 }
72 }
73 }
74
75 void MiddleOutFanRenderStep::writeUniformsAndTextures(const DrawParams& params,
76 PipelineDataGatherer* gatherer) const {
77 SkDEBUGCODE(gatherer->checkRewind());
78 SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
79
80 gatherer->write(params.transform().matrix());
81 }
82
83 } // namespace skgpu::graphite