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