blob: 57f454660bdf56385cebec863ba7490da40041aa [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/GrRecordingContext.h"
9#include "include/private/SkTemplates.h"
10#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrMemoryPool.h"
12#include "src/gpu/GrRecordingContextPriv.h"
13#include "src/gpu/GrRenderTargetContext.h"
14#include "src/gpu/GrRenderTargetPriv.h"
15#include "src/gpu/ops/GrDrawPathOp.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;
Greg Daniel2c3398d2019-06-19 11:58:01 -040054 args.fOutputSwizzle = state.drawOpArgs().fOutputSwizzle;
Brian Salomon972b2f62017-07-31 12:37:02 -040055 return args;
Brian Salomon2bf4b3a2017-03-16 14:19:07 -040056}
57
Chris Daltonb8fff0d2019-03-05 10:11:58 -070058const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis(
Brian Osman5ced0bf2019-03-15 10:15:29 -040059 const GrCaps& caps, const GrAppliedClip* clip, GrFSAAType fsaaType,
60 GrClampType clampType) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070061 fAnalysis = fProcessorSet.finalize(
62 fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass, fsaaType, caps,
Brian Osman5ced0bf2019-03-15 10:15:29 -040063 clampType, &fInputColor);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070064 return fAnalysis;
65}
66
Brian Salomon54d212e2017-03-21 14:22:38 -040067//////////////////////////////////////////////////////////////////////////////
68
69void init_stencil_pass_settings(const GrOpFlushState& flushState,
70 GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
71 const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
72 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
73 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Robert Phillips2890fbf2017-07-26 15:48:41 -040074 flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040075}
76
77//////////////////////////////////////////////////////////////////////////////
78
Robert Phillipsb97da532019-02-12 15:24:12 -050079std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040080 const SkMatrix& viewMatrix,
81 GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060082 GrAA aa,
Robert Phillips7c525e62018-06-12 10:11:12 -040083 GrPath* path) {
Robert Phillips9da87e02019-02-04 13:26:26 -050084 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040085
Chris Dalton09e56892019-03-13 00:22:01 -060086 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, path);
Robert Phillips7c525e62018-06-12 10:11:12 -040087}
88
Brian Salomon588cec72018-11-14 13:56:37 -050089void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Brian Salomon49348902018-06-26 09:12:38 -040090 GrAppliedClip appliedClip = state->detachAppliedClip();
91 GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
Brian Salomonbfd18cd2017-08-09 16:27:09 -040092 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -040093 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -040094 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040095
96 GrStencilSettings stencil;
97 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Robert Phillipsd0fe8752019-01-31 14:13:59 -050098 state->gpu()->pathRendering()->drawPath(state->drawOpArgs().renderTarget(),
99 state->drawOpArgs().origin(),
100 *pathProc, pipeline, fixedDynamicState, stencil,
Brian Salomon49348902018-06-26 09:12:38 -0400101 fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -0400102}
103
104//////////////////////////////////////////////////////////////////////////////
105
cdaltoncdd46822015-12-08 10:48:31 -0800106inline void pre_translate_transform_values(const float* xforms,
107 GrPathRendering::PathTransformType type, int count,
108 SkScalar x, SkScalar y, float* dst) {
109 if (0 == x && 0 == y) {
110 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -0700111 return;
112 }
cdaltoncdd46822015-12-08 10:48:31 -0800113 switch (type) {
114 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400115 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800116 break;
117 case GrPathRendering::kTranslateX_PathTransformType:
118 SkASSERT(0 == y);
119 for (int i = 0; i < count; i++) {
120 dst[i] = xforms[i] + x;
121 }
122 break;
123 case GrPathRendering::kTranslateY_PathTransformType:
124 SkASSERT(0 == x);
125 for (int i = 0; i < count; i++) {
126 dst[i] = xforms[i] + y;
127 }
128 break;
129 case GrPathRendering::kTranslate_PathTransformType:
130 for (int i = 0; i < 2 * count; i += 2) {
131 dst[i] = xforms[i] + x;
132 dst[i + 1] = xforms[i + 1] + y;
133 }
134 break;
135 case GrPathRendering::kAffine_PathTransformType:
136 for (int i = 0; i < 6 * count; i += 6) {
137 dst[i] = xforms[i];
138 dst[i + 1] = xforms[i + 1];
139 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
140 dst[i + 3] = xforms[i + 3];
141 dst[i + 4] = xforms[i + 4];
142 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
143 }
144 break;
145 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400146 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800147 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700148 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700149}