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/base/SkArenaAlloc.h" 12 #include "src/gpu/BufferWriter.h" 13 #include "src/gpu/ganesh/GrGeometryProcessor.h" 14 #include "src/gpu/ganesh/GrProgramInfo.h" 15 16 class SkArenaAlloc; 17 18 // This is a common base class for shaders in the GPU tessellator. 19 class GrTessellationShader : public GrGeometryProcessor { 20 public: GrTessellationShader(ClassID classID,GrPrimitiveType primitiveType,const SkMatrix & viewMatrix,const SkPMColor4f & color)21 GrTessellationShader(ClassID classID, GrPrimitiveType primitiveType, 22 const SkMatrix& viewMatrix, 23 const SkPMColor4f& color) 24 : GrGeometryProcessor(classID) 25 , fPrimitiveType(primitiveType) 26 , fViewMatrix(viewMatrix) 27 , fColor(color) { 28 } 29 primitiveType()30 GrPrimitiveType primitiveType() const { return fPrimitiveType; } viewMatrix()31 const SkMatrix& viewMatrix() const { return fViewMatrix; } color()32 const SkPMColor4f& color() const { return fColor;} 33 34 struct ProgramArgs { 35 SkArenaAlloc* fArena; 36 const GrSurfaceProxyView& fWriteView; 37 bool fUsesMSAASurface; 38 const GrDstProxyView* fDstProxyView; 39 GrXferBarrierFlags fXferBarrierFlags; 40 GrLoadOp fColorLoadOp; 41 const GrCaps* fCaps; 42 }; 43 44 static const GrPipeline* MakePipeline(const ProgramArgs&, GrAAType, 45 GrAppliedClip&&, GrProcessorSet&&); 46 MakeProgram(const ProgramArgs & args,const GrTessellationShader * shader,const GrPipeline * pipeline,const GrUserStencilSettings * stencil)47 static GrProgramInfo* MakeProgram(const ProgramArgs& args, 48 const GrTessellationShader* shader, 49 const GrPipeline* pipeline, 50 const GrUserStencilSettings* stencil) { 51 return args.fArena->make<GrProgramInfo>(*args.fCaps, args.fWriteView, args.fUsesMSAASurface, 52 pipeline, stencil, shader, shader->fPrimitiveType, 53 args.fXferBarrierFlags, args.fColorLoadOp); 54 } 55 56 // SkSL functions that calculate Wang's formula for cubics or conics. 57 static const char* WangsFormulaSkSL(); 58 59 private: 60 const GrPrimitiveType fPrimitiveType; 61 const SkMatrix fViewMatrix; 62 const SkPMColor4f fColor; 63 }; 64 65 #endif 66