Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / ganesh / ops / PathInnerTriangulateOp.h
1 /*
2  * Copyright 2019 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 PathInnerTriangulateOp_DEFINED
9 #define PathInnerTriangulateOp_DEFINED
10
11 #include "src/gpu/ganesh/geometry/GrInnerFanTriangulator.h"
12 #include "src/gpu/ganesh/ops/FillPathFlags.h"
13 #include "src/gpu/ganesh/ops/GrDrawOp.h"
14 #include "src/gpu/ganesh/tessellate/GrTessellationShader.h"
15
16 namespace skgpu::v1 {
17
18 class PathCurveTessellator;
19
20 // This op is a 3-pass twist on the standard Redbook "stencil then cover" algorithm:
21 //
22 // 1) Tessellate the path's outer curves into the stencil buffer.
23 // 2) Triangulate the path's inner fan and fill it with a stencil test against the curves.
24 // 3) Draw convex hulls around each curve that fill in remaining samples.
25 //
26 // In practice, a path's inner fan takes up a large majority of its pixels. So from a GPU load
27 // perspective, this op is effectively as fast as a single-pass algorithm.
28 class PathInnerTriangulateOp final : public GrDrawOp {
29 private:
30     DEFINE_OP_CLASS_ID
31
32     PathInnerTriangulateOp(const SkMatrix& viewMatrix,
33                            const SkPath& path,
34                            GrPaint&& paint,
35                            GrAAType aaType,
36                            FillPathFlags pathFlags,
37                            const SkRect& drawBounds)
38             : GrDrawOp(ClassID())
39             , fPathFlags(pathFlags)
40             , fViewMatrix(viewMatrix)
41             , fPath(path)
42             , fAAType(aaType)
43             , fColor(paint.getColor4f())
44             , fProcessors(std::move(paint)) {
45         SkASSERT(!fPath.isInverseFillType());
46         this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
47     }
48
49     const char* name() const override { return "PathInnerTriangulateOp"; }
50     void visitProxies(const GrVisitProxyFunc&) const override;
51     FixedFunctionFlags fixedFunctionFlags() const override;
52     GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override;
53
54     // These calls set up the stencil & fill programs we will use prior to preparing and executing.
55     void pushFanStencilProgram(const GrTessellationShader::ProgramArgs&,
56                                const GrPipeline* pipelineForStencils, const GrUserStencilSettings*);
57     void pushFanFillProgram(const GrTessellationShader::ProgramArgs&, const GrUserStencilSettings*);
58     void prePreparePrograms(const GrTessellationShader::ProgramArgs&, GrAppliedClip&&);
59
60     void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
61                       const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
62     void onPrepare(GrOpFlushState*) override;
63     void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
64
65     const FillPathFlags fPathFlags;
66     const SkMatrix fViewMatrix;
67     const SkPath fPath;
68     const GrAAType fAAType;
69     SkPMColor4f fColor;
70     GrProcessorSet fProcessors;
71
72     // Triangulates the inner fan.
73     GrInnerFanTriangulator* fFanTriangulator = nullptr;
74     GrTriangulator::Poly* fFanPolys = nullptr;
75     GrInnerFanTriangulator::BreadcrumbTriangleList fFanBreadcrumbs;
76
77     // This pipeline is shared by all programs that do filling.
78     const GrPipeline* fPipelineForFills = nullptr;
79
80     // Tessellates the outer curves.
81     PathCurveTessellator* fTessellator = nullptr;
82
83     // Pass 1: Tessellate the outer curves into the stencil buffer.
84     const GrProgramInfo* fStencilCurvesProgram = nullptr;
85
86     // Pass 2: Fill the path's inner fan with a stencil test against the curves. (In extenuating
87     // circumstances this might require two separate draws.)
88     SkSTArray<2, const GrProgramInfo*> fFanPrograms;
89
90     // Pass 3: Draw convex hulls around each curve.
91     const GrProgramInfo* fCoverHullsProgram = nullptr;
92
93     // This buffer gets created by fFanTriangulator during onPrepare.
94     sk_sp<const GrBuffer> fFanBuffer;
95     int fBaseFanVertex = 0;
96     int fFanVertexCount = 0;
97
98     // Only used if sk_VertexID is not supported.
99     sk_sp<const GrGpuBuffer> fHullVertexBufferIfNoIDSupport;
100
101     friend class GrOp;  // For ctor.
102 };
103
104 } // namespace skgpu::v1
105
106 #endif // PathInnerTriangulateOp_DEFINED