blob: 93a4d5501b1c3cd62459ad231b7136c7530cf78e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 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 */
bsalomon@google.com30085192011-08-19 15:42:31 +00007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/core/SkDrawProcs.h"
9#include "src/gpu/GrCaps.h"
10#include "src/gpu/GrPaint.h"
11#include "src/gpu/GrPathRenderer.h"
12#include "src/gpu/GrRecordingContextPriv.h"
13#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrUserStencilSettings.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040015#include "src/gpu/geometry/GrShape.h"
bsalomon@google.comffca4002011-02-22 20:34:01 +000016
Brian Salomon653f42f2018-07-10 10:07:31 -040017#ifdef SK_DEBUG
18void GrPathRenderer::StencilPathArgs::validate() const {
19 SkASSERT(fContext);
20 SkASSERT(fRenderTargetContext);
21 SkASSERT(fClipConservativeBounds);
22 SkASSERT(fViewMatrix);
23 SkASSERT(fShape);
24 SkASSERT(fShape->style().isSimpleFill());
Brian Salomon653f42f2018-07-10 10:07:31 -040025 SkPath path;
26 fShape->asPath(&path);
27 SkASSERT(!path.isInverseFillType());
tomhudson@google.comd22b6e42011-06-24 15:53:40 +000028}
Brian Salomon653f42f2018-07-10 10:07:31 -040029#endif
30
31//////////////////////////////////////////////////////////////////////////////
32
33GrPathRenderer::GrPathRenderer() {}
34
35GrPathRenderer::StencilSupport GrPathRenderer::getStencilSupport(const GrShape& shape) const {
36 SkDEBUGCODE(SkPath path;)
37 SkDEBUGCODE(shape.asPath(&path);)
38 SkASSERT(shape.style().isSimpleFill());
39 SkASSERT(!path.isInverseFillType());
40 return this->onGetStencilSupport(shape);
41}
42
43bool GrPathRenderer::drawPath(const DrawPathArgs& args) {
44#ifdef SK_DEBUG
45 args.validate();
46 CanDrawPathArgs canArgs;
Robert Phillips9da87e02019-02-04 13:26:26 -050047 canArgs.fCaps = args.fContext->priv().caps();
Brian Salomon653f42f2018-07-10 10:07:31 -040048 canArgs.fClipConservativeBounds = args.fClipConservativeBounds;
49 canArgs.fViewMatrix = args.fViewMatrix;
50 canArgs.fShape = args.fShape;
Chris Dalton6ce447a2019-06-23 18:07:38 -060051 canArgs.fAAType = args.fAAType;
Greg Danielbe7fc462019-01-03 16:40:42 -050052 canArgs.fTargetIsWrappedVkSecondaryCB = args.fRenderTargetContext->wrapsVkSecondaryCB();
Brian Salomon653f42f2018-07-10 10:07:31 -040053 canArgs.validate();
54
55 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused();
Brian Salomon653f42f2018-07-10 10:07:31 -040056 SkASSERT(CanDrawPath::kNo != this->canDrawPath(canArgs));
57 if (!args.fUserStencilSettings->isUnused()) {
58 SkPath path;
59 args.fShape->asPath(&path);
60 SkASSERT(args.fShape->style().isSimpleFill());
61 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*args.fShape));
62 }
63#endif
64 return this->onDrawPath(args);
65}
66
67bool GrPathRenderer::IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatrix& matrix,
Robert Phillips20390c32018-08-17 11:01:03 -040068 SkScalar* outCoverage) {
Brian Salomon653f42f2018-07-10 10:07:31 -040069 if (style.pathEffect()) {
70 return false;
71 }
72 const SkStrokeRec& stroke = style.strokeRec();
73 if (stroke.isHairlineStyle()) {
74 if (outCoverage) {
75 *outCoverage = SK_Scalar1;
76 }
77 return true;
78 }
79 return stroke.getStyle() == SkStrokeRec::kStroke_Style &&
80 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage);
81}
82
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +000083
84void GrPathRenderer::GetPathDevBounds(const SkPath& path,
85 int devW, int devH,
86 const SkMatrix& matrix,
87 SkRect* bounds) {
88 if (path.isInverseFillType()) {
89 *bounds = SkRect::MakeWH(SkIntToScalar(devW), SkIntToScalar(devH));
90 return;
91 }
92 *bounds = path.getBounds();
93 matrix.mapRect(bounds);
94}
Brian Salomon653f42f2018-07-10 10:07:31 -040095
96void GrPathRenderer::onStencilPath(const StencilPathArgs& args) {
97 static constexpr GrUserStencilSettings kIncrementStencil(
98 GrUserStencilSettings::StaticInit<
99 0xffff,
100 GrUserStencilTest::kAlways,
101 0xffff,
102 GrUserStencilOp::kReplace,
103 GrUserStencilOp::kReplace,
104 0xffff>()
105 );
106
107 GrPaint paint;
108 DrawPathArgs drawArgs{args.fContext,
109 std::move(paint),
110 &kIncrementStencil,
111 args.fRenderTargetContext,
112 nullptr, // clip
113 args.fClipConservativeBounds,
114 args.fViewMatrix,
115 args.fShape,
Chris Dalton6ce447a2019-06-23 18:07:38 -0600116 (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone,
Brian Salomon653f42f2018-07-10 10:07:31 -0400117 false};
118 this->drawPath(drawArgs);
119}