bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrDefaultPathRenderer.h" |
| 9 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 10 | #include "GrBatch.h" |
| 11 | #include "GrBatchTarget.h" |
| 12 | #include "GrBufferAllocPool.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 14 | #include "GrDefaultGeoProcFactory.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 15 | #include "GrPathUtils.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 16 | #include "GrPipelineBuilder.h" |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 17 | #include "SkGeometry.h" |
tomhudson@google.com | dd5f744 | 2011-08-30 15:13:55 +0000 | [diff] [blame] | 18 | #include "SkString.h" |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 19 | #include "SkStrokeRec.h" |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 20 | #include "SkTLazy.h" |
commit-bot@chromium.org | 933e65d | 2014-03-20 20:00:24 +0000 | [diff] [blame] | 21 | #include "SkTraceEvent.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 23 | GrDefaultPathRenderer::GrDefaultPathRenderer(bool separateStencilSupport, |
| 24 | bool stencilWrapOpsSupport) |
| 25 | : fSeparateStencil(separateStencilSupport) |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 26 | , fStencilWrapOps(stencilWrapOpsSupport) { |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 30 | //////////////////////////////////////////////////////////////////////////////// |
| 31 | // Stencil rules for paths |
| 32 | |
| 33 | ////// Even/Odd |
| 34 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 35 | GR_STATIC_CONST_SAME_STENCIL(gEOStencilPass, |
| 36 | kInvert_StencilOp, |
| 37 | kKeep_StencilOp, |
| 38 | kAlwaysIfInClip_StencilFunc, |
| 39 | 0xffff, |
| 40 | 0xffff, |
| 41 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 42 | |
| 43 | // ok not to check clip b/c stencil pass only wrote inside clip |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 44 | GR_STATIC_CONST_SAME_STENCIL(gEOColorPass, |
| 45 | kZero_StencilOp, |
| 46 | kZero_StencilOp, |
| 47 | kNotEqual_StencilFunc, |
| 48 | 0xffff, |
| 49 | 0x0000, |
| 50 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 51 | |
| 52 | // have to check clip b/c outside clip will always be zero. |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 53 | GR_STATIC_CONST_SAME_STENCIL(gInvEOColorPass, |
| 54 | kZero_StencilOp, |
| 55 | kZero_StencilOp, |
| 56 | kEqualIfInClip_StencilFunc, |
| 57 | 0xffff, |
| 58 | 0x0000, |
| 59 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 60 | |
| 61 | ////// Winding |
| 62 | |
| 63 | // when we have separate stencil we increment front faces / decrement back faces |
| 64 | // when we don't have wrap incr and decr we use the stencil test to simulate |
| 65 | // them. |
| 66 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 67 | GR_STATIC_CONST_STENCIL(gWindStencilSeparateWithWrap, |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 68 | kIncWrap_StencilOp, kDecWrap_StencilOp, |
| 69 | kKeep_StencilOp, kKeep_StencilOp, |
| 70 | kAlwaysIfInClip_StencilFunc, kAlwaysIfInClip_StencilFunc, |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 71 | 0xffff, 0xffff, |
| 72 | 0xffff, 0xffff, |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 73 | 0xffff, 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 74 | |
| 75 | // if inc'ing the max value, invert to make 0 |
| 76 | // if dec'ing zero invert to make all ones. |
| 77 | // we can't avoid touching the stencil on both passing and |
| 78 | // failing, so we can't resctrict ourselves to the clip. |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 79 | GR_STATIC_CONST_STENCIL(gWindStencilSeparateNoWrap, |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 80 | kInvert_StencilOp, kInvert_StencilOp, |
| 81 | kIncClamp_StencilOp, kDecClamp_StencilOp, |
| 82 | kEqual_StencilFunc, kEqual_StencilFunc, |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 83 | 0xffff, 0xffff, |
| 84 | 0xffff, 0x0000, |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 85 | 0xffff, 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 86 | |
| 87 | // When there are no separate faces we do two passes to setup the winding rule |
| 88 | // stencil. First we draw the front faces and inc, then we draw the back faces |
| 89 | // and dec. These are same as the above two split into the incrementing and |
| 90 | // decrementing passes. |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 91 | GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilWithWrapInc, |
| 92 | kIncWrap_StencilOp, |
| 93 | kKeep_StencilOp, |
| 94 | kAlwaysIfInClip_StencilFunc, |
| 95 | 0xffff, |
| 96 | 0xffff, |
| 97 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 98 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 99 | GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilWithWrapDec, |
| 100 | kDecWrap_StencilOp, |
| 101 | kKeep_StencilOp, |
| 102 | kAlwaysIfInClip_StencilFunc, |
| 103 | 0xffff, |
| 104 | 0xffff, |
| 105 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 106 | |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 107 | GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilNoWrapInc, |
| 108 | kInvert_StencilOp, |
| 109 | kIncClamp_StencilOp, |
| 110 | kEqual_StencilFunc, |
| 111 | 0xffff, |
| 112 | 0xffff, |
| 113 | 0xffff); |
| 114 | |
| 115 | GR_STATIC_CONST_SAME_STENCIL(gWindSingleStencilNoWrapDec, |
| 116 | kInvert_StencilOp, |
| 117 | kDecClamp_StencilOp, |
| 118 | kEqual_StencilFunc, |
| 119 | 0xffff, |
| 120 | 0x0000, |
| 121 | 0xffff); |
| 122 | |
| 123 | // Color passes are the same whether we use the two-sided stencil or two passes |
| 124 | |
| 125 | GR_STATIC_CONST_SAME_STENCIL(gWindColorPass, |
| 126 | kZero_StencilOp, |
| 127 | kZero_StencilOp, |
| 128 | kNonZeroIfInClip_StencilFunc, |
| 129 | 0xffff, |
| 130 | 0x0000, |
| 131 | 0xffff); |
| 132 | |
| 133 | GR_STATIC_CONST_SAME_STENCIL(gInvWindColorPass, |
| 134 | kZero_StencilOp, |
| 135 | kZero_StencilOp, |
| 136 | kEqualIfInClip_StencilFunc, |
| 137 | 0xffff, |
| 138 | 0x0000, |
| 139 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 140 | |
| 141 | ////// Normal render to stencil |
| 142 | |
| 143 | // Sometimes the default path renderer can draw a path directly to the stencil |
| 144 | // buffer without having to first resolve the interior / exterior. |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 145 | GR_STATIC_CONST_SAME_STENCIL(gDirectToStencil, |
| 146 | kZero_StencilOp, |
| 147 | kIncClamp_StencilOp, |
| 148 | kAlwaysIfInClip_StencilFunc, |
| 149 | 0xffff, |
| 150 | 0x0000, |
| 151 | 0xffff); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 152 | |
| 153 | //////////////////////////////////////////////////////////////////////////////// |
| 154 | // Helpers for drawPath |
| 155 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 156 | #define STENCIL_OFF 0 // Always disable stencil (even when needed) |
| 157 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 158 | static inline bool single_pass_path(const SkPath& path, const SkStrokeRec& stroke) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 159 | #if STENCIL_OFF |
| 160 | return true; |
| 161 | #else |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 162 | if (!stroke.isHairlineStyle() && !path.isInverseFillType()) { |
bsalomon@google.com | 7d72c45 | 2012-01-30 14:02:44 +0000 | [diff] [blame] | 163 | return path.isConvex(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 164 | } |
| 165 | return false; |
| 166 | #endif |
| 167 | } |
| 168 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 169 | GrPathRenderer::StencilSupport |
| 170 | GrDefaultPathRenderer::onGetStencilSupport(const GrDrawTarget*, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 171 | const GrPipelineBuilder*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 172 | const SkPath& path, |
| 173 | const SkStrokeRec& stroke) const { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 174 | if (single_pass_path(path, stroke)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 175 | return GrPathRenderer::kNoRestriction_StencilSupport; |
| 176 | } else { |
| 177 | return GrPathRenderer::kStencilOnly_StencilSupport; |
| 178 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 179 | } |
| 180 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 181 | static inline void append_countour_edge_indices(bool hairLine, |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 182 | uint16_t fanCenterIdx, |
| 183 | uint16_t edgeV0Idx, |
| 184 | uint16_t** indices) { |
| 185 | // when drawing lines we're appending line segments along |
| 186 | // the contour. When applying the other fill rules we're |
| 187 | // drawing triangle fans around fanCenterIdx. |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 188 | if (!hairLine) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 189 | *((*indices)++) = fanCenterIdx; |
| 190 | } |
| 191 | *((*indices)++) = edgeV0Idx; |
| 192 | *((*indices)++) = edgeV0Idx + 1; |
| 193 | } |
| 194 | |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 195 | static inline void add_quad(SkPoint** vert, const SkPoint* base, const SkPoint pts[], |
| 196 | SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol, bool indexed, |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 197 | bool isHairline, uint16_t subpathIdxStart, int offset, uint16_t** idx) { |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 198 | // first pt of quad is the pt we ended on in previous step |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 199 | uint16_t firstQPtIdx = (uint16_t)(*vert - base) - 1 + offset; |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 200 | uint16_t numPts = (uint16_t) |
| 201 | GrPathUtils::generateQuadraticPoints( |
| 202 | pts[0], pts[1], pts[2], |
| 203 | srcSpaceTolSqd, vert, |
| 204 | GrPathUtils::quadraticPointCount(pts, srcSpaceTol)); |
| 205 | if (indexed) { |
| 206 | for (uint16_t i = 0; i < numPts; ++i) { |
| 207 | append_countour_edge_indices(isHairline, subpathIdxStart, |
| 208 | firstQPtIdx + i, idx); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 213 | class DefaultPathBatch : public GrBatch { |
| 214 | public: |
| 215 | struct Geometry { |
| 216 | GrColor fColor; |
| 217 | SkPath fPath; |
| 218 | SkScalar fTolerance; |
| 219 | SkDEBUGCODE(SkRect fDevBounds;) |
| 220 | }; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 221 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 222 | static GrBatch* Create(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix, |
| 223 | bool isHairline) { |
| 224 | return SkNEW_ARGS(DefaultPathBatch, (geometry, coverage, viewMatrix, isHairline)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 225 | } |
| 226 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 227 | const char* name() const SK_OVERRIDE { return "DefaultPathBatch"; } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 228 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 229 | void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { |
| 230 | // When this is called on a batch, there is only one geometry bundle |
| 231 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 232 | } |
| 233 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE { |
joshualitt | 233c6ce | 2015-02-24 08:17:49 -0800 | [diff] [blame^] | 234 | out->setKnownSingleComponent(this->coverage()); |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 235 | } |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 236 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 237 | void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { |
| 238 | // Handle any color overrides |
| 239 | if (init.fColorIgnored) { |
| 240 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 241 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 242 | fGeoData[0].fColor = init.fOverrideColor; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 243 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 244 | |
| 245 | // setup batch properties |
| 246 | fBatch.fColorIgnored = init.fColorIgnored; |
| 247 | fBatch.fColor = fGeoData[0].fColor; |
| 248 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 249 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 250 | } |
| 251 | |
| 252 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { |
| 253 | SkAutoTUnref<const GrGeometryProcessor> gp( |
| 254 | GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, |
| 255 | this->color(), |
| 256 | this->viewMatrix(), |
| 257 | SkMatrix::I(), |
| 258 | false, |
| 259 | this->coverage())); |
| 260 | |
| 261 | size_t vertexStride = gp->getVertexStride(); |
| 262 | SkASSERT(vertexStride == sizeof(SkPoint)); |
| 263 | |
| 264 | batchTarget->initDraw(gp, pipeline); |
| 265 | |
| 266 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 267 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 268 | // everywhere we can remove this nastiness |
| 269 | GrPipelineInfo init; |
| 270 | init.fColorIgnored = fBatch.fColorIgnored; |
| 271 | init.fOverrideColor = GrColor_ILLEGAL; |
| 272 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 273 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 274 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 275 | |
| 276 | int instanceCount = fGeoData.count(); |
| 277 | |
| 278 | // compute number of vertices |
| 279 | int maxVertices = 0; |
| 280 | |
| 281 | // We will use index buffers if we have multiple paths or one path with multiple contours |
| 282 | bool isIndexed = instanceCount > 1; |
| 283 | for (int i = 0; i < instanceCount; i++) { |
| 284 | Geometry& args = fGeoData[i]; |
| 285 | |
| 286 | int contourCount; |
| 287 | maxVertices += GrPathUtils::worstCasePointCount(args.fPath, &contourCount, |
| 288 | args.fTolerance); |
| 289 | |
| 290 | isIndexed = isIndexed || contourCount > 1; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 291 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 292 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 293 | // determine primitiveType |
| 294 | int maxIndices = 0; |
| 295 | GrPrimitiveType primitiveType; |
| 296 | if (this->isHairline()) { |
| 297 | if (isIndexed) { |
| 298 | maxIndices = 2 * maxVertices; |
| 299 | primitiveType = kLines_GrPrimitiveType; |
| 300 | } else { |
| 301 | primitiveType = kLineStrip_GrPrimitiveType; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 302 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 303 | } else { |
| 304 | if (isIndexed) { |
| 305 | maxIndices = 3 * maxVertices; |
| 306 | primitiveType = kTriangles_GrPrimitiveType; |
| 307 | } else { |
| 308 | primitiveType = kTriangleFan_GrPrimitiveType; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | // allocate vertex / index buffers |
| 313 | const GrVertexBuffer* vertexBuffer; |
| 314 | int firstVertex; |
| 315 | |
| 316 | void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 317 | maxVertices, |
| 318 | &vertexBuffer, |
| 319 | &firstVertex); |
| 320 | |
| 321 | const GrIndexBuffer* indexBuffer; |
| 322 | int firstIndex; |
| 323 | |
| 324 | void* indices = NULL; |
| 325 | if (isIndexed) { |
| 326 | indices = batchTarget->indexPool()->makeSpace(maxIndices, |
| 327 | &indexBuffer, |
| 328 | &firstIndex); |
| 329 | } |
| 330 | |
| 331 | // fill buffers |
| 332 | int vertexOffset = 0; |
| 333 | int indexOffset = 0; |
| 334 | for (int i = 0; i < instanceCount; i++) { |
| 335 | Geometry& args = fGeoData[i]; |
| 336 | |
| 337 | int vertexCnt = 0; |
| 338 | int indexCnt = 0; |
| 339 | if (!this->createGeom(vertices, |
| 340 | vertexOffset, |
| 341 | indices, |
| 342 | indexOffset, |
| 343 | &vertexCnt, |
| 344 | &indexCnt, |
| 345 | args.fPath, |
| 346 | args.fTolerance, |
| 347 | isIndexed)) { |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | vertexOffset += vertexCnt; |
| 352 | indexOffset += indexCnt; |
| 353 | SkASSERT(vertexOffset <= maxVertices && indexOffset <= maxIndices); |
| 354 | } |
| 355 | |
| 356 | GrDrawTarget::DrawInfo drawInfo; |
| 357 | drawInfo.setPrimitiveType(primitiveType); |
| 358 | drawInfo.setVertexBuffer(vertexBuffer); |
| 359 | drawInfo.setStartVertex(firstVertex); |
| 360 | drawInfo.setVertexCount(vertexOffset); |
| 361 | if (isIndexed) { |
| 362 | drawInfo.setIndexBuffer(indexBuffer); |
| 363 | drawInfo.setStartIndex(firstIndex); |
| 364 | drawInfo.setIndexCount(indexOffset); |
| 365 | } else { |
| 366 | drawInfo.setStartIndex(0); |
| 367 | drawInfo.setIndexCount(0); |
| 368 | } |
| 369 | batchTarget->draw(drawInfo); |
| 370 | } |
| 371 | |
| 372 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 373 | |
| 374 | private: |
| 375 | DefaultPathBatch(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix, |
| 376 | bool isHairline) { |
| 377 | this->initClassID<DefaultPathBatch>(); |
| 378 | fBatch.fCoverage = coverage; |
| 379 | fBatch.fIsHairline = isHairline; |
| 380 | fBatch.fViewMatrix = viewMatrix; |
| 381 | fGeoData.push_back(geometry); |
| 382 | } |
| 383 | |
| 384 | bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { |
| 385 | DefaultPathBatch* that = t->cast<DefaultPathBatch>(); |
| 386 | |
| 387 | if (this->color() != that->color()) { |
| 388 | return false; |
| 389 | } |
| 390 | |
| 391 | if (this->coverage() != that->coverage()) { |
| 392 | return false; |
| 393 | } |
| 394 | |
| 395 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | if (this->isHairline() != that->isHairline()) { |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | bool createGeom(void* vertices, |
| 408 | size_t vertexOffset, |
| 409 | void* indices, |
| 410 | size_t indexOffset, |
| 411 | int* vertexCnt, |
| 412 | int* indexCnt, |
| 413 | const SkPath& path, |
| 414 | SkScalar srcSpaceTol, |
| 415 | bool isIndexed) { |
| 416 | { |
| 417 | SkScalar srcSpaceTolSqd = SkScalarMul(srcSpaceTol, srcSpaceTol); |
| 418 | |
| 419 | uint16_t indexOffsetU16 = (uint16_t)indexOffset; |
| 420 | uint16_t vertexOffsetU16 = (uint16_t)vertexOffset; |
| 421 | |
| 422 | uint16_t* idxBase = reinterpret_cast<uint16_t*>(indices) + indexOffsetU16; |
| 423 | uint16_t* idx = idxBase; |
| 424 | uint16_t subpathIdxStart = vertexOffsetU16; |
| 425 | |
| 426 | SkPoint* base = reinterpret_cast<SkPoint*>(vertices) + vertexOffset; |
| 427 | SkPoint* vert = base; |
| 428 | |
| 429 | SkPoint pts[4]; |
| 430 | |
| 431 | bool first = true; |
| 432 | int subpath = 0; |
| 433 | |
| 434 | SkPath::Iter iter(path, false); |
| 435 | |
| 436 | bool done = false; |
| 437 | while (!done) { |
| 438 | SkPath::Verb verb = iter.next(pts); |
| 439 | switch (verb) { |
| 440 | case SkPath::kMove_Verb: |
| 441 | if (!first) { |
| 442 | uint16_t currIdx = (uint16_t) (vert - base) + vertexOffsetU16; |
| 443 | subpathIdxStart = currIdx; |
| 444 | ++subpath; |
| 445 | } |
| 446 | *vert = pts[0]; |
| 447 | vert++; |
| 448 | break; |
| 449 | case SkPath::kLine_Verb: |
| 450 | if (isIndexed) { |
| 451 | uint16_t prevIdx = (uint16_t)(vert - base) - 1 + vertexOffsetU16; |
| 452 | append_countour_edge_indices(this->isHairline(), subpathIdxStart, |
| 453 | prevIdx, &idx); |
| 454 | } |
| 455 | *(vert++) = pts[1]; |
| 456 | break; |
| 457 | case SkPath::kConic_Verb: { |
| 458 | SkScalar weight = iter.conicWeight(); |
| 459 | SkAutoConicToQuads converter; |
| 460 | // Converting in src-space, hance the finer tolerance (0.25) |
| 461 | // TODO: find a way to do this in dev-space so the tolerance means something |
| 462 | const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.25f); |
| 463 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 464 | add_quad(&vert, base, quadPts + i*2, srcSpaceTolSqd, srcSpaceTol, |
| 465 | isIndexed, this->isHairline(), subpathIdxStart, |
| 466 | (int)vertexOffset, &idx); |
| 467 | } |
| 468 | break; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 469 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 470 | case SkPath::kQuad_Verb: |
| 471 | add_quad(&vert, base, pts, srcSpaceTolSqd, srcSpaceTol, isIndexed, |
| 472 | this->isHairline(), subpathIdxStart, (int)vertexOffset, &idx); |
| 473 | break; |
| 474 | case SkPath::kCubic_Verb: { |
| 475 | // first pt of cubic is the pt we ended on in previous step |
| 476 | uint16_t firstCPtIdx = (uint16_t)(vert - base) - 1 + vertexOffsetU16; |
| 477 | uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints( |
| 478 | pts[0], pts[1], pts[2], pts[3], |
| 479 | srcSpaceTolSqd, &vert, |
| 480 | GrPathUtils::cubicPointCount(pts, srcSpaceTol)); |
| 481 | if (isIndexed) { |
| 482 | for (uint16_t i = 0; i < numPts; ++i) { |
| 483 | append_countour_edge_indices(this->isHairline(), subpathIdxStart, |
| 484 | firstCPtIdx + i, &idx); |
| 485 | } |
| 486 | } |
| 487 | break; |
| 488 | } |
| 489 | case SkPath::kClose_Verb: |
| 490 | break; |
| 491 | case SkPath::kDone_Verb: |
| 492 | done = true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 493 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 494 | first = false; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 495 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 496 | |
| 497 | *vertexCnt = static_cast<int>(vert - base); |
| 498 | *indexCnt = static_cast<int>(idx - idxBase); |
| 499 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 500 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 501 | return true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 502 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 503 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 504 | GrColor color() const { return fBatch.fColor; } |
| 505 | uint8_t coverage() const { return fBatch.fCoverage; } |
| 506 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 507 | const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 508 | bool isHairline() const { return fBatch.fIsHairline; } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 509 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 510 | struct BatchTracker { |
| 511 | GrColor fColor; |
| 512 | uint8_t fCoverage; |
| 513 | SkMatrix fViewMatrix; |
| 514 | bool fUsesLocalCoords; |
| 515 | bool fColorIgnored; |
| 516 | bool fCoverageIgnored; |
| 517 | bool fIsHairline; |
| 518 | }; |
| 519 | |
| 520 | BatchTracker fBatch; |
| 521 | SkSTArray<1, Geometry, true> fGeoData; |
| 522 | }; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 523 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 524 | bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 525 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 526 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 527 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 528 | const SkPath& path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 529 | const SkStrokeRec& origStroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 530 | bool stencilOnly) { |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 531 | SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); |
| 532 | |
| 533 | SkScalar hairlineCoverage; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 534 | uint8_t newCoverage = 0xff; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 535 | if (IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, &hairlineCoverage)) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 536 | newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 537 | |
| 538 | if (!stroke->isHairlineStyle()) { |
| 539 | stroke.writable()->setHairlineStyle(); |
| 540 | } |
| 541 | } |
| 542 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 543 | const bool isHairline = stroke->isHairlineStyle(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 544 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 545 | // Save the current xp on the draw state so we can reset it if needed |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 546 | SkAutoTUnref<const GrXPFactory> backupXPFactory(SkRef(pipelineBuilder->getXPFactory())); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 547 | // face culling doesn't make sense here |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 548 | SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace()); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 549 | |
| 550 | int passCount = 0; |
| 551 | const GrStencilSettings* passes[3]; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 552 | GrPipelineBuilder::DrawFace drawFace[3]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 553 | bool reverse = false; |
| 554 | bool lastPassIsBounds; |
| 555 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 556 | if (isHairline) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 557 | passCount = 1; |
| 558 | if (stencilOnly) { |
| 559 | passes[0] = &gDirectToStencil; |
| 560 | } else { |
| 561 | passes[0] = NULL; |
| 562 | } |
| 563 | lastPassIsBounds = false; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 564 | drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 565 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 566 | if (single_pass_path(path, *stroke)) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 567 | passCount = 1; |
| 568 | if (stencilOnly) { |
| 569 | passes[0] = &gDirectToStencil; |
| 570 | } else { |
| 571 | passes[0] = NULL; |
| 572 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 573 | drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 574 | lastPassIsBounds = false; |
| 575 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 576 | switch (path.getFillType()) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 577 | case SkPath::kInverseEvenOdd_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 578 | reverse = true; |
| 579 | // fallthrough |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 580 | case SkPath::kEvenOdd_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 581 | passes[0] = &gEOStencilPass; |
| 582 | if (stencilOnly) { |
| 583 | passCount = 1; |
| 584 | lastPassIsBounds = false; |
| 585 | } else { |
| 586 | passCount = 2; |
| 587 | lastPassIsBounds = true; |
| 588 | if (reverse) { |
| 589 | passes[1] = &gInvEOColorPass; |
| 590 | } else { |
| 591 | passes[1] = &gEOColorPass; |
| 592 | } |
| 593 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 594 | drawFace[0] = drawFace[1] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 595 | break; |
| 596 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 597 | case SkPath::kInverseWinding_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 598 | reverse = true; |
| 599 | // fallthrough |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 600 | case SkPath::kWinding_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 601 | if (fSeparateStencil) { |
| 602 | if (fStencilWrapOps) { |
| 603 | passes[0] = &gWindStencilSeparateWithWrap; |
| 604 | } else { |
| 605 | passes[0] = &gWindStencilSeparateNoWrap; |
| 606 | } |
| 607 | passCount = 2; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 608 | drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 609 | } else { |
| 610 | if (fStencilWrapOps) { |
| 611 | passes[0] = &gWindSingleStencilWithWrapInc; |
| 612 | passes[1] = &gWindSingleStencilWithWrapDec; |
| 613 | } else { |
| 614 | passes[0] = &gWindSingleStencilNoWrapInc; |
| 615 | passes[1] = &gWindSingleStencilNoWrapDec; |
| 616 | } |
| 617 | // which is cw and which is ccw is arbitrary. |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 618 | drawFace[0] = GrPipelineBuilder::kCW_DrawFace; |
| 619 | drawFace[1] = GrPipelineBuilder::kCCW_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 620 | passCount = 3; |
| 621 | } |
| 622 | if (stencilOnly) { |
| 623 | lastPassIsBounds = false; |
| 624 | --passCount; |
| 625 | } else { |
| 626 | lastPassIsBounds = true; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 627 | drawFace[passCount-1] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 628 | if (reverse) { |
| 629 | passes[passCount-1] = &gInvWindColorPass; |
| 630 | } else { |
| 631 | passes[passCount-1] = &gWindColorPass; |
| 632 | } |
| 633 | } |
| 634 | break; |
| 635 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 636 | SkDEBUGFAIL("Unknown path fFill!"); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 637 | return false; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 642 | SkScalar tol = SK_Scalar1; |
| 643 | SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds()); |
| 644 | |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 645 | SkRect devBounds; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 646 | GetPathDevBounds(path, pipelineBuilder->getRenderTarget(), viewMatrix, &devBounds); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 647 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 648 | for (int p = 0; p < passCount; ++p) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 649 | pipelineBuilder->setDrawFace(drawFace[p]); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 650 | if (passes[p]) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 651 | *pipelineBuilder->stencil() = *passes[p]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | if (lastPassIsBounds && (p == passCount-1)) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 655 | // Reset the XP Factory on pipelineBuilder |
| 656 | pipelineBuilder->setXPFactory(backupXPFactory); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 657 | SkRect bounds; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 658 | SkMatrix localMatrix = SkMatrix::I(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 659 | if (reverse) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 660 | SkASSERT(pipelineBuilder->getRenderTarget()); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 661 | // draw over the dev bounds (which will be the whole dst surface for inv fill). |
| 662 | bounds = devBounds; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 663 | SkMatrix vmi; |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 664 | // mapRect through persp matrix may not be correct |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 665 | if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 666 | vmi.mapRect(&bounds); |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 667 | } else { |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 668 | if (!viewMatrix.invert(&localMatrix)) { |
| 669 | return false; |
| 670 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 671 | } |
| 672 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 673 | bounds = path.getBounds(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 674 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 675 | GrDrawTarget::AutoGeometryPush agp(target); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 676 | const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() : |
| 677 | viewMatrix; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 678 | target->drawRect(pipelineBuilder, color, viewM, bounds, NULL, &localMatrix); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 679 | } else { |
| 680 | if (passCount > 1) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 681 | pipelineBuilder->setDisableColorXPFactory(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 682 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 683 | |
| 684 | DefaultPathBatch::Geometry geometry; |
| 685 | geometry.fColor = color; |
| 686 | geometry.fPath = path; |
| 687 | geometry.fTolerance = srcSpaceTol; |
| 688 | SkDEBUGCODE(geometry.fDevBounds = devBounds;) |
| 689 | |
| 690 | SkAutoTUnref<GrBatch> batch(DefaultPathBatch::Create(geometry, newCoverage, viewMatrix, |
| 691 | isHairline)); |
| 692 | |
| 693 | target->drawBatch(pipelineBuilder, batch, &devBounds); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 696 | return true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 697 | } |
| 698 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 699 | bool GrDefaultPathRenderer::canDrawPath(const GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 700 | const GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 701 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 702 | const SkPath& path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 703 | const SkStrokeRec& stroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 704 | bool antiAlias) const { |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 705 | // this class can draw any path with any fill but doesn't do any anti-aliasing. |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 706 | return !antiAlias && (stroke.isFillStyle() || IsStrokeHairlineOrEquivalent(stroke, |
| 707 | viewMatrix, |
| 708 | NULL)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 709 | } |
| 710 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 711 | bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 712 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 713 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 714 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 715 | const SkPath& path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 716 | const SkStrokeRec& stroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 717 | bool antiAlias) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 718 | return this->internalDrawPath(target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 719 | pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 720 | color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 721 | viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 722 | path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 723 | stroke, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 724 | false); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 725 | } |
| 726 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 727 | void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 728 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 729 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 730 | const SkPath& path, |
| 731 | const SkStrokeRec& stroke) { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 732 | SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); |
| 733 | SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 734 | this->internalDrawPath(target, pipelineBuilder, GrColor_WHITE, viewMatrix, path, stroke, true); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 735 | } |