blob: c0cc4d49d9d86cd9e255407173678bf7da1923e9 [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"
Robert Phillips901aff02019-10-08 12:32:56 -040012#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrRecordingContextPriv.h"
14#include "src/gpu/GrRenderTargetContext.h"
15#include "src/gpu/GrRenderTargetPriv.h"
16#include "src/gpu/ops/GrDrawPathOp.h"
Brian Salomonc48af932017-03-16 19:51:42 +000017
Chris Daltonb8fff0d2019-03-05 10:11:58 -070018static constexpr GrUserStencilSettings kCoverPass{
19 GrUserStencilSettings::StaticInit<
20 0x0000,
21 GrUserStencilTest::kNotEqual,
22 0xffff,
23 GrUserStencilOp::kZero,
24 GrUserStencilOp::kKeep,
25 0xffff>()
26};
27
Brian Salomon54d212e2017-03-21 14:22:38 -040028GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060029 GrPathRendering::FillType fill, GrAA aa)
Brian Salomon54d212e2017-03-21 14:22:38 -040030 : INHERITED(classID)
31 , fViewMatrix(viewMatrix)
Brian Osmancf860852018-10-31 14:04:39 -040032 , fInputColor(paint.getColor4f())
Brian Salomon54d212e2017-03-21 14:22:38 -040033 , fFillType(fill)
Chris Dalton09e56892019-03-13 00:22:01 -060034 , fDoAA(GrAA::kYes == aa)
Brian Salomon611572c2017-04-28 08:57:12 -040035 , fProcessorSet(std::move(paint)) {}
cdalton193d9cf2016-05-12 11:52:02 -070036
Brian Osman9a390ac2018-11-12 09:47:48 -050037#ifdef SK_DEBUG
Brian Salomon82c263f2016-12-15 09:54:06 -050038SkString GrDrawPathOp::dumpInfo() const {
bsalomon1fcc01c2015-09-09 09:48:06 -070039 SkString string;
stephana1dc17212016-04-25 07:01:22 -070040 string.printf("PATH: 0x%p", fPath.get());
robertphillips44fbc792016-06-29 06:56:12 -070041 string.append(INHERITED::dumpInfo());
bsalomon1fcc01c2015-09-09 09:48:06 -070042 return string;
43}
Brian Osman9a390ac2018-11-12 09:47:48 -050044#endif
bsalomon1fcc01c2015-09-09 09:48:06 -070045
Brian Salomon972b2f62017-07-31 12:37:02 -040046GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& state) {
Brian Salomon54d212e2017-03-21 14:22:38 -040047 GrPipeline::InitArgs args;
Chris Dalton09e56892019-03-13 00:22:01 -060048 if (fDoAA) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060049 args.fInputFlags |= GrPipeline::InputFlags::kHWAntialias;
Brian Salomon611572c2017-04-28 08:57:12 -040050 }
Brian Salomon54d212e2017-03-21 14:22:38 -040051 args.fUserStencil = &kCoverPass;
Brian Salomon54d212e2017-03-21 14:22:38 -040052 args.fCaps = &state.caps();
Greg Daniel524e28b2019-11-01 11:48:53 -040053 args.fDstProxyView = state.drawOpArgs().dstProxyView();
Robert Phillips405413f2019-10-04 10:39:28 -040054 args.fOutputSwizzle = state.drawOpArgs().outputSwizzle();
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(
Chris Dalton6ce447a2019-06-23 18:07:38 -060059 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
Brian Osman5ced0bf2019-03-15 10:15:29 -040060 GrClampType clampType) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070061 fAnalysis = fProcessorSet.finalize(
Chris Dalton6ce447a2019-06-23 18:07:38 -060062 fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass,
63 hasMixedSampledCoverage, caps, 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) {
Robert Phillips405413f2019-10-04 10:39:28 -040071 const GrAppliedClip* appliedClip = flushState.drawOpArgs().appliedClip();
Brian Salomon54d212e2017-03-21 14:22:38 -040072 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
Chris Dalton5e8cdfd2019-11-11 15:23:30 -070073 GrRenderTarget* rt = flushState.drawOpArgs().proxy()->peekRenderTarget();
Brian Salomon54d212e2017-03-21 14:22:38 -040074 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Chris Dalton5e8cdfd2019-11-11 15:23:30 -070075 rt->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040076}
77
78//////////////////////////////////////////////////////////////////////////////
79
Robert Phillipsb97da532019-02-12 15:24:12 -050080std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040081 const SkMatrix& viewMatrix,
82 GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060083 GrAA aa,
Robert Phillipse1efd382019-08-21 10:07:10 -040084 sk_sp<const GrPath> path) {
Robert Phillips9da87e02019-02-04 13:26:26 -050085 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040086
Robert Phillipse1efd382019-08-21 10:07:10 -040087 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, std::move(path));
Robert Phillips7c525e62018-06-12 10:11:12 -040088}
89
Brian Salomon588cec72018-11-14 13:56:37 -050090void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Brian Salomon49348902018-06-26 09:12:38 -040091 GrAppliedClip appliedClip = state->detachAppliedClip();
92 GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
Brian Salomonbfd18cd2017-08-09 16:27:09 -040093 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -040094 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -040095 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040096
Chris Dalton5e8cdfd2019-11-11 15:23:30 -070097 GrProgramInfo programInfo(state->proxy()->numSamples(),
98 state->proxy()->numStencilSamples(),
Robert Phillips901aff02019-10-08 12:32:56 -040099 state->drawOpArgs().origin(),
Robert Phillips67a625e2019-11-15 15:37:07 -0500100 &pipeline,
101 pathProc.get(),
Robert Phillips901aff02019-10-08 12:32:56 -0400102 &fixedDynamicState,
Robert Phillipscea290f2019-11-06 11:21:03 -0500103 nullptr, 0,
104 GrPrimitiveType::kPath);
Robert Phillips901aff02019-10-08 12:32:56 -0400105
Brian Salomon54d212e2017-03-21 14:22:38 -0400106 GrStencilSettings stencil;
107 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Chris Dalton5e8cdfd2019-11-11 15:23:30 -0700108 state->gpu()->pathRendering()->drawPath(state->drawOpArgs().proxy()->peekRenderTarget(),
Robert Phillips901aff02019-10-08 12:32:56 -0400109 programInfo, stencil, fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -0400110}
111
112//////////////////////////////////////////////////////////////////////////////
113
cdaltoncdd46822015-12-08 10:48:31 -0800114inline void pre_translate_transform_values(const float* xforms,
115 GrPathRendering::PathTransformType type, int count,
116 SkScalar x, SkScalar y, float* dst) {
117 if (0 == x && 0 == y) {
118 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -0700119 return;
120 }
cdaltoncdd46822015-12-08 10:48:31 -0800121 switch (type) {
122 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400123 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800124 break;
125 case GrPathRendering::kTranslateX_PathTransformType:
126 SkASSERT(0 == y);
127 for (int i = 0; i < count; i++) {
128 dst[i] = xforms[i] + x;
129 }
130 break;
131 case GrPathRendering::kTranslateY_PathTransformType:
132 SkASSERT(0 == x);
133 for (int i = 0; i < count; i++) {
134 dst[i] = xforms[i] + y;
135 }
136 break;
137 case GrPathRendering::kTranslate_PathTransformType:
138 for (int i = 0; i < 2 * count; i += 2) {
139 dst[i] = xforms[i] + x;
140 dst[i + 1] = xforms[i + 1] + y;
141 }
142 break;
143 case GrPathRendering::kAffine_PathTransformType:
144 for (int i = 0; i < 6 * count; i += 6) {
145 dst[i] = xforms[i];
146 dst[i + 1] = xforms[i + 1];
147 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
148 dst[i + 3] = xforms[i + 3];
149 dst[i + 4] = xforms[i + 4];
150 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
151 }
152 break;
153 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400154 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800155 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700156 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700157}