blob: 1eaad48cbe4dc6655eae7ddec5d467ddb261f5f4 [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"
12
Robert Phillipsf2361d22016-10-25 14:20:06 -040013#include "SkRefCnt.h"
14#include "SkTDArray.h"
15
16//#define ENABLE_MDB 1
17
Brian Osman62e7b5f2016-10-26 12:02:18 -040018class GrAuditTrail;
Robert Phillipsee683652017-04-26 11:53:10 -040019class GrCaps;
Brian Salomon742e31d2016-12-07 17:06:19 -050020class GrOpFlushState;
Brian Osman45580d32016-11-23 09:37:01 -050021class GrRenderTargetOpList;
Robert Phillips318c4192017-05-17 09:36:38 -040022class GrResourceProvider;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040023class GrSurfaceProxy;
Brian Osman45580d32016-11-23 09:37:01 -050024class GrTextureOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040025
26class GrOpList : public SkRefCnt {
27public:
Robert Phillipsb6deea82017-05-11 14:14:30 -040028 GrOpList(GrSurfaceProxy*, GrAuditTrail*);
Robert Phillipsf2361d22016-10-25 14:20:06 -040029 ~GrOpList() override;
30
Robert Phillips318c4192017-05-17 09:36:38 -040031 // These three methods are invoked at flush time
32 bool instantiate(GrResourceProvider* resourceProvider);
Brian Salomon742e31d2016-12-07 17:06:19 -050033 virtual void prepareOps(GrOpFlushState* flushState) = 0;
34 virtual bool executeOps(GrOpFlushState* flushState) = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -040035
Robert Phillipsee683652017-04-26 11:53:10 -040036 virtual void makeClosed(const GrCaps&) {
Robert Phillipsf2361d22016-10-25 14:20:06 -040037 this->setFlag(kClosed_Flag);
Robert Phillipsf2361d22016-10-25 14:20:06 -040038 }
39
Robert Phillips6cdc22c2017-05-11 16:29:14 -040040 virtual void reset();
Robert Phillipsf2361d22016-10-25 14:20:06 -040041
42 // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like
43 // these could go away
44 virtual void abandonGpuResources() = 0;
45 virtual void freeGpuResources() = 0;
46
Robert Phillipsf2361d22016-10-25 14:20:06 -040047 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
48
49 /*
50 * Notify this GrOpList that it relies on the contents of 'dependedOn'
51 */
Robert Phillipsee683652017-04-26 11:53:10 -040052 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040053
54 /*
55 * Does this opList depend on 'dependedOn'?
56 */
57 bool dependsOn(GrOpList* dependedOn) const {
58 return fDependencies.find(dependedOn) >= 0;
59 }
60
61 /*
Brian Osman45580d32016-11-23 09:37:01 -050062 * Safely cast this GrOpList to a GrTextureOpList (if possible).
63 */
64 virtual GrTextureOpList* asTextureOpList() { return nullptr; }
65
66 /*
67 * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
68 */
69 virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
70
Robert Phillipsc0138922017-03-08 11:50:55 -050071 int32_t uniqueID() const { return fUniqueID; }
72
Brian Osman45580d32016-11-23 09:37:01 -050073 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040074 * Dump out the GrOpList dependency DAG
75 */
76 SkDEBUGCODE(virtual void dump() const;)
77
Robert Phillipsc84c0302017-05-08 15:35:11 -040078 SkDEBUGCODE(virtual int numOps() const = 0;)
79 SkDEBUGCODE(virtual int numClips() const { return 0; })
80
Robert Phillipsdc83b892017-04-13 12:23:54 -040081protected:
Robert Phillips6cdc22c2017-05-11 16:29:14 -040082 GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fTarget;
83 GrAuditTrail* fAuditTrail;
Robert Phillipsdc83b892017-04-13 12:23:54 -040084
Robert Phillipsf2361d22016-10-25 14:20:06 -040085private:
86 friend class GrDrawingManager; // for resetFlag & TopoSortTraits
87
Robert Phillipsc0138922017-03-08 11:50:55 -050088 static uint32_t CreateUniqueID();
89
Robert Phillipsf2361d22016-10-25 14:20:06 -040090 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050091 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -040092
93 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
94 kTempMark_Flag = 0x04, //!< Flag for topological sorting
95 };
96
97 void setFlag(uint32_t flag) {
98 fFlags |= flag;
99 }
100
101 void resetFlag(uint32_t flag) {
102 fFlags &= ~flag;
103 }
104
105 bool isSetFlag(uint32_t flag) const {
106 return SkToBool(fFlags & flag);
107 }
108
109 struct TopoSortTraits {
110 static void Output(GrOpList* dt, int /* index */) {
111 dt->setFlag(GrOpList::kWasOutput_Flag);
112 }
113 static bool WasOutput(const GrOpList* dt) {
114 return dt->isSetFlag(GrOpList::kWasOutput_Flag);
115 }
116 static void SetTempMark(GrOpList* dt) {
117 dt->setFlag(GrOpList::kTempMark_Flag);
118 }
119 static void ResetTempMark(GrOpList* dt) {
120 dt->resetFlag(GrOpList::kTempMark_Flag);
121 }
122 static bool IsTempMarked(const GrOpList* dt) {
123 return dt->isSetFlag(GrOpList::kTempMark_Flag);
124 }
125 static int NumDependencies(const GrOpList* dt) {
126 return dt->fDependencies.count();
127 }
128 static GrOpList* Dependency(GrOpList* dt, int index) {
129 return dt->fDependencies[index];
130 }
131 };
132
133 void addDependency(GrOpList* dependedOn);
134
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400135 uint32_t fUniqueID;
136 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400137
138 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400139 SkTDArray<GrOpList*> fDependencies;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400140
Robert Phillipsf2361d22016-10-25 14:20:06 -0400141 typedef SkRefCnt INHERITED;
142};
143
144#endif