blob: 51f529162f5f8caddc89e55f7601bec07abdaf52 [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();
Robert Phillipsff2f3802019-11-18 16:36:54 -050092
93 GrPipeline::FixedDynamicState* fixedDynamicState = nullptr, storage;
94
95 if (appliedClip.scissorState().enabled()) {
96 storage.fScissorRect = appliedClip.scissorState().rect();
97 fixedDynamicState = &storage;
98 }
99
Brian Salomonbfd18cd2017-08-09 16:27:09 -0400100 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -0400101 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -0400102 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -0400103
Chris Dalton5e8cdfd2019-11-11 15:23:30 -0700104 GrProgramInfo programInfo(state->proxy()->numSamples(),
105 state->proxy()->numStencilSamples(),
Robert Phillips901aff02019-10-08 12:32:56 -0400106 state->drawOpArgs().origin(),
Robert Phillips67a625e2019-11-15 15:37:07 -0500107 &pipeline,
108 pathProc.get(),
Robert Phillipsff2f3802019-11-18 16:36:54 -0500109 fixedDynamicState,
Robert Phillipscea290f2019-11-06 11:21:03 -0500110 nullptr, 0,
111 GrPrimitiveType::kPath);
Robert Phillips901aff02019-10-08 12:32:56 -0400112
Brian Salomon54d212e2017-03-21 14:22:38 -0400113 GrStencilSettings stencil;
114 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Chris Dalton5e8cdfd2019-11-11 15:23:30 -0700115 state->gpu()->pathRendering()->drawPath(state->drawOpArgs().proxy()->peekRenderTarget(),
Robert Phillips901aff02019-10-08 12:32:56 -0400116 programInfo, stencil, fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -0400117}
118
119//////////////////////////////////////////////////////////////////////////////
120
cdaltoncdd46822015-12-08 10:48:31 -0800121inline void pre_translate_transform_values(const float* xforms,
122 GrPathRendering::PathTransformType type, int count,
123 SkScalar x, SkScalar y, float* dst) {
124 if (0 == x && 0 == y) {
125 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -0700126 return;
127 }
cdaltoncdd46822015-12-08 10:48:31 -0800128 switch (type) {
129 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400130 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800131 break;
132 case GrPathRendering::kTranslateX_PathTransformType:
133 SkASSERT(0 == y);
134 for (int i = 0; i < count; i++) {
135 dst[i] = xforms[i] + x;
136 }
137 break;
138 case GrPathRendering::kTranslateY_PathTransformType:
139 SkASSERT(0 == x);
140 for (int i = 0; i < count; i++) {
141 dst[i] = xforms[i] + y;
142 }
143 break;
144 case GrPathRendering::kTranslate_PathTransformType:
145 for (int i = 0; i < 2 * count; i += 2) {
146 dst[i] = xforms[i] + x;
147 dst[i + 1] = xforms[i + 1] + y;
148 }
149 break;
150 case GrPathRendering::kAffine_PathTransformType:
151 for (int i = 0; i < 6 * count; i += 6) {
152 dst[i] = xforms[i];
153 dst[i + 1] = xforms[i + 1];
154 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
155 dst[i + 3] = xforms[i + 3];
156 dst[i + 4] = xforms[i + 4];
157 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
158 }
159 break;
160 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400161 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800162 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700163 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700164}