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