• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/gpu/ganesh/ops/DashLinePathRenderer.h"
9 
10 #include "src/gpu/ganesh/GrAuditTrail.h"
11 #include "src/gpu/ganesh/GrGpu.h"
12 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
13 #include "src/gpu/ganesh/SurfaceDrawContext.h"
14 #include "src/gpu/ganesh/geometry/GrStyledShape.h"
15 #include "src/gpu/ganesh/ops/DashOp.h"
16 #include "src/gpu/ganesh/ops/GrMeshDrawOp.h"
17 
18 namespace skgpu::ganesh {
19 
onCanDrawPath(const CanDrawPathArgs & args) const20 skgpu::v1::PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(
21         const CanDrawPathArgs& args) const {
22     SkPoint pts[2];
23     bool inverted;
24     if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
25         // We should never have an inverse dashed case.
26         SkASSERT(!inverted);
27         if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
28             return CanDrawPath::kNo;
29         }
30         return CanDrawPath::kYes;
31     }
32     return CanDrawPath::kNo;
33 }
34 
onDrawPath(const DrawPathArgs & args)35 bool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
36     GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
37                               "DashLinePathRenderer::onDrawPath");
38     DashOp::AAMode aaMode;
39     switch (args.fAAType) {
40         case GrAAType::kNone:
41             aaMode = DashOp::AAMode::kNone;
42             break;
43         case GrAAType::kMSAA:
44             // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
45             // we can wind up with external edges antialiased and internal edges unantialiased.
46             aaMode = DashOp::AAMode::kCoverageWithMSAA;
47             break;
48         case GrAAType::kCoverage:
49             aaMode = DashOp::AAMode::kCoverage;
50             break;
51     }
52     SkPoint pts[2];
53     SkAssertResult(args.fShape->asLine(pts, nullptr));
54     GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint),
55                                             *args.fViewMatrix, pts, aaMode, args.fShape->style(),
56                                             args.fUserStencilSettings);
57     if (!op) {
58         return false;
59     }
60     args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op));
61     return true;
62 }
63 
64 } // namespace skgpu::ganesh
65