blob: 2c1075177836fba51d08c93474e852674cb1f798 [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
Brian Salomonee783962018-08-01 09:55:10 -040011#include "GrProxyRef.h"
Robert Phillips62000362018-02-01 09:10:04 -050012#include "GrTextureProxy.h"
Brian Osman9a9baae2018-11-05 15:06:26 -050013#include "SkColorData.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;
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 Phillipsc994a932018-06-19 13:09:54 -040033 GrOpList(GrResourceProvider*, sk_sp<GrOpMemoryPool>, 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);
52 fTarget.removeRef();
53 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040054 }
55
Chris Daltona84cacf2017-10-04 10:30:29 -060056 // Called when this class will survive a flush and needs to truncate its ops and start over.
57 // TODO: ultimately it should be invalid for an op list to survive a flush.
58 // https://bugs.chromium.org/p/skia/issues/detail?id=7111
59 virtual void endFlush();
Robert Phillipsf2361d22016-10-25 14:20:06 -040060
Robert Phillipsf2361d22016-10-25 14:20:06 -040061 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
62
63 /*
64 * Notify this GrOpList that it relies on the contents of 'dependedOn'
65 */
Robert Phillipsee683652017-04-26 11:53:10 -040066 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040067
68 /*
69 * Does this opList depend on 'dependedOn'?
70 */
Robert Phillipsce3c28f2018-07-18 13:52:40 -040071 bool dependsOn(const GrOpList* dependedOn) const;
Robert Phillipsf2361d22016-10-25 14:20:06 -040072
73 /*
Brian Osman45580d32016-11-23 09:37:01 -050074 * Safely cast this GrOpList to a GrTextureOpList (if possible).
75 */
76 virtual GrTextureOpList* asTextureOpList() { return nullptr; }
77
78 /*
79 * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
80 */
81 virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
82
Chris Daltona32a3c32017-12-05 10:05:21 -070083 uint32_t uniqueID() const { return fUniqueID; }
Robert Phillipsc0138922017-03-08 11:50:55 -050084
Brian Osman45580d32016-11-23 09:37:01 -050085 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040086 * Dump out the GrOpList dependency DAG
87 */
Robert Phillips27483912018-04-20 12:43:18 -040088 SkDEBUGCODE(virtual void dump(bool printDependencies) const;)
Robert Phillipsf2361d22016-10-25 14:20:06 -040089
Robert Phillipsc84c0302017-05-08 15:35:11 -040090 SkDEBUGCODE(virtual int numClips() const { return 0; })
91
Robert Phillipsdc83b892017-04-13 12:23:54 -040092protected:
Robert Phillips4150eea2018-02-07 17:08:21 -050093 bool isInstantiated() const;
Robert Phillips09dfc472017-09-13 15:25:47 -040094
Robert Phillips01a91282018-07-26 08:03:04 -040095 // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if
96 // it is required)?
97 bool isFullyInstantiated() const;
98
Robert Phillipsc994a932018-06-19 13:09:54 -040099 // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops.
100 // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its
101 // constituent opLists survive.
102 sk_sp<GrOpMemoryPool> fOpMemoryPool;
103 GrSurfaceProxyRef fTarget;
104 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -0400105
Robert Phillipsc994a932018-06-19 13:09:54 -0400106 GrLoadOp fColorLoadOp = GrLoadOp::kLoad;
Brian Osman9a9baae2018-11-05 15:06:26 -0500107 SkPMColor4f fLoadClearColor = SK_PMColor4fTRANSPARENT;
Robert Phillipsc994a932018-06-19 13:09:54 -0400108 GrLoadOp fStencilLoadOp = GrLoadOp::kLoad;
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400109
Brian Osman099fa0f2017-10-02 16:38:32 -0400110 // List of texture proxies whose contents are being prepared on a worker thread
111 SkTArray<GrTextureProxy*, true> fDeferredProxies;
112
Robert Phillipsf2361d22016-10-25 14:20:06 -0400113private:
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400114 friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
115
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400116 void addDependency(GrOpList* dependedOn);
Robert Phillipse6d06182018-08-06 16:56:26 -0400117 void addDependent(GrOpList* dependent);
118 SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const);
119 SkDEBUGCODE(void validate() const);
Robert Phillips46acf9d2018-10-09 09:31:40 -0400120 void closeThoseWhoDependOnMe(const GrCaps&);
Robert Phillipsce3c28f2018-07-18 13:52:40 -0400121
Brian Salomon967df202018-12-07 11:15:53 -0500122 // Remove all Ops which reference proxies that are not instantiated.
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500123 virtual void purgeOpsWithUninstantiatedProxies() = 0;
124
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400125 // Feed proxy usage intervals to the GrResourceAllocator class
126 virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400127
Robert Phillipsc0138922017-03-08 11:50:55 -0500128 static uint32_t CreateUniqueID();
129
Robert Phillipsf2361d22016-10-25 14:20:06 -0400130 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500131 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400132
133 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
134 kTempMark_Flag = 0x04, //!< Flag for topological sorting
135 };
136
137 void setFlag(uint32_t flag) {
138 fFlags |= flag;
139 }
140
141 void resetFlag(uint32_t flag) {
142 fFlags &= ~flag;
143 }
144
145 bool isSetFlag(uint32_t flag) const {
146 return SkToBool(fFlags & flag);
147 }
148
149 struct TopoSortTraits {
Robert Phillips4150eea2018-02-07 17:08:21 -0500150 static void Output(GrOpList* opList, int /* index */) {
151 opList->setFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400152 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500153 static bool WasOutput(const GrOpList* opList) {
154 return opList->isSetFlag(GrOpList::kWasOutput_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400155 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500156 static void SetTempMark(GrOpList* opList) {
157 opList->setFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400158 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500159 static void ResetTempMark(GrOpList* opList) {
160 opList->resetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400161 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500162 static bool IsTempMarked(const GrOpList* opList) {
163 return opList->isSetFlag(GrOpList::kTempMark_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400164 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500165 static int NumDependencies(const GrOpList* opList) {
166 return opList->fDependencies.count();
Robert Phillipsf2361d22016-10-25 14:20:06 -0400167 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500168 static GrOpList* Dependency(GrOpList* opList, int index) {
169 return opList->fDependencies[index];
Robert Phillipsf2361d22016-10-25 14:20:06 -0400170 }
171 };
172
Brian Osman407b3422017-08-22 15:01:32 -0400173 virtual void onPrepare(GrOpFlushState* flushState) = 0;
174 virtual bool onExecute(GrOpFlushState* flushState) = 0;
175
Robert Phillips73fd0d62017-09-15 11:48:08 +0000176 uint32_t fUniqueID;
177 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400178
179 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips73fd0d62017-09-15 11:48:08 +0000180 SkSTArray<1, GrOpList*, true> fDependencies;
Robert Phillipse6d06182018-08-06 16:56:26 -0400181 // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents'
182 SkSTArray<1, GrOpList*, true> fDependents;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400183
Robert Phillipsf2361d22016-10-25 14:20:06 -0400184 typedef SkRefCnt INHERITED;
185};
186
187#endif