blob: 801e445da51969c4b528a75ff664925587cb0d15 [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 Dalton7ae272f2021-06-10 11:45:14 -060049 this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, &dstProxyView,
50 renderPassXferBarriers, colorLoadOp, context->priv().caps()},
51 (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
52 SkASSERT(fTessellationProgram);
53 context->priv().recordProgramInfo(fTessellationProgram);
54}
55
Robert Phillips62bd6332021-08-26 09:56:55 -040056void PathTessellateOp::onPrepare(GrOpFlushState* flushState) {
Chris Dalton7ae272f2021-06-10 11:45:14 -060057 if (!fTessellator) {
58 this->prepareTessellator({flushState->allocator(), flushState->writeView(),
59 &flushState->dstProxyView(), flushState->renderPassBarriers(),
60 flushState->colorLoadOp(), &flushState->caps()},
61 flushState->detachAppliedClip());
62 SkASSERT(fTessellator);
63 }
Chris Dalton17eaf622021-07-28 09:43:52 -060064 fTessellator->prepare(flushState, this->bounds(), {SkMatrix::I(), fPath}, fPath.countVerbs());
Chris Dalton7ae272f2021-06-10 11:45:14 -060065}
66
Robert Phillips62bd6332021-08-26 09:56:55 -040067void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
Chris Dalton7ae272f2021-06-10 11:45:14 -060068 SkASSERT(fTessellator);
69 SkASSERT(fTessellationProgram);
70 flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds());
71 flushState->bindTextures(fTessellationProgram->geomProc(), nullptr,
72 fTessellationProgram->pipeline());
Robert Phillipsf0d21cf2021-08-13 10:26:37 -040073
Chris Dalton7ae272f2021-06-10 11:45:14 -060074 fTessellator->draw(flushState);
Chris Dalton7ae272f2021-06-10 11:45:14 -060075}
Robert Phillips62bd6332021-08-26 09:56:55 -040076
77} // namespace skgpu::v1