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