f0dc1c192c418412aa7565c6c18a4996518f003b
[platform/upstream/libSkiaSharp.git] / src / gpu / GrOpList.h
1 /*
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 "GrGpuResourceRef.h"
12
13 #include "SkRefCnt.h"
14 #include "SkTDArray.h"
15
16 //#define ENABLE_MDB 1
17
18 class GrAuditTrail;
19 class GrCaps;
20 class GrOpFlushState;
21 class GrRenderTargetOpList;
22 class GrSurfaceProxy;
23 class GrTextureOpList;
24
25 class GrOpList : public SkRefCnt {
26 public:
27     GrOpList(GrSurfaceProxy*, GrAuditTrail*);
28     ~GrOpList() override;
29
30     // These two methods are invoked as flush time
31     virtual void prepareOps(GrOpFlushState* flushState) = 0;
32     virtual bool executeOps(GrOpFlushState* flushState) = 0;
33
34     virtual void makeClosed(const GrCaps&) {
35         this->setFlag(kClosed_Flag);
36     }
37
38     virtual void reset();
39
40     // TODO: in an MDB world, where the OpLists don't allocate GPU resources, it seems like
41     // these could go away
42     virtual void abandonGpuResources() = 0;
43     virtual void freeGpuResources() = 0;
44
45     bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
46
47     /*
48      * Notify this GrOpList that it relies on the contents of 'dependedOn'
49      */
50     void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
51
52     /*
53      * Does this opList depend on 'dependedOn'?
54      */
55     bool dependsOn(GrOpList* dependedOn) const {
56         return fDependencies.find(dependedOn) >= 0;
57     }
58
59     /*
60      * Safely cast this GrOpList to a GrTextureOpList (if possible).
61      */
62     virtual GrTextureOpList* asTextureOpList() { return nullptr; }
63
64     /*
65      * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
66      */
67     virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
68
69     int32_t uniqueID() const { return fUniqueID; }
70
71     /*
72      * Dump out the GrOpList dependency DAG
73      */
74     SkDEBUGCODE(virtual void dump() const;)
75
76     SkDEBUGCODE(virtual void validateTargetsSingleRenderTarget() const = 0;)
77
78     SkDEBUGCODE(virtual int numOps() const = 0;)
79     SkDEBUGCODE(virtual int numClips() const { return 0; })
80
81 protected:
82     GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fTarget;
83     GrAuditTrail*                                        fAuditTrail;
84
85 private:
86     friend class GrDrawingManager; // for resetFlag & TopoSortTraits
87
88     static uint32_t CreateUniqueID();
89
90     enum Flags {
91         kClosed_Flag    = 0x01,   //!< This GrOpList can't accept any more ops
92
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
135     uint32_t              fUniqueID;
136     uint32_t              fFlags;
137
138     // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
139     SkTDArray<GrOpList*>  fDependencies;
140
141     typedef SkRefCnt INHERITED;
142 };
143
144 #endif