| 1 | /* |
| 2 | * Copyright 2015 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 GrDrawPathOp_DEFINED |
| 9 | #define GrDrawPathOp_DEFINED |
| 10 | |
| 11 | #include "src/gpu/GrOpFlushState.h" |
| 12 | #include "src/gpu/GrPath.h" |
| 13 | #include "src/gpu/GrPathProcessor.h" |
| 14 | #include "src/gpu/GrPathRendering.h" |
| 15 | #include "src/gpu/GrProcessorSet.h" |
| 16 | #include "src/gpu/GrStencilSettings.h" |
| 17 | #include "src/gpu/ops/GrDrawOp.h" |
| 18 | |
| 19 | class GrPaint; |
| 20 | class GrRecordingContext; |
| 21 | |
| 22 | class GrDrawPathOpBase : public GrDrawOp { |
| 23 | protected: |
| 24 | GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&&, |
| 25 | GrPathRendering::FillType, GrAA); |
| 26 | |
| 27 | FixedFunctionFlags fixedFunctionFlags() const override { |
| 28 | return (fDoAA) |
| 29 | ? FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil |
| 30 | : FixedFunctionFlags::kUsesStencil; |
| 31 | } |
| 32 | GrProcessorSet::Analysis finalize( |
| 33 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 34 | GrClampType clampType) override { |
| 35 | return this->doProcessorAnalysis(caps, clip, hasMixedSampledCoverage, clampType); |
| 36 | } |
| 37 | |
| 38 | void visitProxies(const VisitProxyFunc& func) const override { |
| 39 | fProcessorSet.visitProxies(func); |
| 40 | } |
| 41 | |
| 42 | protected: |
| 43 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 44 | const SkPMColor4f& color() const { return fInputColor; } |
| 45 | GrPathRendering::FillType fillType() const { return fFillType; } |
| 46 | bool doAA() const { return fDoAA; } |
| 47 | const GrProcessorSet& processors() const { return fProcessorSet; } |
| 48 | GrProcessorSet detachProcessorSet() { return std::move(fProcessorSet); } |
| 49 | const GrProcessorSet::Analysis& doProcessorAnalysis( |
| 50 | const GrCaps&, const GrAppliedClip*, bool hasMixedSampledCoverage, GrClampType); |
| 51 | const GrProcessorSet::Analysis& processorAnalysis() const { |
| 52 | SkASSERT(fAnalysis.isInitialized()); |
| 53 | return fAnalysis; |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | void onPrePrepare(GrRecordingContext*, |
| 58 | const GrSurfaceProxyView* writeView, |
| 59 | GrAppliedClip*, |
| 60 | const GrXferProcessor::DstProxyView&) final {} |
| 61 | |
| 62 | void onPrepare(GrOpFlushState*) final {} |
| 63 | |
| 64 | SkMatrix fViewMatrix; |
| 65 | SkPMColor4f fInputColor; |
| 66 | GrProcessorSet::Analysis fAnalysis; |
| 67 | GrPathRendering::FillType fFillType; |
| 68 | bool fDoAA; |
| 69 | GrProcessorSet fProcessorSet; |
| 70 | |
| 71 | typedef GrDrawOp INHERITED; |
| 72 | }; |
| 73 | |
| 74 | class GrDrawPathOp final : public GrDrawPathOpBase { |
| 75 | public: |
| 76 | DEFINE_OP_CLASS_ID |
| 77 | |
| 78 | static std::unique_ptr<GrDrawOp> Make( |
| 79 | GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, sk_sp<const GrPath>); |
| 80 | |
| 81 | const char* name() const override { return "DrawPath" ; } |
| 82 | |
| 83 | #ifdef SK_DEBUG |
| 84 | SkString dumpInfo() const override; |
| 85 | #endif |
| 86 | |
| 87 | private: |
| 88 | friend class GrOpMemoryPool; // for ctor |
| 89 | |
| 90 | GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, sk_sp<const GrPath> path) |
| 91 | : GrDrawPathOpBase( |
| 92 | ClassID(), viewMatrix, std::move(paint), path->getFillType(), aa) |
| 93 | , fPath(std::move(path)) { |
| 94 | this->setTransformedBounds(fPath->getBounds(), viewMatrix, HasAABloat::kNo, |
| 95 | IsHairline::kNo); |
| 96 | } |
| 97 | |
| 98 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
| 99 | |
| 100 | sk_sp<const GrPath> fPath; |
| 101 | |
| 102 | typedef GrDrawPathOpBase INHERITED; |
| 103 | }; |
| 104 | |
| 105 | #endif |
| 106 | |