blob: c5a84d7c3b2acd355355d43bc74ccd0bb7132996 [file] [log] [blame]
Robert Phillipsf2361d22016-10-25 14:20:06 -04001/*
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 Phillips6b47c7d2017-08-29 07:24:09 -040011#include "GrColor.h"
Brian Salomonee783962018-08-01 09:55:10 -040012#include "GrProxyRef.h"
Robert Phillips62000362018-02-01 09:10:04 -050013#include "GrTextureProxy.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040014#include "SkRefCnt.h"
15#include "SkTDArray.h"
16
Brian Osman62e7b5f2016-10-26 12:02:18 -040017class GrAuditTrail;
Robert Phillipsee683652017-04-26 11:53:10 -040018class GrCaps;
Brian Salomon742e31d2016-12-07 17:06:19 -050019class GrOpFlushState;
Robert Phillipsc994a932018-06-19 13:09:54 -040020class GrOpMemoryPool;
Brian Osman45580d32016-11-23 09:37:01 -050021class GrRenderTargetOpList;
Robert Phillipsd375dbf2017-09-14 12:45:25 -040022class GrResourceAllocator;
Robert Phillips318c4192017-05-17 09:36:38 -040023class GrResourceProvider;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040024class GrSurfaceProxy;
Brian Osman45580d32016-11-23 09:37:01 -050025class GrTextureOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040026
Robert Phillips2de8cfa2017-06-28 10:33:41 -040027struct SkIPoint;
28struct SkIRect;
29
Robert Phillipsf2361d22016-10-25 14:20:06 -040030class GrOpList : public SkRefCnt {
31public:
Robert Phillipsc994a932018-06-19 13:09:54 -040032 GrOpList(GrResourceProvider*, sk_sp<GrOpMemoryPool>, GrSurfaceProxy*, GrAuditTrail*);
Robert Phillipsf2361d22016-10-25 14:20:06 -040033 ~GrOpList() override;
34
Brian Osman099fa0f2017-10-02 16:38:32 -040035 // These four methods are invoked at flush time
Robert Phillips318c4192017-05-17 09:36:38 -040036 bool instantiate(GrResourceProvider* resourceProvider);
Brian Osman099fa0f2017-10-02 16:38:32 -040037 // Instantiates any "threaded" texture proxies that are being prepared elsewhere
38 void instantiateDeferredProxies(GrResourceProvider* resourceProvider);
Brian Osman407b3422017-08-22 15:01:32 -040039 void prepare(GrOpFlushState* flushState);
40 bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
Robert Phillipsf2361d22016-10-25 14:20:06 -040041
Robert Phillips7c525e62018-06-12 10:11:12 -040042 virtual bool copySurface(GrContext*,
Robert Phillips2de8cfa2017-06-28 10:33:41 -040043 GrSurfaceProxy* dst,
44 GrSurfaceProxy* src,
45 const SkIRect& srcRect,
46 const SkIPoint& dstPoint) = 0;
47
Robert Phillipsee683652017-04-26 11:53:10 -040048 virtual void makeClosed(const GrCaps&) {
Robert Phillipsd9914862017-06-14 15:16:59 -040049 if (!this->isClosed()) {
50 this->setFlag(kClosed_Flag);
51 fTarget.removeRef();
52 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040053 }
54
Chris Daltona84cacf2017-10-04 10:30:29 -060055 // 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 Phillipsf2361d22016-10-25 14:20:06 -040059
Robert Phillipsf2361d22016-10-25 14:20:06 -040060 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
61
62 /*
63 * Notify this GrOpList that it relies on the contents of 'dependedOn'
64 */
Robert Phillipsee683652017-04-26 11:53:10 -040065 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040066
67 /*
68 * Does this opList depend on 'dependedOn'?
69 */
Robert Phillipsce3c28f2018-07-18 13:52:40 -040070 bool dependsOn(const GrOpList* dependedOn) const;
Robert Phillipsf2361d22016-10-25 14:20:06 -040071
72 /*
Brian Osman45580d32016-11-23 09:37:01 -050073 * 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 Daltona32a3c32017-12-05 10:05:21 -070082 uint32_t uniqueID() const { return fUniqueID; }
Robert Phillipsc0138922017-03-08 11:50:55 -050083
Brian Osman45580d32016-11-23 09:37:01 -050084 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040085 * Dump out the GrOpList dependency DAG
86 */
Robert Phillips27483912018-04-20 12:43:18 -040087 SkDEBUGCODE(virtual void dump(bool printDependencies) const;)
Robert Phillipsf2361d22016-10-25 14:20:06 -040088
Robert Phillipsc84c0302017-05-08 15:35:11 -040089 SkDEBUGCODE(virtual int numOps() const = 0;)
90 SkDEBUGCODE(virtual int numClips() const { return 0; })
91
Robert Phillips380b90c2017-08-30 07:41:07 -040092 // TODO: it would be nice for this to be hidden
Robert Phillips6b47c7d2017-08-29 07:24:09 -040093 void setStencilLoadOp(GrLoadOp loadOp) { fStencilLoadOp = loadOp; }
94
Robert Phillipsdc83b892017-04-13 12:23:54 -040095protected:
Robert Phillips4150eea2018-02-07 17:08:21 -050096 bool isInstantiated() const;
Robert Phillips09dfc472017-09-13 15:25:47 -040097
Robert Phillips01a91282018-07-26 08:03:04 -040098 // 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 Phillipsc994a932018-06-19 13:09:54 -0400102 // 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 Phillipsdc83b892017-04-13 12:23:54 -0400108
Robert Phillipsc994a932018-06-19 13:09:54 -0400109 GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
110 GrColor fLoadClearColor = 0x0;
111 GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400112
Brian Osman099fa0f2017-10-02 16:38:32 -0400113 // List of texture proxies whose contents are being prepared on a worker thread
114 SkTArray<GrTextureProxy*, true> fDeferredProxies;
115
Robert Phillipsf2361d22016-10-25 14:20:06 -0400116private:
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400117 friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
118
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400119 void addDependency(GrOpList* dependedOn);
Robert Phillipse6d06182018-08-06 16:56:26 -0400120 void addDependent(GrOpList* dependent);
121 SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const);
122 SkDEBUGCODE(void validate() const);
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400123
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500124 // Remove all Ops which reference proxies that have not been instantiated.
125 virtual void purgeOpsWithUninstantiatedProxies() = 0;
126
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400127 // Feed proxy usage intervals to the GrResourceAllocator class
128 virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400129
Robert Phillipsc0138922017-03-08 11:50:55 -0500130 static uint32_t CreateUniqueID();
131
Robert Phillipsf2361d22016-10-25 14:20:06 -0400132 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500133 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400134
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 Phillips4150eea2018-02-07 17:08:21 -0500152 static void Output(GrOpList* opList, int /* index */) {
153 opList->setFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400154 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500155 static bool WasOutput(const GrOpList* opList) {
156 return opList->isSetFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400157 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500158 static void SetTempMark(GrOpList* opList) {
159 opList->setFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400160 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500161 static void ResetTempMark(GrOpList* opList) {
162 opList->resetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400163 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500164 static bool IsTempMarked(const GrOpList* opList) {
165 return opList->isSetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400166 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500167 static int NumDependencies(const GrOpList* opList) {
168 return opList->fDependencies.count();
Robert Phillipsf2361d22016-10-25 14:20:06 -0400169 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500170 static GrOpList* Dependency(GrOpList* opList, int index) {
171 return opList->fDependencies[index];
Robert Phillipsf2361d22016-10-25 14:20:06 -0400172 }
173 };
174
Brian Osman407b3422017-08-22 15:01:32 -0400175 virtual void onPrepare(GrOpFlushState* flushState) = 0;
176 virtual bool onExecute(GrOpFlushState* flushState) = 0;
177
Robert Phillips73fd0d62017-09-15 11:48:08 +0000178 uint32_t fUniqueID;
179 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400180
181 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips73fd0d62017-09-15 11:48:08 +0000182 SkSTArray<1, GrOpList*, true> fDependencies;
Robert Phillipse6d06182018-08-06 16:56:26 -0400183 // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents'
184 SkSTArray<1, GrOpList*, true> fDependents;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400185
Robert Phillipsf2361d22016-10-25 14:20:06 -0400186 typedef SkRefCnt INHERITED;
187};
188
189#endif