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