xref: /aosp_15_r20/external/skia/src/gpu/ganesh/tessellate/GrTessellationShader.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2020 Google LLC.
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker #ifndef GrTessellationShader_DEFINED
8*c8dee2aaSAndroid Build Coastguard Worker #define GrTessellationShader_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker 
10*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkMatrix.h"
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/SkColorData.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "src/base/SkArenaAlloc.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrGeometryProcessor.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/ganesh/GrProgramInfo.h"
15*c8dee2aaSAndroid Build Coastguard Worker 
16*c8dee2aaSAndroid Build Coastguard Worker #include <cstdint>
17*c8dee2aaSAndroid Build Coastguard Worker 
18*c8dee2aaSAndroid Build Coastguard Worker class GrAppliedClip;
19*c8dee2aaSAndroid Build Coastguard Worker class GrCaps;
20*c8dee2aaSAndroid Build Coastguard Worker class GrDstProxyView;
21*c8dee2aaSAndroid Build Coastguard Worker class GrPipeline;
22*c8dee2aaSAndroid Build Coastguard Worker class GrProcessorSet;
23*c8dee2aaSAndroid Build Coastguard Worker class GrSurfaceProxyView;
24*c8dee2aaSAndroid Build Coastguard Worker enum class GrAAType : unsigned int;
25*c8dee2aaSAndroid Build Coastguard Worker enum class GrLoadOp;
26*c8dee2aaSAndroid Build Coastguard Worker enum class GrPrimitiveType : uint8_t;
27*c8dee2aaSAndroid Build Coastguard Worker enum class GrXferBarrierFlags;
28*c8dee2aaSAndroid Build Coastguard Worker struct GrUserStencilSettings;
29*c8dee2aaSAndroid Build Coastguard Worker 
30*c8dee2aaSAndroid Build Coastguard Worker // This is a common base class for shaders in the GPU tessellator.
31*c8dee2aaSAndroid Build Coastguard Worker class GrTessellationShader : public GrGeometryProcessor {
32*c8dee2aaSAndroid Build Coastguard Worker public:
GrTessellationShader(ClassID classID,GrPrimitiveType primitiveType,const SkMatrix & viewMatrix,const SkPMColor4f & color)33*c8dee2aaSAndroid Build Coastguard Worker     GrTessellationShader(ClassID classID, GrPrimitiveType primitiveType,
34*c8dee2aaSAndroid Build Coastguard Worker                          const SkMatrix& viewMatrix,
35*c8dee2aaSAndroid Build Coastguard Worker                          const SkPMColor4f& color)
36*c8dee2aaSAndroid Build Coastguard Worker             : GrGeometryProcessor(classID)
37*c8dee2aaSAndroid Build Coastguard Worker             , fPrimitiveType(primitiveType)
38*c8dee2aaSAndroid Build Coastguard Worker             , fViewMatrix(viewMatrix)
39*c8dee2aaSAndroid Build Coastguard Worker             , fColor(color) {
40*c8dee2aaSAndroid Build Coastguard Worker     }
41*c8dee2aaSAndroid Build Coastguard Worker 
primitiveType()42*c8dee2aaSAndroid Build Coastguard Worker     GrPrimitiveType primitiveType() const { return fPrimitiveType; }
viewMatrix()43*c8dee2aaSAndroid Build Coastguard Worker     const SkMatrix& viewMatrix() const { return fViewMatrix; }
color()44*c8dee2aaSAndroid Build Coastguard Worker     const SkPMColor4f& color() const { return fColor;}
45*c8dee2aaSAndroid Build Coastguard Worker 
46*c8dee2aaSAndroid Build Coastguard Worker     struct ProgramArgs {
47*c8dee2aaSAndroid Build Coastguard Worker         SkArenaAlloc* fArena;
48*c8dee2aaSAndroid Build Coastguard Worker         const GrSurfaceProxyView& fWriteView;
49*c8dee2aaSAndroid Build Coastguard Worker         bool fUsesMSAASurface;
50*c8dee2aaSAndroid Build Coastguard Worker         const GrDstProxyView* fDstProxyView;
51*c8dee2aaSAndroid Build Coastguard Worker         GrXferBarrierFlags fXferBarrierFlags;
52*c8dee2aaSAndroid Build Coastguard Worker         GrLoadOp fColorLoadOp;
53*c8dee2aaSAndroid Build Coastguard Worker         const GrCaps* fCaps;
54*c8dee2aaSAndroid Build Coastguard Worker     };
55*c8dee2aaSAndroid Build Coastguard Worker 
56*c8dee2aaSAndroid Build Coastguard Worker     static const GrPipeline* MakePipeline(const ProgramArgs&, GrAAType,
57*c8dee2aaSAndroid Build Coastguard Worker                                           GrAppliedClip&&, GrProcessorSet&&);
58*c8dee2aaSAndroid Build Coastguard Worker 
MakeProgram(const ProgramArgs & args,const GrTessellationShader * shader,const GrPipeline * pipeline,const GrUserStencilSettings * stencil)59*c8dee2aaSAndroid Build Coastguard Worker     static GrProgramInfo* MakeProgram(const ProgramArgs& args,
60*c8dee2aaSAndroid Build Coastguard Worker                                       const GrTessellationShader* shader,
61*c8dee2aaSAndroid Build Coastguard Worker                                       const GrPipeline* pipeline,
62*c8dee2aaSAndroid Build Coastguard Worker                                       const GrUserStencilSettings* stencil) {
63*c8dee2aaSAndroid Build Coastguard Worker         return args.fArena->make<GrProgramInfo>(*args.fCaps, args.fWriteView, args.fUsesMSAASurface,
64*c8dee2aaSAndroid Build Coastguard Worker                                                 pipeline, stencil, shader, shader->fPrimitiveType,
65*c8dee2aaSAndroid Build Coastguard Worker                                                 args.fXferBarrierFlags, args.fColorLoadOp);
66*c8dee2aaSAndroid Build Coastguard Worker     }
67*c8dee2aaSAndroid Build Coastguard Worker 
68*c8dee2aaSAndroid Build Coastguard Worker     // SkSL functions that calculate Wang's formula for cubics or conics.
69*c8dee2aaSAndroid Build Coastguard Worker     static const char* WangsFormulaSkSL();
70*c8dee2aaSAndroid Build Coastguard Worker 
71*c8dee2aaSAndroid Build Coastguard Worker private:
72*c8dee2aaSAndroid Build Coastguard Worker     const GrPrimitiveType fPrimitiveType;
73*c8dee2aaSAndroid Build Coastguard Worker     const SkMatrix fViewMatrix;
74*c8dee2aaSAndroid Build Coastguard Worker     const SkPMColor4f fColor;
75*c8dee2aaSAndroid Build Coastguard Worker };
76*c8dee2aaSAndroid Build Coastguard Worker 
77*c8dee2aaSAndroid Build Coastguard Worker #endif
78