• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 #include "experimental/graphite/src/Renderer.h"
9 
10 #include "experimental/graphite/src/geom/Shape.h"
11 #include "src/gpu/BufferWriter.h"
12 
13 namespace skgpu {
14 
15 namespace {
16 
17 // TODO: Hand off to csmartdalton, this should roughly correspond to the fStencilFanProgram and
18 // simple triangulator shader stage of the skgpu::v1::PathStencilCoverOp
19 /*
20 class StencilFanRenderStep : public RenderStep {
21 public:
22     StencilFanRenderStep() {}
23 
24     ~StencilFanRenderStep() override {}
25 
26     const char* name()            const override { return "stencil-fan"; }
27     bool        requiresStencil() const override { return true; }
28     bool        requiresMSAA()    const override { return true; }
29     bool        performsShading() const override { return false; }
30 
31 private:
32 };
33 */
34 
35 // TODO: Hand off to csmartdalton, this should roughly correspond to the fStencilPathProgram stage
36 // of skgpu::v1::PathStencilCoverOp using the PathCurveTessellator
37 /*
38 class StencilCurvesRenderStep : public RenderStep {
39 public:
40     StencilCurvesRenderStep() {}
41 
42     ~StencilCurvesRenderStep() override {}
43 
44     const char* name()            const override { return "stencil-curves"; }
45     bool        requiresStencil() const override { return true;  }
46     bool        requiresMSAA()    const override { return true;  }
47     bool        performsShading() const override { return false; }
48 
49 private:
50 };
51 */
52 
53 // TODO: Hand off to csmartdalton, this should roughly correspond to the fCoverBBoxProgram stage
54 // of skgpu::v1::PathStencilCoverOp.
55 class FillBoundsRenderStep : public RenderStep {
56 public:
FillBoundsRenderStep()57     FillBoundsRenderStep() {}
58 
~FillBoundsRenderStep()59     ~FillBoundsRenderStep() override {}
60 
name() const61     const char* name()            const override { return "fill-bounds"; }
62     // TODO: true when combined with a stencil step
requiresStencil() const63     bool        requiresStencil() const override { return false; }
requiresMSAA() const64     bool        requiresMSAA()    const override { return false; }
performsShading() const65     bool        performsShading() const override { return true;  }
66 
requiredVertexSpace(const Shape &) const67     size_t requiredVertexSpace(const Shape&) const override {
68         return 8 * sizeof(float);
69     }
70 
requiredIndexSpace(const Shape &) const71     size_t requiredIndexSpace(const Shape&) const override {
72         return 0;
73     }
74 
writeVertices(VertexWriter vertexWriter,IndexWriter indexWriter,const Shape & shape) const75     void writeVertices(VertexWriter vertexWriter,
76                        IndexWriter indexWriter,
77                        const Shape& shape) const override {
78         vertexWriter.writeQuad(VertexWriter::TriStripFromRect(shape.bounds().asSkRect()));
79     }
80 
81 
82 private:
83 };
84 
85 } // anonymous namespace
86 
StencilAndFillPath()87 const Renderer& Renderer::StencilAndFillPath() {
88     // TODO: Uncomment and include in kRenderer to draw flattened paths instead of bboxes
89     // static const StencilFanRenderStep kStencilFan;
90     // TODO: Uncomment and include in kRenderer to draw curved paths
91     // static const StencilCurvesRenderStep kStencilCurves;
92     // TODO: This could move into a header and be reused across renderers
93     static const FillBoundsRenderStep kCover;
94     static const Renderer kRenderer("stencil-and-fill",
95                                     /*&kStencilFan,*/ /*&kStencilCurves,*/ &kCover);
96 
97     return kRenderer;
98 }
99 
100 } // namespace skgpu
101