GrStencilAtlasOp.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2019 Google LLC.
  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 GrStencilAtlasOp_DEFINED
  8. #define GrStencilAtlasOp_DEFINED
  9. #include "src/gpu/GrMemoryPool.h"
  10. #include "src/gpu/ccpr/GrCCFiller.h"
  11. #include "src/gpu/ccpr/GrCCStroker.h"
  12. #include "src/gpu/ops/GrDrawOp.h"
  13. class GrCCPerFlushResources;
  14. // Renders literal A8 coverage to a CCPR atlas using an intermediate MSAA stencil buffer.
  15. class GrStencilAtlasOp : public GrDrawOp {
  16. public:
  17. DEFINE_OP_CLASS_ID
  18. using FillBatchID = GrCCFiller::BatchID;
  19. using StrokeBatchID = GrCCStroker::BatchID;
  20. // Once all the paths in an atlas have been drawn to the stencil buffer, we make a final pass
  21. // where we draw "resolve" rects over each path whose purpose is to convert winding counts to A8
  22. // coverage.
  23. struct ResolveRectInstance {
  24. int16_t l, t, r, b;
  25. };
  26. // GrDrawOp interface.
  27. const char* name() const override { return "StencilAtlasOp (CCPR)"; }
  28. FixedFunctionFlags fixedFunctionFlags() const override {
  29. return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil;
  30. }
  31. GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
  32. bool hasMixedSampledCoverage, GrClampType) override {
  33. return GrProcessorSet::EmptySetAnalysis();
  34. }
  35. CombineResult onCombineIfPossible(GrOp* other, const GrCaps&) override {
  36. // We will only make multiple copy ops if they have different source proxies.
  37. // TODO: make use of texture chaining.
  38. return CombineResult::kCannotCombine;
  39. }
  40. void onPrepare(GrOpFlushState*) override {}
  41. static std::unique_ptr<GrDrawOp> Make(
  42. GrRecordingContext*, sk_sp<const GrCCPerFlushResources>, FillBatchID, StrokeBatchID,
  43. int baseStencilResolveInstance, int endStencilResolveInstance,
  44. const SkISize& drawBounds);
  45. void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override;
  46. private:
  47. friend class ::GrOpMemoryPool; // for ctor
  48. GrStencilAtlasOp(sk_sp<const GrCCPerFlushResources> resources, FillBatchID fillBatchID,
  49. StrokeBatchID strokeBatchID, int baseStencilResolveInstance,
  50. int endStencilResolveInstance, const SkISize& drawBounds)
  51. : GrDrawOp(ClassID())
  52. , fResources(std::move(resources))
  53. , fFillBatchID(fillBatchID)
  54. , fStrokeBatchID(strokeBatchID)
  55. , fBaseStencilResolveInstance(baseStencilResolveInstance)
  56. , fEndStencilResolveInstance(endStencilResolveInstance)
  57. , fDrawBounds(drawBounds) {
  58. this->setBounds(SkRect::MakeIWH(fDrawBounds.width(), fDrawBounds.height()),
  59. GrOp::HasAABloat::kNo, GrOp::IsZeroArea::kNo);
  60. }
  61. const sk_sp<const GrCCPerFlushResources> fResources;
  62. const FillBatchID fFillBatchID;
  63. const StrokeBatchID fStrokeBatchID;
  64. const int fBaseStencilResolveInstance;
  65. const int fEndStencilResolveInstance;
  66. const SkISize fDrawBounds;
  67. int fResolveBaseVertex;
  68. };
  69. #endif