blob: da2b7b98afeaebeeeb92c05151c27f3ec830483e [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRefCnt.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/private/SkColorData.h"
13#include "include/private/SkTDArray.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "src/gpu/GrTextureProxy.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015
Brian Osman62e7b5f2016-10-26 12:02:18 -040016class GrAuditTrail;
Robert Phillipsee683652017-04-26 11:53:10 -040017class GrCaps;
Brian Salomon742e31d2016-12-07 17:06:19 -050018class GrOpFlushState;
Robert Phillipsc994a932018-06-19 13:09:54 -040019class GrOpMemoryPool;
Robert Phillipsbe9aff22019-02-15 11:33:22 -050020class GrRecordingContext;
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 Phillips12c46292019-04-23 07:36:17 -040032 GrOpList(sk_sp<GrOpMemoryPool>, sk_sp<GrSurfaceProxy>, GrAuditTrail*);
Robert Phillipsf2361d22016-10-25 14:20:06 -040033 ~GrOpList() override;
34
Robert Phillips82774f82019-06-20 14:38:27 -040035 // These two methods are only invoked at flush time
Brian Osman407b3422017-08-22 15:01:32 -040036 void prepare(GrOpFlushState* flushState);
37 bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
Robert Phillipsf2361d22016-10-25 14:20:06 -040038
Robert Phillipsbe9aff22019-02-15 11:33:22 -050039 virtual bool copySurface(GrRecordingContext*,
Robert Phillips2de8cfa2017-06-28 10:33:41 -040040 GrSurfaceProxy* dst,
41 GrSurfaceProxy* src,
42 const SkIRect& srcRect,
43 const SkIPoint& dstPoint) = 0;
44
Robert Phillipsee683652017-04-26 11:53:10 -040045 virtual void makeClosed(const GrCaps&) {
Robert Phillipsd9914862017-06-14 15:16:59 -040046 if (!this->isClosed()) {
47 this->setFlag(kClosed_Flag);
Robert Phillipsd9914862017-06-14 15:16:59 -040048 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040049 }
50
Chris Daltona84cacf2017-10-04 10:30:29 -060051 // Called when this class will survive a flush and needs to truncate its ops and start over.
52 // TODO: ultimately it should be invalid for an op list to survive a flush.
53 // https://bugs.chromium.org/p/skia/issues/detail?id=7111
54 virtual void endFlush();
Robert Phillipsf2361d22016-10-25 14:20:06 -040055
Robert Phillipsf2361d22016-10-25 14:20:06 -040056 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
57
58 /*
59 * Notify this GrOpList that it relies on the contents of 'dependedOn'
60 */
Robert Phillipsee683652017-04-26 11:53:10 -040061 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040062
63 /*
64 * Does this opList depend on 'dependedOn'?
65 */
Robert Phillipsce3c28f2018-07-18 13:52:40 -040066 bool dependsOn(const GrOpList* dependedOn) const;
Robert Phillipsf2361d22016-10-25 14:20:06 -040067
68 /*
Brian Osman45580d32016-11-23 09:37:01 -050069 * Safely cast this GrOpList to a GrTextureOpList (if possible).
70 */
71 virtual GrTextureOpList* asTextureOpList() { return nullptr; }
72
73 /*
Robert Phillips82774f82019-06-20 14:38:27 -040074 * Safely cast this GrOpList to a GrRenderTargetOpList (if possible).
Brian Osman45580d32016-11-23 09:37:01 -050075 */
76 virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
77
Chris Daltona32a3c32017-12-05 10:05:21 -070078 uint32_t uniqueID() const { return fUniqueID; }
Robert Phillipsc0138922017-03-08 11:50:55 -050079
Brian Osman45580d32016-11-23 09:37:01 -050080 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040081 * Dump out the GrOpList dependency DAG
82 */
Robert Phillips27483912018-04-20 12:43:18 -040083 SkDEBUGCODE(virtual void dump(bool printDependencies) const;)
Robert Phillipsf2361d22016-10-25 14:20:06 -040084
Robert Phillipsc84c0302017-05-08 15:35:11 -040085 SkDEBUGCODE(virtual int numClips() const { return 0; })
86
Robert Phillipsdc83b892017-04-13 12:23:54 -040087protected:
Robert Phillips01a91282018-07-26 08:03:04 -040088 // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if
89 // it is required)?
Robert Phillips82774f82019-06-20 14:38:27 -040090 bool isInstantiated() const;
91
92 SkDEBUGCODE(bool deferredProxiesAreInstantiated() const;)
Robert Phillips01a91282018-07-26 08:03:04 -040093
Robert Phillipsc994a932018-06-19 13:09:54 -040094 // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops.
95 // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its
96 // constituent opLists survive.
97 sk_sp<GrOpMemoryPool> fOpMemoryPool;
Robert Phillipsb5204762019-06-19 14:12:13 -040098 sk_sp<GrSurfaceProxy> fTarget;
Robert Phillipsc994a932018-06-19 13:09:54 -040099 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -0400100
Robert Phillipsc994a932018-06-19 13:09:54 -0400101 GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
Brian Osman9a9baae2018-11-05 15:06:26 -0500102 SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT;
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000103 GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400104
Brian Osman099fa0f2017-10-02 16:38:32 -0400105 // List of texture proxies whose contents are being prepared on a worker thread
Robert Phillips82774f82019-06-20 14:38:27 -0400106 // TODO: this list exists so we can fire off the proper upload when an opList begins
107 // executing. Can this be replaced?
Brian Osman099fa0f2017-10-02 16:38:32 -0400108 SkTArray<GrTextureProxy*, true> fDeferredProxies;
109
Robert Phillipsf2361d22016-10-25 14:20:06 -0400110private:
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400111 friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
112
Robert Phillips9313aa72019-04-09 18:41:27 -0400113 virtual bool onIsUsed(GrSurfaceProxy*) const = 0;
114
115 bool isUsed(GrSurfaceProxy* proxy) const {
116 if (proxy == fTarget.get()) {
117 return true;
118 }
119
120 return this->onIsUsed(proxy);
121 }
122
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400123 void addDependency(GrOpList* dependedOn);
Robert Phillipse6d06182018-08-06 16:56:26 -0400124 void addDependent(GrOpList* dependent);
Nico Weber0af08132019-02-28 13:23:38 -0500125 SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const;)
126 SkDEBUGCODE(void validate() const;)
Robert Phillips46acf9d2018-10-09 09:31:40 -0400127 void closeThoseWhoDependOnMe(const GrCaps&);
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400128
Brian Salomon967df202018-12-07 11:15:53 -0500129 // Remove all Ops which reference proxies that are not instantiated.
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500130 virtual void purgeOpsWithUninstantiatedProxies() = 0;
131
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400132 // Feed proxy usage intervals to the GrResourceAllocator class
133 virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400134
Robert Phillipsc0138922017-03-08 11:50:55 -0500135 static uint32_t CreateUniqueID();
136
Robert Phillipsf2361d22016-10-25 14:20:06 -0400137 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500138 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400139
140 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
141 kTempMark_Flag = 0x04, //!< Flag for topological sorting
142 };
143
144 void setFlag(uint32_t flag) {
145 fFlags |= flag;
146 }
147
148 void resetFlag(uint32_t flag) {
149 fFlags &= ~flag;
150 }
151
152 bool isSetFlag(uint32_t flag) const {
153 return SkToBool(fFlags & flag);
154 }
155
156 struct TopoSortTraits {
Robert Phillips4150eea2018-02-07 17:08:21 -0500157 static void Output(GrOpList* opList, int /* index */) {
158 opList->setFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400159 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500160 static bool WasOutput(const GrOpList* opList) {
161 return opList->isSetFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400162 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500163 static void SetTempMark(GrOpList* opList) {
164 opList->setFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400165 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500166 static void ResetTempMark(GrOpList* opList) {
167 opList->resetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400168 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500169 static bool IsTempMarked(const GrOpList* opList) {
170 return opList->isSetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400171 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500172 static int NumDependencies(const GrOpList* opList) {
173 return opList->fDependencies.count();
Robert Phillipsf2361d22016-10-25 14:20:06 -0400174 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500175 static GrOpList* Dependency(GrOpList* opList, int index) {
176 return opList->fDependencies[index];
Robert Phillipsf2361d22016-10-25 14:20:06 -0400177 }
178 };
179
Brian Osman407b3422017-08-22 15:01:32 -0400180 virtual void onPrepare(GrOpFlushState* flushState) = 0;
181 virtual bool onExecute(GrOpFlushState* flushState) = 0;
182
Robert Phillips82774f82019-06-20 14:38:27 -0400183 const uint32_t fUniqueID;
Robert Phillips73fd0d62017-09-15 11:48:08 +0000184 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 Phillipse6d06182018-08-06 16:56:26 -0400188 // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents'
189 SkSTArray<1, GrOpList*, true> fDependents;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400190
Robert Phillipsf2361d22016-10-25 14:20:06 -0400191 typedef SkRefCnt INHERITED;
192};
193
194#endif