blob: eb4b7702b054337f5310b246d04d737a9558a3c7 [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 Phillips294723d2021-06-17 09:23:58 -040015void GrPathTessellateOp::visitProxies(const GrVisitProxyFunc& func) const {
Chris Dalton7ae272f2021-06-10 11:45:14 -060016 if (fTessellationProgram) {
Robert Phillips294723d2021-06-17 09:23:58 -040017 fTessellationProgram->pipeline().visitProxies(func);
Chris Dalton7ae272f2021-06-10 11:45:14 -060018 } else {
Robert Phillips294723d2021-06-17 09:23:58 -040019 fProcessors.visitProxies(func);
Chris Dalton7ae272f2021-06-10 11:45:14 -060020 }
21}
22
23GrProcessorSet::Analysis GrPathTessellateOp::finalize(const GrCaps& caps,
24 const GrAppliedClip* clip,
25 GrClampType clampType) {
26 return fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, nullptr, caps,
27 clampType, &fColor);
28}
29
30void GrPathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args,
31 GrAppliedClip&& appliedClip) {
32 SkASSERT(!fTessellator);
33 SkASSERT(!fTessellationProgram);
34 auto* pipeline = GrTessellationShader::MakePipeline(args, fAAType, std::move(appliedClip),
35 std::move(fProcessors));
36 fTessellator = GrPathWedgeTessellator::Make(args.fArena, fViewMatrix, fColor,
37 fPath.countVerbs(), *pipeline, *args.fCaps);
38 fTessellationProgram = GrTessellationShader::MakeProgram(args, fTessellator->shader(), pipeline,
39 fStencil);
40}
41
42void GrPathTessellateOp::onPrePrepare(GrRecordingContext* context,
43 const GrSurfaceProxyView& writeView, GrAppliedClip* clip,
44 const GrDstProxyView& dstProxyView,
45 GrXferBarrierFlags renderPassXferBarriers,
46 GrLoadOp colorLoadOp) {
47 this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, &dstProxyView,
48 renderPassXferBarriers, colorLoadOp, context->priv().caps()},
49 (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
50 SkASSERT(fTessellationProgram);
51 context->priv().recordProgramInfo(fTessellationProgram);
52}
53
54void GrPathTessellateOp::onPrepare(GrOpFlushState* flushState) {
55 if (!fTessellator) {
56 this->prepareTessellator({flushState->allocator(), flushState->writeView(),
57 &flushState->dstProxyView(), flushState->renderPassBarriers(),
58 flushState->colorLoadOp(), &flushState->caps()},
59 flushState->detachAppliedClip());
60 SkASSERT(fTessellator);
61 }
Chris Dalton17eaf622021-07-28 09:43:52 -060062 fTessellator->prepare(flushState, this->bounds(), {SkMatrix::I(), fPath}, fPath.countVerbs());
Chris Dalton7ae272f2021-06-10 11:45:14 -060063}
64
65void GrPathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
66 SkASSERT(fTessellator);
67 SkASSERT(fTessellationProgram);
68 flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds());
69 flushState->bindTextures(fTessellationProgram->geomProc(), nullptr,
70 fTessellationProgram->pipeline());
Robert Phillipsf0d21cf2021-08-13 10:26:37 -040071
Chris Dalton7ae272f2021-06-10 11:45:14 -060072 fTessellator->draw(flushState);
Chris Dalton7ae272f2021-06-10 11:45:14 -060073}