blob: 8f671048295236090bed99872fa566c3d73edf8c [file] [log] [blame]
bsalomonadd79ef2015-08-19 13:26:49 -07001/*
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
Brian Salomon82c263f2016-12-15 09:54:06 -05008#ifndef GrDrawPathOp_DEFINED
9#define GrDrawPathOp_DEFINED
bsalomonadd79ef2015-08-19 13:26:49 -070010
Brian Salomon9afd3712016-12-01 10:59:09 -050011#include "GrDrawOp.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050012#include "GrOpFlushState.h"
bsalomonadd79ef2015-08-19 13:26:49 -070013#include "GrPath.h"
bsalomonadd79ef2015-08-19 13:26:49 -070014#include "GrPathProcessor.h"
Brian Salomon742e31d2016-12-07 17:06:19 -050015#include "GrPathRendering.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040016#include "GrProcessorSet.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070017#include "GrStencilSettings.h"
bsalomonadd79ef2015-08-19 13:26:49 -070018
Brian Salomon54d212e2017-03-21 14:22:38 -040019class GrPaint;
20
Brian Salomon82c263f2016-12-15 09:54:06 -050021class GrDrawPathOpBase : public GrDrawOp {
bsalomon1fcc01c2015-09-09 09:48:06 -070022protected:
Brian Salomon48d1b4c2017-04-08 07:38:53 -040023 GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&&,
24 GrPathRendering::FillType, GrAAType);
Robert Phillipsb493eeb2017-09-13 13:10:52 -040025
Brian Salomon54d212e2017-03-21 14:22:38 -040026 FixedFunctionFlags fixedFunctionFlags() const override {
Brian Salomon48d1b4c2017-04-08 07:38:53 -040027 if (GrAATypeIsHW(fAAType)) {
28 return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil;
29 }
30 return FixedFunctionFlags::kUsesStencil;
Brian Salomonc48af932017-03-16 19:51:42 +000031 }
Chris Dalton4b62aed2019-01-15 11:53:00 -070032 GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
33 return this->doProcessorAnalysis(caps, clip);
Brian Salomon54d212e2017-03-21 14:22:38 -040034 }
35
Brian Salomon7d94bb52018-10-12 14:37:19 -040036 void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040037 fProcessorSet.visitProxies(func);
38 }
39
Brian Salomon92aee3d2016-12-21 09:20:25 -050040protected:
joshualittf2384692015-09-10 11:00:51 -070041 const SkMatrix& viewMatrix() const { return fViewMatrix; }
Brian Osmancf860852018-10-31 14:04:39 -040042 const SkPMColor4f& color() const { return fInputColor; }
cdalton193d9cf2016-05-12 11:52:02 -070043 GrPathRendering::FillType fillType() const { return fFillType; }
Brian Salomon54d212e2017-03-21 14:22:38 -040044 const GrProcessorSet& processors() const { return fProcessorSet; }
Brian Salomon91326c32017-08-09 16:02:19 -040045 GrProcessorSet detachProcessors() { return std::move(fProcessorSet); }
Brian Salomon972b2f62017-07-31 12:37:02 -040046 inline GrPipeline::InitArgs pipelineInitArgs(const GrOpFlushState&);
Brian Salomona811b122017-03-30 08:21:32 -040047 const GrProcessorSet::Analysis& doProcessorAnalysis(const GrCaps& caps,
Brian Osman532b3f92018-07-11 10:02:07 -040048 const GrAppliedClip* clip) {
Brian Salomon48d1b4c2017-04-08 07:38:53 -040049 bool isMixedSamples = GrAAType::kMixedSamples == fAAType;
50 fAnalysis = fProcessorSet.finalize(fInputColor, GrProcessorAnalysisCoverage::kNone, clip,
Brian Osman532b3f92018-07-11 10:02:07 -040051 isMixedSamples, caps, &fInputColor);
Brian Salomon54d212e2017-03-21 14:22:38 -040052 return fAnalysis;
53 }
Brian Salomona811b122017-03-30 08:21:32 -040054 const GrProcessorSet::Analysis& processorAnalysis() const {
Brian Salomon48d1b4c2017-04-08 07:38:53 -040055 SkASSERT(fAnalysis.isInitialized());
Brian Salomon54d212e2017-03-21 14:22:38 -040056 return fAnalysis;
57 }
joshualittf2384692015-09-10 11:00:51 -070058
bsalomon1fcc01c2015-09-09 09:48:06 -070059private:
Brian Salomon54d212e2017-03-21 14:22:38 -040060 void onPrepare(GrOpFlushState*) final {}
cdalton193d9cf2016-05-12 11:52:02 -070061
Brian Salomon82c263f2016-12-15 09:54:06 -050062 SkMatrix fViewMatrix;
Brian Osmancf860852018-10-31 14:04:39 -040063 SkPMColor4f fInputColor;
Brian Salomona811b122017-03-30 08:21:32 -040064 GrProcessorSet::Analysis fAnalysis;
Brian Salomon82c263f2016-12-15 09:54:06 -050065 GrPathRendering::FillType fFillType;
Brian Salomon48d1b4c2017-04-08 07:38:53 -040066 GrAAType fAAType;
Brian Salomon611572c2017-04-28 08:57:12 -040067 GrProcessorSet fProcessorSet;
bsalomon1fcc01c2015-09-09 09:48:06 -070068
Brian Salomon9afd3712016-12-01 10:59:09 -050069 typedef GrDrawOp INHERITED;
bsalomon1fcc01c2015-09-09 09:48:06 -070070};
71
Brian Salomon82c263f2016-12-15 09:54:06 -050072class GrDrawPathOp final : public GrDrawPathOpBase {
bsalomon1fcc01c2015-09-09 09:48:06 -070073public:
Brian Salomon25a88092016-12-01 09:36:50 -050074 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070075
Robert Phillips7c525e62018-06-12 10:11:12 -040076 static std::unique_ptr<GrDrawOp> Make(GrContext*,
77 const SkMatrix& viewMatrix,
78 GrPaint&&,
79 GrAAType,
80 GrPath*);
bsalomonadd79ef2015-08-19 13:26:49 -070081
82 const char* name() const override { return "DrawPath"; }
83
Brian Osman9a390ac2018-11-12 09:47:48 -050084#ifdef SK_DEBUG
bsalomon1fcc01c2015-09-09 09:48:06 -070085 SkString dumpInfo() const override;
Brian Osman9a390ac2018-11-12 09:47:48 -050086#endif
bsalomonadd79ef2015-08-19 13:26:49 -070087
88private:
Robert Phillips7c525e62018-06-12 10:11:12 -040089 friend class GrOpMemoryPool; // for ctor
90
Brian Salomon48d1b4c2017-04-08 07:38:53 -040091 GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAAType aaType, const GrPath* path)
92 : GrDrawPathOpBase(ClassID(), viewMatrix, std::move(paint), path->getFillType(), aaType)
Brian Salomon54d212e2017-03-21 14:22:38 -040093 , fPath(path) {
bsalomon88cf17d2016-07-08 06:40:56 -070094 this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
bsalomonadd79ef2015-08-19 13:26:49 -070095 }
stephana1dc17212016-04-25 07:01:22 -070096
Brian Salomon588cec72018-11-14 13:56:37 -050097 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
bsalomon1fcc01c2015-09-09 09:48:06 -070098
99 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
stephana1dc17212016-04-25 07:01:22 -0700100
Brian Salomon82c263f2016-12-15 09:54:06 -0500101 typedef GrDrawPathOpBase INHERITED;
bsalomon1fcc01c2015-09-09 09:48:06 -0700102};
103
bsalomonadd79ef2015-08-19 13:26:49 -0700104#endif