• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrProxyRef.h"
12 #include "GrTextureProxy.h"
13 #include "SkColorData.h"
14 #include "SkRefCnt.h"
15 #include "SkTDArray.h"
16 
17 class GrAuditTrail;
18 class GrCaps;
19 class GrOpFlushState;
20 class GrOpMemoryPool;
21 class GrRecordingContext;
22 class GrRenderTargetOpList;
23 class GrResourceAllocator;
24 class GrResourceProvider;
25 class GrSurfaceProxy;
26 class GrTextureOpList;
27 
28 struct SkIPoint;
29 struct SkIRect;
30 
31 class GrOpList : public SkRefCnt {
32 public:
33     GrOpList(GrResourceProvider*, sk_sp<GrOpMemoryPool>, GrSurfaceProxy*, GrAuditTrail*);
34     ~GrOpList() override;
35 
36     // These four methods are invoked at flush time
37     bool instantiate(GrResourceProvider* resourceProvider);
38     // Instantiates any "threaded" texture proxies that are being prepared elsewhere
39     void instantiateDeferredProxies(GrResourceProvider* resourceProvider);
40     void prepare(GrOpFlushState* flushState);
execute(GrOpFlushState * flushState)41     bool execute(GrOpFlushState* flushState) { return this->onExecute(flushState); }
42 
43     virtual bool copySurface(GrRecordingContext*,
44                              GrSurfaceProxy* dst,
45                              GrSurfaceProxy* src,
46                              const SkIRect& srcRect,
47                              const SkIPoint& dstPoint) = 0;
48 
makeClosed(const GrCaps &)49     virtual void makeClosed(const GrCaps&) {
50         if (!this->isClosed()) {
51             this->setFlag(kClosed_Flag);
52             fTarget.removeRef();
53         }
54     }
55 
56     // Called when this class will survive a flush and needs to truncate its ops and start over.
57     // TODO: ultimately it should be invalid for an op list to survive a flush.
58     // https://bugs.chromium.org/p/skia/issues/detail?id=7111
59     virtual void endFlush();
60 
isClosed()61     bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
62 
63     /*
64      * Notify this GrOpList that it relies on the contents of 'dependedOn'
65      */
66     void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
67 
68     /*
69      * Does this opList depend on 'dependedOn'?
70      */
71     bool dependsOn(const GrOpList* dependedOn) const;
72 
73     /*
74      * Safely cast this GrOpList to a GrTextureOpList (if possible).
75      */
asTextureOpList()76     virtual GrTextureOpList* asTextureOpList() { return nullptr; }
77 
78     /*
79      * Safely case this GrOpList to a GrRenderTargetOpList (if possible).
80      */
asRenderTargetOpList()81     virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
82 
uniqueID()83     uint32_t uniqueID() const { return fUniqueID; }
84 
85     /*
86      * Dump out the GrOpList dependency DAG
87      */
88     SkDEBUGCODE(virtual void dump(bool printDependencies) const;)
89 
90     SkDEBUGCODE(virtual int numClips() const { return 0; })
91 
92 protected:
93     bool isInstantiated() const;
94 
95     // In addition to just the GrSurface being allocated, has the stencil buffer been allocated (if
96     // it is required)?
97     bool isFullyInstantiated() const;
98 
99     // This is a backpointer to the GrOpMemoryPool that holds the memory for this opLists' ops.
100     // In the DDL case, these back pointers keep the DDL's GrOpMemoryPool alive as long as its
101     // constituent opLists survive.
102     sk_sp<GrOpMemoryPool> fOpMemoryPool;
103     GrSurfaceProxyRef     fTarget;
104     GrAuditTrail*         fAuditTrail;
105 
106     GrLoadOp              fColorLoadOp    = GrLoadOp::kLoad;
107     SkPMColor4f           fLoadClearColor = SK_PMColor4fTRANSPARENT;
108     GrLoadOp              fStencilLoadOp  = GrLoadOp::kLoad;
109 
110     // List of texture proxies whose contents are being prepared on a worker thread
111     SkTArray<GrTextureProxy*, true> fDeferredProxies;
112 
113 private:
114     friend class GrDrawingManager; // for resetFlag, TopoSortTraits & gatherProxyIntervals
115 
116     void addDependency(GrOpList* dependedOn);
117     void addDependent(GrOpList* dependent);
118     SkDEBUGCODE(bool isDependedent(const GrOpList* dependent) const;)
119     SkDEBUGCODE(void validate() const;)
120     void closeThoseWhoDependOnMe(const GrCaps&);
121 
122     // Remove all Ops which reference proxies that are not instantiated.
123     virtual void purgeOpsWithUninstantiatedProxies() = 0;
124 
125     // Feed proxy usage intervals to the GrResourceAllocator class
126     virtual void gatherProxyIntervals(GrResourceAllocator*) const = 0;
127 
128     static uint32_t CreateUniqueID();
129 
130     enum Flags {
131         kClosed_Flag    = 0x01,   //!< This GrOpList can't accept any more ops
132 
133         kWasOutput_Flag = 0x02,   //!< Flag for topological sorting
134         kTempMark_Flag  = 0x04,   //!< Flag for topological sorting
135     };
136 
setFlag(uint32_t flag)137     void setFlag(uint32_t flag) {
138         fFlags |= flag;
139     }
140 
resetFlag(uint32_t flag)141     void resetFlag(uint32_t flag) {
142         fFlags &= ~flag;
143     }
144 
isSetFlag(uint32_t flag)145     bool isSetFlag(uint32_t flag) const {
146         return SkToBool(fFlags & flag);
147     }
148 
149     struct TopoSortTraits {
OutputTopoSortTraits150         static void Output(GrOpList* opList, int /* index */) {
151             opList->setFlag(GrOpList::kWasOutput_Flag);
152         }
WasOutputTopoSortTraits153         static bool WasOutput(const GrOpList* opList) {
154             return opList->isSetFlag(GrOpList::kWasOutput_Flag);
155         }
SetTempMarkTopoSortTraits156         static void SetTempMark(GrOpList* opList) {
157             opList->setFlag(GrOpList::kTempMark_Flag);
158         }
ResetTempMarkTopoSortTraits159         static void ResetTempMark(GrOpList* opList) {
160             opList->resetFlag(GrOpList::kTempMark_Flag);
161         }
IsTempMarkedTopoSortTraits162         static bool IsTempMarked(const GrOpList* opList) {
163             return opList->isSetFlag(GrOpList::kTempMark_Flag);
164         }
NumDependenciesTopoSortTraits165         static int NumDependencies(const GrOpList* opList) {
166             return opList->fDependencies.count();
167         }
DependencyTopoSortTraits168         static GrOpList* Dependency(GrOpList* opList, int index) {
169             return opList->fDependencies[index];
170         }
171     };
172 
173     virtual void onPrepare(GrOpFlushState* flushState) = 0;
174     virtual bool onExecute(GrOpFlushState* flushState) = 0;
175 
176     uint32_t               fUniqueID;
177     uint32_t               fFlags;
178 
179     // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies'
180     SkSTArray<1, GrOpList*, true> fDependencies;
181     // 'this' GrOpList's output is relied on by the GrOpLists in 'fDependents'
182     SkSTArray<1, GrOpList*, true> fDependents;
183 
184     typedef SkRefCnt INHERITED;
185 };
186 
187 #endif
188