blob: d6700d36ec4e02687dd4575fbba416599544e5de [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();
Robert Phillips405413f2019-10-04 10:39:28 -040053 args.fDstProxy = state.drawOpArgs().dstProxy();
54 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();
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 Phillipse1efd382019-08-21 10:07:10 -040083 sk_sp<const GrPath> path) {
Robert Phillips9da87e02019-02-04 13:26:26 -050084 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040085
Robert Phillipse1efd382019-08-21 10:07:10 -040086 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, std::move(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
Robert Phillips901aff02019-10-08 12:32:56 -040096 GrProgramInfo programInfo(state->drawOpArgs().numSamples(),
97 state->drawOpArgs().origin(),
98 pipeline,
99 *pathProc,
100 &fixedDynamicState,
101 nullptr);
102
Brian Salomon54d212e2017-03-21 14:22:38 -0400103 GrStencilSettings stencil;
104 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Robert Phillipsd0fe8752019-01-31 14:13:59 -0500105 state->gpu()->pathRendering()->drawPath(state->drawOpArgs().renderTarget(),
Robert Phillips901aff02019-10-08 12:32:56 -0400106 programInfo, stencil, fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -0400107}
108
109//////////////////////////////////////////////////////////////////////////////
110
cdaltoncdd46822015-12-08 10:48:31 -0800111inline void pre_translate_transform_values(const float* xforms,
112 GrPathRendering::PathTransformType type, int count,
113 SkScalar x, SkScalar y, float* dst) {
114 if (0 == x && 0 == y) {
115 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -0700116 return;
117 }
cdaltoncdd46822015-12-08 10:48:31 -0800118 switch (type) {
119 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400120 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800121 break;
122 case GrPathRendering::kTranslateX_PathTransformType:
123 SkASSERT(0 == y);
124 for (int i = 0; i < count; i++) {
125 dst[i] = xforms[i] + x;
126 }
127 break;
128 case GrPathRendering::kTranslateY_PathTransformType:
129 SkASSERT(0 == x);
130 for (int i = 0; i < count; i++) {
131 dst[i] = xforms[i] + y;
132 }
133 break;
134 case GrPathRendering::kTranslate_PathTransformType:
135 for (int i = 0; i < 2 * count; i += 2) {
136 dst[i] = xforms[i] + x;
137 dst[i + 1] = xforms[i + 1] + y;
138 }
139 break;
140 case GrPathRendering::kAffine_PathTransformType:
141 for (int i = 0; i < 6 * count; i += 6) {
142 dst[i] = xforms[i];
143 dst[i + 1] = xforms[i + 1];
144 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
145 dst[i + 3] = xforms[i + 3];
146 dst[i + 4] = xforms[i + 4];
147 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
148 }
149 break;
150 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400151 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800152 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700153 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700154}