blob: d7f2cc298c42720b4b3fad404ae0132ecf4f01f7 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#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"
bsalomonadd79ef2015-08-19 13:26:49 -070018
Brian Salomon54d212e2017-03-21 14:22:38 -040019class GrPaint;
Robert Phillipsb97da532019-02-12 15:24:12 -050020class GrRecordingContext;
Brian Salomon54d212e2017-03-21 14:22:38 -040021
Brian Salomon82c263f2016-12-15 09:54:06 -050022class GrDrawPathOpBase : public GrDrawOp {
bsalomon1fcc01c2015-09-09 09:48:06 -070023protected:
Brian Salomon48d1b4c2017-04-08 07:38:53 -040024 GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&&,
Chris Dalton09e56892019-03-13 00:22:01 -060025 GrPathRendering::FillType, GrAA);
Robert Phillipsb493eeb2017-09-13 13:10:52 -040026
Brian Salomon54d212e2017-03-21 14:22:38 -040027 FixedFunctionFlags fixedFunctionFlags() const override {
Chris Dalton09e56892019-03-13 00:22:01 -060028 return (fDoAA)
29 ? FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil
30 : FixedFunctionFlags::kUsesStencil;
Brian Salomonc48af932017-03-16 19:51:42 +000031 }
Chris Dalton6ce447a2019-06-23 18:07:38 -060032 GrProcessorSet::Analysis finalize(
33 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
34 GrClampType clampType) override {
35 return this->doProcessorAnalysis(caps, clip, hasMixedSampledCoverage, clampType);
Brian Salomon54d212e2017-03-21 14:22:38 -040036 }
37
Chris Dalton1706cbf2019-05-21 19:35:29 -060038 void visitProxies(const VisitProxyFunc& func) const override {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040039 fProcessorSet.visitProxies(func);
40 }
41
Brian Salomon92aee3d2016-12-21 09:20:25 -050042protected:
joshualittf2384692015-09-10 11:00:51 -070043 const SkMatrix& viewMatrix() const { return fViewMatrix; }
Brian Osmancf860852018-10-31 14:04:39 -040044 const SkPMColor4f& color() const { return fInputColor; }
cdalton193d9cf2016-05-12 11:52:02 -070045 GrPathRendering::FillType fillType() const { return fFillType; }
Robert Phillips3968fcb2019-12-05 16:40:31 -050046 bool doAA() const { return fDoAA; }
Brian Salomon54d212e2017-03-21 14:22:38 -040047 const GrProcessorSet& processors() const { return fProcessorSet; }
Robert Phillips3968fcb2019-12-05 16:40:31 -050048 GrProcessorSet detachProcessorSet() { return std::move(fProcessorSet); }
Chris Daltonb8fff0d2019-03-05 10:11:58 -070049 const GrProcessorSet::Analysis& doProcessorAnalysis(
Chris Dalton6ce447a2019-06-23 18:07:38 -060050 const GrCaps&, const GrAppliedClip*, bool hasMixedSampledCoverage, GrClampType);
Brian Salomona811b122017-03-30 08:21:32 -040051 const GrProcessorSet::Analysis& processorAnalysis() const {
Brian Salomon48d1b4c2017-04-08 07:38:53 -040052 SkASSERT(fAnalysis.isInitialized());
Brian Salomon54d212e2017-03-21 14:22:38 -040053 return fAnalysis;
54 }
joshualittf2384692015-09-10 11:00:51 -070055
bsalomon1fcc01c2015-09-09 09:48:06 -070056private:
Robert Phillipsc655c3a2020-03-18 13:23:45 -040057 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -040058 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040059 GrAppliedClip*,
60 const GrXferProcessor::DstProxyView&) final {}
61
Brian Salomon54d212e2017-03-21 14:22:38 -040062 void onPrepare(GrOpFlushState*) final {}
cdalton193d9cf2016-05-12 11:52:02 -070063
Brian Salomon82c263f2016-12-15 09:54:06 -050064 SkMatrix fViewMatrix;
Brian Osmancf860852018-10-31 14:04:39 -040065 SkPMColor4f fInputColor;
Brian Salomona811b122017-03-30 08:21:32 -040066 GrProcessorSet::Analysis fAnalysis;
Brian Salomon82c263f2016-12-15 09:54:06 -050067 GrPathRendering::FillType fFillType;
Chris Dalton09e56892019-03-13 00:22:01 -060068 bool fDoAA;
Brian Salomon611572c2017-04-28 08:57:12 -040069 GrProcessorSet fProcessorSet;
bsalomon1fcc01c2015-09-09 09:48:06 -070070
Brian Salomon9afd3712016-12-01 10:59:09 -050071 typedef GrDrawOp INHERITED;
bsalomon1fcc01c2015-09-09 09:48:06 -070072};
73
Brian Salomon82c263f2016-12-15 09:54:06 -050074class GrDrawPathOp final : public GrDrawPathOpBase {
bsalomon1fcc01c2015-09-09 09:48:06 -070075public:
Brian Salomon25a88092016-12-01 09:36:50 -050076 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070077
Chris Dalton09e56892019-03-13 00:22:01 -060078 static std::unique_ptr<GrDrawOp> Make(
Robert Phillipse1efd382019-08-21 10:07:10 -040079 GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, sk_sp<const GrPath>);
bsalomonadd79ef2015-08-19 13:26:49 -070080
81 const char* name() const override { return "DrawPath"; }
82
Brian Osman9a390ac2018-11-12 09:47:48 -050083#ifdef SK_DEBUG
bsalomon1fcc01c2015-09-09 09:48:06 -070084 SkString dumpInfo() const override;
Brian Osman9a390ac2018-11-12 09:47:48 -050085#endif
bsalomonadd79ef2015-08-19 13:26:49 -070086
87private:
Robert Phillips7c525e62018-06-12 10:11:12 -040088 friend class GrOpMemoryPool; // for ctor
89
Robert Phillipse1efd382019-08-21 10:07:10 -040090 GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, sk_sp<const GrPath> path)
Chris Dalton09e56892019-03-13 00:22:01 -060091 : GrDrawPathOpBase(
92 ClassID(), viewMatrix, std::move(paint), path->getFillType(), aa)
Robert Phillipse1efd382019-08-21 10:07:10 -040093 , fPath(std::move(path)) {
Greg Daniel5faf4742019-10-01 15:14:44 -040094 this->setTransformedBounds(fPath->getBounds(), viewMatrix, HasAABloat::kNo,
95 IsHairline::kNo);
bsalomonadd79ef2015-08-19 13:26:49 -070096 }
stephana1dc17212016-04-25 07:01:22 -070097
Brian Salomon588cec72018-11-14 13:56:37 -050098 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
bsalomon1fcc01c2015-09-09 09:48:06 -070099
Robert Phillipse1efd382019-08-21 10:07:10 -0400100 sk_sp<const GrPath> fPath;
stephana1dc17212016-04-25 07:01:22 -0700101
Brian Salomon82c263f2016-12-15 09:54:06 -0500102 typedef GrDrawPathOpBase INHERITED;
bsalomon1fcc01c2015-09-09 09:48:06 -0700103};
104
bsalomonadd79ef2015-08-19 13:26:49 -0700105#endif