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