1/* 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 "src/gpu/ops/DashLinePathRenderer.h" 9 10#include "src/gpu/GrAuditTrail.h" 11#include "src/gpu/GrGpu.h" 12#include "src/gpu/geometry/GrStyledShape.h" 13#include "src/gpu/ops/DashOp.h" 14#include "src/gpu/ops/GrMeshDrawOp.h" 15#include "src/gpu/v1/SurfaceDrawContext_v1.h" 16 17namespace skgpu::v1 { 18 19PathRenderer::CanDrawPath DashLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { 20 SkPoint pts[2]; 21 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); 25 if (!DashOp::CanDrawDashLine(pts, args.fShape->style(), *args.fViewMatrix)) { 26 return CanDrawPath::kNo; 27 } 28 return CanDrawPath::kYes; 29 } 30 return CanDrawPath::kNo; 31} 32 33bool DashLinePathRenderer::onDrawPath(const DrawPathArgs& args) { 34 GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(), 35 "DashLinePathRenderer::onDrawPath"); 36 DashOp::AAMode aaMode; 37 switch (args.fAAType) { 38 case GrAAType::kNone: 39 aaMode = DashOp::AAMode::kNone; 40 break; 41 case GrAAType::kMSAA: 42 // 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. 44 aaMode = DashOp::AAMode::kCoverageWithMSAA; 45 break; 46 case GrAAType::kCoverage: 47 aaMode = DashOp::AAMode::kCoverage; 48 break; 49 } 50 SkPoint pts[2]; 51 SkAssertResult(args.fShape->asLine(pts, nullptr)); 52 GrOp::Owner op = DashOp::MakeDashLineOp(args.fContext, std::move(args.fPaint), 53 *args.fViewMatrix, pts, aaMode, args.fShape->style(), 54 args.fUserStencilSettings); 55 if (!op) { 56 return false; 57 } 58 args.fSurfaceDrawContext->addDrawOp(args.fClip, std::move(op)); 59 return true; 60} 61 62} // namespace skgpu::v1 63