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