| 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 GrStencilPathShader_DEFINED |
| 9 | #define GrStencilPathShader_DEFINED |
| 10 | |
| 11 | #include "src/gpu/tessellate/GrPathShader.h" |
| 12 | |
| 13 | // This is the base class for shaders that stencil path elements, namely, triangles, standalone |
| 14 | // cubics, and wedges. |
| 15 | class GrStencilPathShader : public GrPathShader { |
| 16 | public: |
| 17 | GrStencilPathShader(ClassID classID, const SkMatrix& viewMatrix, GrPrimitiveType primitiveType, |
| 18 | int tessellationPatchVertexCount = 0) |
| 19 | : GrPathShader(classID, viewMatrix, primitiveType, tessellationPatchVertexCount) { |
| 20 | constexpr static Attribute kPointAttrib = { |
| 21 | "point" , kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
| 22 | this->setVertexAttributes(&kPointAttrib, 1); |
| 23 | } |
| 24 | |
| 25 | private: |
| 26 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final { |
| 27 | b->add32(this->viewMatrix().isIdentity()); |
| 28 | } |
| 29 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final; |
| 30 | |
| 31 | class Impl; |
| 32 | }; |
| 33 | |
| 34 | // Draws simple triangles to the stencil buffer. |
| 35 | class GrStencilTriangleShader : public GrStencilPathShader { |
| 36 | public: |
| 37 | GrStencilTriangleShader(const SkMatrix& viewMatrix) : GrStencilPathShader( |
| 38 | kTessellate_GrStencilTriangleShader_ClassID, viewMatrix, GrPrimitiveType::kTriangles) {} |
| 39 | const char* name() const override { return "tessellate_GrStencilTriangleShader" ; } |
| 40 | }; |
| 41 | |
| 42 | // Uses GPU tessellation shaders to linearize, triangulate, and render standalone cubics. Here, a |
| 43 | // "cubic" is a standalone closed contour consisting of a single cubic bezier. |
| 44 | // TODO: Eventually we want to use rational cubic wedges in order to support perspective and conics. |
| 45 | class GrStencilCubicShader : public GrStencilPathShader { |
| 46 | public: |
| 47 | GrStencilCubicShader(const SkMatrix& viewMatrix) : GrStencilPathShader( |
| 48 | kTessellate_GrStencilCubicShader_ClassID, viewMatrix, GrPrimitiveType::kPatches, 4) {} |
| 49 | const char* name() const override { return "tessellate_GrStencilCubicShader" ; } |
| 50 | |
| 51 | private: |
| 52 | SkString getTessControlShaderGLSL(const char* versionAndExtensionDecls, |
| 53 | const GrShaderCaps&) const override; |
| 54 | SkString getTessEvaluationShaderGLSL(const char* versionAndExtensionDecls, |
| 55 | const GrShaderCaps&) const override; |
| 56 | }; |
| 57 | |
| 58 | // Uses GPU tessellation shaders to linearize, triangulate, and render cubic "wedge" patches. A |
| 59 | // wedge is a 5-point patch consisting of 4 cubic control points, plus an anchor point fanning from |
| 60 | // the center of the curve's resident contour. |
| 61 | // TODO: Eventually we want to use rational cubic wedges in order to support perspective and conics. |
| 62 | class GrStencilWedgeShader : public GrStencilPathShader { |
| 63 | public: |
| 64 | GrStencilWedgeShader(const SkMatrix& viewMatrix) : GrStencilPathShader( |
| 65 | kTessellate_GrStencilWedgeShader_ClassID, viewMatrix, GrPrimitiveType::kPatches, 5) {} |
| 66 | const char* name() const override { return "tessellate_GrStencilWedgeShader" ; } |
| 67 | |
| 68 | private: |
| 69 | SkString getTessControlShaderGLSL(const char* versionAndExtensionDecls, |
| 70 | const GrShaderCaps&) const override; |
| 71 | SkString getTessEvaluationShaderGLSL(const char* versionAndExtensionDecls, |
| 72 | const GrShaderCaps&) const override; |
| 73 | }; |
| 74 | |
| 75 | #endif |
| 76 | |