• 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 
10 #include "GrAuditTrail.h"
11 #include "GrGpu.h"
12 #include "GrPipelineBuilder.h"
13 #include "ops/GrDashOp.h"
14 #include "ops/GrMeshDrawOp.h"
15 
onCanDrawPath(const CanDrawPathArgs & args) const16 bool GrDashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
17     SkPoint pts[2];
18     bool inverted;
19     if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
20         if (args.fAAType == GrAAType::kMixedSamples) {
21             return false;
22         }
23         // We should never have an inverse dashed case.
24         SkASSERT(!inverted);
25         return GrDashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix);
26     }
27     return false;
28 }
29 
onDrawPath(const DrawPathArgs & args)30 bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
31     GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
32                               "GrDashLinePathRenderer::onDrawPath");
33     GrDashOp::AAMode aaMode = GrDashOp::AAMode::kNone;
34     switch (args.fAAType) {
35         case GrAAType::kNone:
36             break;
37         case GrAAType::kCoverage:
38         case GrAAType::kMixedSamples:
39             aaMode = GrDashOp::AAMode::kCoverage;
40             break;
41         case GrAAType::kMSAA:
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.
44             aaMode = GrDashOp::AAMode::kCoverageWithMSAA;
45             break;
46     }
47     SkPoint pts[2];
48     SkAssertResult(args.fShape->asLine(pts, nullptr));
49     std::unique_ptr<GrMeshDrawOp> op = GrDashOp::MakeDashLineOp(
50             args.fPaint.getColor(), *args.fViewMatrix, pts, aaMode, args.fShape->style());
51     if (!op) {
52         return false;
53     }
54 
55     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
56     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
57 
58     args.fRenderTargetContext->addMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
59     return true;
60 }
61