blob: 73c2b3e8f225259566cef2dd3d3948e83941a187 [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"
9
robertphillips5d1676c2016-07-21 08:18:05 -070010#include "GrAuditTrail.h"
robertphillips5fa7f302016-07-21 09:21:04 -070011#include "GrGpu.h"
Brian Salomon89527432016-12-16 09:52:16 -050012#include "ops/GrDashOp.h"
Brian Salomon649a3412017-03-09 13:50:43 -050013#include "ops/GrMeshDrawOp.h"
kkinnunen18996512015-04-26 23:18:49 -070014
Chris Dalton5ed44232017-09-07 13:22:46 -060015GrPathRenderer::CanDrawPath
16GrDashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
kkinnunen18996512015-04-26 23:18:49 -070017 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070018 bool inverted;
19 if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050020 if (args.fAAType == GrAAType::kMixedSamples) {
Chris Dalton5ed44232017-09-07 13:22:46 -060021 return CanDrawPath::kNo;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050022 }
bsalomon0a0f67e2016-06-28 11:56:42 -070023 // We should never have an inverse dashed case.
24 SkASSERT(!inverted);
Chris Dalton5ed44232017-09-07 13:22:46 -060025 if (!GrDashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) {
26 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
bsalomon0aff2fa2015-07-31 06:48:27 -070033bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -040034 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -070035 "GrDashLinePathRenderer::onDrawPath");
Brian Salomona6aa5902016-12-16 09:32:00 -050036 GrDashOp::AAMode aaMode = GrDashOp::AAMode::kNone;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050037 switch (args.fAAType) {
38 case GrAAType::kNone:
39 break;
40 case GrAAType::kCoverage:
41 case GrAAType::kMixedSamples:
Brian Salomona6aa5902016-12-16 09:32:00 -050042 aaMode = GrDashOp::AAMode::kCoverage;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050043 break;
44 case GrAAType::kMSAA:
45 // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
46 // we can wind up with external edges antialiased and internal edges unantialiased.
Brian Salomona6aa5902016-12-16 09:32:00 -050047 aaMode = GrDashOp::AAMode::kCoverageWithMSAA;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050048 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));
Brian Salomon98222ac2017-07-12 15:27:54 -040052 std::unique_ptr<GrDrawOp> op =
53 GrDashOp::MakeDashLineOp(std::move(args.fPaint), *args.fViewMatrix, pts, aaMode,
54 args.fShape->style(), args.fUserStencilSettings);
Brian Salomon24f19782016-12-13 15:10:11 -050055 if (!op) {
robertphillips73c4e642016-03-02 11:36:59 -080056 return false;
57 }
Brian Salomon98222ac2017-07-12 15:27:54 -040058 args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
robertphillips73c4e642016-03-02 11:36:59 -080059 return true;
kkinnunen18996512015-04-26 23:18:49 -070060}