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 | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 49 | // 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 Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 54 | (clip) ? std::move(*clip) : GrAppliedClip::Disabled()); |
| 55 | SkASSERT(fTessellationProgram); |
| 56 | context->priv().recordProgramInfo(fTessellationProgram); |
| 57 | } |
| 58 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 59 | void PathTessellateOp::onPrepare(GrOpFlushState* flushState) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 60 | if (!fTessellator) { |
| 61 | this->prepareTessellator({flushState->allocator(), flushState->writeView(), |
Chris Dalton | 2a26c50 | 2021-08-26 10:05:11 -0600 | [diff] [blame] | 62 | flushState->usesMSAASurface(), &flushState->dstProxyView(), |
| 63 | flushState->renderPassBarriers(), flushState->colorLoadOp(), |
| 64 | &flushState->caps()}, flushState->detachAppliedClip()); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 65 | SkASSERT(fTessellator); |
| 66 | } |
Chris Dalton | 17eaf62 | 2021-07-28 09:43:52 -0600 | [diff] [blame] | 67 | fTessellator->prepare(flushState, this->bounds(), {SkMatrix::I(), fPath}, fPath.countVerbs()); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 68 | } |
| 69 | |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 70 | void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 71 | SkASSERT(fTessellator); |
| 72 | SkASSERT(fTessellationProgram); |
| 73 | flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds()); |
| 74 | flushState->bindTextures(fTessellationProgram->geomProc(), nullptr, |
| 75 | fTessellationProgram->pipeline()); |
Robert Phillips | f0d21cf | 2021-08-13 10:26:37 -0400 | [diff] [blame] | 76 | |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 77 | fTessellator->draw(flushState); |
Chris Dalton | 7ae272f | 2021-06-10 11:45:14 -0600 | [diff] [blame] | 78 | } |
Robert Phillips | 62bd633 | 2021-08-26 09:56:55 -0400 | [diff] [blame] | 79 | |
| 80 | } // namespace skgpu::v1 |