blob: 71a34ea08a80d1cc3cdb37b6f5642688c2bb3a2a [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
bsalomon@google.comffca4002011-02-22 20:34:01 +00008#include "GrPathRenderer.h"
Brian Salomon653f42f2018-07-10 10:07:31 -04009#include "GrCaps.h"
10#include "GrContextPriv.h"
11#include "GrPaint.h"
12#include "GrRenderTargetContext.h"
13#include "GrShape.h"
14#include "GrUserStencilSettings.h"
15#include "SkDrawProcs.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());
25 SkASSERT(GrAAType::kCoverage != fAAType);
26 SkPath path;
27 fShape->asPath(&path);
28 SkASSERT(!path.isInverseFillType());
tomhudson@google.comd22b6e42011-06-24 15:53:40 +000029}
Brian Salomon653f42f2018-07-10 10:07:31 -040030#endif
31
32//////////////////////////////////////////////////////////////////////////////
33
34GrPathRenderer::GrPathRenderer() {}
35
36GrPathRenderer::StencilSupport GrPathRenderer::getStencilSupport(const GrShape& shape) const {
37 SkDEBUGCODE(SkPath path;)
38 SkDEBUGCODE(shape.asPath(&path);)
39 SkASSERT(shape.style().isSimpleFill());
40 SkASSERT(!path.isInverseFillType());
41 return this->onGetStencilSupport(shape);
42}
43
44bool GrPathRenderer::drawPath(const DrawPathArgs& args) {
45#ifdef SK_DEBUG
46 args.validate();
47 CanDrawPathArgs canArgs;
48 canArgs.fCaps = args.fContext->contextPriv().caps();
49 canArgs.fClipConservativeBounds = args.fClipConservativeBounds;
50 canArgs.fViewMatrix = args.fViewMatrix;
51 canArgs.fShape = args.fShape;
52 canArgs.fAAType = args.fAAType;
53 canArgs.validate();
54
55 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused();
56 SkASSERT(!(canArgs.fAAType == GrAAType::kMSAA &&
57 GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType()));
58 SkASSERT(!(canArgs.fAAType == GrAAType::kMixedSamples &&
59 GrFSAAType::kMixedSamples != args.fRenderTargetContext->fsaaType()));
60 SkASSERT(CanDrawPath::kNo != this->canDrawPath(canArgs));
61 if (!args.fUserStencilSettings->isUnused()) {
62 SkPath path;
63 args.fShape->asPath(&path);
64 SkASSERT(args.fShape->style().isSimpleFill());
65 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*args.fShape));
66 }
67#endif
68 return this->onDrawPath(args);
69}
70
71bool GrPathRenderer::IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatrix& matrix,
Robert Phillips20390c32018-08-17 11:01:03 -040072 SkScalar* outCoverage) {
Brian Salomon653f42f2018-07-10 10:07:31 -040073 if (style.pathEffect()) {
74 return false;
75 }
76 const SkStrokeRec& stroke = style.strokeRec();
77 if (stroke.isHairlineStyle()) {
78 if (outCoverage) {
79 *outCoverage = SK_Scalar1;
80 }
81 return true;
82 }
83 return stroke.getStyle() == SkStrokeRec::kStroke_Style &&
84 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage);
85}
86
bsalomon@google.com1dd9baa2013-05-20 16:49:06 +000087
88void GrPathRenderer::GetPathDevBounds(const SkPath& path,
89 int devW, int devH,
90 const SkMatrix& matrix,
91 SkRect* bounds) {
92 if (path.isInverseFillType()) {
93 *bounds = SkRect::MakeWH(SkIntToScalar(devW), SkIntToScalar(devH));
94 return;
95 }
96 *bounds = path.getBounds();
97 matrix.mapRect(bounds);
98}
Brian Salomon653f42f2018-07-10 10:07:31 -040099
100void GrPathRenderer::onStencilPath(const StencilPathArgs& args) {
101 static constexpr GrUserStencilSettings kIncrementStencil(
102 GrUserStencilSettings::StaticInit<
103 0xffff,
104 GrUserStencilTest::kAlways,
105 0xffff,
106 GrUserStencilOp::kReplace,
107 GrUserStencilOp::kReplace,
108 0xffff>()
109 );
110
111 GrPaint paint;
112 DrawPathArgs drawArgs{args.fContext,
113 std::move(paint),
114 &kIncrementStencil,
115 args.fRenderTargetContext,
116 nullptr, // clip
117 args.fClipConservativeBounds,
118 args.fViewMatrix,
119 args.fShape,
120 args.fAAType,
121 false};
122 this->drawPath(drawArgs);
123}