xref: /aosp_15_r20/external/skia/src/gpu/ganesh/ops/DashLinePathRenderer.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include "src/gpu/ganesh/ops/DashLinePathRenderer.h"
8 
9 #include "include/core/SkPoint.h"
10 #include "include/gpu/ganesh/GrRecordingContext.h"
11 #include "include/private/base/SkAssert.h"
12 #include "include/private/gpu/ganesh/GrTypesPriv.h"
13 #include "src/gpu/ganesh/GrAuditTrail.h"
14 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
15 #include "src/gpu/ganesh/GrStyle.h"
16 #include "src/gpu/ganesh/SurfaceDrawContext.h"
17 #include "src/gpu/ganesh/geometry/GrStyledShape.h"
18 #include "src/gpu/ganesh/ops/DashOp.h"
19 #include "src/gpu/ganesh/ops/GrOp.h"
20 
21 #include <utility>
22 
23 namespace skgpu::ganesh {
24 
onCanDrawPath(const CanDrawPathArgs & args) const25 skgpu::ganesh::PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(
26         const CanDrawPathArgs& args) const {
27     SkPoint pts[2];
28     bool inverted;
29     if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
30         // We should never have an inverse dashed case.
31         SkASSERT(!inverted);
32         if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
33             return CanDrawPath::kNo;
34         }
35         return CanDrawPath::kYes;
36     }
37     return CanDrawPath::kNo;
38 }
39 
onDrawPath(const DrawPathArgs & args)40 bool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
41     GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
42                               "DashLinePathRenderer::onDrawPath");
43     DashOp::AAMode aaMode;
44     switch (args.fAAType) {
45         case GrAAType::kNone:
46             aaMode = DashOp::AAMode::kNone;
47             break;
48         case GrAAType::kMSAA:
49             // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
50             // we can wind up with external edges antialiased and internal edges unantialiased.
51             aaMode = DashOp::AAMode::kCoverageWithMSAA;
52             break;
53         case GrAAType::kCoverage:
54             aaMode = DashOp::AAMode::kCoverage;
55             break;
56     }
57     SkPoint pts[2];
58     SkAssertResult(args.fShape->asLine(pts, nullptr));
59     GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint),
60                                             *args.fViewMatrix, pts, aaMode, args.fShape->style(),
61                                             args.fUserStencilSettings);
62     if (!op) {
63         return false;
64     }
65     args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op));
66     return true;
67 }
68 
69 } // namespace skgpu::ganesh
70