blob: fd9631b761cafa67f20a72388fb1c66595668a54 [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; }
Brian Salomon54d212e2017-03-21 14:22:38 -040046 const GrProcessorSet& processors() const { return fProcessorSet; }
Brian Salomon91326c32017-08-09 16:02:19 -040047 GrProcessorSet detachProcessors() { return std::move(fProcessorSet); }
Brian Salomon972b2f62017-07-31 12:37:02 -040048 inline GrPipeline::InitArgs pipelineInitArgs(const GrOpFlushState&);
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:
Brian Salomon54d212e2017-03-21 14:22:38 -040057 void onPrepare(GrOpFlushState*) final {}
cdalton193d9cf2016-05-12 11:52:02 -070058
Brian Salomon82c263f2016-12-15 09:54:06 -050059 SkMatrix fViewMatrix;
Brian Osmancf860852018-10-31 14:04:39 -040060 SkPMColor4f fInputColor;
Brian Salomona811b122017-03-30 08:21:32 -040061 GrProcessorSet::Analysis fAnalysis;
Brian Salomon82c263f2016-12-15 09:54:06 -050062 GrPathRendering::FillType fFillType;
Chris Dalton09e56892019-03-13 00:22:01 -060063 bool fDoAA;
Brian Salomon611572c2017-04-28 08:57:12 -040064 GrProcessorSet fProcessorSet;
bsalomon1fcc01c2015-09-09 09:48:06 -070065
Brian Salomon9afd3712016-12-01 10:59:09 -050066 typedef GrDrawOp INHERITED;
bsalomon1fcc01c2015-09-09 09:48:06 -070067};
68
Brian Salomon82c263f2016-12-15 09:54:06 -050069class GrDrawPathOp final : public GrDrawPathOpBase {
bsalomon1fcc01c2015-09-09 09:48:06 -070070public:
Brian Salomon25a88092016-12-01 09:36:50 -050071 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070072
Chris Dalton09e56892019-03-13 00:22:01 -060073 static std::unique_ptr<GrDrawOp> Make(
Robert Phillipse1efd382019-08-21 10:07:10 -040074 GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, sk_sp<const GrPath>);
bsalomonadd79ef2015-08-19 13:26:49 -070075
76 const char* name() const override { return "DrawPath"; }
77
Brian Osman9a390ac2018-11-12 09:47:48 -050078#ifdef SK_DEBUG
bsalomon1fcc01c2015-09-09 09:48:06 -070079 SkString dumpInfo() const override;
Brian Osman9a390ac2018-11-12 09:47:48 -050080#endif
bsalomonadd79ef2015-08-19 13:26:49 -070081
82private:
Robert Phillips7c525e62018-06-12 10:11:12 -040083 friend class GrOpMemoryPool; // for ctor
84
Robert Phillipse1efd382019-08-21 10:07:10 -040085 GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, sk_sp<const GrPath> path)
Chris Dalton09e56892019-03-13 00:22:01 -060086 : GrDrawPathOpBase(
87 ClassID(), viewMatrix, std::move(paint), path->getFillType(), aa)
Robert Phillipse1efd382019-08-21 10:07:10 -040088 , fPath(std::move(path)) {
89 this->setTransformedBounds(fPath->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
bsalomonadd79ef2015-08-19 13:26:49 -070090 }
stephana1dc17212016-04-25 07:01:22 -070091
Brian Salomon588cec72018-11-14 13:56:37 -050092 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
bsalomon1fcc01c2015-09-09 09:48:06 -070093
Robert Phillipse1efd382019-08-21 10:07:10 -040094 sk_sp<const GrPath> fPath;
stephana1dc17212016-04-25 07:01:22 -070095
Brian Salomon82c263f2016-12-15 09:54:06 -050096 typedef GrDrawPathOpBase INHERITED;
bsalomon1fcc01c2015-09-09 09:48:06 -070097};
98
bsalomonadd79ef2015-08-19 13:26:49 -070099#endif