Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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/GrGpuTessellationPathRenderer.h" |
| 9 | |
| 10 | #include "src/core/SkPathPriv.h" |
| 11 | #include "src/gpu/GrClip.h" |
| 12 | #include "src/gpu/GrMemoryPool.h" |
| 13 | #include "src/gpu/GrRecordingContextPriv.h" |
| 14 | #include "src/gpu/GrRenderTargetContext.h" |
| 15 | #include "src/gpu/geometry/GrShape.h" |
| 16 | #include "src/gpu/tessellate/GrTessellatePathOp.h" |
| 17 | |
| 18 | GrPathRenderer::CanDrawPath GrGpuTessellationPathRenderer::onCanDrawPath( |
| 19 | const CanDrawPathArgs& args) const { |
| 20 | // This class should not have been added to the chain without tessellation support. |
| 21 | SkASSERT(args.fCaps->shaderCaps()->tessellationSupport()); |
Chris Dalton | 0f6bb8a | 2020-01-15 09:40:54 -0700 | [diff] [blame] | 22 | if (!args.fShape->style().isSimpleFill() || args.fShape->inverseFilled() || |
| 23 | args.fViewMatrix->hasPerspective()) { |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 24 | return CanDrawPath::kNo; |
| 25 | } |
| 26 | if (GrAAType::kCoverage == args.fAAType) { |
| 27 | SkASSERT(1 == args.fProxy->numSamples()); |
| 28 | if (!args.fProxy->canUseMixedSamples(*args.fCaps)) { |
| 29 | return CanDrawPath::kNo; |
| 30 | } |
| 31 | } |
| 32 | SkPath path; |
| 33 | args.fShape->asPath(&path); |
| 34 | if (SkPathPriv::ConicWeightCnt(path)) { |
| 35 | return CanDrawPath::kNo; |
| 36 | } |
| 37 | return CanDrawPath::kYes; |
| 38 | } |
| 39 | |
| 40 | bool GrGpuTessellationPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 41 | SkPath path; |
| 42 | args.fShape->asPath(&path); |
| 43 | |
Chris Dalton | f9aea7f | 2020-01-21 11:19:26 -0700 | [diff] [blame^] | 44 | auto op = args.fContext->priv().opMemoryPool()->allocate<GrTessellatePathOp>( |
| 45 | *args.fViewMatrix, path, std::move(args.fPaint), args.fAAType); |
| 46 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 47 | |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | void GrGpuTessellationPathRenderer::onStencilPath(const StencilPathArgs& args) { |
| 52 | SkPath path; |
| 53 | args.fShape->asPath(&path); |
| 54 | |
| 55 | GrAAType aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone; |
| 56 | |
Chris Dalton | f9aea7f | 2020-01-21 11:19:26 -0700 | [diff] [blame^] | 57 | auto op = args.fContext->priv().opMemoryPool()->allocate<GrTessellatePathOp>( |
| 58 | *args.fViewMatrix, path, GrPaint(), aaType, GrTessellatePathOp::Flags::kStencilOnly); |
| 59 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 60 | } |