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 | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 11 | #include "GrGpuResourceRef.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 12 | #include "SkRefCnt.h" |
| 13 | #include "SkTDArray.h" |
| 14 | |
| 15 | //#define ENABLE_MDB 1 |
| 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; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 20 | class GrRenderTargetOpList; |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 21 | class GrResourceProvider; |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 22 | class GrSurfaceProxy; |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 23 | class GrTextureProxy; |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 24 | class GrTextureOpList; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 25 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 26 | struct SkIPoint; |
| 27 | struct SkIRect; |
| 28 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 29 | class GrOpList : public SkRefCnt { |
| 30 | public: |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 31 | GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 32 | ~GrOpList() override; |
| 33 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 34 | // These three methods are invoked at flush time |
| 35 | bool instantiate(GrResourceProvider* resourceProvider); |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 36 | virtual void prepareOps(GrOpFlushState* flushState) = 0; |
| 37 | virtual bool executeOps(GrOpFlushState* flushState) = 0; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 38 | |
Robert Phillips | 2de8cfa | 2017-06-28 10:33:41 -0400 | [diff] [blame] | 39 | virtual bool copySurface(const GrCaps& caps, |
| 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); |
| 48 | fTarget.removeRef(); |
| 49 | } |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 52 | virtual void reset(); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 53 | |
| 54 | // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like |
| 55 | // these could go away |
| 56 | virtual void abandonGpuResources() = 0; |
| 57 | virtual void freeGpuResources() = 0; |
| 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 | */ |
| 69 | bool dependsOn(GrOpList* dependedOn) const { |
| 70 | return fDependencies.find(dependedOn) >= 0; |
| 71 | } |
| 72 | |
| 73 | /* |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 74 | * Safely cast this GrOpList to a GrTextureOpList (if possible). |
| 75 | */ |
| 76 | virtual GrTextureOpList* asTextureOpList() { return nullptr; } |
| 77 | |
| 78 | /* |
| 79 | * Safely case this GrOpList to a GrRenderTargetOpList (if possible). |
| 80 | */ |
| 81 | virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; } |
| 82 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 83 | int32_t uniqueID() const { return fUniqueID; } |
| 84 | |
Brian Osman | 45580d3 | 2016-11-23 09:37:01 -0500 | [diff] [blame] | 85 | /* |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 86 | * Dump out the GrOpList dependency DAG |
| 87 | */ |
| 88 | SkDEBUGCODE(virtual void dump() const;) |
| 89 | |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 90 | SkDEBUGCODE(virtual int numOps() const = 0;) |
| 91 | SkDEBUGCODE(virtual int numClips() const { return 0; }) |
| 92 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 93 | protected: |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 94 | GrSurfaceProxyRef fTarget; |
| 95 | GrAuditTrail* fAuditTrail; |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 96 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 97 | private: |
| 98 | friend class GrDrawingManager; // for resetFlag & TopoSortTraits |
| 99 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 100 | static uint32_t CreateUniqueID(); |
| 101 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 102 | enum Flags { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 103 | kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 104 | |
| 105 | kWasOutput_Flag = 0x02, //!< Flag for topological sorting |
| 106 | kTempMark_Flag = 0x04, //!< Flag for topological sorting |
| 107 | }; |
| 108 | |
| 109 | void setFlag(uint32_t flag) { |
| 110 | fFlags |= flag; |
| 111 | } |
| 112 | |
| 113 | void resetFlag(uint32_t flag) { |
| 114 | fFlags &= ~flag; |
| 115 | } |
| 116 | |
| 117 | bool isSetFlag(uint32_t flag) const { |
| 118 | return SkToBool(fFlags & flag); |
| 119 | } |
| 120 | |
| 121 | struct TopoSortTraits { |
| 122 | static void Output(GrOpList* dt, int /* index */) { |
| 123 | dt->setFlag(GrOpList::kWasOutput_Flag); |
| 124 | } |
| 125 | static bool WasOutput(const GrOpList* dt) { |
| 126 | return dt->isSetFlag(GrOpList::kWasOutput_Flag); |
| 127 | } |
| 128 | static void SetTempMark(GrOpList* dt) { |
| 129 | dt->setFlag(GrOpList::kTempMark_Flag); |
| 130 | } |
| 131 | static void ResetTempMark(GrOpList* dt) { |
| 132 | dt->resetFlag(GrOpList::kTempMark_Flag); |
| 133 | } |
| 134 | static bool IsTempMarked(const GrOpList* dt) { |
| 135 | return dt->isSetFlag(GrOpList::kTempMark_Flag); |
| 136 | } |
| 137 | static int NumDependencies(const GrOpList* dt) { |
| 138 | return dt->fDependencies.count(); |
| 139 | } |
| 140 | static GrOpList* Dependency(GrOpList* dt, int index) { |
| 141 | return dt->fDependencies[index]; |
| 142 | } |
| 143 | }; |
| 144 | |
| 145 | void addDependency(GrOpList* dependedOn); |
| 146 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 147 | uint32_t fUniqueID; |
| 148 | uint32_t fFlags; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 149 | |
| 150 | // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies' |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 151 | SkTDArray<GrOpList*> fDependencies; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 152 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 153 | typedef SkRefCnt INHERITED; |
| 154 | }; |
| 155 | |
| 156 | #endif |