blob: 0139b6b4d3278bc560af7ff8dcdb4c87080e8718 [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 Phillipsdc83b892017-04-13 12:23:54 -040025 GrOpList(sk_sp<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
Robert Phillipsdc83b892017-04-13 12:23:54 -040083protected:
84 GrSurfaceProxy* fTarget;
85 GrAuditTrail* fAuditTrail;
86
Robert Phillipsf2361d22016-10-25 14:20:06 -040087private:
88 friend class GrDrawingManager; // for resetFlag & TopoSortTraits
89
Robert Phillipsc0138922017-03-08 11:50:55 -050090 static uint32_t CreateUniqueID();
91
Robert Phillipsf2361d22016-10-25 14:20:06 -040092 enum Flags {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050093 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
Robert Phillipsf2361d22016-10-25 14:20:06 -040094
95 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
96 kTempMark_Flag = 0x04, //!< Flag for topological sorting
97 };
98
99 void setFlag(uint32_t flag) {
100 fFlags |= flag;
101 }
102
103 void resetFlag(uint32_t flag) {
104 fFlags &= ~flag;
105 }
106
107 bool isSetFlag(uint32_t flag) const {
108 return SkToBool(fFlags & flag);
109 }
110
111 struct TopoSortTraits {
112 static void Output(GrOpList* dt, int /* index */) {
113 dt->setFlag(GrOpList::kWasOutput_Flag);
114 }
115 static bool WasOutput(const GrOpList* dt) {
116 return dt->isSetFlag(GrOpList::kWasOutput_Flag);
117 }
118 static void SetTempMark(GrOpList* dt) {
119 dt->setFlag(GrOpList::kTempMark_Flag);
120 }
121 static void ResetTempMark(GrOpList* dt) {
122 dt->resetFlag(GrOpList::kTempMark_Flag);
123 }
124 static bool IsTempMarked(const GrOpList* dt) {
125 return dt->isSetFlag(GrOpList::kTempMark_Flag);
126 }
127 static int NumDependencies(const GrOpList* dt) {
128 return dt->fDependencies.count();
129 }
130 static GrOpList* Dependency(GrOpList* dt, int index) {
131 return dt->fDependencies[index];
132 }
133 };
134
135 void addDependency(GrOpList* dependedOn);
136
Robert Phillipsc0138922017-03-08 11:50:55 -0500137 uint32_t fUniqueID;
138 uint32_t fFlags;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400139
140 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
Robert Phillipsc0138922017-03-08 11:50:55 -0500141 SkTDArray<GrOpList*> fDependencies;
Robert Phillipsf2361d22016-10-25 14:20:06 -0400142
Robert Phillipsf2361d22016-10-25 14:20:06 -0400143 typedef SkRefCnt INHERITED;
144};
145
146#endif