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 fixedFunctionFlags()27 FixedFunctionFlags fixedFunctionFlags() const override { 28 return (fDoAA) 29 ? FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil 30 : FixedFunctionFlags::kUsesStencil; 31 } finalize(const GrCaps & caps,const GrAppliedClip * clip,bool hasMixedSampledCoverage,GrClampType clampType)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 visitProxies(const VisitProxyFunc & func)38 void visitProxies(const VisitProxyFunc& func) const override { 39 fProcessorSet.visitProxies(func); 40 } 41 42 protected: viewMatrix()43 const SkMatrix& viewMatrix() const { return fViewMatrix; } color()44 const SkPMColor4f& color() const { return fInputColor; } fillType()45 GrPathRendering::FillType fillType() const { return fFillType; } processors()46 const GrProcessorSet& processors() const { return fProcessorSet; } detachProcessors()47 GrProcessorSet detachProcessors() { return std::move(fProcessorSet); } 48 inline GrPipeline::InitArgs pipelineInitArgs(const GrOpFlushState&); 49 const GrProcessorSet::Analysis& doProcessorAnalysis( 50 const GrCaps&, const GrAppliedClip*, bool hasMixedSampledCoverage, GrClampType); processorAnalysis()51 const GrProcessorSet::Analysis& processorAnalysis() const { 52 SkASSERT(fAnalysis.isInitialized()); 53 return fAnalysis; 54 } 55 56 private: onPrepare(GrOpFlushState *)57 void onPrepare(GrOpFlushState*) final {} 58 59 SkMatrix fViewMatrix; 60 SkPMColor4f fInputColor; 61 GrProcessorSet::Analysis fAnalysis; 62 GrPathRendering::FillType fFillType; 63 bool fDoAA; 64 GrProcessorSet fProcessorSet; 65 66 typedef GrDrawOp INHERITED; 67 }; 68 69 class GrDrawPathOp final : public GrDrawPathOpBase { 70 public: 71 DEFINE_OP_CLASS_ID 72 73 static std::unique_ptr<GrDrawOp> Make( 74 GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, GrPath*); 75 name()76 const char* name() const override { return "DrawPath"; } 77 78 #ifdef SK_DEBUG 79 SkString dumpInfo() const override; 80 #endif 81 82 private: 83 friend class GrOpMemoryPool; // for ctor 84 GrDrawPathOp(const SkMatrix & viewMatrix,GrPaint && paint,GrAA aa,const GrPath * path)85 GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, const GrPath* path) 86 : GrDrawPathOpBase( 87 ClassID(), viewMatrix, std::move(paint), path->getFillType(), aa) 88 , fPath(path) { 89 this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); 90 } 91 92 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; 93 94 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; 95 96 typedef GrDrawPathOpBase INHERITED; 97 }; 98 99 #endif 100