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