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 | 5b27b14 | 2015-02-24 12:58:46 -0800 | [diff] [blame] | 293 | if (maxVertices == 0 || maxVertices > ((int)SK_MaxU16 + 1)) { |
| 294 | SkDebugf("Cannot render path (%d)\n", maxVertices); |
| 295 | return; |
| 296 | } |
| 297 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 298 | // determine primitiveType |
| 299 | int maxIndices = 0; |
| 300 | GrPrimitiveType primitiveType; |
| 301 | if (this->isHairline()) { |
| 302 | if (isIndexed) { |
| 303 | maxIndices = 2 * maxVertices; |
| 304 | primitiveType = kLines_GrPrimitiveType; |
| 305 | } else { |
| 306 | primitiveType = kLineStrip_GrPrimitiveType; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 307 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 308 | } else { |
| 309 | if (isIndexed) { |
| 310 | maxIndices = 3 * maxVertices; |
| 311 | primitiveType = kTriangles_GrPrimitiveType; |
| 312 | } else { |
| 313 | primitiveType = kTriangleFan_GrPrimitiveType; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | // allocate vertex / index buffers |
| 318 | const GrVertexBuffer* vertexBuffer; |
| 319 | int firstVertex; |
| 320 | |
| 321 | void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 322 | maxVertices, |
| 323 | &vertexBuffer, |
| 324 | &firstVertex); |
| 325 | |
| 326 | const GrIndexBuffer* indexBuffer; |
| 327 | int firstIndex; |
| 328 | |
| 329 | void* indices = NULL; |
| 330 | if (isIndexed) { |
| 331 | indices = batchTarget->indexPool()->makeSpace(maxIndices, |
| 332 | &indexBuffer, |
| 333 | &firstIndex); |
| 334 | } |
| 335 | |
| 336 | // fill buffers |
| 337 | int vertexOffset = 0; |
| 338 | int indexOffset = 0; |
| 339 | for (int i = 0; i < instanceCount; i++) { |
| 340 | Geometry& args = fGeoData[i]; |
| 341 | |
| 342 | int vertexCnt = 0; |
| 343 | int indexCnt = 0; |
| 344 | if (!this->createGeom(vertices, |
| 345 | vertexOffset, |
| 346 | indices, |
| 347 | indexOffset, |
| 348 | &vertexCnt, |
| 349 | &indexCnt, |
| 350 | args.fPath, |
| 351 | args.fTolerance, |
| 352 | isIndexed)) { |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | vertexOffset += vertexCnt; |
| 357 | indexOffset += indexCnt; |
| 358 | SkASSERT(vertexOffset <= maxVertices && indexOffset <= maxIndices); |
| 359 | } |
| 360 | |
| 361 | GrDrawTarget::DrawInfo drawInfo; |
| 362 | drawInfo.setPrimitiveType(primitiveType); |
| 363 | drawInfo.setVertexBuffer(vertexBuffer); |
| 364 | drawInfo.setStartVertex(firstVertex); |
| 365 | drawInfo.setVertexCount(vertexOffset); |
| 366 | if (isIndexed) { |
| 367 | drawInfo.setIndexBuffer(indexBuffer); |
| 368 | drawInfo.setStartIndex(firstIndex); |
| 369 | drawInfo.setIndexCount(indexOffset); |
| 370 | } else { |
| 371 | drawInfo.setStartIndex(0); |
| 372 | drawInfo.setIndexCount(0); |
| 373 | } |
| 374 | batchTarget->draw(drawInfo); |
joshualitt | 6065b88 | 2015-02-24 13:20:59 -0800 | [diff] [blame] | 375 | |
| 376 | // put back reserves |
| 377 | batchTarget->putBackIndices((size_t)(maxIndices - indexOffset)); |
| 378 | batchTarget->putBackVertices((size_t)(maxVertices - vertexOffset), (size_t)vertexStride); |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 382 | |
| 383 | private: |
| 384 | DefaultPathBatch(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix, |
| 385 | bool isHairline) { |
| 386 | this->initClassID<DefaultPathBatch>(); |
| 387 | fBatch.fCoverage = coverage; |
| 388 | fBatch.fIsHairline = isHairline; |
| 389 | fBatch.fViewMatrix = viewMatrix; |
| 390 | fGeoData.push_back(geometry); |
| 391 | } |
| 392 | |
| 393 | bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { |
| 394 | DefaultPathBatch* that = t->cast<DefaultPathBatch>(); |
| 395 | |
| 396 | if (this->color() != that->color()) { |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | if (this->coverage() != that->coverage()) { |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 405 | return false; |
| 406 | } |
| 407 | |
| 408 | if (this->isHairline() != that->isHairline()) { |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
| 413 | return true; |
| 414 | } |
| 415 | |
| 416 | bool createGeom(void* vertices, |
| 417 | size_t vertexOffset, |
| 418 | void* indices, |
| 419 | size_t indexOffset, |
| 420 | int* vertexCnt, |
| 421 | int* indexCnt, |
| 422 | const SkPath& path, |
| 423 | SkScalar srcSpaceTol, |
| 424 | bool isIndexed) { |
| 425 | { |
| 426 | SkScalar srcSpaceTolSqd = SkScalarMul(srcSpaceTol, srcSpaceTol); |
| 427 | |
| 428 | uint16_t indexOffsetU16 = (uint16_t)indexOffset; |
| 429 | uint16_t vertexOffsetU16 = (uint16_t)vertexOffset; |
| 430 | |
| 431 | uint16_t* idxBase = reinterpret_cast<uint16_t*>(indices) + indexOffsetU16; |
| 432 | uint16_t* idx = idxBase; |
| 433 | uint16_t subpathIdxStart = vertexOffsetU16; |
| 434 | |
| 435 | SkPoint* base = reinterpret_cast<SkPoint*>(vertices) + vertexOffset; |
| 436 | SkPoint* vert = base; |
| 437 | |
| 438 | SkPoint pts[4]; |
| 439 | |
| 440 | bool first = true; |
| 441 | int subpath = 0; |
| 442 | |
| 443 | SkPath::Iter iter(path, false); |
| 444 | |
| 445 | bool done = false; |
| 446 | while (!done) { |
| 447 | SkPath::Verb verb = iter.next(pts); |
| 448 | switch (verb) { |
| 449 | case SkPath::kMove_Verb: |
| 450 | if (!first) { |
| 451 | uint16_t currIdx = (uint16_t) (vert - base) + vertexOffsetU16; |
| 452 | subpathIdxStart = currIdx; |
| 453 | ++subpath; |
| 454 | } |
| 455 | *vert = pts[0]; |
| 456 | vert++; |
| 457 | break; |
| 458 | case SkPath::kLine_Verb: |
| 459 | if (isIndexed) { |
| 460 | uint16_t prevIdx = (uint16_t)(vert - base) - 1 + vertexOffsetU16; |
| 461 | append_countour_edge_indices(this->isHairline(), subpathIdxStart, |
| 462 | prevIdx, &idx); |
| 463 | } |
| 464 | *(vert++) = pts[1]; |
| 465 | break; |
| 466 | case SkPath::kConic_Verb: { |
| 467 | SkScalar weight = iter.conicWeight(); |
| 468 | SkAutoConicToQuads converter; |
| 469 | // Converting in src-space, hance the finer tolerance (0.25) |
| 470 | // TODO: find a way to do this in dev-space so the tolerance means something |
| 471 | const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.25f); |
| 472 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 473 | add_quad(&vert, base, quadPts + i*2, srcSpaceTolSqd, srcSpaceTol, |
| 474 | isIndexed, this->isHairline(), subpathIdxStart, |
| 475 | (int)vertexOffset, &idx); |
| 476 | } |
| 477 | break; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 478 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 479 | case SkPath::kQuad_Verb: |
| 480 | add_quad(&vert, base, pts, srcSpaceTolSqd, srcSpaceTol, isIndexed, |
| 481 | this->isHairline(), subpathIdxStart, (int)vertexOffset, &idx); |
| 482 | break; |
| 483 | case SkPath::kCubic_Verb: { |
| 484 | // first pt of cubic is the pt we ended on in previous step |
| 485 | uint16_t firstCPtIdx = (uint16_t)(vert - base) - 1 + vertexOffsetU16; |
| 486 | uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints( |
| 487 | pts[0], pts[1], pts[2], pts[3], |
| 488 | srcSpaceTolSqd, &vert, |
| 489 | GrPathUtils::cubicPointCount(pts, srcSpaceTol)); |
| 490 | if (isIndexed) { |
| 491 | for (uint16_t i = 0; i < numPts; ++i) { |
| 492 | append_countour_edge_indices(this->isHairline(), subpathIdxStart, |
| 493 | firstCPtIdx + i, &idx); |
| 494 | } |
| 495 | } |
| 496 | break; |
| 497 | } |
| 498 | case SkPath::kClose_Verb: |
| 499 | break; |
| 500 | case SkPath::kDone_Verb: |
| 501 | done = true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 502 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 503 | first = false; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 504 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 505 | |
| 506 | *vertexCnt = static_cast<int>(vert - base); |
| 507 | *indexCnt = static_cast<int>(idx - idxBase); |
| 508 | |
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 | return true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 511 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 512 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 513 | GrColor color() const { return fBatch.fColor; } |
| 514 | uint8_t coverage() const { return fBatch.fCoverage; } |
| 515 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 516 | const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 517 | bool isHairline() const { return fBatch.fIsHairline; } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 518 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 519 | struct BatchTracker { |
| 520 | GrColor fColor; |
| 521 | uint8_t fCoverage; |
| 522 | SkMatrix fViewMatrix; |
| 523 | bool fUsesLocalCoords; |
| 524 | bool fColorIgnored; |
| 525 | bool fCoverageIgnored; |
| 526 | bool fIsHairline; |
| 527 | }; |
| 528 | |
| 529 | BatchTracker fBatch; |
| 530 | SkSTArray<1, Geometry, true> fGeoData; |
| 531 | }; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 532 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 533 | bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 534 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 535 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 536 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 537 | const SkPath& path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 538 | const SkStrokeRec& origStroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 539 | bool stencilOnly) { |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 540 | SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); |
| 541 | |
| 542 | SkScalar hairlineCoverage; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 543 | uint8_t newCoverage = 0xff; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 544 | if (IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, &hairlineCoverage)) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 545 | newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 546 | |
| 547 | if (!stroke->isHairlineStyle()) { |
| 548 | stroke.writable()->setHairlineStyle(); |
| 549 | } |
| 550 | } |
| 551 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 552 | const bool isHairline = stroke->isHairlineStyle(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 553 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 554 | // 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] | 555 | SkAutoTUnref<const GrXPFactory> backupXPFactory(SkRef(pipelineBuilder->getXPFactory())); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 556 | // face culling doesn't make sense here |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 557 | SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace()); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 558 | |
| 559 | int passCount = 0; |
| 560 | const GrStencilSettings* passes[3]; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 561 | GrPipelineBuilder::DrawFace drawFace[3]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 562 | bool reverse = false; |
| 563 | bool lastPassIsBounds; |
| 564 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 565 | if (isHairline) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 566 | passCount = 1; |
| 567 | if (stencilOnly) { |
| 568 | passes[0] = &gDirectToStencil; |
| 569 | } else { |
| 570 | passes[0] = NULL; |
| 571 | } |
| 572 | lastPassIsBounds = false; |
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 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 575 | if (single_pass_path(path, *stroke)) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 576 | passCount = 1; |
| 577 | if (stencilOnly) { |
| 578 | passes[0] = &gDirectToStencil; |
| 579 | } else { |
| 580 | passes[0] = NULL; |
| 581 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 582 | drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 583 | lastPassIsBounds = false; |
| 584 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 585 | switch (path.getFillType()) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 586 | case SkPath::kInverseEvenOdd_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 587 | reverse = true; |
| 588 | // fallthrough |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 589 | case SkPath::kEvenOdd_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 590 | passes[0] = &gEOStencilPass; |
| 591 | if (stencilOnly) { |
| 592 | passCount = 1; |
| 593 | lastPassIsBounds = false; |
| 594 | } else { |
| 595 | passCount = 2; |
| 596 | lastPassIsBounds = true; |
| 597 | if (reverse) { |
| 598 | passes[1] = &gInvEOColorPass; |
| 599 | } else { |
| 600 | passes[1] = &gEOColorPass; |
| 601 | } |
| 602 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 603 | drawFace[0] = drawFace[1] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 604 | break; |
| 605 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 606 | case SkPath::kInverseWinding_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 607 | reverse = true; |
| 608 | // fallthrough |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 609 | case SkPath::kWinding_FillType: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 610 | if (fSeparateStencil) { |
| 611 | if (fStencilWrapOps) { |
| 612 | passes[0] = &gWindStencilSeparateWithWrap; |
| 613 | } else { |
| 614 | passes[0] = &gWindStencilSeparateNoWrap; |
| 615 | } |
| 616 | passCount = 2; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 617 | drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 618 | } else { |
| 619 | if (fStencilWrapOps) { |
| 620 | passes[0] = &gWindSingleStencilWithWrapInc; |
| 621 | passes[1] = &gWindSingleStencilWithWrapDec; |
| 622 | } else { |
| 623 | passes[0] = &gWindSingleStencilNoWrapInc; |
| 624 | passes[1] = &gWindSingleStencilNoWrapDec; |
| 625 | } |
| 626 | // which is cw and which is ccw is arbitrary. |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 627 | drawFace[0] = GrPipelineBuilder::kCW_DrawFace; |
| 628 | drawFace[1] = GrPipelineBuilder::kCCW_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 629 | passCount = 3; |
| 630 | } |
| 631 | if (stencilOnly) { |
| 632 | lastPassIsBounds = false; |
| 633 | --passCount; |
| 634 | } else { |
| 635 | lastPassIsBounds = true; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 636 | drawFace[passCount-1] = GrPipelineBuilder::kBoth_DrawFace; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 637 | if (reverse) { |
| 638 | passes[passCount-1] = &gInvWindColorPass; |
| 639 | } else { |
| 640 | passes[passCount-1] = &gWindColorPass; |
| 641 | } |
| 642 | } |
| 643 | break; |
| 644 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 645 | SkDEBUGFAIL("Unknown path fFill!"); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 646 | return false; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 651 | SkScalar tol = SK_Scalar1; |
| 652 | SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds()); |
| 653 | |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 654 | SkRect devBounds; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 655 | GetPathDevBounds(path, pipelineBuilder->getRenderTarget(), viewMatrix, &devBounds); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 656 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 657 | for (int p = 0; p < passCount; ++p) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 658 | pipelineBuilder->setDrawFace(drawFace[p]); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 659 | if (passes[p]) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 660 | *pipelineBuilder->stencil() = *passes[p]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | if (lastPassIsBounds && (p == passCount-1)) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 664 | // Reset the XP Factory on pipelineBuilder |
| 665 | pipelineBuilder->setXPFactory(backupXPFactory); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 666 | SkRect bounds; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 667 | SkMatrix localMatrix = SkMatrix::I(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 668 | if (reverse) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 669 | SkASSERT(pipelineBuilder->getRenderTarget()); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 670 | // draw over the dev bounds (which will be the whole dst surface for inv fill). |
| 671 | bounds = devBounds; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 672 | SkMatrix vmi; |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 673 | // mapRect through persp matrix may not be correct |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 674 | if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 675 | vmi.mapRect(&bounds); |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 676 | } else { |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 677 | if (!viewMatrix.invert(&localMatrix)) { |
| 678 | return false; |
| 679 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 680 | } |
| 681 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 682 | bounds = path.getBounds(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 683 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 684 | GrDrawTarget::AutoGeometryPush agp(target); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 685 | const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() : |
| 686 | viewMatrix; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 687 | target->drawRect(pipelineBuilder, color, viewM, bounds, NULL, &localMatrix); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 688 | } else { |
| 689 | if (passCount > 1) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 690 | pipelineBuilder->setDisableColorXPFactory(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 691 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 692 | |
| 693 | DefaultPathBatch::Geometry geometry; |
| 694 | geometry.fColor = color; |
| 695 | geometry.fPath = path; |
| 696 | geometry.fTolerance = srcSpaceTol; |
| 697 | SkDEBUGCODE(geometry.fDevBounds = devBounds;) |
| 698 | |
| 699 | SkAutoTUnref<GrBatch> batch(DefaultPathBatch::Create(geometry, newCoverage, viewMatrix, |
| 700 | isHairline)); |
| 701 | |
| 702 | target->drawBatch(pipelineBuilder, batch, &devBounds); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 703 | } |
| 704 | } |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 705 | return true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 706 | } |
| 707 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 708 | bool GrDefaultPathRenderer::canDrawPath(const GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 709 | const GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 710 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 711 | const SkPath& path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 712 | const SkStrokeRec& stroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 713 | bool antiAlias) const { |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 714 | // 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] | 715 | return !antiAlias && (stroke.isFillStyle() || IsStrokeHairlineOrEquivalent(stroke, |
| 716 | viewMatrix, |
| 717 | NULL)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 718 | } |
| 719 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 720 | bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 721 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 722 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 723 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 724 | const SkPath& path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 725 | const SkStrokeRec& stroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 726 | bool antiAlias) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 727 | return this->internalDrawPath(target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 728 | pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 729 | color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 730 | viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 731 | path, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 732 | stroke, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 733 | false); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 734 | } |
| 735 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 736 | void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 737 | GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 738 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 739 | const SkPath& path, |
| 740 | const SkStrokeRec& stroke) { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 741 | SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); |
| 742 | SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 743 | this->internalDrawPath(target, pipelineBuilder, GrColor_WHITE, viewMatrix, path, stroke, true); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 744 | } |