blob: 066582b37d9582df45dc73a0f2919ac06e2b4ec6 [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/GrProxyRef.h"
15#include "src/gpu/GrTextureProxy.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040016
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;
Robert Phillipsbe9aff22019-02-15 11:33:22 -050021class GrRecordingContext;
Brian Osman45580d32016-11-23 09:37:01 -050022class GrRenderTargetOpList;
Robert Phillipsd375dbf2017-09-14 12:45:25 -040023class GrResourceAllocator;
Robert Phillips318c4192017-05-17 09:36:38 -040024class GrResourceProvider;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040025class GrSurfaceProxy;
Brian Osman45580d32016-11-23 09:37:01 -050026class GrTextureOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040027
Robert Phillips2de8cfa2017-06-28 10:33:41 -040028struct SkIPoint;
29struct SkIRect;
30
Robert Phillipsf2361d22016-10-25 14:20:06 -040031class GrOpList : public SkRefCnt {
32public:
Robert Phillips12c46292019-04-23 07:36:17 -040033 GrOpList(sk_sp<GrOpMemoryPool>, sk_sp<GrSurfaceProxy>, GrAuditTrail*);
Robert Phillipsf2361d22016-10-25 14:20:06 -040034 ~GrOpList() override;
35
Brian Osman099fa0f2017-10-02 16:38:32 -040036 // These four methods are invoked at flush time
Robert Phillips318c4192017-05-17 09:36:38 -040037 bool instantiate(GrResourceProvider* resourceProvider);
Brian Osman099fa0f2017-10-02 16:38:32 -040038 // Instantiates any "threaded" texture proxies that are being prepared elsewhere
39 void instantiateDeferredProxies(GrResourceProvider* resourceProvider);
Brian Osman407b3422017-08-22 15:01:32 -040040 void prepare(GrOpFlushState* flushState);
41 bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
Robert Phillipsf2361d22016-10-25 14:20:06 -040042
Robert Phillipsbe9aff22019-02-15 11:33:22 -050043 virtual bool copySurface(GrRecordingContext*,
Robert Phillips2de8cfa2017-06-28 10:33:41 -040044 GrSurfaceProxy* dst,
45 GrSurfaceProxy* src,
46 const SkIRect& srcRect,
47 const SkIPoint& dstPoint) = 0;
48
Robert Phillipsee683652017-04-26 11:53:10 -040049 virtual void makeClosed(const GrCaps&) {
Robert Phillipsd9914862017-06-14 15:16:59 -040050 if (!this->isClosed()) {
51 this->setFlag(kClosed_Flag);
Robert Phillipsd9914862017-06-14 15:16:59 -040052 }
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 numClips() const { return 0; })
90
Robert Phillipsdc83b892017-04-13 12:23:54 -040091protected:
Robert Phillips4150eea2018-02-07 17:08:21 -050092 bool isInstantiated() const;
Robert Phillips09dfc472017-09-13 15:25:47 -040093
Robert Phillips01a91282018-07-26 08:03:04 -040094 // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if
95 // it is required)?
96 bool isFullyInstantiated() const;
97
Robert Phillipsc994a932018-06-19 13:09:54 -040098 // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops.
99 // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its
100 // constituent opLists survive.
101 sk_sp<GrOpMemoryPool> fOpMemoryPool;
102 GrSurfaceProxyRef fTarget;
103 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -0400104
Robert Phillipsc994a932018-06-19 13:09:54 -0400105 GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
Brian Osman9a9baae2018-11-05 15:06:26 -0500106 SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT;
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000107 GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400108
Brian Osman099fa0f2017-10-02 16:38:32 -0400109 // List of texture proxies whose contents are being prepared on a worker thread
110 SkTArray<GrTextureProxy*, true> fDeferredProxies;
111
Robert Phillipsf2361d22016-10-25 14:20:06 -0400112private:
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400113 friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
114
Robert Phillips9313aa72019-04-09 18:41:27 -0400115 virtual bool onIsUsed(GrSurfaceProxy*) const = 0;
116
117 bool isUsed(GrSurfaceProxy* proxy) const {
118 if (proxy == fTarget.get()) {
119 return true;
120 }
121
122 return this->onIsUsed(proxy);
123 }
124
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400125 void addDependency(GrOpList* dependedOn);
Robert Phillipse6d06182018-08-06 16:56:26 -0400126 void addDependent(GrOpList* dependent);
Nico Weber0af08132019-02-28 13:23:38 -0500127 SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const;)
128 SkDEBUGCODE(void validate() const;)
Robert Phillips46acf9d2018-10-09 09:31:40 -0400129 void closeThoseWhoDependOnMe(const GrCaps&);
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400130
Brian Salomon967df202018-12-07 11:15:53 -0500131 // Remove all Ops which reference proxies that are not instantiated.
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500132 virtual void purgeOpsWithUninstantiatedProxies() = 0;
133
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400134 // Feed proxy usage intervals to the GrResourceAllocator class
135 virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400136
Robert Phillipsc0138922017-03-08 11:50:55 -0500137 static uint32_t CreateUniqueID();
138
Robert Phillipsf2361d22016-10-25 14:20:06 -0400139 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500140 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400141
142 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
143 kTempMark_Flag = 0x04, //!< Flag for topological sorting
144 };
145
146 void setFlag(uint32_t flag) {
147 fFlags |= flag;
148 }
149
150 void resetFlag(uint32_t flag) {
151 fFlags &= ~flag;
152 }
153
154 bool isSetFlag(uint32_t flag) const {
155 return SkToBool(fFlags & flag);
156 }
157
158 struct TopoSortTraits {
Robert Phillips4150eea2018-02-07 17:08:21 -0500159 static void Output(GrOpList* opList, int /* index */) {
160 opList->setFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400161 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500162 static bool WasOutput(const GrOpList* opList) {
163 return opList->isSetFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400164 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500165 static void SetTempMark(GrOpList* opList) {
166 opList->setFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400167 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500168 static void ResetTempMark(GrOpList* opList) {
169 opList->resetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400170 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500171 static bool IsTempMarked(const GrOpList* opList) {
172 return opList->isSetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400173 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500174 static int NumDependencies(const GrOpList* opList) {
175 return opList->fDependencies.count();
Robert Phillipsf2361d22016-10-25 14:20:06 -0400176 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500177 static GrOpList* Dependency(GrOpList* opList, int index) {
178 return opList->fDependencies[index];
Robert Phillipsf2361d22016-10-25 14:20:06 -0400179 }
180 };
181
Brian Osman407b3422017-08-22 15:01:32 -0400182 virtual void onPrepare(GrOpFlushState* flushState) = 0;
183 virtual bool onExecute(GrOpFlushState* flushState) = 0;
184
Robert Phillips73fd0d62017-09-15 11:48:08 +0000185 uint32_t fUniqueID;
186 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400187
188 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips73fd0d62017-09-15 11:48:08 +0000189 SkSTArray<1, GrOpList*, true> fDependencies;
Robert Phillipse6d06182018-08-06 16:56:26 -0400190 // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents'
191 SkSTArray<1, GrOpList*, true> fDependents;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400192
Robert Phillipsf2361d22016-10-25 14:20:06 -0400193 typedef SkRefCnt INHERITED;
194};
195
196#endif