2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrOpList_DEFINED
9 #define GrOpList_DEFINED
11 #include "GrGpuResourceRef.h"
14 #include "SkTDArray.h"
16 //#define ENABLE_MDB 1
21 class GrRenderTargetOpList;
23 class GrTextureOpList;
25 class GrOpList : public SkRefCnt {
27 GrOpList(GrSurfaceProxy*, GrAuditTrail*);
30 // These two methods are invoked as flush time
31 virtual void prepareOps(GrOpFlushState* flushState) = 0;
32 virtual bool executeOps(GrOpFlushState* flushState) = 0;
34 virtual void makeClosed(const GrCaps&) {
35 this->setFlag(kClosed_Flag);
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;
45 bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
48 * Notify this GrOpList that it relies on the contents of 'dependedOn'
50 void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
53 * Does this opList depend on 'dependedOn'?
55 bool dependsOn(GrOpList* dependedOn) const {
56 return fDependencies.find(dependedOn) >= 0;
60 * Safely cast this GrOpList to a GrTextureOpList (if possible).
62 virtual GrTextureOpList* asTextureOpList() { return nullptr; }
65 * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
67 virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
69 int32_t uniqueID() const { return fUniqueID; }
72 * Dump out the GrOpList dependency DAG
74 SkDEBUGCODE(virtual void dump() const;)
76 SkDEBUGCODE(virtual void validateTargetsSingleRenderTarget() const = 0;)
78 SkDEBUGCODE(virtual int numOps() const = 0;)
79 SkDEBUGCODE(virtual int numClips() const { return 0; })
82 GrPendingIOResource<GrSurfaceProxy, kWrite_GrIOType> fTarget;
83 GrAuditTrail* fAuditTrail;
86 friend class GrDrawingManager; // for resetFlag & TopoSortTraits
88 static uint32_t CreateUniqueID();
91 kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
93 kWasOutput_Flag = 0x02, //!< Flag for topological sorting
94 kTempMark_Flag = 0x04, //!< Flag for topological sorting
97 void setFlag(uint32_t flag) {
101 void resetFlag(uint32_t flag) {
105 bool isSetFlag(uint32_t flag) const {
106 return SkToBool(fFlags & flag);
109 struct TopoSortTraits {
110 static void Output(GrOpList* dt, int /* index */) {
111 dt->setFlag(GrOpList::kWasOutput_Flag);
113 static bool WasOutput(const GrOpList* dt) {
114 return dt->isSetFlag(GrOpList::kWasOutput_Flag);
116 static void SetTempMark(GrOpList* dt) {
117 dt->setFlag(GrOpList::kTempMark_Flag);
119 static void ResetTempMark(GrOpList* dt) {
120 dt->resetFlag(GrOpList::kTempMark_Flag);
122 static bool IsTempMarked(const GrOpList* dt) {
123 return dt->isSetFlag(GrOpList::kTempMark_Flag);
125 static int NumDependencies(const GrOpList* dt) {
126 return dt->fDependencies.count();
128 static GrOpList* Dependency(GrOpList* dt, int index) {
129 return dt->fDependencies[index];
133 void addDependency(GrOpList* dependedOn);
138 // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
139 SkTDArray<GrOpList*> fDependencies;
141 typedef SkRefCnt INHERITED;