blob: 4da6756681db33bdb4dc6ee76c37945ca467e579 [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"
Robert Phillips3968fcb2019-12-05 16:40:31 -050017#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Brian Salomonc48af932017-03-16 19:51:42 +000018
Chris Daltonb8fff0d2019-03-05 10:11:58 -070019static constexpr GrUserStencilSettings kCoverPass{
20 GrUserStencilSettings::StaticInit<
21 0x0000,
22 GrUserStencilTest::kNotEqual,
23 0xffff,
24 GrUserStencilOp::kZero,
25 GrUserStencilOp::kKeep,
26 0xffff>()
27};
28
Brian Salomon54d212e2017-03-21 14:22:38 -040029GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060030 GrPathRendering::FillType fill, GrAA aa)
Brian Salomon54d212e2017-03-21 14:22:38 -040031 : INHERITED(classID)
32 , fViewMatrix(viewMatrix)
Brian Osmancf860852018-10-31 14:04:39 -040033 , fInputColor(paint.getColor4f())
Brian Salomon54d212e2017-03-21 14:22:38 -040034 , fFillType(fill)
Chris Dalton09e56892019-03-13 00:22:01 -060035 , fDoAA(GrAA::kYes == aa)
Brian Salomon611572c2017-04-28 08:57:12 -040036 , fProcessorSet(std::move(paint)) {}
cdalton193d9cf2016-05-12 11:52:02 -070037
Brian Osman9a390ac2018-11-12 09:47:48 -050038#ifdef SK_DEBUG
Brian Salomon82c263f2016-12-15 09:54:06 -050039SkString GrDrawPathOp::dumpInfo() const {
bsalomon1fcc01c2015-09-09 09:48:06 -070040 SkString string;
stephana1dc17212016-04-25 07:01:22 -070041 string.printf("PATH: 0x%p", fPath.get());
robertphillips44fbc792016-06-29 06:56:12 -070042 string.append(INHERITED::dumpInfo());
bsalomon1fcc01c2015-09-09 09:48:06 -070043 return string;
44}
Brian Osman9a390ac2018-11-12 09:47:48 -050045#endif
bsalomon1fcc01c2015-09-09 09:48:06 -070046
Chris Daltonb8fff0d2019-03-05 10:11:58 -070047const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis(
Chris Dalton6ce447a2019-06-23 18:07:38 -060048 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
Brian Osman5ced0bf2019-03-15 10:15:29 -040049 GrClampType clampType) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070050 fAnalysis = fProcessorSet.finalize(
Chris Dalton6ce447a2019-06-23 18:07:38 -060051 fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass,
52 hasMixedSampledCoverage, caps, clampType, &fInputColor);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070053 return fAnalysis;
54}
55
Brian Salomon54d212e2017-03-21 14:22:38 -040056//////////////////////////////////////////////////////////////////////////////
57
58void init_stencil_pass_settings(const GrOpFlushState& flushState,
59 GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
Robert Phillips405413f2019-10-04 10:39:28 -040060 const GrAppliedClip* appliedClip = flushState.drawOpArgs().appliedClip();
Brian Salomon54d212e2017-03-21 14:22:38 -040061 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
Chris Dalton5e8cdfd2019-11-11 15:23:30 -070062 GrRenderTarget* rt = flushState.drawOpArgs().proxy()->peekRenderTarget();
Brian Salomon54d212e2017-03-21 14:22:38 -040063 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Chris Dalton5e8cdfd2019-11-11 15:23:30 -070064 rt->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040065}
66
67//////////////////////////////////////////////////////////////////////////////
68
Robert Phillipsb97da532019-02-12 15:24:12 -050069std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040070 const SkMatrix& viewMatrix,
71 GrPaint&& paint,
Chris Dalton09e56892019-03-13 00:22:01 -060072 GrAA aa,
Robert Phillipse1efd382019-08-21 10:07:10 -040073 sk_sp<const GrPath> path) {
Robert Phillips9da87e02019-02-04 13:26:26 -050074 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040075
Robert Phillipse1efd382019-08-21 10:07:10 -040076 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, std::move(path));
Robert Phillips7c525e62018-06-12 10:11:12 -040077}
78
Robert Phillips3968fcb2019-12-05 16:40:31 -050079void GrDrawPathOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
Robert Phillips3968fcb2019-12-05 16:40:31 -050080 GrPipeline::InputFlags pipelineFlags = GrPipeline::InputFlags::kNone;
81 if (this->doAA()) {
82 pipelineFlags |= GrPipeline::InputFlags::kHWAntialias;
83 }
84
85 auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState,
86 this->detachProcessorSet(),
87 pipelineFlags,
88 &kCoverPass);
89
Brian Salomone7d30482017-03-29 12:09:15 -040090 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040091
Robert Phillips3968fcb2019-12-05 16:40:31 -050092 GrRenderTargetProxy* proxy = flushState->proxy();
93 GrProgramInfo programInfo(proxy->numSamples(),
94 proxy->numStencilSamples(),
95 proxy->backendFormat(),
Brian Salomon8afde5f2020-04-01 16:22:00 -040096 flushState->writeView()->origin(),
Robert Phillips3968fcb2019-12-05 16:40:31 -050097 pipeline,
Robert Phillips67a625e2019-11-15 15:37:07 -050098 pathProc.get(),
Robert Phillipscea290f2019-11-06 11:21:03 -050099 GrPrimitiveType::kPath);
Robert Phillips901aff02019-10-08 12:32:56 -0400100
Chris Dalton304e14d2020-03-17 14:29:06 -0600101 flushState->bindPipelineAndScissorClip(programInfo, this->bounds());
102 flushState->bindTextures(programInfo.primProc(), nullptr, programInfo.pipeline());
103
Brian Salomon54d212e2017-03-21 14:22:38 -0400104 GrStencilSettings stencil;
Robert Phillips3968fcb2019-12-05 16:40:31 -0500105 init_stencil_pass_settings(*flushState, this->fillType(), &stencil);
106 flushState->gpu()->pathRendering()->drawPath(proxy->peekRenderTarget(),
107 programInfo, stencil, fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -0400108}
109
110//////////////////////////////////////////////////////////////////////////////
111
cdaltoncdd46822015-12-08 10:48:31 -0800112inline void pre_translate_transform_values(const float* xforms,
113 GrPathRendering::PathTransformType type, int count,
114 SkScalar x, SkScalar y, float* dst) {
115 if (0 == x && 0 == y) {
116 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -0700117 return;
118 }
cdaltoncdd46822015-12-08 10:48:31 -0800119 switch (type) {
120 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400121 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800122 break;
123 case GrPathRendering::kTranslateX_PathTransformType:
124 SkASSERT(0 == y);
125 for (int i = 0; i < count; i++) {
126 dst[i] = xforms[i] + x;
127 }
128 break;
129 case GrPathRendering::kTranslateY_PathTransformType:
130 SkASSERT(0 == x);
131 for (int i = 0; i < count; i++) {
132 dst[i] = xforms[i] + y;
133 }
134 break;
135 case GrPathRendering::kTranslate_PathTransformType:
136 for (int i = 0; i < 2 * count; i += 2) {
137 dst[i] = xforms[i] + x;
138 dst[i + 1] = xforms[i + 1] + y;
139 }
140 break;
141 case GrPathRendering::kAffine_PathTransformType:
142 for (int i = 0; i < 6 * count; i += 6) {
143 dst[i] = xforms[i];
144 dst[i + 1] = xforms[i + 1];
145 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
146 dst[i + 3] = xforms[i + 3];
147 dst[i + 4] = xforms[i + 4];
148 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
149 }
150 break;
151 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400152 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800153 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700154 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700155}