kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 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 | 461c539 | 2021-08-17 16:42:51 -0400 | [diff] [blame] | 8 | #include "src/gpu/ops/DashLinePathRenderer.h" |
Robert Phillips | 06273bc | 2021-08-11 15:43:50 -0400 | [diff] [blame] | 9 | |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 10 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrGpu.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 12 | #include "src/gpu/geometry/GrStyledShape.h" |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 13 | #include "src/gpu/ops/DashOp.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/ops/GrMeshDrawOp.h" |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 15 | #include "src/gpu/v1/SurfaceDrawContext_v1.h" |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 16 | |
Robert Phillips | 461c539 | 2021-08-17 16:42:51 -0400 | [diff] [blame] | 17 | namespace skgpu::v1 { |
| 18 | |
Robert Phillips | db0ec08 | 2021-08-19 12:30:12 -0400 | [diff] [blame] | 19 | PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 20 | SkPoint pts[2]; |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 21 | bool inverted; |
| 22 | if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) { |
| 23 | // We should never have an inverse dashed case. |
| 24 | SkASSERT(!inverted); |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 25 | if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 26 | return CanDrawPath::kNo; |
| 27 | } |
| 28 | return CanDrawPath::kYes; |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 29 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 30 | return CanDrawPath::kNo; |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Robert Phillips | 461c539 | 2021-08-17 16:42:51 -0400 | [diff] [blame] | 33 | bool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) { |
Robert Phillips | a92913e | 2021-07-12 16:31:52 -0400 | [diff] [blame] | 34 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(), |
Robert Phillips | 461c539 | 2021-08-17 16:42:51 -0400 | [diff] [blame] | 35 | "DashLinePathRenderer::onDrawPath"); |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 36 | DashOp::AAMode aaMode; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 37 | switch (args.fAAType) { |
| 38 | case GrAAType::kNone: |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 39 | aaMode = DashOp::AAMode::kNone; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 40 | break; |
| 41 | case GrAAType::kMSAA: |
Chris Dalton | 36c1804 | 2021-07-14 02:23:02 -0600 | [diff] [blame] | 42 | // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise, |
| 43 | // we can wind up with external edges antialiased and internal edges unantialiased. |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 44 | aaMode = DashOp::AAMode::kCoverageWithMSAA; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 45 | break; |
| 46 | case GrAAType::kCoverage: |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 47 | aaMode = DashOp::AAMode::kCoverage; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 48 | break; |
bsalomon | af18fb4 | 2016-06-07 08:10:46 -0700 | [diff] [blame] | 49 | } |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 50 | SkPoint pts[2]; |
bsalomon | 0a0f67e | 2016-06-28 11:56:42 -0700 | [diff] [blame] | 51 | SkAssertResult(args.fShape->asLine(pts, nullptr)); |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 52 | GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint), |
| 53 | *args.fViewMatrix, pts, aaMode, args.fShape->style(), |
| 54 | args.fUserStencilSettings); |
Brian Salomon | 24f1978 | 2016-12-13 15:10:11 -0500 | [diff] [blame] | 55 | if (!op) { |
robertphillips | 73c4e64 | 2016-03-02 11:36:59 -0800 | [diff] [blame] | 56 | return false; |
| 57 | } |
John Stiles | 0fbc6a3 | 2021-06-04 14:40:57 -0400 | [diff] [blame] | 58 | args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op)); |
robertphillips | 73c4e64 | 2016-03-02 11:36:59 -0800 | [diff] [blame] | 59 | return true; |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 60 | } |
Robert Phillips | 461c539 | 2021-08-17 16:42:51 -0400 | [diff] [blame] | 61 | |
| 62 | } // namespace skgpu::v1 |