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