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 | |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 11 | #include "GrColor.h" |
Brian Salomon | ee78396 | 2018-08-01 09:55:10 -0400 | [diff] [blame] | 12 | #include "GrProxyRef.h" |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 13 | #include "GrTextureProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
| 15 | #include "SkTDArray.h" |
| 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; |
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 | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 32 | GrOpList(GrResourceProvider*, sk_sp<GrOpMemoryPool>, 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 | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 42 | virtual bool copySurface(GrContext*, |
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); |
| 51 | fTarget.removeRef(); |
| 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 numOps() const = 0;) |
| 90 | SkDEBUGCODE(virtual int numClips() const { return 0; }) |
| 91 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 92 | // TODO: it would be nice for this to be hidden |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 93 | void setStencilLoadOp(GrLoadOp loadOp) { fStencilLoadOp = loadOp; } |
| 94 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 95 | protected: |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 96 | bool isInstantiated() const; |
Robert Phillips | 09dfc47 | 2017-09-13 15:25:47 -0400 | [diff] [blame] | 97 | |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 98 | // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if |
| 99 | // it is required)? |
| 100 | bool isFullyInstantiated() const; |
| 101 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 102 | // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops. |
| 103 | // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its |
| 104 | // constituent opLists survive. |
| 105 | sk_sp<GrOpMemoryPool> fOpMemoryPool; |
| 106 | GrSurfaceProxyRef fTarget; |
| 107 | GrAuditTrail* fAuditTrail; |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 108 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 109 | GrLoadOp fColorLoadOp = GrLoadOp::kLoad; |
| 110 | GrColor fLoadClearColor = 0x0; |
| 111 | GrLoadOp fStencilLoadOp = GrLoadOp::kLoad; |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 112 | |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 113 | // List of texture proxies whose contents are being prepared on a worker thread |
| 114 | SkTArray<GrTextureProxy*, true> fDeferredProxies; |
| 115 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 116 | private: |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 117 | friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals |
| 118 | |
Robert Phillips | ce3c28f | 2018-07-18 13:52:40 -0400 | [diff] [blame] | 119 | void addDependency(GrOpList* dependedOn); |
Robert Phillips | e6d0618 | 2018-08-06 16:56:26 -0400 | [diff] [blame] | 120 | void addDependent(GrOpList* dependent); |
| 121 | SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const); |
| 122 | SkDEBUGCODE(void validate() const); |
Robert Phillips | ce3c28f | 2018-07-18 13:52:40 -0400 | [diff] [blame] | 123 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 124 | // Remove all Ops which reference proxies that have not been instantiated. |
| 125 | virtual void purgeOpsWithUninstantiatedProxies() = 0; |
| 126 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 127 | // Feed proxy usage intervals to the GrResourceAllocator class |
| 128 | virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 129 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 130 | static uint32_t CreateUniqueID(); |
| 131 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 132 | enum Flags { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 133 | kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 134 | |
| 135 | kWasOutput_Flag = 0x02, //!< Flag for topological sorting |
| 136 | kTempMark_Flag = 0x04, //!< Flag for topological sorting |
| 137 | }; |
| 138 | |
| 139 | void setFlag(uint32_t flag) { |
| 140 | fFlags |= flag; |
| 141 | } |
| 142 | |
| 143 | void resetFlag(uint32_t flag) { |
| 144 | fFlags &= ~flag; |
| 145 | } |
| 146 | |
| 147 | bool isSetFlag(uint32_t flag) const { |
| 148 | return SkToBool(fFlags & flag); |
| 149 | } |
| 150 | |
| 151 | struct TopoSortTraits { |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 152 | static void Output(GrOpList* opList, int /* index */) { |
| 153 | opList->setFlag(GrOpList::kWasOutput_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 154 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 155 | static bool WasOutput(const GrOpList* opList) { |
| 156 | return opList->isSetFlag(GrOpList::kWasOutput_Flag); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 157 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 158 | static void SetTempMark(GrOpList* opList) { |
| 159 | opList->setFlag(GrOpList::kTempMark_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 void ResetTempMark(GrOpList* opList) { |
| 162 | opList->resetFlag(GrOpList::kTempMark_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 bool IsTempMarked(const GrOpList* opList) { |
| 165 | return opList->isSetFlag(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 int NumDependencies(const GrOpList* opList) { |
| 168 | return opList->fDependencies.count(); |
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 GrOpList* Dependency(GrOpList* opList, int index) { |
| 171 | return opList->fDependencies[index]; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 172 | } |
| 173 | }; |
| 174 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 175 | virtual void onPrepare(GrOpFlushState* flushState) = 0; |
| 176 | virtual bool onExecute(GrOpFlushState* flushState) = 0; |
| 177 | |
Robert Phillips | 73fd0d6 | 2017-09-15 11:48:08 +0000 | [diff] [blame] | 178 | uint32_t fUniqueID; |
| 179 | uint32_t fFlags; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 180 | |
| 181 | // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies' |
Robert Phillips | 73fd0d6 | 2017-09-15 11:48:08 +0000 | [diff] [blame] | 182 | SkSTArray<1, GrOpList*, true> fDependencies; |
Robert Phillips | e6d0618 | 2018-08-06 16:56:26 -0400 | [diff] [blame] | 183 | // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents' |
| 184 | SkSTArray<1, GrOpList*, true> fDependents; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 185 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 186 | typedef SkRefCnt INHERITED; |
| 187 | }; |
| 188 | |
| 189 | #endif |