GrCCDrawPathsOp.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2018 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 GrCCDrawPathsOp_DEFINED
  8. #define GrCCDrawPathsOp_DEFINED
  9. #include "src/core/SkTInternalLList.h"
  10. #include "src/gpu/ccpr/GrCCPathCache.h"
  11. #include "src/gpu/ccpr/GrCCSTLList.h"
  12. #include "src/gpu/geometry/GrShape.h"
  13. #include "src/gpu/ops/GrDrawOp.h"
  14. class GrCCAtlas;
  15. class GrCCPerFlushResources;
  16. struct GrCCPerFlushResourceSpecs;
  17. struct GrCCPerOpListPaths;
  18. class GrOnFlushResourceProvider;
  19. class GrRecordingContext;
  20. /**
  21. * This is the Op that draws paths to the actual canvas, using atlases generated by CCPR.
  22. */
  23. class GrCCDrawPathsOp : public GrDrawOp {
  24. public:
  25. DEFINE_OP_CLASS_ID
  26. SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrCCDrawPathsOp);
  27. static std::unique_ptr<GrCCDrawPathsOp> Make(GrRecordingContext*, const SkIRect& clipIBounds,
  28. const SkMatrix&, const GrShape&, GrPaint&&);
  29. ~GrCCDrawPathsOp() override;
  30. const char* name() const override { return "GrCCDrawPathsOp"; }
  31. FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
  32. GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
  33. bool hasMixedSampledCoverage, GrClampType) override;
  34. CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override;
  35. void visitProxies(const VisitProxyFunc& fn) const override {
  36. for (const auto& range : fInstanceRanges) {
  37. fn(range.fAtlasProxy, GrMipMapped::kNo);
  38. }
  39. fProcessors.visitProxies(fn);
  40. }
  41. void onPrepare(GrOpFlushState*) override {}
  42. void addToOwningPerOpListPaths(sk_sp<GrCCPerOpListPaths> owningPerOpListPaths);
  43. // Makes decisions about how to draw each path (cached, copied, rendered, etc.), and
  44. // increments/fills out the corresponding GrCCPerFlushResourceSpecs.
  45. void accountForOwnPaths(GrCCPathCache*, GrOnFlushResourceProvider*, GrCCPerFlushResourceSpecs*);
  46. // Allows the caller to decide whether to actually do the suggested copies from cached 16-bit
  47. // coverage count atlases, and into 8-bit literal coverage atlases. Purely to save space.
  48. enum class DoCopiesToA8Coverage : bool {
  49. kNo = false,
  50. kYes = true
  51. };
  52. // Allocates the GPU resources indicated by accountForOwnPaths(), in preparation for drawing. If
  53. // DoCopiesToA8Coverage is kNo, the paths slated for copy will instead be left in their 16-bit
  54. // coverage count atlases.
  55. //
  56. // NOTE: If using DoCopiesToA8Coverage::kNo, it is the caller's responsibility to have called
  57. // cancelCopies() on the GrCCPerFlushResourceSpecs, prior to making this call.
  58. void setupResources(GrCCPathCache*, GrOnFlushResourceProvider*, GrCCPerFlushResources*,
  59. DoCopiesToA8Coverage);
  60. void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
  61. private:
  62. friend class GrOpMemoryPool;
  63. static std::unique_ptr<GrCCDrawPathsOp> InternalMake(GrRecordingContext*,
  64. const SkIRect& clipIBounds,
  65. const SkMatrix&, const GrShape&,
  66. float strokeDevWidth,
  67. const SkRect& conservativeDevBounds,
  68. GrPaint&&);
  69. GrCCDrawPathsOp(const SkMatrix&, const GrShape&, float strokeDevWidth,
  70. const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds,
  71. const SkRect& conservativeDevBounds, GrPaint&&);
  72. void recordInstance(
  73. GrCCPathProcessor::CoverageMode, GrTextureProxy* atlasProxy, int instanceIdx);
  74. const SkMatrix fViewMatrixIfUsingLocalCoords;
  75. class SingleDraw {
  76. public:
  77. SingleDraw(const SkMatrix&, const GrShape&, float strokeDevWidth,
  78. const SkIRect& shapeConservativeIBounds, const SkIRect& maskDevIBounds,
  79. const SkPMColor4f&);
  80. // See the corresponding methods in GrCCDrawPathsOp.
  81. GrProcessorSet::Analysis finalize(
  82. const GrCaps&, const GrAppliedClip*, bool hasMixedSampledCoverage, GrClampType,
  83. GrProcessorSet*);
  84. void accountForOwnPath(GrCCPathCache*, GrOnFlushResourceProvider*,
  85. GrCCPerFlushResourceSpecs*);
  86. void setupResources(GrCCPathCache*, GrOnFlushResourceProvider*, GrCCPerFlushResources*,
  87. DoCopiesToA8Coverage, GrCCDrawPathsOp*);
  88. private:
  89. bool shouldCachePathMask(int maxRenderTargetSize) const;
  90. SkMatrix fMatrix;
  91. GrShape fShape;
  92. float fStrokeDevWidth;
  93. const SkIRect fShapeConservativeIBounds;
  94. SkIRect fMaskDevIBounds;
  95. SkPMColor4f fColor;
  96. GrCCPathCache::OnFlushEntryRef fCacheEntry;
  97. SkIVector fCachedMaskShift;
  98. bool fDoCopyToA8Coverage = false;
  99. bool fDoCachePathMask = false;
  100. SkDEBUGCODE(bool fWasCountedAsRender = false);
  101. SingleDraw* fNext = nullptr;
  102. friend class GrCCSTLList<SingleDraw>; // To access fNext.
  103. };
  104. // Declare fOwningPerOpListPaths first, before fDraws. The draws use memory allocated by
  105. // fOwningPerOpListPaths, so it must not be unreffed until after fDraws is destroyed.
  106. sk_sp<GrCCPerOpListPaths> fOwningPerOpListPaths;
  107. GrCCSTLList<SingleDraw> fDraws;
  108. SkDEBUGCODE(int fNumDraws = 1);
  109. GrProcessorSet fProcessors;
  110. struct InstanceRange {
  111. GrCCPathProcessor::CoverageMode fCoverageMode;
  112. GrTextureProxy* fAtlasProxy;
  113. int fEndInstanceIdx;
  114. };
  115. SkSTArray<2, InstanceRange, true> fInstanceRanges;
  116. int fBaseInstance SkDEBUGCODE(= -1);
  117. };
  118. #endif