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