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