joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 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 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 8 | #ifndef GrOp_DEFINED |
| 9 | #define GrOp_DEFINED |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMatrix.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "include/core/SkString.h" |
| 14 | #include "include/gpu/GrGpuResource.h" |
| 15 | #include "src/gpu/GrNonAtomicRef.h" |
| 16 | #include "src/gpu/GrTracing.h" |
| 17 | #include "src/gpu/GrXferProcessor.h" |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 18 | #include <atomic> |
| 19 | #include <new> |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 20 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 21 | class GrCaps; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | class GrGpuCommandBuffer; |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 23 | class GrOpFlushState; |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 24 | class GrRenderTargetOpList; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 25 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 26 | /** |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 27 | * GrOp is the base class for all Ganesh deferred GPU operations. To facilitate reordering and to |
| 28 | * minimize draw calls, Ganesh does not generate geometry inline with draw calls. Instead, it |
| 29 | * captures the arguments to the draw and then generates the geometry when flushing. This gives GrOp |
| 30 | * subclasses complete freedom to decide how/when to combine in order to produce fewer draw calls |
| 31 | * and minimize state changes. |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 32 | * |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 33 | * Ops of the same subclass may be merged or chained using combineIfPossible. When two ops merge, |
| 34 | * one takes on the union of the data and the other is left empty. The merged op becomes responsible |
| 35 | * for drawing the data from both the original ops. When ops are chained each op maintains its own |
| 36 | * data but they are linked in a list and the head op becomes responsible for executing the work for |
| 37 | * the chain. |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 38 | * |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 39 | * It is required that chainability is transitive. Moreover, if op A is able to merge with B then |
| 40 | * it must be the case that any op that can chain with A will either merge or chain with any op |
| 41 | * that can chain to B. |
| 42 | * |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 43 | * The bounds of the op must contain all the vertices in device space *irrespective* of the clip. |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 44 | * The bounds are used in determining which clip elements must be applied and thus the bounds cannot |
| 45 | * in turn depend upon the clip. |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 46 | */ |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 47 | #define GR_OP_SPEW 0 |
| 48 | #if GR_OP_SPEW |
| 49 | #define GrOP_SPEW(code) code |
| 50 | #define GrOP_INFO(...) SkDebugf(__VA_ARGS__) |
joshualitt | ca1f07e | 2015-08-07 08:11:19 -0700 | [diff] [blame] | 51 | #else |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 52 | #define GrOP_SPEW(code) |
| 53 | #define GrOP_INFO(...) |
joshualitt | ca1f07e | 2015-08-07 08:11:19 -0700 | [diff] [blame] | 54 | #endif |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 55 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 56 | // Print out op information at flush time |
| 57 | #define GR_FLUSH_TIME_OP_SPEW 0 |
| 58 | |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 59 | // A helper macro to generate a class static id |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 60 | #define DEFINE_OP_CLASS_ID \ |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 61 | static uint32_t ClassID() { \ |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 62 | static uint32_t kClassID = GenOpClassID(); \ |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 63 | return kClassID; \ |
| 64 | } |
| 65 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 66 | class GrOp : private SkNoncopyable { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 67 | public: |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 68 | virtual ~GrOp() = default; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 69 | |
| 70 | virtual const char* name() const = 0; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 71 | |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 72 | typedef std::function<void(GrSurfaceProxy*)> VisitProxyFunc; |
| 73 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 74 | virtual void visitProxies(const VisitProxyFunc&) const { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 75 | // This default implementation assumes the op has no proxies |
| 76 | } |
| 77 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 78 | enum class CombineResult { |
| 79 | /** |
| 80 | * The op that combineIfPossible was called on now represents its own work plus that of |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 81 | * the passed op. The passed op should be destroyed without being flushed. Currently it |
| 82 | * is not legal to merge an op passed to combineIfPossible() the passed op is already in a |
| 83 | * chain (though the op on which combineIfPossible() was called may be). |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 84 | */ |
| 85 | kMerged, |
| 86 | /** |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 87 | * The caller *may* (but is not required) to chain these ops together. If they are chained |
| 88 | * then prepare() and execute() will be called on the head op but not the other ops in the |
| 89 | * chain. The head op will prepare and execute on behalf of all the ops in the chain. |
| 90 | */ |
| 91 | kMayChain, |
| 92 | /** |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 93 | * The ops cannot be combined. |
| 94 | */ |
| 95 | kCannotCombine |
| 96 | }; |
| 97 | |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 98 | CombineResult combineIfPossible(GrOp* that, const GrCaps& caps); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 99 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 100 | const SkRect& bounds() const { |
| 101 | SkASSERT(kUninitialized_BoundsFlag != fBoundsFlags); |
| 102 | return fBounds; |
| 103 | } |
| 104 | |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 105 | void setClippedBounds(const SkRect& clippedBounds) { |
| 106 | fBounds = clippedBounds; |
| 107 | // The clipped bounds already incorporate any effect of the bounds flags. |
| 108 | fBoundsFlags = 0; |
| 109 | } |
| 110 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 111 | bool hasAABloat() const { |
| 112 | SkASSERT(fBoundsFlags != kUninitialized_BoundsFlag); |
| 113 | return SkToBool(fBoundsFlags & kAABloat_BoundsFlag); |
| 114 | } |
| 115 | |
| 116 | bool hasZeroArea() const { |
| 117 | SkASSERT(fBoundsFlags != kUninitialized_BoundsFlag); |
| 118 | return SkToBool(fBoundsFlags & kZeroArea_BoundsFlag); |
| 119 | } |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 120 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 121 | #ifdef SK_DEBUG |
| 122 | // All GrOp-derived classes should be allocated in and deleted from a GrMemoryPool |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 123 | void* operator new(size_t size); |
| 124 | void operator delete(void* target); |
| 125 | |
| 126 | void* operator new(size_t size, void* placement) { |
| 127 | return ::operator new(size, placement); |
| 128 | } |
| 129 | void operator delete(void* target, void* placement) { |
| 130 | ::operator delete(target, placement); |
| 131 | } |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 132 | #endif |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 133 | |
| 134 | /** |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 135 | * Helper for safely down-casting to a GrOp subclass |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 136 | */ |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 137 | template <typename T> const T& cast() const { |
| 138 | SkASSERT(T::ClassID() == this->classID()); |
| 139 | return *static_cast<const T*>(this); |
| 140 | } |
| 141 | |
| 142 | template <typename T> T* cast() { |
| 143 | SkASSERT(T::ClassID() == this->classID()); |
| 144 | return static_cast<T*>(this); |
| 145 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 146 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 147 | uint32_t classID() const { SkASSERT(kIllegalOpID != fClassID); return fClassID; } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 148 | |
joshualitt | 08e65e7 | 2016-03-08 09:31:15 -0800 | [diff] [blame] | 149 | // We lazily initialize the uniqueID because currently the only user is GrAuditTrail |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 150 | uint32_t uniqueID() const { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 151 | if (kIllegalOpID == fUniqueID) { |
| 152 | fUniqueID = GenOpID(); |
joshualitt | 08e65e7 | 2016-03-08 09:31:15 -0800 | [diff] [blame] | 153 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 154 | return fUniqueID; |
joshualitt | 08e65e7 | 2016-03-08 09:31:15 -0800 | [diff] [blame] | 155 | } |
joshualitt | ca1f07e | 2015-08-07 08:11:19 -0700 | [diff] [blame] | 156 | |
Brian Salomon | bde4285 | 2016-12-21 11:37:49 -0500 | [diff] [blame] | 157 | /** |
| 158 | * Called prior to executing. The op should perform any resource creation or data transfers |
| 159 | * necessary before execute() is called. |
| 160 | */ |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 161 | void prepare(GrOpFlushState* state) { this->onPrepare(state); } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 162 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 163 | /** Issues the op's commands to GrGpu. */ |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 164 | void execute(GrOpFlushState* state, const SkRect& chainBounds) { |
Xiao Yu | 9712601 | 2018-04-25 18:11:44 -0700 | [diff] [blame] | 165 | TRACE_EVENT0("skia", name()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 166 | this->onExecute(state, chainBounds); |
Xiao Yu | 9712601 | 2018-04-25 18:11:44 -0700 | [diff] [blame] | 167 | } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 168 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 169 | /** Used for spewing information about ops when debugging. */ |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 170 | #ifdef SK_DEBUG |
robertphillips | 44fbc79 | 2016-06-29 06:56:12 -0700 | [diff] [blame] | 171 | virtual SkString dumpInfo() const { |
| 172 | SkString string; |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 173 | string.appendf("OpBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
robertphillips | 44fbc79 | 2016-06-29 06:56:12 -0700 | [diff] [blame] | 174 | fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom); |
| 175 | return string; |
| 176 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 177 | #else |
| 178 | SkString dumpInfo() const { return SkString("<Op information unavailable>"); } |
| 179 | #endif |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 180 | |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 181 | /** |
| 182 | * A helper for iterating over an op chain in a range for loop that also downcasts to a GrOp |
| 183 | * subclass. E.g.: |
| 184 | * for (MyOpSubClass& op : ChainRange<MyOpSubClass>(this)) { |
| 185 | * // ... |
| 186 | * } |
| 187 | */ |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 188 | template <typename OpSubclass = GrOp> class ChainRange { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 189 | private: |
| 190 | class Iter { |
| 191 | public: |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 192 | explicit Iter(const OpSubclass* head) : fCurr(head) {} |
| 193 | inline Iter& operator++() { |
| 194 | return *this = Iter(static_cast<const OpSubclass*>(fCurr->nextInChain())); |
| 195 | } |
| 196 | const OpSubclass& operator*() const { return *fCurr; } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 197 | bool operator!=(const Iter& that) const { return fCurr != that.fCurr; } |
| 198 | |
| 199 | private: |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 200 | const OpSubclass* fCurr; |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 201 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 202 | const OpSubclass* fHead; |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 203 | |
| 204 | public: |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 205 | explicit ChainRange(const OpSubclass* head) : fHead(head) {} |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 206 | Iter begin() { return Iter(fHead); } |
| 207 | Iter end() { return Iter(nullptr); } |
| 208 | }; |
| 209 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 210 | /** |
| 211 | * Concatenates two op chains. This op must be a tail and the passed op must be a head. The ops |
| 212 | * must be of the same subclass. |
| 213 | */ |
| 214 | void chainConcat(std::unique_ptr<GrOp>); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 215 | /** Returns true if this is the head of a chain (including a length 1 chain). */ |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 216 | bool isChainHead() const { return !fPrevInChain; } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 217 | /** Returns true if this is the tail of a chain (including a length 1 chain). */ |
| 218 | bool isChainTail() const { return !fNextInChain; } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 219 | /** The next op in the chain. */ |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 220 | GrOp* nextInChain() const { return fNextInChain.get(); } |
| 221 | /** The previous op in the chain. */ |
| 222 | GrOp* prevInChain() const { return fPrevInChain; } |
| 223 | /** |
| 224 | * Cuts the chain after this op. The returned op is the op that was previously next in the |
| 225 | * chain or null if this was already a tail. |
| 226 | */ |
| 227 | std::unique_ptr<GrOp> cutChain(); |
| 228 | SkDEBUGCODE(void validateChain(GrOp* expectedTail = nullptr) const); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 229 | |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 230 | #ifdef SK_DEBUG |
| 231 | virtual void validate() const {} |
| 232 | #endif |
| 233 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 234 | protected: |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 235 | GrOp(uint32_t classID); |
| 236 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 237 | /** |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 238 | * Indicates that the op will produce geometry that extends beyond its bounds for the |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 239 | * purpose of ensuring that the fragment shader runs on partially covered pixels for |
| 240 | * non-MSAA antialiasing. |
| 241 | */ |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 242 | enum class HasAABloat : bool { |
| 243 | kNo = false, |
| 244 | kYes = true |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 245 | }; |
| 246 | /** |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 247 | * Indicates that the geometry represented by the op has zero area (e.g. it is hairline or |
| 248 | * points). |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 249 | */ |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 250 | enum class IsZeroArea : bool { |
| 251 | kNo = false, |
| 252 | kYes = true |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 253 | }; |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 254 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 255 | void setBounds(const SkRect& newBounds, HasAABloat aabloat, IsZeroArea zeroArea) { |
| 256 | fBounds = newBounds; |
| 257 | this->setBoundsFlags(aabloat, zeroArea); |
| 258 | } |
| 259 | void setTransformedBounds(const SkRect& srcBounds, const SkMatrix& m, |
| 260 | HasAABloat aabloat, IsZeroArea zeroArea) { |
| 261 | m.mapRect(&fBounds, srcBounds); |
| 262 | this->setBoundsFlags(aabloat, zeroArea); |
| 263 | } |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 264 | void makeFullScreen(GrSurfaceProxy* proxy) { |
| 265 | this->setBounds(SkRect::MakeIWH(proxy->width(), proxy->height()), |
| 266 | HasAABloat::kNo, IsZeroArea::kNo); |
| 267 | } |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 268 | |
Brian Salomon | b41417f | 2018-10-24 08:58:48 -0400 | [diff] [blame] | 269 | static uint32_t GenOpClassID() { return GenID(&gCurrOpClassID); } |
| 270 | |
| 271 | private: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 272 | void joinBounds(const GrOp& that) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 273 | if (that.hasAABloat()) { |
| 274 | fBoundsFlags |= kAABloat_BoundsFlag; |
| 275 | } |
| 276 | if (that.hasZeroArea()) { |
| 277 | fBoundsFlags |= kZeroArea_BoundsFlag; |
| 278 | } |
| 279 | return fBounds.joinPossiblyEmptyRect(that.fBounds); |
| 280 | } |
| 281 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 282 | virtual CombineResult onCombineIfPossible(GrOp*, const GrCaps&) { |
| 283 | return CombineResult::kCannotCombine; |
| 284 | } |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 285 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 286 | virtual void onPrepare(GrOpFlushState*) = 0; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 287 | // If this op is chained then chainBounds is the union of the bounds of all ops in the chain. |
| 288 | // Otherwise, this op's bounds. |
| 289 | virtual void onExecute(GrOpFlushState*, const SkRect& chainBounds) = 0; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 290 | |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 291 | static uint32_t GenID(std::atomic<uint32_t>* idCounter) { |
| 292 | uint32_t id = (*idCounter)++; |
| 293 | if (id == 0) { |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 294 | SK_ABORT("This should never wrap as it should only be called once for each GrOp " |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 295 | "subclass."); |
| 296 | } |
| 297 | return id; |
| 298 | } |
| 299 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 300 | void setBoundsFlags(HasAABloat aabloat, IsZeroArea zeroArea) { |
| 301 | fBoundsFlags = 0; |
| 302 | fBoundsFlags |= (HasAABloat::kYes == aabloat) ? kAABloat_BoundsFlag : 0; |
| 303 | fBoundsFlags |= (IsZeroArea ::kYes == zeroArea) ? kZeroArea_BoundsFlag : 0; |
| 304 | } |
| 305 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 306 | enum { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 307 | kIllegalOpID = 0, |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 308 | }; |
| 309 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 310 | enum BoundsFlags { |
| 311 | kAABloat_BoundsFlag = 0x1, |
| 312 | kZeroArea_BoundsFlag = 0x2, |
| 313 | SkDEBUGCODE(kUninitialized_BoundsFlag = 0x4) |
| 314 | }; |
| 315 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 316 | std::unique_ptr<GrOp> fNextInChain; |
| 317 | GrOp* fPrevInChain = nullptr; |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 318 | const uint16_t fClassID; |
| 319 | uint16_t fBoundsFlags; |
| 320 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 321 | static uint32_t GenOpID() { return GenID(&gCurrOpUniqueID); } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 322 | mutable uint32_t fUniqueID = SK_InvalidUniqueID; |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 323 | SkRect fBounds; |
| 324 | |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 325 | static std::atomic<uint32_t> gCurrOpUniqueID; |
| 326 | static std::atomic<uint32_t> gCurrOpClassID; |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 329 | #endif |