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" |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 12 | #include "GrGpuResourceRef.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 13 | #include "SkRefCnt.h" |
| 14 | #include "SkTDArray.h" |
| 15 | |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 16 | |
| 17 | // Turn on/off the explicit distribution of GPU resources at flush time |
| 18 | //#define MDB_ALLOC_RESOURCES 1 |
| 19 | |
| 20 | // Turn on/off the sorting of opLists at flush time |
| 21 | //#define ENABLE_MDB_SORT 1 |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 22 | |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 23 | class GrAuditTrail; |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 24 | class GrCaps; |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 25 | class GrOpFlushState; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 26 | class GrRenderTargetOpList; |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 27 | class GrResourceAllocator; |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 28 | class GrResourceProvider; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 29 | class GrSurfaceProxy; |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 30 | class GrTextureProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 31 | class GrTextureOpList; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 32 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 33 | struct SkIPoint; |
| 34 | struct SkIRect; |
| 35 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 36 | class GrOpList : public SkRefCnt { |
| 37 | public: |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 38 | GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 39 | ~GrOpList() override; |
| 40 | |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 41 | // These four methods are invoked at flush time |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 42 | bool instantiate(GrResourceProvider* resourceProvider); |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 43 | // Instantiates any "threaded" texture proxies that are being prepared elsewhere |
| 44 | void instantiateDeferredProxies(GrResourceProvider* resourceProvider); |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 45 | void prepare(GrOpFlushState* flushState); |
| 46 | bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 47 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 48 | virtual bool copySurface(const GrCaps& caps, |
| 49 | GrSurfaceProxy* dst, |
| 50 | GrSurfaceProxy* src, |
| 51 | const SkIRect& srcRect, |
| 52 | const SkIPoint& dstPoint) = 0; |
| 53 | |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 54 | virtual void makeClosed(const GrCaps&) { |
Robert Phillips | d991486 | 2017-06-14 15:16:59 -0400 | [diff] [blame] | 55 | if (!this->isClosed()) { |
| 56 | this->setFlag(kClosed_Flag); |
| 57 | fTarget.removeRef(); |
| 58 | } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 61 | // Called when this class will survive a flush and needs to truncate its ops and start over. |
| 62 | // TODO: ultimately it should be invalid for an op list to survive a flush. |
| 63 | // https://bugs.chromium.org/p/skia/issues/detail?id=7111 |
| 64 | virtual void endFlush(); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 65 | |
| 66 | // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like |
| 67 | // these could go away |
| 68 | virtual void abandonGpuResources() = 0; |
| 69 | virtual void freeGpuResources() = 0; |
| 70 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 71 | bool isClosed() const { return this->isSetFlag(kClosed_Flag); } |
| 72 | |
| 73 | /* |
| 74 | * Notify this GrOpList that it relies on the contents of 'dependedOn' |
| 75 | */ |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 76 | void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Does this opList depend on 'dependedOn'? |
| 80 | */ |
| 81 | bool dependsOn(GrOpList* dependedOn) const { |
Robert Phillips | 73fd0d6 | 2017-09-15 11:48:08 +0000 | [diff] [blame] | 82 | for (int i = 0; i < fDependencies.count(); ++i) { |
| 83 | if (fDependencies[i] == dependedOn) { |
| 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return false; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 92 | * Safely cast this GrOpList to a GrTextureOpList (if possible). |
| 93 | */ |
| 94 | virtual GrTextureOpList* asTextureOpList() { return nullptr; } |
| 95 | |
| 96 | /* |
| 97 | * Safely case this GrOpList to a GrRenderTargetOpList (if possible). |
| 98 | */ |
| 99 | virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; } |
| 100 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 101 | int32_t uniqueID() const { return fUniqueID; } |
| 102 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 103 | /* |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 104 | * Dump out the GrOpList dependency DAG |
| 105 | */ |
| 106 | SkDEBUGCODE(virtual void dump() const;) |
| 107 | |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 108 | SkDEBUGCODE(virtual int numOps() const = 0;) |
| 109 | SkDEBUGCODE(virtual int numClips() const { return 0; }) |
| 110 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 111 | // TODO: it would be nice for this to be hidden |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 112 | void setStencilLoadOp(GrLoadOp loadOp) { fStencilLoadOp = loadOp; } |
| 113 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 114 | protected: |
Robert Phillips | 09dfc47 | 2017-09-13 15:25:47 -0400 | [diff] [blame] | 115 | SkDEBUGCODE(bool isInstantiated() const;) |
| 116 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 117 | GrSurfaceProxyRef fTarget; |
| 118 | GrAuditTrail* fAuditTrail; |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 119 | |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 120 | GrLoadOp fColorLoadOp = GrLoadOp::kLoad; |
| 121 | GrColor fLoadClearColor = 0x0; |
| 122 | GrLoadOp fStencilLoadOp = GrLoadOp::kLoad; |
| 123 | |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 124 | // List of texture proxies whose contents are being prepared on a worker thread |
| 125 | SkTArray<GrTextureProxy*, true> fDeferredProxies; |
| 126 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 127 | private: |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 128 | friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals |
| 129 | |
| 130 | // Feed proxy usage intervals to the GrResourceAllocator class |
| 131 | virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 132 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 133 | static uint32_t CreateUniqueID(); |
| 134 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 135 | enum Flags { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 136 | kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 137 | |
| 138 | kWasOutput_Flag = 0x02, //!< Flag for topological sorting |
| 139 | kTempMark_Flag = 0x04, //!< Flag for topological sorting |
| 140 | }; |
| 141 | |
| 142 | void setFlag(uint32_t flag) { |
| 143 | fFlags |= flag; |
| 144 | } |
| 145 | |
| 146 | void resetFlag(uint32_t flag) { |
| 147 | fFlags &= ~flag; |
| 148 | } |
| 149 | |
| 150 | bool isSetFlag(uint32_t flag) const { |
| 151 | return SkToBool(fFlags & flag); |
| 152 | } |
| 153 | |
| 154 | struct TopoSortTraits { |
| 155 | static void Output(GrOpList* dt, int /* index */) { |
| 156 | dt->setFlag(GrOpList::kWasOutput_Flag); |
| 157 | } |
| 158 | static bool WasOutput(const GrOpList* dt) { |
| 159 | return dt->isSetFlag(GrOpList::kWasOutput_Flag); |
| 160 | } |
| 161 | static void SetTempMark(GrOpList* dt) { |
| 162 | dt->setFlag(GrOpList::kTempMark_Flag); |
| 163 | } |
| 164 | static void ResetTempMark(GrOpList* dt) { |
| 165 | dt->resetFlag(GrOpList::kTempMark_Flag); |
| 166 | } |
| 167 | static bool IsTempMarked(const GrOpList* dt) { |
| 168 | return dt->isSetFlag(GrOpList::kTempMark_Flag); |
| 169 | } |
| 170 | static int NumDependencies(const GrOpList* dt) { |
| 171 | return dt->fDependencies.count(); |
| 172 | } |
| 173 | static GrOpList* Dependency(GrOpList* dt, int index) { |
| 174 | return dt->fDependencies[index]; |
| 175 | } |
| 176 | }; |
| 177 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 178 | virtual void onPrepare(GrOpFlushState* flushState) = 0; |
| 179 | virtual bool onExecute(GrOpFlushState* flushState) = 0; |
| 180 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 181 | void addDependency(GrOpList* dependedOn); |
| 182 | |
Robert Phillips | 73fd0d6 | 2017-09-15 11:48:08 +0000 | [diff] [blame] | 183 | uint32_t fUniqueID; |
| 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 | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 188 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 189 | typedef SkRefCnt INHERITED; |
| 190 | }; |
| 191 | |
| 192 | #endif |