blob: 5e9b369ee259bec0adedadd9761320d39663f3a8 [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
8#include "GrDashLinePathRenderer.h"
robertphillips5d1676c2016-07-21 08:18:05 -07009#include "GrAuditTrail.h"
robertphillips5fa7f302016-07-21 09:21:04 -070010#include "GrGpu.h"
Brian Salomon653f42f2018-07-10 10:07:31 -040011#include "GrRenderTargetContext.h"
12#include "GrShape.h"
Brian Salomon89527432016-12-16 09:52:16 -050013#include "ops/GrDashOp.h"
Brian Salomon649a3412017-03-09 13:50:43 -050014#include "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)) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050021 if (args.fAAType == GrAAType::kMixedSamples) {
Chris Dalton5ed44232017-09-07 13:22:46 -060022 return CanDrawPath::kNo;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050023 }
bsalomon0a0f67e2016-06-28 11:56:42 -070024 // We should never have an inverse dashed case.
25 SkASSERT(!inverted);
Chris Dalton5ed44232017-09-07 13:22:46 -060026 if (!GrDashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
27 return CanDrawPath::kNo;
28 }
29 return CanDrawPath::kYes;
kkinnunen18996512015-04-26 23:18:49 -070030 }
Chris Dalton5ed44232017-09-07 13:22:46 -060031 return CanDrawPath::kNo;
kkinnunen18996512015-04-26 23:18:49 -070032}
33
bsalomon0aff2fa2015-07-31 06:48:27 -070034bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -040035 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -070036 "GrDashLinePathRenderer::onDrawPath");
Brian Salomona6aa5902016-12-16 09:32:00 -050037 GrDashOp::AAMode aaMode = GrDashOp::AAMode::kNone;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050038 switch (args.fAAType) {
39 case GrAAType::kNone:
40 break;
41 case GrAAType::kCoverage:
42 case GrAAType::kMixedSamples:
Brian Salomona6aa5902016-12-16 09:32:00 -050043 aaMode = GrDashOp::AAMode::kCoverage;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050044 break;
45 case GrAAType::kMSAA:
46 // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
47 // we can wind up with external edges antialiased and internal edges unantialiased.
Brian Salomona6aa5902016-12-16 09:32:00 -050048 aaMode = GrDashOp::AAMode::kCoverageWithMSAA;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050049 break;
bsalomonaf18fb42016-06-07 08:10:46 -070050 }
kkinnunen18996512015-04-26 23:18:49 -070051 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070052 SkAssertResult(args.fShape->asLine(pts, nullptr));
Brian Salomon98222ac2017-07-12 15:27:54 -040053 std::unique_ptr<GrDrawOp> op =
Robert Phillips7c525e62018-06-12 10:11:12 -040054 GrDashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint), *args.fViewMatrix, pts,
55 aaMode, args.fShape->style(), args.fUserStencilSettings);
Brian Salomon24f19782016-12-13 15:10:11 -050056 if (!op) {
robertphillips73c4e642016-03-02 11:36:59 -080057 return false;
58 }
Brian Salomon98222ac2017-07-12 15:27:54 -040059 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
robertphillips73c4e642016-03-02 11:36:59 -080060 return true;
kkinnunen18996512015-04-26 23:18:49 -070061}