blob: 9304885c9d86eccaca78a2e63796711c323220c4 [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"
bsalomonbb243832016-07-22 07:10:19 -070012#include "GrPipelineBuilder.h"
kkinnunen18996512015-04-26 23:18:49 -070013#include "effects/GrDashingEffect.h"
14
bsalomon0aff2fa2015-07-31 06:48:27 -070015bool GrDashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
kkinnunen18996512015-04-26 23:18:49 -070016 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070017 bool inverted;
18 if (args.fShape->style().isDashed() && args.fShape->asLine(pts, &inverted)) {
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050019 if (args.fAAType == GrAAType::kMixedSamples) {
20 return false;
21 }
bsalomon0a0f67e2016-06-28 11:56:42 -070022 // We should never have an inverse dashed case.
23 SkASSERT(!inverted);
bsalomon8acedde2016-06-24 10:42:16 -070024 return GrDashingEffect::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix);
kkinnunen18996512015-04-26 23:18:49 -070025 }
26 return false;
27}
28
bsalomon0aff2fa2015-07-31 06:48:27 -070029bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
Brian Osman11052242016-10-27 14:47:55 -040030 GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
robertphillips976f5f02016-06-03 10:59:20 -070031 "GrDashLinePathRenderer::onDrawPath");
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050032 GrDashingEffect::AAMode aaMode = GrDashingEffect::AAMode::kNone;
33 switch (args.fAAType) {
34 case GrAAType::kNone:
35 break;
36 case GrAAType::kCoverage:
37 case GrAAType::kMixedSamples:
38 aaMode = GrDashingEffect::AAMode::kCoverage;
39 break;
40 case GrAAType::kMSAA:
41 // In this mode we will use aa between dashes but the outer border uses MSAA. Otherwise,
42 // we can wind up with external edges antialiased and internal edges unantialiased.
43 aaMode = GrDashingEffect::AAMode::kCoverageWithMSAA;
44 break;
bsalomonaf18fb42016-06-07 08:10:46 -070045 }
kkinnunen18996512015-04-26 23:18:49 -070046 SkPoint pts[2];
bsalomon0a0f67e2016-06-28 11:56:42 -070047 SkAssertResult(args.fShape->asLine(pts, nullptr));
Brian Salomon9afd3712016-12-01 10:59:09 -050048 sk_sp<GrDrawOp> batch(GrDashingEffect::CreateDashLineBatch(args.fPaint->getColor(),
49 *args.fViewMatrix,
50 pts,
51 aaMode,
52 args.fShape->style()));
robertphillips73c4e642016-03-02 11:36:59 -080053 if (!batch) {
54 return false;
55 }
56
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050057 GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
bsalomonbb243832016-07-22 07:10:19 -070058 pipelineBuilder.setUserStencil(args.fUserStencilSettings);
59
Brian Salomon42521e82016-12-07 16:44:58 -050060 args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
robertphillips73c4e642016-03-02 11:36:59 -080061 return true;
kkinnunen18996512015-04-26 23:18:49 -070062}