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 | |
Robert Phillips | e453fa0 | 2021-08-19 14:57:05 -0400 | [diff] [blame] | 8 | #include "src/gpu/ops/PathTessellateOp.h" |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 9 | |
Robert Phillips | 06273bc | 2021-08-11 15:43:50 -0400 | [diff] [blame] | 10 | #include "src/gpu/GrAppliedClip.h" |
| 11 | #include "src/gpu/GrOpFlushState.h" |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 12 | #include "src/gpu/tessellate/GrPathWedgeTessellator.h" |
| 13 | #include "src/gpu/tessellate/shaders/GrPathTessellationShader.h" |
| 14 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 15 | namespace skgpu::v1 { |
| 16 | |
| 17 | void PathTessellateOp::visitProxies(const GrVisitProxyFunc& func) const { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 18 | if (fTessellationProgram) { |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 19 | fTessellationProgram->pipeline().visitProxies(func); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 20 | } else { |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 21 | fProcessors.visitProxies(func); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 22 | } |
| 23 | } |
| 24 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 25 | GrProcessorSet::Analysis PathTessellateOp::finalize(const GrCaps& caps, |
| 26 | const GrAppliedClip* clip, |
| 27 | GrClampType clampType) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 28 | return fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, nullptr, caps, |
| 29 | clampType, &fColor); |
| 30 | } |
| 31 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 32 | void PathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args, |
| 33 | GrAppliedClip&& appliedClip) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 34 | 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 Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 44 | void PathTessellateOp::onPrePrepare(GrRecordingContext* context, |
| 45 | const GrSurfaceProxyView& writeView, GrAppliedClip* clip, |
| 46 | const GrDstProxyView& dstProxyView, |
| 47 | GrXferBarrierFlags renderPassXferBarriers, |
| 48 | GrLoadOp colorLoadOp) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 49 | 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 Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 56 | void PathTessellateOp::onPrepare(GrOpFlushState* flushState) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 57 | 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 Dalton | 17eaf62 | 2021-07-28 09:43:52 -0600 | [diff] [blame] | 64 | fTessellator->prepare(flushState, this->bounds(), {SkMatrix::I(), fPath}, fPath.countVerbs()); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 65 | } |
| 66 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 67 | void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 68 | SkASSERT(fTessellator); |
| 69 | SkASSERT(fTessellationProgram); |
| 70 | flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds()); |
| 71 | flushState->bindTextures(fTessellationProgram->geomProc(), nullptr, |
| 72 | fTessellationProgram->pipeline()); |
Robert Phillips | f0d21cf | 2021-08-13 10:26:37 -0400 | [diff] [blame] | 73 | |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 74 | fTessellator->draw(flushState); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 75 | } |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame^] | 76 | |
| 77 | } // namespace skgpu::v1 |