blob: cd0b50035ef5a1b922ab66e2f014e8119db2fcc6 [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"
Robert Phillips6cdc22c2017-05-11 16:29:14 -040012#include "GrGpuResourceRef.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040013#include "SkRefCnt.h"
14#include "SkTDArray.h"
15
Robert Phillips9d6c64f2017-09-14 10:56:45 -040016
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 Phillipsf2361d22016-10-25 14:20:06 -040022
Brian Osman62e7b5f2016-10-26 12:02:18 -040023class GrAuditTrail;
Robert Phillipsee683652017-04-26 11:53:10 -040024class GrCaps;
Brian Salomon742e31d2016-12-07 17:06:19 -050025class GrOpFlushState;
Brian Osman45580d32016-11-23 09:37:01 -050026class GrRenderTargetOpList;
Robert Phillipsd375dbf2017-09-14 12:45:25 -040027class GrResourceAllocator;
Robert Phillips318c4192017-05-17 09:36:38 -040028class GrResourceProvider;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040029class GrSurfaceProxy;
Robert Phillips18166ee2017-06-01 12:55:44 -040030class GrTextureProxy;
Brian Osman45580d32016-11-23 09:37:01 -050031class GrTextureOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040032
Robert Phillips2de8cfa2017-06-28 10:33:41 -040033struct SkIPoint;
34struct SkIRect;
35
Robert Phillipsf2361d22016-10-25 14:20:06 -040036class GrOpList : public SkRefCnt {
37public:
Robert Phillips5efd5ea2017-05-30 13:47:32 -040038 GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*);
Robert Phillipsf2361d22016-10-25 14:20:06 -040039 ~GrOpList() override;
40
Brian Osman099fa0f2017-10-02 16:38:32 -040041 // These four methods are invoked at flush time
Robert Phillips318c4192017-05-17 09:36:38 -040042 bool instantiate(GrResourceProvider* resourceProvider);
Brian Osman099fa0f2017-10-02 16:38:32 -040043 // Instantiates any "threaded" texture proxies that are being prepared elsewhere
44 void instantiateDeferredProxies(GrResourceProvider* resourceProvider);
Brian Osman407b3422017-08-22 15:01:32 -040045 void prepare(GrOpFlushState* flushState);
46 bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
Robert Phillipsf2361d22016-10-25 14:20:06 -040047
Robert Phillips2de8cfa2017-06-28 10:33:41 -040048 virtual bool copySurface(const GrCaps& caps,
49 GrSurfaceProxy* dst,
50 GrSurfaceProxy* src,
51 const SkIRect& srcRect,
52 const SkIPoint& dstPoint) = 0;
53
Robert Phillipsee683652017-04-26 11:53:10 -040054 virtual void makeClosed(const GrCaps&) {
Robert Phillipsd9914862017-06-14 15:16:59 -040055 if (!this->isClosed()) {
56 this->setFlag(kClosed_Flag);
57 fTarget.removeRef();
58 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040059 }
60
Chris Daltona84cacf2017-10-04 10:30:29 -060061 // 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 Phillipsf2361d22016-10-25 14:20:06 -040065
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 Phillipsf2361d22016-10-25 14:20:06 -040071 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
72
73 /*
74 * Notify this GrOpList that it relies on the contents of 'dependedOn'
75 */
Robert Phillipsee683652017-04-26 11:53:10 -040076 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040077
78 /*
79 * Does this opList depend on 'dependedOn'?
80 */
81 bool dependsOn(GrOpList* dependedOn) const {
Robert Phillips73fd0d62017-09-15 11:48:08 +000082 for (int i = 0; i < fDependencies.count(); ++i) {
83 if (fDependencies[i] == dependedOn) {
84 return true;
85 }
86 }
87
88 return false;
Robert Phillipsf2361d22016-10-25 14:20:06 -040089 }
90
91 /*
Brian Osman45580d32016-11-23 09:37:01 -050092 * 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 Phillipsc0138922017-03-08 11:50:55 -0500101 int32_t uniqueID() const { return fUniqueID; }
102
Brian Osman45580d32016-11-23 09:37:01 -0500103 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -0400104 * Dump out the GrOpList dependency DAG
105 */
106 SkDEBUGCODE(virtual void dump() const;)
107
Robert Phillipsc84c0302017-05-08 15:35:11 -0400108 SkDEBUGCODE(virtual int numOps() const = 0;)
109 SkDEBUGCODE(virtual int numClips() const { return 0; })
110
Robert Phillips380b90c2017-08-30 07:41:07 -0400111 // TODO: it would be nice for this to be hidden
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400112 void setStencilLoadOp(GrLoadOp loadOp) { fStencilLoadOp = loadOp; }
113
Robert Phillipsdc83b892017-04-13 12:23:54 -0400114protected:
Robert Phillips09dfc472017-09-13 15:25:47 -0400115 SkDEBUGCODE(bool isInstantiated() const;)
116
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400117 GrSurfaceProxyRef fTarget;
118 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -0400119
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400120 GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
121 GrColor fLoadClearColor = 0x0;
122 GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
123
Brian Osman099fa0f2017-10-02 16:38:32 -0400124 // List of texture proxies whose contents are being prepared on a worker thread
125 SkTArray<GrTextureProxy*, true> fDeferredProxies;
126
Robert Phillipsf2361d22016-10-25 14:20:06 -0400127private:
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400128 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 Phillipsf2361d22016-10-25 14:20:06 -0400132
Robert Phillipsc0138922017-03-08 11:50:55 -0500133 static uint32_t CreateUniqueID();
134
Robert Phillipsf2361d22016-10-25 14:20:06 -0400135 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500136 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400137
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 Osman407b3422017-08-22 15:01:32 -0400178 virtual void onPrepare(GrOpFlushState* flushState) = 0;
179 virtual bool onExecute(GrOpFlushState* flushState) = 0;
180
Robert Phillipsf2361d22016-10-25 14:20:06 -0400181 void addDependency(GrOpList* dependedOn);
182
Robert Phillips73fd0d62017-09-15 11:48:08 +0000183 uint32_t fUniqueID;
184 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400185
186 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips73fd0d62017-09-15 11:48:08 +0000187 SkSTArray<1, GrOpList*, true> fDependencies;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400188
Robert Phillipsf2361d22016-10-25 14:20:06 -0400189 typedef SkRefCnt INHERITED;
190};
191
192#endif