• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 GrTessellationShader_DEFINED
9 #define GrTessellationShader_DEFINED
10 
11 #include "src/gpu/BufferWriter.h"
12 #include "src/gpu/GrGeometryProcessor.h"
13 #include "src/gpu/GrProgramInfo.h"
14 
15 class SkArenaAlloc;
16 
17  // This is a common base class for shaders in the GPU tessellator.
18 class GrTessellationShader : public GrGeometryProcessor {
19 public:
GrTessellationShader(ClassID classID,GrPrimitiveType primitiveType,int tessellationPatchVertexCount,const SkMatrix & viewMatrix,const SkPMColor4f & color)20     GrTessellationShader(ClassID classID, GrPrimitiveType primitiveType,
21                          int tessellationPatchVertexCount, const SkMatrix& viewMatrix,
22                          const SkPMColor4f& color)
23             : GrGeometryProcessor(classID)
24             , fPrimitiveType(primitiveType)
25             , fTessellationPatchVertexCount(tessellationPatchVertexCount)
26             , fViewMatrix(viewMatrix)
27             , fColor(color) {
28         if (fTessellationPatchVertexCount) {
29             this->setWillUseTessellationShaders();
30         }
31     }
32 
primitiveType()33     GrPrimitiveType primitiveType() const { return fPrimitiveType; }
tessellationPatchVertexCount()34     int tessellationPatchVertexCount() const { return fTessellationPatchVertexCount; }
viewMatrix()35     const SkMatrix& viewMatrix() const { return fViewMatrix; }
color()36     const SkPMColor4f& color() const { return fColor;}
37 
38     // Fills in a 4-point patch in such a way that the shader will recognize it as a conic.
WriteConicPatch(const SkPoint pts[3],float w,skgpu::VertexWriter * writer)39     static void WriteConicPatch(const SkPoint pts[3], float w, skgpu::VertexWriter* writer) {
40         using skgpu::VertexWriter;
41         // Write out the 3 conic points to patch[0..2], the weight to patch[3].x, and then set
42         // patch[3].y as NaN to flag this patch as a conic.
43         *writer << VertexWriter::Array(pts, 3) << w << VertexWriter::kIEEE_32_infinity;
44     }
WriteConicPatch(const SkPoint pts[3],float w,SkPoint patch[4])45     static void WriteConicPatch(const SkPoint pts[3], float w, SkPoint patch[4]) {
46         skgpu::VertexWriter writer(patch, 4*sizeof(SkPoint));
47         WriteConicPatch(pts, w, &writer);
48     }
49 
50     struct ProgramArgs {
51         SkArenaAlloc* fArena;
52         const GrSurfaceProxyView& fWriteView;
53         bool fUsesMSAASurface;
54         const GrDstProxyView* fDstProxyView;
55         GrXferBarrierFlags fXferBarrierFlags;
56         GrLoadOp fColorLoadOp;
57         const GrCaps* fCaps;
58     };
59 
60     static const GrPipeline* MakePipeline(const ProgramArgs&, GrAAType,
61                                           GrAppliedClip&&, GrProcessorSet&&);
62 
MakeProgram(const ProgramArgs & args,const GrTessellationShader * shader,const GrPipeline * pipeline,const GrUserStencilSettings * stencil)63     static GrProgramInfo* MakeProgram(const ProgramArgs& args,
64                                       const GrTessellationShader* shader,
65                                       const GrPipeline* pipeline,
66                                       const GrUserStencilSettings* stencil) {
67         return args.fArena->make<GrProgramInfo>(*args.fCaps, args.fWriteView, args.fUsesMSAASurface,
68                                                 pipeline, stencil, shader, shader->fPrimitiveType,
69                                                 shader->fTessellationPatchVertexCount,
70                                                 args.fXferBarrierFlags, args.fColorLoadOp);
71     }
72 
73 private:
74     const GrPrimitiveType fPrimitiveType;
75     const int fTessellationPatchVertexCount;
76     const SkMatrix fViewMatrix;
77     const SkPMColor4f fColor;
78 };
79 
80 #endif
81