blob: 987ddb04ad16ccd33dd7355786771b2e6ee89c74 [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
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 Phillipsbe9aff22019-02-15 11:33:22 -050042 virtual bool copySurface(GrRecordingContext*,
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);
Robert Phillipsd9914862017-06-14 15:16:59 -040051 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040052 }
53
Chris Daltona84cacf2017-10-04 10:30:29 -060054 // Called when this class will survive a flush and needs to truncate its ops and start over.
55 // TODO: ultimately it should be invalid for an op list to survive a flush.
56 // https://bugs.chromium.org/p/skia/issues/detail?id=7111
57 virtual void endFlush();
Robert Phillipsf2361d22016-10-25 14:20:06 -040058
Robert Phillipsf2361d22016-10-25 14:20:06 -040059 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
60
61 /*
62 * Notify this GrOpList that it relies on the contents of 'dependedOn'
63 */
Robert Phillipsee683652017-04-26 11:53:10 -040064 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040065
66 /*
67 * Does this opList depend on 'dependedOn'?
68 */
Robert Phillipsce3c28f2018-07-18 13:52:40 -040069 bool dependsOn(const GrOpList* dependedOn) const;
Robert Phillipsf2361d22016-10-25 14:20:06 -040070
71 /*
Brian Osman45580d32016-11-23 09:37:01 -050072 * Safely cast this GrOpList to a GrTextureOpList (if possible).
73 */
74 virtual GrTextureOpList* asTextureOpList() { return nullptr; }
75
76 /*
77 * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
78 */
79 virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
80
Chris Daltona32a3c32017-12-05 10:05:21 -070081 uint32_t uniqueID() const { return fUniqueID; }
Robert Phillipsc0138922017-03-08 11:50:55 -050082
Brian Osman45580d32016-11-23 09:37:01 -050083 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040084 * Dump out the GrOpList dependency DAG
85 */
Robert Phillips27483912018-04-20 12:43:18 -040086 SkDEBUGCODE(virtual void dump(bool printDependencies) const;)
Robert Phillipsf2361d22016-10-25 14:20:06 -040087
Robert Phillipsc84c0302017-05-08 15:35:11 -040088 SkDEBUGCODE(virtual int numClips() const { return 0; })
89
Robert Phillipsdc83b892017-04-13 12:23:54 -040090protected:
Robert Phillips4150eea2018-02-07 17:08:21 -050091 bool isInstantiated() const;
Robert Phillips09dfc472017-09-13 15:25:47 -040092
Robert Phillips01a91282018-07-26 08:03:04 -040093 // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if
94 // it is required)?
95 bool isFullyInstantiated() const;
96
Robert Phillipsc994a932018-06-19 13:09:54 -040097 // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops.
98 // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its
99 // constituent opLists survive.
100 sk_sp<GrOpMemoryPool> fOpMemoryPool;
Robert Phillipsb5204762019-06-19 14:12:13 -0400101 sk_sp<GrSurfaceProxy> fTarget;
Robert Phillipsc994a932018-06-19 13:09:54 -0400102 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -0400103
Robert Phillipsc994a932018-06-19 13:09:54 -0400104 GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
Brian Osman9a9baae2018-11-05 15:06:26 -0500105 SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT;
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000106 GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400107
Brian Osman099fa0f2017-10-02 16:38:32 -0400108 // List of texture proxies whose contents are being prepared on a worker thread
109 SkTArray<GrTextureProxy*, true> fDeferredProxies;
110
Robert Phillipsf2361d22016-10-25 14:20:06 -0400111private:
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400112 friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
113
Robert Phillips9313aa72019-04-09 18:41:27 -0400114 virtual bool onIsUsed(GrSurfaceProxy*) const = 0;
115
116 bool isUsed(GrSurfaceProxy* proxy) const {
117 if (proxy == fTarget.get()) {
118 return true;
119 }
120
121 return this->onIsUsed(proxy);
122 }
123
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400124 void addDependency(GrOpList* dependedOn);
Robert Phillipse6d06182018-08-06 16:56:26 -0400125 void addDependent(GrOpList* dependent);
Nico Weber0af08132019-02-28 13:23:38 -0500126 SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const;)
127 SkDEBUGCODE(void validate() const;)
Robert Phillips46acf9d2018-10-09 09:31:40 -0400128 void closeThoseWhoDependOnMe(const GrCaps&);
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400129
Brian Salomon967df202018-12-07 11:15:53 -0500130 // Remove all Ops which reference proxies that are not instantiated.
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500131 virtual void purgeOpsWithUninstantiatedProxies() = 0;
132
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400133 // Feed proxy usage intervals to the GrResourceAllocator class
134 virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400135
Robert Phillipsc0138922017-03-08 11:50:55 -0500136 static uint32_t CreateUniqueID();
137
Robert Phillipsf2361d22016-10-25 14:20:06 -0400138 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500139 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400140
141 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
142 kTempMark_Flag = 0x04, //!< Flag for topological sorting
143 };
144
145 void setFlag(uint32_t flag) {
146 fFlags |= flag;
147 }
148
149 void resetFlag(uint32_t flag) {
150 fFlags &= ~flag;
151 }
152
153 bool isSetFlag(uint32_t flag) const {
154 return SkToBool(fFlags & flag);
155 }
156
157 struct TopoSortTraits {
Robert Phillips4150eea2018-02-07 17:08:21 -0500158 static void Output(GrOpList* opList, int /* index */) {
159 opList->setFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400160 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500161 static bool WasOutput(const GrOpList* opList) {
162 return opList->isSetFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400163 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500164 static void SetTempMark(GrOpList* opList) {
165 opList->setFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400166 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500167 static void ResetTempMark(GrOpList* opList) {
168 opList->resetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400169 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500170 static bool IsTempMarked(const GrOpList* opList) {
171 return opList->isSetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400172 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500173 static int NumDependencies(const GrOpList* opList) {
174 return opList->fDependencies.count();
Robert Phillipsf2361d22016-10-25 14:20:06 -0400175 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500176 static GrOpList* Dependency(GrOpList* opList, int index) {
177 return opList->fDependencies[index];
Robert Phillipsf2361d22016-10-25 14:20:06 -0400178 }
179 };
180
Brian Osman407b3422017-08-22 15:01:32 -0400181 virtual void onPrepare(GrOpFlushState* flushState) = 0;
182 virtual bool onExecute(GrOpFlushState* flushState) = 0;
183
Robert Phillips73fd0d62017-09-15 11:48:08 +0000184 uint32_t fUniqueID;
185 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400186
187 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips73fd0d62017-09-15 11:48:08 +0000188 SkSTArray<1, GrOpList*, true> fDependencies;
Robert Phillipse6d06182018-08-06 16:56:26 -0400189 // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents'
190 SkSTArray<1, GrOpList*, true> fDependents;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400191
Robert Phillipsf2361d22016-10-25 14:20:06 -0400192 typedef SkRefCnt INHERITED;
193};
194
195#endif