epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 7 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 8 | #include "GrPathRenderer.h" |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 9 | #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.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 16 | |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 17 | #ifdef SK_DEBUG |
| 18 | void 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.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 29 | } |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | ////////////////////////////////////////////////////////////////////////////// |
| 33 | |
| 34 | GrPathRenderer::GrPathRenderer() {} |
| 35 | |
| 36 | GrPathRenderer::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 | |
| 44 | bool 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 | |
| 71 | bool GrPathRenderer::IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatrix& matrix, |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 72 | SkScalar* outCoverage) { |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 73 | 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.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 87 | |
| 88 | void 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 Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 99 | |
| 100 | void 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 | } |