Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/gpu/tessellate/GrPathTessellator.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef GrPathTessellator_DEFINED
9
#define GrPathTessellator_DEFINED
10
11
#include "src/core/SkPathPriv.h"
12
#include "src/gpu/GrVertexWriter.h"
13
#include "src/gpu/GrVx.h"
14
#include "src/gpu/geometry/GrInnerFanTriangulator.h"
15
16
class SkPath;
17
class GrMeshDrawTarget;
18
class GrGpuBuffer;
19
class GrOpFlushState;
20
class GrPathTessellationShader;
21
22
// Prepares GPU data for, and then draws a path's tessellated geometry. Depending on the subclass,
23
// the caller may or may not be required to draw the path's inner fan separately.
24
class GrPathTessellator {
25
public:
26
    using BreadcrumbTriangleList = GrInnerFanTriangulator::BreadcrumbTriangleList;
27
28
    struct PathDrawList {
29
        PathDrawList(const SkMatrix& pathMatrix, const SkPath& path, PathDrawList* next = nullptr)
30
0
                : fPathMatrix(pathMatrix), fPath(path), fNext(next) {}
31
32
        SkMatrix fPathMatrix;
33
        SkPath fPath;
34
        PathDrawList* fNext;
35
36
        struct Iter {
37
0
            void operator++() { fHead = fHead->fNext; }
38
0
            bool operator!=(const Iter& b) const { return fHead != b.fHead; }
39
0
            std::tuple<const SkMatrix&, const SkPath&> operator*() const {
40
0
                return {fHead->fPathMatrix, fHead->fPath};
41
0
            }
42
            const PathDrawList* fHead;
43
        };
44
0
        Iter begin() const { return {this}; }
45
0
        Iter end() const { return {nullptr}; }
46
    };
47
48
0
    virtual ~GrPathTessellator() {}
49
50
0
    const GrPathTessellationShader* shader() const { return fShader; }
51
52
    // Called before draw(). Prepares GPU buffers containing the geometry to tessellate.
53
    //
54
    // Each path's fPathMatrix in the list is applied on the CPU while the geometry is being written
55
    // out. This is a tool for batching, and is applied in addition to the shader's on-GPU matrix.
56
    virtual void prepare(GrMeshDrawTarget*,
57
                         const SkRect& cullBounds,
58
                         const PathDrawList&,
59
                         int totalCombinedPathVerbCnt) = 0;
60
61
#if SK_GPU_V1
62
    // Issues draw calls for the tessellated geometry. The caller is responsible for binding its
63
    // desired pipeline ahead of time.
64
    virtual void draw(GrOpFlushState*) const = 0;
65
#endif
66
67
    // Returns an upper bound on the number of combined edges there might be from all inner fans in
68
    // a PathDrawList.
69
0
    static int MaxCombinedFanEdgesInPathDrawList(int totalCombinedPathVerbCnt) {
70
        // Path fans might have an extra edge from an implicit kClose at the end, but they also
71
        // always begin with kMove. So the max possible number of edges in a single path is equal to
72
        // the number of verbs. Therefore, the max number of combined fan edges in a PathDrawList is
73
        // the number of combined path verbs in that PathDrawList.
74
0
        return totalCombinedPathVerbCnt;
75
0
    }
76
77
protected:
78
0
    GrPathTessellator(GrPathTessellationShader* shader) : fShader(shader) {}
79
80
    GrPathTessellationShader* fShader;
81
};
82
83
#endif