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