GrOpList.h 6.2 KB

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