blob: ccfd5bad65bed07875c7f20eba9888e0fe80f90d [file] [log] [blame]
kkinnunen18996512015-04-26 23:18:49 -07001/*
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
Robert Phillips461c5392021-08-17 16:42:51 -04008#include "src/gpu/ops/DashLinePathRenderer.h"
Robert Phillips06273bc2021-08-11 15:43:50 -04009
Greg Danielf91aeb22019-06-18 09:58:02 -040010#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrGpu.h"
Michael Ludwig2686d692020-04-17 20:21:37 +000012#include "src/gpu/geometry/GrStyledShape.h"
Robert Phillips46d7bd52021-09-01 13:02:28 -040013#include "src/gpu/ops/DashOp.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/ops/GrMeshDrawOp.h"
Robert Phillips4dca8312021-07-28 15:13:20 -040015#include "src/gpu/v1/SurfaceDrawContext_v1.h"
kkinnunen18996512015-04-26 23:18:49 -070016
Robert Phillips461c5392021-08-17 16:42:51 -040017namespace skgpu::v1 {
18
Robert Phillipsdb0ec082021-08-19 12:30:12 -040019PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
kkinnunen18996512015-04-26 23:18:49 -070020 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070021 bool inverted;
22 if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
23 // We should never have an inverse dashed case.
24 SkASSERT(!inverted);
Robert Phillips46d7bd52021-09-01 13:02:28 -040025 if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
Chris Dalton5ed44232017-09-07 13:22:46 -060026 return CanDrawPath::kNo;
27 }
28 return CanDrawPath::kYes;
kkinnunen18996512015-04-26 23:18:49 -070029 }
Chris Dalton5ed44232017-09-07 13:22:46 -060030 return CanDrawPath::kNo;
kkinnunen18996512015-04-26 23:18:49 -070031}
32
Robert Phillips461c5392021-08-17 16:42:51 -040033bool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
Robert Phillipsa92913e2021-07-12 16:31:52 -040034 GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
Robert Phillips461c5392021-08-17 16:42:51 -040035 "DashLinePathRenderer::onDrawPath");
Robert Phillips46d7bd52021-09-01 13:02:28 -040036 DashOp::AAMode aaMode;
Chris Dalton6ce447a2019-06-23 18:07:38 -060037 switch (args.fAAType) {
38 case GrAAType::kNone:
Robert Phillips46d7bd52021-09-01 13:02:28 -040039 aaMode = DashOp::AAMode::kNone;
Chris Dalton6ce447a2019-06-23 18:07:38 -060040 break;
41 case GrAAType::kMSAA:
Chris Dalton36c18042021-07-14 02:23:02 -060042 // 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.
Robert Phillips46d7bd52021-09-01 13:02:28 -040044 aaMode = DashOp::AAMode::kCoverageWithMSAA;
Chris Dalton6ce447a2019-06-23 18:07:38 -060045 break;
46 case GrAAType::kCoverage:
Robert Phillips46d7bd52021-09-01 13:02:28 -040047 aaMode = DashOp::AAMode::kCoverage;
Chris Dalton6ce447a2019-06-23 18:07:38 -060048 break;
bsalomonaf18fb42016-06-07 08:10:46 -070049 }
kkinnunen18996512015-04-26 23:18:49 -070050 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070051 SkAssertResult(args.fShape->asLine(pts, nullptr));
Robert Phillips46d7bd52021-09-01 13:02:28 -040052 GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint),
53 *args.fViewMatrix, pts, aaMode, args.fShape->style(),
54 args.fUserStencilSettings);
Brian Salomon24f19782016-12-13 15:10:11 -050055 if (!op) {
robertphillips73c4e642016-03-02 11:36:59 -080056 return false;
57 }
John Stiles0fbc6a32021-06-04 14:40:57 -040058 args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op));
robertphillips73c4e642016-03-02 11:36:59 -080059 return true;
kkinnunen18996512015-04-26 23:18:49 -070060}
Robert Phillips461c5392021-08-17 16:42:51 -040061
62} // namespace skgpu::v1