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