GrOpList.h 6.1 KB

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