bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef GrPathRenderer_DEFINED |
| 9 | #define GrPathRenderer_DEFINED |
| 10 | |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 12 | #include "GrRenderTargetContext.h" |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 13 | #include "GrPaint.h" |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 14 | #include "GrShape.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 15 | #include "GrUserStencilSettings.h" |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 16 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 17 | #include "SkDrawProcs.h" |
bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 18 | #include "SkTArray.h" |
| 19 | |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 20 | class SkPath; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 21 | class GrFixedClip; |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 22 | class GrHardClip; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 23 | struct GrPoint; |
| 24 | |
| 25 | /** |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 26 | * Base class for drawing paths into a GrOpList. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 27 | */ |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 28 | class SK_API GrPathRenderer : public SkRefCnt { |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 29 | public: |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 30 | GrPathRenderer(); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 33 | * A caller may wish to use a path renderer to draw a path into the stencil buffer. However, |
| 34 | * the path renderer itself may require use of the stencil buffer. Also a path renderer may |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 35 | * use a GrProcessor coverage stage that sets coverage to zero to eliminate pixels that are |
| 36 | * covered by bounding geometry but outside the path. These exterior pixels would still be |
| 37 | * rendered into the stencil. |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 38 | * |
| 39 | * A GrPathRenderer can provide three levels of support for stenciling paths: |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 40 | * 1) kNoRestriction: This is the most general. The caller passes a GrPaint and calls drawPath(). |
| 41 | * The path is rendered exactly as the draw state indicates including support |
| 42 | * for simultaneous color and stenciling with arbitrary stenciling rules. |
| 43 | * Pixels partially covered by AA paths are affected by the stencil settings. |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 44 | * 2) kStencilOnly: The path renderer cannot apply arbitrary stencil rules nor shade and stencil |
| 45 | * simultaneously. The path renderer does support the stencilPath() function |
| 46 | * which performs no color writes and writes a non-zero stencil value to pixels |
| 47 | * covered by the path. |
| 48 | * 3) kNoSupport: This path renderer cannot be used to stencil the path. |
| 49 | */ |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 50 | enum StencilSupport { |
| 51 | kNoSupport_StencilSupport, |
| 52 | kStencilOnly_StencilSupport, |
| 53 | kNoRestriction_StencilSupport, |
| 54 | }; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 57 | * This function is to get the stencil support for a particular path. The path's fill must |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 58 | * not be an inverse type. The path will always be filled and not stroked. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 59 | * |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 60 | * @param shape the shape that will be drawn. Must be simple fill styled and non-inverse |
| 61 | * filled. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 62 | */ |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 63 | StencilSupport getStencilSupport(const GrShape& shape) const { |
| 64 | SkDEBUGCODE(SkPath path;) |
| 65 | SkDEBUGCODE(shape.asPath(&path);) |
| 66 | SkASSERT(shape.style().isSimpleFill()); |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 67 | SkASSERT(!path.isInverseFillType()); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 68 | return this->onGetStencilSupport(shape); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 69 | } |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 70 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 71 | enum class CanDrawPath { |
| 72 | kNo, |
| 73 | kAsBackup, // i.e. This renderer is better than SW fallback if no others can draw the path. |
| 74 | kYes |
| 75 | }; |
| 76 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 77 | struct CanDrawPathArgs { |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 78 | SkDEBUGCODE(CanDrawPathArgs() { memset(this, 0, sizeof(*this)); }) // For validation. |
| 79 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 80 | const GrCaps* fCaps; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 81 | const SkIRect* fClipConservativeBounds; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 82 | const SkMatrix* fViewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 83 | const GrShape* fShape; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 84 | GrAAType fAAType; |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 85 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 86 | // These next two are only used by GrStencilAndCoverPathRenderer |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 87 | bool fHasUserStencilSettings; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 88 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 89 | #ifdef SK_DEBUG |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 90 | void validate() const { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 91 | SkASSERT(fCaps); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 92 | SkASSERT(fClipConservativeBounds); |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 93 | SkASSERT(fViewMatrix); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 94 | SkASSERT(fShape); |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 95 | } |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 96 | #endif |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame] | 99 | /** |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 100 | * Returns how well this path renderer is able to render the given path. Returning kNo or |
| 101 | * kAsBackup allows the caller to keep searching for a better path renderer. This function is |
| 102 | * called when searching for the best path renderer to draw a path. |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame] | 103 | */ |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 104 | CanDrawPath canDrawPath(const CanDrawPathArgs& args) const { |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 105 | SkDEBUGCODE(args.validate();) |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 106 | return this->onCanDrawPath(args); |
| 107 | } |
| 108 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 109 | struct DrawPathArgs { |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 110 | GrContext* fContext; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 111 | GrPaint&& fPaint; |
| 112 | const GrUserStencilSettings* fUserStencilSettings; |
| 113 | GrRenderTargetContext* fRenderTargetContext; |
| 114 | const GrClip* fClip; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 115 | const SkIRect* fClipConservativeBounds; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 116 | const SkMatrix* fViewMatrix; |
| 117 | const GrShape* fShape; |
| 118 | GrAAType fAAType; |
| 119 | bool fGammaCorrect; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 120 | #ifdef SK_DEBUG |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 121 | void validate() const { |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 122 | SkASSERT(fContext); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 123 | SkASSERT(fUserStencilSettings); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 124 | SkASSERT(fRenderTargetContext); |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 125 | SkASSERT(fClip); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 126 | SkASSERT(fClipConservativeBounds); |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 127 | SkASSERT(fViewMatrix); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 128 | SkASSERT(fShape); |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 129 | } |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 130 | #endif |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 133 | /** |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 134 | * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 135 | * the subclass must respect the stencil settings. |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 136 | */ |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 137 | bool drawPath(const DrawPathArgs& args) { |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 138 | SkDEBUGCODE(args.validate();) |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 139 | #ifdef SK_DEBUG |
| 140 | CanDrawPathArgs canArgs; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 141 | canArgs.fCaps = args.fContext->caps(); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 142 | canArgs.fClipConservativeBounds = args.fClipConservativeBounds; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 143 | canArgs.fViewMatrix = args.fViewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 144 | canArgs.fShape = args.fShape; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 145 | canArgs.fAAType = args.fAAType; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 146 | canArgs.validate(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 147 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 148 | canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused(); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 149 | SkASSERT(!(canArgs.fAAType == GrAAType::kMSAA && |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 150 | GrFSAAType::kUnifiedMSAA != args.fRenderTargetContext->fsaaType())); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 151 | SkASSERT(!(canArgs.fAAType == GrAAType::kMixedSamples && |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 152 | GrFSAAType::kMixedSamples != args.fRenderTargetContext->fsaaType())); |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 153 | SkASSERT(CanDrawPath::kNo != this->canDrawPath(canArgs)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 154 | if (!args.fUserStencilSettings->isUnused()) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 155 | SkPath path; |
| 156 | args.fShape->asPath(&path); |
| 157 | SkASSERT(args.fShape->style().isSimpleFill()); |
| 158 | SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*args.fShape)); |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 159 | } |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 160 | #endif |
| 161 | return this->onDrawPath(args); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 162 | } |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 163 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 164 | /** |
| 165 | * Args to stencilPath(). fAAType cannot be kCoverage. |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 166 | */ |
| 167 | struct StencilPathArgs { |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 168 | SkDEBUGCODE(StencilPathArgs() { memset(this, 0, sizeof(*this)); }) // For validation. |
| 169 | |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 170 | GrContext* fContext; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 171 | GrRenderTargetContext* fRenderTargetContext; |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 172 | const GrHardClip* fClip; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 173 | const SkIRect* fClipConservativeBounds; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 174 | const SkMatrix* fViewMatrix; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 175 | GrAAType fAAType; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 176 | const GrShape* fShape; |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 177 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 178 | #ifdef SK_DEBUG |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 179 | void validate() const { |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 180 | SkASSERT(fContext); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 181 | SkASSERT(fRenderTargetContext); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 182 | SkASSERT(fClipConservativeBounds); |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 183 | SkASSERT(fViewMatrix); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 184 | SkASSERT(fShape); |
caryclark | d656200 | 2016-07-27 12:02:07 -0700 | [diff] [blame] | 185 | SkASSERT(fShape->style().isSimpleFill()); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 186 | SkASSERT(GrAAType::kCoverage != fAAType); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 187 | SkPath path; |
| 188 | fShape->asPath(&path); |
| 189 | SkASSERT(!path.isInverseFillType()); |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 190 | } |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 191 | #endif |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 194 | /** |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 195 | * Draws the path to the stencil buffer. Assume the writable stencil bits are already |
| 196 | * initialized to zero. The pixels inside the path will have non-zero stencil values afterwards. |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 197 | */ |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 198 | void stencilPath(const StencilPathArgs& args) { |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 199 | SkDEBUGCODE(args.validate();) |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 200 | SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fShape)); |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 201 | this->onStencilPath(args); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 202 | } |
| 203 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 204 | // Helper for determining if we can treat a thin stroke as a hairline w/ coverage. |
| 205 | // If we can, we draw lots faster (raster device does this same test). |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 206 | static bool IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatrix& matrix, |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 207 | SkScalar* outCoverage) { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 208 | if (style.pathEffect()) { |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 209 | return false; |
| 210 | } |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 211 | const SkStrokeRec& stroke = style.strokeRec(); |
kkinnunen | d156d36 | 2015-05-18 22:23:54 -0700 | [diff] [blame] | 212 | if (stroke.isHairlineStyle()) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 213 | if (outCoverage) { |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 214 | *outCoverage = SK_Scalar1; |
| 215 | } |
| 216 | return true; |
| 217 | } |
kkinnunen | d156d36 | 2015-05-18 22:23:54 -0700 | [diff] [blame] | 218 | return stroke.getStyle() == SkStrokeRec::kStroke_Style && |
| 219 | SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 220 | } |
| 221 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 222 | protected: |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 223 | // Helper for getting the device bounds of a path. Inverse filled paths will have bounds set |
| 224 | // by devSize. Non-inverse path bounds will not necessarily be clipped to devSize. |
| 225 | static void GetPathDevBounds(const SkPath& path, |
| 226 | int devW, |
| 227 | int devH, |
| 228 | const SkMatrix& matrix, |
| 229 | SkRect* bounds); |
| 230 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 231 | private: |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Subclass overrides if it has any limitations of stenciling support. |
| 234 | */ |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 235 | virtual StencilSupport onGetStencilSupport(const GrShape&) const { |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 236 | return kNoRestriction_StencilSupport; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Subclass implementation of drawPath() |
| 241 | */ |
| 242 | virtual bool onDrawPath(const DrawPathArgs& args) = 0; |
| 243 | |
| 244 | /** |
| 245 | * Subclass implementation of canDrawPath() |
| 246 | */ |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 247 | virtual CanDrawPath onCanDrawPath(const CanDrawPathArgs& args) const = 0; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * Subclass implementation of stencilPath(). Subclass must override iff it ever returns |
| 251 | * kStencilOnly in onGetStencilSupport(). |
| 252 | */ |
| 253 | virtual void onStencilPath(const StencilPathArgs& args) { |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 254 | static constexpr GrUserStencilSettings kIncrementStencil( |
| 255 | GrUserStencilSettings::StaticInit< |
| 256 | 0xffff, |
| 257 | GrUserStencilTest::kAlways, |
| 258 | 0xffff, |
| 259 | GrUserStencilOp::kReplace, |
| 260 | GrUserStencilOp::kReplace, |
| 261 | 0xffff>() |
| 262 | ); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 263 | |
| 264 | GrPaint paint; |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 265 | DrawPathArgs drawArgs{args.fContext, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 266 | std::move(paint), |
| 267 | &kIncrementStencil, |
| 268 | args.fRenderTargetContext, |
| 269 | nullptr, // clip |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 270 | args.fClipConservativeBounds, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 271 | args.fViewMatrix, |
| 272 | args.fShape, |
| 273 | args.fAAType, |
| 274 | false}; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 275 | this->drawPath(drawArgs); |
| 276 | } |
| 277 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 278 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 279 | }; |
| 280 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 281 | #endif |