blob: 2d80386fad2fe0e0a70b4f2be04136860d3b0c66 [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 Phillips6cdc22c2017-05-11 16:29:14 -040011#include "GrGpuResourceRef.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040012#include "SkRefCnt.h"
13#include "SkTDArray.h"
14
15//#define ENABLE_MDB 1
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;
Brian Osman45580d32016-11-23 09:37:01 -050020class GrRenderTargetOpList;
Robert Phillips318c4192017-05-17 09:36:38 -040021class GrResourceProvider;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040022class GrSurfaceProxy;
Robert Phillips18166ee2017-06-01 12:55:44 -040023class GrTextureProxy;
Brian Osman45580d32016-11-23 09:37:01 -050024class GrTextureOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040025
Robert Phillips2de8cfa2017-06-28 10:33:41 -040026struct SkIPoint;
27struct SkIRect;
28
Robert Phillipsf2361d22016-10-25 14:20:06 -040029class GrOpList : public SkRefCnt {
30public:
Robert Phillips5efd5ea2017-05-30 13:47:32 -040031 GrOpList(GrResourceProvider*, GrSurfaceProxy*, GrAuditTrail*);
Robert Phillipsf2361d22016-10-25 14:20:06 -040032 ~GrOpList() override;
33
Robert Phillips318c4192017-05-17 09:36:38 -040034 // These three methods are invoked at flush time
35 bool instantiate(GrResourceProvider* resourceProvider);
Brian Salomon742e31d2016-12-07 17:06:19 -050036 virtual void prepareOps(GrOpFlushState* flushState) = 0;
37 virtual bool executeOps(GrOpFlushState* flushState) = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -040038
Robert Phillips2de8cfa2017-06-28 10:33:41 -040039 virtual bool copySurface(const GrCaps& caps,
40 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);
48 fTarget.removeRef();
49 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040050 }
51
Robert Phillips6cdc22c2017-05-11 16:29:14 -040052 virtual void reset();
Robert Phillipsf2361d22016-10-25 14:20:06 -040053
54 // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like
55 // these could go away
56 virtual void abandonGpuResources() = 0;
57 virtual void freeGpuResources() = 0;
58
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 */
69 bool dependsOn(GrOpList* dependedOn) const {
70 return fDependencies.find(dependedOn) >= 0;
71 }
72
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
Robert Phillipsc0138922017-03-08 11:50:55 -050083 int32_t uniqueID() const { return fUniqueID; }
84
Brian Osman45580d32016-11-23 09:37:01 -050085 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040086 * Dump out the GrOpList dependency DAG
87 */
88 SkDEBUGCODE(virtual void dump() const;)
89
Robert Phillipsc84c0302017-05-08 15:35:11 -040090 SkDEBUGCODE(virtual int numOps() const = 0;)
91 SkDEBUGCODE(virtual int numClips() const { return 0; })
92
Robert Phillipsdc83b892017-04-13 12:23:54 -040093protected:
Robert Phillips5efd5ea2017-05-30 13:47:32 -040094 GrSurfaceProxyRef fTarget;
95 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -040096
Robert Phillipsf2361d22016-10-25 14:20:06 -040097private:
98 friend class GrDrawingManager; // for resetFlag & TopoSortTraits
99
Robert Phillipsc0138922017-03-08 11:50:55 -0500100 static uint32_t CreateUniqueID();
101
Robert Phillipsf2361d22016-10-25 14:20:06 -0400102 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500103 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -0400104
105 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
106 kTempMark_Flag = 0x04, //!< Flag for topological sorting
107 };
108
109 void setFlag(uint32_t flag) {
110 fFlags |= flag;
111 }
112
113 void resetFlag(uint32_t flag) {
114 fFlags &= ~flag;
115 }
116
117 bool isSetFlag(uint32_t flag) const {
118 return SkToBool(fFlags & flag);
119 }
120
121 struct TopoSortTraits {
122 static void Output(GrOpList* dt, int /* index */) {
123 dt->setFlag(GrOpList::kWasOutput_Flag);
124 }
125 static bool WasOutput(const GrOpList* dt) {
126 return dt->isSetFlag(GrOpList::kWasOutput_Flag);
127 }
128 static void SetTempMark(GrOpList* dt) {
129 dt->setFlag(GrOpList::kTempMark_Flag);
130 }
131 static void ResetTempMark(GrOpList* dt) {
132 dt->resetFlag(GrOpList::kTempMark_Flag);
133 }
134 static bool IsTempMarked(const GrOpList* dt) {
135 return dt->isSetFlag(GrOpList::kTempMark_Flag);
136 }
137 static int NumDependencies(const GrOpList* dt) {
138 return dt->fDependencies.count();
139 }
140 static GrOpList* Dependency(GrOpList* dt, int index) {
141 return dt->fDependencies[index];
142 }
143 };
144
145 void addDependency(GrOpList* dependedOn);
146
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400147 uint32_t fUniqueID;
148 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400149
150 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400151 SkTDArray<GrOpList*> fDependencies;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400152
Robert Phillipsf2361d22016-10-25 14:20:06 -0400153 typedef SkRefCnt INHERITED;
154};
155
156#endif