blob: f15309ccb02295604c28584c71197c9f488b6d29 [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
Greg Danielf91aeb22019-06-18 09:58:02 -04008#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrGpu.h"
10#include "src/gpu/GrRenderTargetContext.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040011#include "src/gpu/geometry/GrShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/ops/GrDashLinePathRenderer.h"
13#include "src/gpu/ops/GrDashOp.h"
14#include "src/gpu/ops/GrMeshDrawOp.h"
kkinnunen18996512015-04-26 23:18:49 -070015
Chris Dalton5ed44232017-09-07 13:22:46 -060016GrPathRenderer::CanDrawPath
17GrDashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
kkinnunen18996512015-04-26 23:18:49 -070018 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070019 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);
Chris Dalton5ed44232017-09-07 13:22:46 -060023 if (!GrDashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
24 return CanDrawPath::kNo;
25 }
26 return CanDrawPath::kYes;
kkinnunen18996512015-04-26 23:18:49 -070027 }
Chris Dalton5ed44232017-09-07 13:22:46 -060028 return CanDrawPath::kNo;
kkinnunen18996512015-04-26 23:18:49 -070029}
30
bsalomon0aff2fa2015-07-31 06:48:27 -070031bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -040032 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -070033 "GrDashLinePathRenderer::onDrawPath");
Chris Dalton6ce447a2019-06-23 18:07:38 -060034 GrDashOp::AAMode aaMode;
35 switch (args.fAAType) {
36 case GrAAType::kNone:
37 aaMode = GrDashOp::AAMode::kNone;
38 break;
39 case GrAAType::kMSAA:
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050040 // 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.
Brian Salomona6aa5902016-12-16 09:32:00 -050042 aaMode = GrDashOp::AAMode::kCoverageWithMSAA;
Chris Dalton6ce447a2019-06-23 18:07:38 -060043 break;
44 case GrAAType::kCoverage:
Chris Dalton09e56892019-03-13 00:22:01 -060045 aaMode = GrDashOp::AAMode::kCoverage;
Chris Dalton6ce447a2019-06-23 18:07:38 -060046 break;
bsalomonaf18fb42016-06-07 08:10:46 -070047 }
kkinnunen18996512015-04-26 23:18:49 -070048 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070049 SkAssertResult(args.fShape->asLine(pts, nullptr));
Brian Salomon98222ac2017-07-12 15:27:54 -040050 std::unique_ptr<GrDrawOp> op =
Robert Phillips7c525e62018-06-12 10:11:12 -040051 GrDashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint), *args.fViewMatrix, pts,
52 aaMode, args.fShape->style(), args.fUserStencilSettings);
Brian Salomon24f19782016-12-13 15:10:11 -050053 if (!op) {
robertphillips73c4e642016-03-02 11:36:59 -080054 return false;
55 }
Brian Salomon98222ac2017-07-12 15:27:54 -040056 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
robertphillips73c4e642016-03-02 11:36:59 -080057 return true;
kkinnunen18996512015-04-26 23:18:49 -070058}