Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 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 "SkTInternalLList.h" |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 12 | #include "ccpr/GrCCPathParser.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 13 | #include "ccpr/GrCCPathProcessor.h" |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 14 | #include "ccpr/GrCCSTLList.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 15 | #include "ops/GrDrawOp.h" |
| 16 | |
| 17 | class GrCCAtlas; |
| 18 | class GrCCPerFlushResources; |
| 19 | struct GrCCRTPendingPaths; |
| 20 | class GrCoverageCountingPathRenderer; |
| 21 | |
| 22 | /** |
| 23 | * This is the Op that draws paths to the actual canvas, using atlases generated by CCPR. |
| 24 | */ |
| 25 | class GrCCDrawPathsOp : public GrDrawOp { |
| 26 | public: |
| 27 | DEFINE_OP_CLASS_ID |
| 28 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrCCDrawPathsOp); |
| 29 | |
| 30 | GrCCDrawPathsOp(GrCoverageCountingPathRenderer*, GrPaint&&, const SkIRect& clipIBounds, |
| 31 | const SkMatrix&, const SkPath&, const SkRect& devBounds); |
| 32 | ~GrCCDrawPathsOp() override; |
| 33 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 34 | const char* name() const override { return "GrCCDrawOp"; } |
| 35 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 36 | RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*, |
| 37 | GrPixelConfigIsClamped) override; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 38 | bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override; |
| 39 | void visitProxies(const VisitProxyFunc& func) const override { |
| 40 | fProcessors.visitProxies(func); |
| 41 | } |
| 42 | void onPrepare(GrOpFlushState*) override {} |
| 43 | |
Chris Dalton | f104fec | 2018-05-22 16:17:48 -0600 | [diff] [blame] | 44 | void wasRecorded(GrCCRTPendingPaths* owningRTPendingPaths); |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 45 | int countPaths(GrCCPathParser::PathStats*) const; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 46 | void setupResources(GrCCPerFlushResources*, GrOnFlushResourceProvider*); |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 47 | SkDEBUGCODE(int numSkippedInstances_debugOnly() const { return fNumSkippedInstances; }) |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 48 | |
| 49 | void onExecute(GrOpFlushState*) override; |
| 50 | |
| 51 | private: |
| 52 | SkPath::FillType getFillType() const { |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 53 | SkASSERT(fNumDraws >= 1); |
| 54 | return fDraws.head().fPath.getFillType(); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | struct AtlasBatch { |
| 58 | const GrCCAtlas* fAtlas; |
| 59 | int fEndInstanceIdx; |
| 60 | }; |
| 61 | |
| 62 | void addAtlasBatch(const GrCCAtlas* atlas, int endInstanceIdx) { |
| 63 | SkASSERT(endInstanceIdx > fBaseInstance); |
| 64 | SkASSERT(fAtlasBatches.empty() || |
| 65 | endInstanceIdx > fAtlasBatches.back().fEndInstanceIdx); |
| 66 | fAtlasBatches.push_back() = {atlas, endInstanceIdx}; |
| 67 | } |
| 68 | |
| 69 | GrCoverageCountingPathRenderer* const fCCPR; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 70 | const uint32_t fSRGBFlags; |
Chris Dalton | 1c54894 | 2018-05-22 13:09:48 -0600 | [diff] [blame] | 71 | const SkMatrix fViewMatrixIfUsingLocalCoords; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 72 | |
| 73 | struct SingleDraw { |
| 74 | SkIRect fClipIBounds; |
| 75 | SkMatrix fMatrix; |
| 76 | SkPath fPath; |
| 77 | GrColor fColor; |
| 78 | SingleDraw* fNext; |
| 79 | }; |
| 80 | |
| 81 | GrCCSTLList<SingleDraw> fDraws; |
| 82 | SkDEBUGCODE(int fNumDraws = 1); |
| 83 | |
| 84 | GrProcessorSet fProcessors; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 85 | GrCCRTPendingPaths* fOwningRTPendingPaths = nullptr; |
| 86 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 87 | int fBaseInstance; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 88 | SkSTArray<1, AtlasBatch, true> fAtlasBatches; |
Chris Dalton | 4bfb50b | 2018-05-21 09:10:53 -0600 | [diff] [blame] | 89 | SkDEBUGCODE(int fNumSkippedInstances = 0); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | #endif |