1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "src/gpu/ops/DashLinePathRenderer.h"
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci#include "src/gpu/GrAuditTrail.h"
11cb93a386Sopenharmony_ci#include "src/gpu/GrGpu.h"
12cb93a386Sopenharmony_ci#include "src/gpu/geometry/GrStyledShape.h"
13cb93a386Sopenharmony_ci#include "src/gpu/ops/DashOp.h"
14cb93a386Sopenharmony_ci#include "src/gpu/ops/GrMeshDrawOp.h"
15cb93a386Sopenharmony_ci#include "src/gpu/v1/SurfaceDrawContext_v1.h"
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_cinamespace skgpu::v1 {
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_ciPathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
20cb93a386Sopenharmony_ci    SkPoint pts[2];
21cb93a386Sopenharmony_ci    bool inverted;
22cb93a386Sopenharmony_ci    if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
23cb93a386Sopenharmony_ci        // We should never have an inverse dashed case.
24cb93a386Sopenharmony_ci        SkASSERT(!inverted);
25cb93a386Sopenharmony_ci        if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
26cb93a386Sopenharmony_ci            return CanDrawPath::kNo;
27cb93a386Sopenharmony_ci        }
28cb93a386Sopenharmony_ci        return CanDrawPath::kYes;
29cb93a386Sopenharmony_ci    }
30cb93a386Sopenharmony_ci    return CanDrawPath::kNo;
31cb93a386Sopenharmony_ci}
32cb93a386Sopenharmony_ci
33cb93a386Sopenharmony_cibool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
34cb93a386Sopenharmony_ci    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
35cb93a386Sopenharmony_ci                              "DashLinePathRenderer::onDrawPath");
36cb93a386Sopenharmony_ci    DashOp::AAMode aaMode;
37cb93a386Sopenharmony_ci    switch (args.fAAType) {
38cb93a386Sopenharmony_ci        case GrAAType::kNone:
39cb93a386Sopenharmony_ci            aaMode = DashOp::AAMode::kNone;
40cb93a386Sopenharmony_ci            break;
41cb93a386Sopenharmony_ci        case GrAAType::kMSAA:
42cb93a386Sopenharmony_ci            // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
43cb93a386Sopenharmony_ci            // we can wind up with external edges antialiased and internal edges unantialiased.
44cb93a386Sopenharmony_ci            aaMode = DashOp::AAMode::kCoverageWithMSAA;
45cb93a386Sopenharmony_ci            break;
46cb93a386Sopenharmony_ci        case GrAAType::kCoverage:
47cb93a386Sopenharmony_ci            aaMode = DashOp::AAMode::kCoverage;
48cb93a386Sopenharmony_ci            break;
49cb93a386Sopenharmony_ci    }
50cb93a386Sopenharmony_ci    SkPoint pts[2];
51cb93a386Sopenharmony_ci    SkAssertResult(args.fShape->asLine(pts, nullptr));
52cb93a386Sopenharmony_ci    GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint),
53cb93a386Sopenharmony_ci                                            *args.fViewMatrix, pts, aaMode, args.fShape->style(),
54cb93a386Sopenharmony_ci                                            args.fUserStencilSettings);
55cb93a386Sopenharmony_ci    if (!op) {
56cb93a386Sopenharmony_ci        return false;
57cb93a386Sopenharmony_ci    }
58cb93a386Sopenharmony_ci    args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op));
59cb93a386Sopenharmony_ci    return true;
60cb93a386Sopenharmony_ci}
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ci} // namespace skgpu::v1
63