Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame^] | 1 | /* |
| 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 | |
| 8 | #include "src/gpu/tessellate/GrPathTessellateOp.h" |
| 9 | |
| 10 | #include "src/gpu/tessellate/GrPathWedgeTessellator.h" |
| 11 | #include "src/gpu/tessellate/shaders/GrPathTessellationShader.h" |
| 12 | |
| 13 | void GrPathTessellateOp::visitProxies(const VisitProxyFunc& fn) const { |
| 14 | if (fTessellationProgram) { |
| 15 | fTessellationProgram->pipeline().visitProxies(fn); |
| 16 | } else { |
| 17 | fProcessors.visitProxies(fn); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | GrProcessorSet::Analysis GrPathTessellateOp::finalize(const GrCaps& caps, |
| 22 | const GrAppliedClip* clip, |
| 23 | GrClampType clampType) { |
| 24 | return fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, nullptr, caps, |
| 25 | clampType, &fColor); |
| 26 | } |
| 27 | |
| 28 | void GrPathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args, |
| 29 | GrAppliedClip&& appliedClip) { |
| 30 | SkASSERT(!fTessellator); |
| 31 | SkASSERT(!fTessellationProgram); |
| 32 | auto* pipeline = GrTessellationShader::MakePipeline(args, fAAType, std::move(appliedClip), |
| 33 | std::move(fProcessors)); |
| 34 | fTessellator = GrPathWedgeTessellator::Make(args.fArena, fViewMatrix, fColor, |
| 35 | fPath.countVerbs(), *pipeline, *args.fCaps); |
| 36 | fTessellationProgram = GrTessellationShader::MakeProgram(args, fTessellator->shader(), pipeline, |
| 37 | fStencil); |
| 38 | } |
| 39 | |
| 40 | void GrPathTessellateOp::onPrePrepare(GrRecordingContext* context, |
| 41 | const GrSurfaceProxyView& writeView, GrAppliedClip* clip, |
| 42 | const GrDstProxyView& dstProxyView, |
| 43 | GrXferBarrierFlags renderPassXferBarriers, |
| 44 | GrLoadOp colorLoadOp) { |
| 45 | this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, &dstProxyView, |
| 46 | renderPassXferBarriers, colorLoadOp, context->priv().caps()}, |
| 47 | (clip) ? std::move(*clip) : GrAppliedClip::Disabled()); |
| 48 | SkASSERT(fTessellationProgram); |
| 49 | context->priv().recordProgramInfo(fTessellationProgram); |
| 50 | } |
| 51 | |
| 52 | void GrPathTessellateOp::onPrepare(GrOpFlushState* flushState) { |
| 53 | if (!fTessellator) { |
| 54 | this->prepareTessellator({flushState->allocator(), flushState->writeView(), |
| 55 | &flushState->dstProxyView(), flushState->renderPassBarriers(), |
| 56 | flushState->colorLoadOp(), &flushState->caps()}, |
| 57 | flushState->detachAppliedClip()); |
| 58 | SkASSERT(fTessellator); |
| 59 | } |
| 60 | fTessellator->prepare(flushState, this->bounds(), fPath); |
| 61 | } |
| 62 | |
| 63 | void GrPathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
| 64 | SkASSERT(fTessellator); |
| 65 | SkASSERT(fTessellationProgram); |
| 66 | flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds()); |
| 67 | flushState->bindTextures(fTessellationProgram->geomProc(), nullptr, |
| 68 | fTessellationProgram->pipeline()); |
| 69 | fTessellator->draw(flushState); |
| 70 | } |