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 GrFillPathShader_DEFINED |
9 | #define GrFillPathShader_DEFINED |
10 | |
11 | #include "src/gpu/tessellate/GrPathShader.h" |
12 | |
13 | class GrGLSLUniformHandler; |
14 | class GrGLSLVertexBuilder; |
15 | |
16 | // This is the base class for shaders that fill a path's pixels in the final render target. |
17 | class GrFillPathShader : public GrPathShader { |
18 | public: |
19 | GrFillPathShader(ClassID classID, const SkMatrix& viewMatrix, SkPMColor4f color, |
20 | GrPrimitiveType primitiveType) |
21 | : GrPathShader(classID, viewMatrix, primitiveType, 0) |
22 | , fColor(color) { |
23 | } |
24 | |
25 | void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} |
26 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final; |
27 | |
28 | protected: |
29 | class Impl; |
30 | |
31 | virtual void emitVertexCode(Impl*, GrGLSLVertexBuilder*, const char* viewMatrix, |
32 | GrGLSLUniformHandler*) const = 0; |
33 | |
34 | private: |
35 | const SkPMColor4f fColor; |
36 | }; |
37 | |
38 | // Fills a simple array of triangles. |
39 | class GrFillTriangleShader : public GrFillPathShader { |
40 | public: |
41 | GrFillTriangleShader(const SkMatrix& viewMatrix, SkPMColor4f color) |
42 | : GrFillPathShader(kTessellate_GrFillTriangleShader_ClassID, viewMatrix, color, |
43 | GrPrimitiveType::kTriangles) { |
44 | static constexpr Attribute kPtAttrib = { |
45 | "input_point" , kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
46 | this->setVertexAttributes(&kPtAttrib, 1); |
47 | } |
48 | |
49 | private: |
50 | const char* name() const override { return "GrFillTriangleShader" ; } |
51 | void emitVertexCode(Impl*, GrGLSLVertexBuilder*, const char* viewMatrix, |
52 | GrGLSLUniformHandler*) const override; |
53 | }; |
54 | |
55 | // Fills an array of convex hulls surrounding 4-point cubic instances. |
56 | class GrFillCubicHullShader : public GrFillPathShader { |
57 | public: |
58 | GrFillCubicHullShader(const SkMatrix& viewMatrix, SkPMColor4f color) |
59 | : GrFillPathShader(kTessellate_GrFillCubicHullShader_ClassID, viewMatrix, color, |
60 | GrPrimitiveType::kTriangleStrip) { |
61 | static constexpr Attribute kPtsAttribs[] = { |
62 | {"input_points_0_1" , kFloat4_GrVertexAttribType, kFloat4_GrSLType}, |
63 | {"input_points_2_3" , kFloat4_GrVertexAttribType, kFloat4_GrSLType}}; |
64 | this->setInstanceAttributes(kPtsAttribs, SK_ARRAY_COUNT(kPtsAttribs)); |
65 | } |
66 | |
67 | private: |
68 | const char* name() const override { return "GrFillCubicHullShader" ; } |
69 | void emitVertexCode(Impl*, GrGLSLVertexBuilder*, const char* viewMatrix, |
70 | GrGLSLUniformHandler*) const override; |
71 | }; |
72 | |
73 | // Fills a path's bounding box, with subpixel outset to avoid possible T-junctions with extreme |
74 | // edges of the path. |
75 | // NOTE: The emitted geometry may not be axis-aligned, depending on the view matrix. |
76 | class GrFillBoundingBoxShader : public GrFillPathShader { |
77 | public: |
78 | GrFillBoundingBoxShader(const SkMatrix& viewMatrix, SkPMColor4f color, const SkRect& pathBounds) |
79 | : GrFillPathShader(kTessellate_GrFillBoundingBoxShader_ClassID, viewMatrix, color, |
80 | GrPrimitiveType::kTriangleStrip) |
81 | , fPathBounds(pathBounds) { |
82 | } |
83 | |
84 | const SkRect& pathBounds() const { return fPathBounds; } |
85 | |
86 | private: |
87 | const char* name() const override { return "GrFillBoundingBoxShader" ; } |
88 | void emitVertexCode(Impl*, GrGLSLVertexBuilder*, const char* viewMatrix, |
89 | GrGLSLUniformHandler*) const override; |
90 | |
91 | const SkRect fPathBounds; |
92 | }; |
93 | |
94 | #endif |
95 | |