blob: 6249a22d11390d50159208afefe0a07fcd43bac1 [file] [log] [blame]
Chris Dalton7ae272f2021-06-10 11:45:14 -06001/*
2 * Copyright 2021 Google LLC.
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
Robert Phillipse453fa02021-08-19 14:57:05 -04008#include "src/gpu/ops/PathTessellateOp.h"
Chris Dalton7ae272f2021-06-10 11:45:14 -06009
Robert Phillips06273bc2021-08-11 15:43:50 -040010#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrOpFlushState.h"
Chris Dalton7ae272f2021-06-10 11:45:14 -060012#include "src/gpu/tessellate/GrPathWedgeTessellator.h"
13#include "src/gpu/tessellate/shaders/GrPathTessellationShader.h"
14
Robert Phillips62bd6332021-08-26 09:56:55 -040015namespace skgpu::v1 {
16
17void PathTessellateOp::visitProxies(const GrVisitProxyFunc& func) const {
Chris Dalton7ae272f2021-06-10 11:45:14 -060018 if (fTessellationProgram) {
Robert Phillips294723d2021-06-17 09:23:58 -040019 fTessellationProgram->pipeline().visitProxies(func);
Chris Dalton7ae272f2021-06-10 11:45:14 -060020 } else {
Robert Phillips294723d2021-06-17 09:23:58 -040021 fProcessors.visitProxies(func);
Chris Dalton7ae272f2021-06-10 11:45:14 -060022 }
23}
24
Robert Phillips62bd6332021-08-26 09:56:55 -040025GrProcessorSet::Analysis PathTessellateOp::finalize(const GrCaps& caps,
26 const GrAppliedClip* clip,
27 GrClampType clampType) {
Chris Dalton7ae272f2021-06-10 11:45:14 -060028 return fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, nullptr, caps,
29 clampType, &fColor);
30}
31
Robert Phillips62bd6332021-08-26 09:56:55 -040032void PathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args,
33 GrAppliedClip&& appliedClip) {
Chris Dalton7ae272f2021-06-10 11:45:14 -060034 SkASSERT(!fTessellator);
35 SkASSERT(!fTessellationProgram);
36 auto* pipeline = GrTessellationShader::MakePipeline(args, fAAType, std::move(appliedClip),
37 std::move(fProcessors));
38 fTessellator = GrPathWedgeTessellator::Make(args.fArena, fViewMatrix, fColor,
39 fPath.countVerbs(), *pipeline, *args.fCaps);
40 fTessellationProgram = GrTessellationShader::MakeProgram(args, fTessellator->shader(), pipeline,
41 fStencil);
42}
43
Robert Phillips62bd6332021-08-26 09:56:55 -040044void PathTessellateOp::onPrePrepare(GrRecordingContext* context,
45 const GrSurfaceProxyView& writeView, GrAppliedClip* clip,
46 const GrDstProxyView& dstProxyView,
47 GrXferBarrierFlags renderPassXferBarriers,
48 GrLoadOp colorLoadOp) {
Chris Dalton2a26c502021-08-26 10:05:11 -060049 // DMSAA is not supported on DDL.
50 bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
51 this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, usesMSAASurface,
52 &dstProxyView, renderPassXferBarriers, colorLoadOp,
53 context->priv().caps()},
Chris Dalton7ae272f2021-06-10 11:45:14 -060054 (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
55 SkASSERT(fTessellationProgram);
56 context->priv().recordProgramInfo(fTessellationProgram);
57}
58
Robert Phillips62bd6332021-08-26 09:56:55 -040059void PathTessellateOp::onPrepare(GrOpFlushState* flushState) {
Chris Dalton7ae272f2021-06-10 11:45:14 -060060 if (!fTessellator) {
61 this->prepareTessellator({flushState->allocator(), flushState->writeView(),
Chris Dalton2a26c502021-08-26 10:05:11 -060062 flushState->usesMSAASurface(), &flushState->dstProxyView(),
63 flushState->renderPassBarriers(), flushState->colorLoadOp(),
64 &flushState->caps()}, flushState->detachAppliedClip());
Chris Dalton7ae272f2021-06-10 11:45:14 -060065 SkASSERT(fTessellator);
66 }
Chris Dalton17eaf622021-07-28 09:43:52 -060067 fTessellator->prepare(flushState, this->bounds(), {SkMatrix::I(), fPath}, fPath.countVerbs());
Chris Dalton7ae272f2021-06-10 11:45:14 -060068}
69
Robert Phillips62bd6332021-08-26 09:56:55 -040070void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
Chris Dalton7ae272f2021-06-10 11:45:14 -060071 SkASSERT(fTessellator);
72 SkASSERT(fTessellationProgram);
73 flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds());
74 flushState->bindTextures(fTessellationProgram->geomProc(), nullptr,
75 fTessellationProgram->pipeline());
Robert Phillipsf0d21cf2021-08-13 10:26:37 -040076
Chris Dalton7ae272f2021-06-10 11:45:14 -060077 fTessellator->draw(flushState);
Chris Dalton7ae272f2021-06-10 11:45:14 -060078}
Robert Phillips62bd6332021-08-26 09:56:55 -040079
80} // namespace skgpu::v1