blob: 72910a1faf36c49a13c299ee7b56449fe3aab00d [file] [log] [blame]
bsalomon1fcc01c2015-09-09 09:48:06 -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#include "GrDrawPathOp.h"
Brian Salomon54d212e2017-03-21 14:22:38 -04009#include "GrAppliedClip.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040010#include "GrMemoryPool.h"
Robert Phillipsb97da532019-02-12 15:24:12 -050011#include "GrRecordingContext.h"
12#include "GrRecordingContextPriv.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040013#include "GrRenderTargetContext.h"
Brian Salomonc48af932017-03-16 19:51:42 +000014#include "GrRenderTargetPriv.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040015#include "SkTemplates.h"
Brian Salomonc48af932017-03-16 19:51:42 +000016
Chris Daltonb8fff0d2019-03-05 10:11:58 -070017static constexpr GrUserStencilSettings kCoverPass{
18 GrUserStencilSettings::StaticInit<
19 0x0000,
20 GrUserStencilTest::kNotEqual,
21 0xffff,
22 GrUserStencilOp::kZero,
23 GrUserStencilOp::kKeep,
24 0xffff>()
25};
26
Brian Salomon54d212e2017-03-21 14:22:38 -040027GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060028 GrPathRendering::FillType fill, GrAA aa)
Brian Salomon54d212e2017-03-21 14:22:38 -040029 : INHERITED(classID)
30 , fViewMatrix(viewMatrix)
Brian Osmancf860852018-10-31 14:04:39 -040031 , fInputColor(paint.getColor4f())
Brian Salomon54d212e2017-03-21 14:22:38 -040032 , fFillType(fill)
Chris Dalton09e56892019-03-13 00:22:01 -060033 , fDoAA(GrAA::kYes == aa)
Brian Salomon611572c2017-04-28 08:57:12 -040034 , fProcessorSet(std::move(paint)) {}
cdalton193d9cf2016-05-12 11:52:02 -070035
Brian Osman9a390ac2018-11-12 09:47:48 -050036#ifdef SK_DEBUG
Brian Salomon82c263f2016-12-15 09:54:06 -050037SkString GrDrawPathOp::dumpInfo() const {
bsalomon1fcc01c2015-09-09 09:48:06 -070038 SkString string;
stephana1dc17212016-04-25 07:01:22 -070039 string.printf("PATH: 0x%p", fPath.get());
robertphillips44fbc792016-06-29 06:56:12 -070040 string.append(INHERITED::dumpInfo());
bsalomon1fcc01c2015-09-09 09:48:06 -070041 return string;
42}
Brian Osman9a390ac2018-11-12 09:47:48 -050043#endif
bsalomon1fcc01c2015-09-09 09:48:06 -070044
Brian Salomon972b2f62017-07-31 12:37:02 -040045GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& state) {
Brian Salomon54d212e2017-03-21 14:22:38 -040046 GrPipeline::InitArgs args;
Chris Dalton09e56892019-03-13 00:22:01 -060047 if (fDoAA) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060048 args.fInputFlags |= GrPipeline::InputFlags::kHWAntialias;
Brian Salomon611572c2017-04-28 08:57:12 -040049 }
Brian Salomon54d212e2017-03-21 14:22:38 -040050 args.fUserStencil = &kCoverPass;
Brian Salomon54d212e2017-03-21 14:22:38 -040051 args.fCaps = &state.caps();
Robert Phillips9bee2e52017-05-29 12:37:20 -040052 args.fResourceProvider = state.resourceProvider();
Robert Phillipsbb581ce2017-05-29 15:05:15 -040053 args.fDstProxy = state.drawOpArgs().fDstProxy;
Brian Salomon972b2f62017-07-31 12:37:02 -040054 return args;
Brian Salomon2bf4b3a2017-03-16 14:19:07 -040055}
56
Chris Daltonb8fff0d2019-03-05 10:11:58 -070057const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis(
Brian Osman5ced0bf2019-03-15 10:15:29 -040058 const GrCaps& caps, const GrAppliedClip* clip, GrFSAAType fsaaType,
59 GrClampType clampType) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070060 fAnalysis = fProcessorSet.finalize(
61 fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass, fsaaType, caps,
Brian Osman5ced0bf2019-03-15 10:15:29 -040062 clampType, &fInputColor);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070063 return fAnalysis;
64}
65
Brian Salomon54d212e2017-03-21 14:22:38 -040066//////////////////////////////////////////////////////////////////////////////
67
68void init_stencil_pass_settings(const GrOpFlushState& flushState,
69 GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
70 const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
71 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
72 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Robert Phillips2890fbf2017-07-26 15:48:41 -040073 flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040074}
75
76//////////////////////////////////////////////////////////////////////////////
77
Robert Phillipsb97da532019-02-12 15:24:12 -050078std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040079 const SkMatrix& viewMatrix,
80 GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060081 GrAA aa,
Robert Phillips7c525e62018-06-12 10:11:12 -040082 GrPath* path) {
Robert Phillips9da87e02019-02-04 13:26:26 -050083 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040084
Chris Dalton09e56892019-03-13 00:22:01 -060085 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, path);
Robert Phillips7c525e62018-06-12 10:11:12 -040086}
87
Brian Salomon588cec72018-11-14 13:56:37 -050088void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Brian Salomon49348902018-06-26 09:12:38 -040089 GrAppliedClip appliedClip = state->detachAppliedClip();
90 GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
Brian Salomonbfd18cd2017-08-09 16:27:09 -040091 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -040092 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -040093 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040094
95 GrStencilSettings stencil;
96 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Robert Phillipsd0fe8752019-01-31 14:13:59 -050097 state->gpu()->pathRendering()->drawPath(state->drawOpArgs().renderTarget(),
98 state->drawOpArgs().origin(),
99 *pathProc, pipeline, fixedDynamicState, stencil,
Brian Salomon49348902018-06-26 09:12:38 -0400100 fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -0400101}
102
103//////////////////////////////////////////////////////////////////////////////
104
cdaltoncdd46822015-12-08 10:48:31 -0800105inline void pre_translate_transform_values(const float* xforms,
106 GrPathRendering::PathTransformType type, int count,
107 SkScalar x, SkScalar y, float* dst) {
108 if (0 == x && 0 == y) {
109 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -0700110 return;
111 }
cdaltoncdd46822015-12-08 10:48:31 -0800112 switch (type) {
113 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400114 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800115 break;
116 case GrPathRendering::kTranslateX_PathTransformType:
117 SkASSERT(0 == y);
118 for (int i = 0; i < count; i++) {
119 dst[i] = xforms[i] + x;
120 }
121 break;
122 case GrPathRendering::kTranslateY_PathTransformType:
123 SkASSERT(0 == x);
124 for (int i = 0; i < count; i++) {
125 dst[i] = xforms[i] + y;
126 }
127 break;
128 case GrPathRendering::kTranslate_PathTransformType:
129 for (int i = 0; i < 2 * count; i += 2) {
130 dst[i] = xforms[i] + x;
131 dst[i + 1] = xforms[i + 1] + y;
132 }
133 break;
134 case GrPathRendering::kAffine_PathTransformType:
135 for (int i = 0; i < 6 * count; i += 6) {
136 dst[i] = xforms[i];
137 dst[i + 1] = xforms[i + 1];
138 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
139 dst[i + 3] = xforms[i + 3];
140 dst[i + 4] = xforms[i + 4];
141 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
142 }
143 break;
144 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400145 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800146 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700147 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700148}