Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrOpList_DEFINED |
| 9 | #define GrOpList_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRefCnt.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/SkColorData.h" |
| 13 | #include "include/private/SkTDArray.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrTextureProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 15 | |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 16 | class GrAuditTrail; |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 17 | class GrCaps; |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 18 | class GrOpFlushState; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 19 | class GrOpMemoryPool; |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 20 | class GrRecordingContext; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 21 | class GrRenderTargetOpList; |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 22 | class GrResourceAllocator; |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 23 | class GrResourceProvider; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 24 | class GrSurfaceProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 25 | class GrTextureOpList; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 26 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 27 | struct SkIPoint; |
| 28 | struct SkIRect; |
| 29 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 30 | class GrOpList : public SkRefCnt { |
| 31 | public: |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 32 | GrOpList(sk_sp<GrOpMemoryPool>, sk_sp<GrSurfaceProxy>, GrAuditTrail*); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 33 | ~GrOpList() override; |
| 34 | |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 35 | // These two methods are only invoked at flush time |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 36 | void prepare(GrOpFlushState* flushState); |
| 37 | bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 38 | |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 39 | virtual bool copySurface(GrRecordingContext*, |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 40 | GrSurfaceProxy* dst, |
| 41 | GrSurfaceProxy* src, |
| 42 | const SkIRect& srcRect, |
| 43 | const SkIPoint& dstPoint) = 0; |
| 44 | |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 45 | virtual void makeClosed(const GrCaps&) { |
Robert Phillips | d991486 | 2017-06-14 15:16:59 -0400 | [diff] [blame] | 46 | if (!this->isClosed()) { |
| 47 | this->setFlag(kClosed_Flag); |
Robert Phillips | d991486 | 2017-06-14 15:16:59 -0400 | [diff] [blame] | 48 | } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 51 | // Called when this class will survive a flush and needs to truncate its ops and start over. |
| 52 | // TODO: ultimately it should be invalid for an op list to survive a flush. |
| 53 | // https://bugs.chromium.org/p/skia/issues/detail?id=7111 |
| 54 | virtual void endFlush(); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 55 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 56 | bool isClosed() const { return this->isSetFlag(kClosed_Flag); } |
| 57 | |
| 58 | /* |
| 59 | * Notify this GrOpList that it relies on the contents of 'dependedOn' |
| 60 | */ |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 61 | void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * Does this opList depend on 'dependedOn'? |
| 65 | */ |
Robert Phillips | ce3c28f | 2018-07-18 13:52:40 -0400 | [diff] [blame] | 66 | bool dependsOn(const GrOpList* dependedOn) const; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 67 | |
| 68 | /* |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 69 | * Safely cast this GrOpList to a GrTextureOpList (if possible). |
| 70 | */ |
| 71 | virtual GrTextureOpList* asTextureOpList() { return nullptr; } |
| 72 | |
| 73 | /* |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 74 | * Safely cast this GrOpList to a GrRenderTargetOpList (if possible). |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 75 | */ |
| 76 | virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; } |
| 77 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 78 | uint32_t uniqueID() const { return fUniqueID; } |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 79 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 80 | /* |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 81 | * Dump out the GrOpList dependency DAG |
| 82 | */ |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 83 | SkDEBUGCODE(virtual void dump(bool printDependencies) const;) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 84 | |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 85 | SkDEBUGCODE(virtual int numClips() const { return 0; }) |
| 86 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 87 | protected: |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 88 | // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if |
| 89 | // it is required)? |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 90 | bool isInstantiated() const; |
| 91 | |
| 92 | SkDEBUGCODE(bool deferredProxiesAreInstantiated() const;) |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 93 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 94 | // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops. |
| 95 | // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its |
| 96 | // constituent opLists survive. |
| 97 | sk_sp<GrOpMemoryPool> fOpMemoryPool; |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 98 | sk_sp<GrSurfaceProxy> fTarget; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 99 | GrAuditTrail* fAuditTrail; |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 100 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 101 | GrLoadOp fColorLoadOp = GrLoadOp::kLoad; |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 102 | SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT; |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 103 | GrLoadOp fStencilLoadOp = GrLoadOp::kLoad; |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 104 | |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 105 | // List of texture proxies whose contents are being prepared on a worker thread |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 106 | // TODO: this list exists so we can fire off the proper upload when an opList begins |
| 107 | // executing. Can this be replaced? |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 108 | SkTArray<GrTextureProxy*, true> fDeferredProxies; |
| 109 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 110 | private: |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 111 | friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals |
| 112 | |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 113 | virtual bool onIsUsed(GrSurfaceProxy*) const = 0; |
| 114 | |
| 115 | bool isUsed(GrSurfaceProxy* proxy) const { |
| 116 | if (proxy == fTarget.get()) { |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | return this->onIsUsed(proxy); |
| 121 | } |
| 122 | |
Robert Phillips | ce3c28f | 2018-07-18 13:52:40 -0400 | [diff] [blame] | 123 | void addDependency(GrOpList* dependedOn); |
Robert Phillips | e6d0618 | 2018-08-06 16:56:26 -0400 | [diff] [blame] | 124 | void addDependent(GrOpList* dependent); |
Nico Weber | 0af0813 | 2019-02-28 13:23:38 -0500 | [diff] [blame] | 125 | SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const;) |
| 126 | SkDEBUGCODE(void validate() const;) |
Robert Phillips | 46acf9d | 2018-10-09 09:31:40 -0400 | [diff] [blame] | 127 | void closeThoseWhoDependOnMe(const GrCaps&); |
Robert Phillips | ce3c28f | 2018-07-18 13:52:40 -0400 | [diff] [blame] | 128 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 129 | // Remove all Ops which reference proxies that are not instantiated. |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 130 | virtual void purgeOpsWithUninstantiatedProxies() = 0; |
| 131 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 132 | // Feed proxy usage intervals to the GrResourceAllocator class |
| 133 | virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 134 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 135 | static uint32_t CreateUniqueID(); |
| 136 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 137 | enum Flags { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 138 | kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 139 | |
| 140 | kWasOutput_Flag = 0x02, //!< Flag for topological sorting |
| 141 | kTempMark_Flag = 0x04, //!< Flag for topological sorting |
| 142 | }; |
| 143 | |
| 144 | void setFlag(uint32_t flag) { |
| 145 | fFlags |= flag; |
| 146 | } |
| 147 | |
| 148 | void resetFlag(uint32_t flag) { |
| 149 | fFlags &= ~flag; |
| 150 | } |
| 151 | |
| 152 | bool isSetFlag(uint32_t flag) const { |
| 153 | return SkToBool(fFlags & flag); |
| 154 | } |
| 155 | |
| 156 | struct TopoSortTraits { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 157 | static void Output(GrOpList* opList, int /* index */) { |
| 158 | opList->setFlag(GrOpList::kWasOutput_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 159 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 160 | static bool WasOutput(const GrOpList* opList) { |
| 161 | return opList->isSetFlag(GrOpList::kWasOutput_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 162 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 163 | static void SetTempMark(GrOpList* opList) { |
| 164 | opList->setFlag(GrOpList::kTempMark_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 165 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 166 | static void ResetTempMark(GrOpList* opList) { |
| 167 | opList->resetFlag(GrOpList::kTempMark_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 168 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 169 | static bool IsTempMarked(const GrOpList* opList) { |
| 170 | return opList->isSetFlag(GrOpList::kTempMark_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 171 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 172 | static int NumDependencies(const GrOpList* opList) { |
| 173 | return opList->fDependencies.count(); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 174 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 175 | static GrOpList* Dependency(GrOpList* opList, int index) { |
| 176 | return opList->fDependencies[index]; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 177 | } |
| 178 | }; |
| 179 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 180 | virtual void onPrepare(GrOpFlushState* flushState) = 0; |
| 181 | virtual bool onExecute(GrOpFlushState* flushState) = 0; |
| 182 | |
Robert Phillips | 82774f8 | 2019-06-20 14:38:27 -0400 | [diff] [blame] | 183 | const uint32_t fUniqueID; |
Robert Phillips | 73fd0d6 | 2017-09-15 11:48:08 +0000 | [diff] [blame] | 184 | uint32_t fFlags; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 185 | |
| 186 | // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies' |
Robert Phillips | 73fd0d6 | 2017-09-15 11:48:08 +0000 | [diff] [blame] | 187 | SkSTArray<1, GrOpList*, true> fDependencies; |
Robert Phillips | e6d0618 | 2018-08-06 16:56:26 -0400 | [diff] [blame] | 188 | // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents' |
| 189 | SkSTArray<1, GrOpList*, true> fDependents; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 190 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 191 | typedef SkRefCnt INHERITED; |
| 192 | }; |
| 193 | |
| 194 | #endif |