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