Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/gpu/ops/GrDrawOp.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 Google Inc.
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 GrDrawOp_DEFINED
9
#define GrDrawOp_DEFINED
10
11
#include <functional>
12
#include "src/core/SkIPoint16.h"
13
#include "src/gpu/GrDeferredUpload.h"
14
#include "src/gpu/GrPipeline.h"
15
#include "src/gpu/ops/GrOp.h"
16
17
class GrAppliedClip;
18
namespace skgpu { namespace v1 { class SurfaceDrawContext; }}
19
class GrShape;
20
21
/**
22
 * Base class for GrOps that draw. These ops can draw into an op list's GrRenderTarget.
23
 */
24
class GrDrawOp : public GrOp {
25
public:
26
155k
    GrDrawOp(uint32_t classID) : INHERITED(classID) {}
27
28
    /**
29
     * Called before setting up the GrAppliedClip and before finalize. This information is required
30
     * to determine how to compute a GrAppliedClip from a GrClip for this op.
31
     */
32
155k
    virtual bool usesMSAA() const {
33
155k
        return this->fixedFunctionFlags() & FixedFunctionFlags::kUsesHWAA;
34
155k
    }
35
36
    /**
37
     * Specifies the effect of clipToShape().
38
     */
39
    enum class ClipResult {
40
        // No clip was applied.
41
        kFail,
42
        // The clip was applied to the op's actual geometry. The clip stack is free to disable the
43
        // scissor test.
44
        kClippedGeometrically,
45
        // The clip was applied via shader coverage. The clip stack will still use a scissor test
46
        // in order to reduce overdraw of transparent pixels.
47
        kClippedInShader,
48
        // The op can be thrown out entirely.
49
        kClippedOut
50
    };
51
52
    /**
53
     * This is called while the clip is being computed, before finalize(), and before any attempts
54
     * to combine with other ops. If the op knows how to clip its own geometry then it will
55
     * generally be much faster than a generalized clip method.
56
     */
57
    virtual ClipResult clipToShape(skgpu::v1::SurfaceDrawContext*,
58
                                   SkClipOp,
59
                                   const SkMatrix& /* clipMatrix */,
60
                                   const GrShape&,
61
12.6k
                                   GrAA) {
62
12.6k
        return ClipResult::kFail;
63
12.6k
    }
64
65
    /**
66
     * This is called after the GrAppliedClip has been computed and just prior to recording the op
67
     * or combining it with a previously recorded op. The op should convert any proxies or resources
68
     * it owns to "pending io" status so that resource allocation can be more optimal. Additionally,
69
     * at this time the op must report whether a copy of the destination (or destination texture
70
     * itself) needs to be provided to the GrXferProcessor when this op executes.
71
     */
72
    virtual GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) = 0;
73
74
    /**
75
     * Called after finalize, at which point every op should know whether it will need stencil.
76
     */
77
110k
    virtual bool usesStencil() const {
78
110k
        return this->fixedFunctionFlags() & FixedFunctionFlags::kUsesStencil;
79
110k
    }
80
81
#ifdef SK_DEBUG
82
    bool fAddDrawOpCalled = false;
83
84
0
    void validate() const override {
85
0
        SkASSERT(fAddDrawOpCalled);
86
0
    }
87
#endif
88
89
#if GR_TEST_UTILS
90
    // This is really only intended for GrTextureOp and GrFillRectOp to override
91
0
    virtual int numQuads() const { return -1; }
92
#endif
93
94
protected:
95
    /**
96
     * DEPRECATED: This is a legacy implementation for usesMSAA() and usesStencil(). Newer ops
97
     * should override those methods directly.
98
     */
99
    enum class FixedFunctionFlags : uint32_t {
100
        kNone = 0x0,
101
        /** Indices that the op will enable MSAA. */
102
        kUsesHWAA = 0x1,
103
        /** Indices that the op reads and/or writes the stencil buffer */
104
        kUsesStencil = 0x2,
105
    };
106
    GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(FixedFunctionFlags);
107
0
    virtual FixedFunctionFlags fixedFunctionFlags() const {
108
        // Override usesMSAA() and usesStencil() instead.
109
0
        SK_ABORT("fixedFunctionFlags() not implemented.");
110
0
    }
111
112
private:
113
    friend class GrSimpleMeshDrawOpHelper;  // For FixedFunctionFlags.
114
    friend class GrSimpleMeshDrawOpHelperWithStencil;  // For FixedFunctionFlags.
115
116
    using INHERITED = GrOp;
117
};
118
119
GR_MAKE_BITFIELD_CLASS_OPS(GrDrawOp::FixedFunctionFlags)
120
121
#endif