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 GrPathShader_DEFINED 9 #define GrPathShader_DEFINED 10 11 #include "src/core/SkArenaAlloc.h" 12 #include "src/gpu/GrGeometryProcessor.h" 13 #include "src/gpu/GrOpFlushState.h" 14 #include "src/gpu/GrOpsRenderPass.h" 15 #include "src/gpu/GrProgramInfo.h" 16 #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" 17 #include <limits> 18 19 // This is a common base class for shaders in the GPU tessellator. 20 class GrPathShader : public GrGeometryProcessor { 21 public: GrPathShader(ClassID classID,const SkMatrix & viewMatrix,GrPrimitiveType primitiveType,int tessellationPatchVertexCount)22 GrPathShader(ClassID classID, const SkMatrix& viewMatrix, GrPrimitiveType primitiveType, 23 int tessellationPatchVertexCount) 24 : GrGeometryProcessor(classID) 25 , fViewMatrix(viewMatrix) 26 , fPrimitiveType(primitiveType) 27 , fTessellationPatchVertexCount(tessellationPatchVertexCount) { 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; } 36 37 struct ProgramArgs { 38 SkArenaAlloc* fArena; 39 const GrSurfaceProxyView& fWriteView; 40 const GrXferProcessor::DstProxyView* fDstProxyView; 41 GrXferBarrierFlags fXferBarrierFlags; 42 GrLoadOp fColorLoadOp; 43 const GrCaps* fCaps; 44 }; 45 MakeProgram(const ProgramArgs & args,const GrPathShader * shader,const GrPipeline * pipeline,const GrUserStencilSettings * stencil)46 static GrProgramInfo* MakeProgram(const ProgramArgs& args, const GrPathShader* shader, 47 const GrPipeline* pipeline, 48 const GrUserStencilSettings* stencil) { 49 return args.fArena->make<GrProgramInfo>(args.fWriteView, pipeline, stencil, shader, 50 shader->fPrimitiveType, 51 shader->fTessellationPatchVertexCount, 52 args.fXferBarrierFlags, args.fColorLoadOp); 53 } 54 55 // 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,SkPoint patch[4])56 static void WriteConicPatch(const SkPoint pts[3], float w, SkPoint patch[4]) { 57 // Write out the 3 conic points to patch[0..2], the weight to patch[3].x, and then set 58 // patch[3].y as NaN to flag this patch as a conic. 59 memcpy(patch, pts, sizeof(SkPoint) * 3); 60 patch[3].set(w, std::numeric_limits<float>::infinity()); 61 } 62 63 private: 64 const SkMatrix fViewMatrix; 65 const GrPrimitiveType fPrimitiveType; 66 const int fTessellationPatchVertexCount; 67 68 class Impl; 69 }; 70 71 #endif 72