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