blob: 557126681a3cc06020152d8a7425636ae6d73ffd [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
11#include "SkRefCnt.h"
12#include "SkTDArray.h"
13
14//#define ENABLE_MDB 1
15
Brian Osman62e7b5f2016-10-26 12:02:18 -040016class GrAuditTrail;
Brian Salomon742e31d2016-12-07 17:06:19 -050017class GrOpFlushState;
Brian Osman45580d32016-11-23 09:37:01 -050018class GrRenderTargetOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040019class GrSurface;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040020class GrSurfaceProxy;
Brian Osman45580d32016-11-23 09:37:01 -050021class GrTextureOpList;
Robert Phillipsf2361d22016-10-25 14:20:06 -040022
23class GrOpList : public SkRefCnt {
24public:
Robert Phillipsc7635fa2016-10-28 13:25:24 -040025 GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail);
Robert Phillipsf2361d22016-10-25 14:20:06 -040026 ~GrOpList() override;
27
Robert Phillips294870f2016-11-11 12:38:40 -050028 // These two methods are invoked as flush time
Brian Salomon742e31d2016-12-07 17:06:19 -050029 virtual void prepareOps(GrOpFlushState* flushState) = 0;
30 virtual bool executeOps(GrOpFlushState* flushState) = 0;
Robert Phillipsf2361d22016-10-25 14:20:06 -040031
32 virtual void makeClosed() {
33 // We only close GrOpLists when MDB is enabled. When MDB is disabled there is only
34 // ever one GrOpLists and all calls will be funnelled into it.
35#ifdef ENABLE_MDB
36 this->setFlag(kClosed_Flag);
37#endif
38 }
39
40 // TODO: it seems a bit odd that GrOpList has nothing to clear on reset
41 virtual void reset() = 0;
42
43 // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like
44 // these could go away
45 virtual void abandonGpuResources() = 0;
46 virtual void freeGpuResources() = 0;
47
48 // TODO: this entry point is only needed in the non-MDB world. Remove when
49 // we make the switch to MDB
50 void clearTarget() { fTarget = nullptr; }
51
52 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
53
54 /*
55 * Notify this GrOpList that it relies on the contents of 'dependedOn'
56 */
57 void addDependency(GrSurface* dependedOn);
58
59 /*
60 * Does this opList depend on 'dependedOn'?
61 */
62 bool dependsOn(GrOpList* dependedOn) const {
63 return fDependencies.find(dependedOn) >= 0;
64 }
65
66 /*
Brian Osman45580d32016-11-23 09:37:01 -050067 * Safely cast this GrOpList to a GrTextureOpList (if possible).
68 */
69 virtual GrTextureOpList* asTextureOpList() { return nullptr; }
70
71 /*
72 * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
73 */
74 virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
75
Robert Phillipsc0138922017-03-08 11:50:55 -050076 int32_t uniqueID() const { return fUniqueID; }
77
Brian Osman45580d32016-11-23 09:37:01 -050078 /*
Robert Phillipsf2361d22016-10-25 14:20:06 -040079 * Dump out the GrOpList dependency DAG
80 */
81 SkDEBUGCODE(virtual void dump() const;)
82
83private:
84 friend class GrDrawingManager; // for resetFlag & TopoSortTraits
85
Robert Phillipsc0138922017-03-08 11:50:55 -050086 static uint32_t CreateUniqueID();
87
Robert Phillipsf2361d22016-10-25 14:20:06 -040088 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050089 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -040090
91 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
92 kTempMark_Flag = 0x04, //!< Flag for topological sorting
93 };
94
95 void setFlag(uint32_t flag) {
96 fFlags |= flag;
97 }
98
99 void resetFlag(uint32_t flag) {
100 fFlags &= ~flag;
101 }
102
103 bool isSetFlag(uint32_t flag) const {
104 return SkToBool(fFlags & flag);
105 }
106
107 struct TopoSortTraits {
108 static void Output(GrOpList* dt, int /* index */) {
109 dt->setFlag(GrOpList::kWasOutput_Flag);
110 }
111 static bool WasOutput(const GrOpList* dt) {
112 return dt->isSetFlag(GrOpList::kWasOutput_Flag);
113 }
114 static void SetTempMark(GrOpList* dt) {
115 dt->setFlag(GrOpList::kTempMark_Flag);
116 }
117 static void ResetTempMark(GrOpList* dt) {
118 dt->resetFlag(GrOpList::kTempMark_Flag);
119 }
120 static bool IsTempMarked(const GrOpList* dt) {
121 return dt->isSetFlag(GrOpList::kTempMark_Flag);
122 }
123 static int NumDependencies(const GrOpList* dt) {
124 return dt->fDependencies.count();
125 }
126 static GrOpList* Dependency(GrOpList* dt, int index) {
127 return dt->fDependencies[index];
128 }
129 };
130
131 void addDependency(GrOpList* dependedOn);
132
Robert Phillipsc0138922017-03-08 11:50:55 -0500133 uint32_t fUniqueID;
134 uint32_t fFlags;
135 GrSurfaceProxy* fTarget;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400136
137 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillipsc0138922017-03-08 11:50:55 -0500138 SkTDArray<GrOpList*> fDependencies;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400139
Brian Osman62e7b5f2016-10-26 12:02:18 -0400140protected:
Robert Phillipsc0138922017-03-08 11:50:55 -0500141 GrAuditTrail* fAuditTrail;
Brian Osman62e7b5f2016-10-26 12:02:18 -0400142
Robert Phillipsf2361d22016-10-25 14:20:06 -0400143 typedef SkRefCnt INHERITED;
144};
145
146#endif