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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/ops/GrDefaultPathRenderer.h" |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkString.h" |
| 11 | #include "include/core/SkStrokeRec.h" |
| 12 | #include "src/core/SkGeometry.h" |
Michael Ludwig | fbe2859 | 2020-06-26 16:02:15 -0400 | [diff] [blame] | 13 | #include "src/core/SkMatrixPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/core/SkTLazy.h" |
| 15 | #include "src/core/SkTraceEvent.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrCaps.h" |
Michael Ludwig | 58f569b | 2020-05-21 17:03:08 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrClip.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrDefaultGeoProcFactory.h" |
| 20 | #include "src/gpu/GrDrawOpTest.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrOpFlushState.h" |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrProgramInfo.h" |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 23 | #include "src/gpu/GrSimpleMesh.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrStyle.h" |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 25 | #include "src/gpu/GrUtil.h" |
Robert Phillips | 550de7f | 2021-07-06 16:28:52 -0400 | [diff] [blame] | 26 | #include "src/gpu/effects/GrDisableColorXP.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 27 | #include "src/gpu/geometry/GrPathUtils.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 28 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/gpu/ops/GrMeshDrawOp.h" |
Robert Phillips | 55f681f | 2020-02-28 08:58:15 -0500 | [diff] [blame] | 30 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h" |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame^] | 31 | #include "src/gpu/v1/SurfaceDrawContext_v1.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 32 | |
Brian Salomon | 15b2509 | 2017-05-08 11:10:53 -0400 | [diff] [blame] | 33 | GrDefaultPathRenderer::GrDefaultPathRenderer() { |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 36 | //////////////////////////////////////////////////////////////////////////////// |
| 37 | // Helpers for drawPath |
| 38 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 39 | #define STENCIL_OFF 0 // Always disable stencil (even when needed) |
| 40 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 41 | static inline bool single_pass_shape(const GrStyledShape& shape) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 42 | #if STENCIL_OFF |
| 43 | return true; |
| 44 | #else |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 45 | // Inverse fill is always two pass. |
| 46 | if (shape.inverseFilled()) { |
| 47 | return false; |
| 48 | } |
| 49 | // This path renderer only accepts simple fill paths or stroke paths that are either hairline |
| 50 | // or have a stroke width small enough to treat as hairline. Hairline paths are always single |
| 51 | // pass. Filled paths are single pass if they're convex. |
| 52 | if (shape.style().isSimpleFill()) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 53 | return shape.knownToBeConvex(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 54 | } |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 55 | return true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 56 | #endif |
| 57 | } |
| 58 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 59 | GrPathRenderer::StencilSupport |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 60 | GrDefaultPathRenderer::onGetStencilSupport(const GrStyledShape& shape) const { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 61 | if (single_pass_shape(shape)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 62 | return GrPathRenderer::kNoRestriction_StencilSupport; |
| 63 | } else { |
| 64 | return GrPathRenderer::kStencilOnly_StencilSupport; |
| 65 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 68 | namespace { |
| 69 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 70 | class PathGeoBuilder { |
| 71 | public: |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 72 | PathGeoBuilder(GrPrimitiveType primitiveType, |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 73 | GrMeshDrawTarget* target, |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 74 | SkTDArray<GrSimpleMesh*>* meshes) |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 75 | : fPrimitiveType(primitiveType) |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 76 | , fTarget(target) |
| 77 | , fVertexStride(sizeof(SkPoint)) |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 78 | , fFirstIndex(0) |
| 79 | , fIndicesInChunk(0) |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 80 | , fIndices(nullptr) |
| 81 | , fMeshes(meshes) { |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 82 | this->allocNewBuffers(); |
Brian Osman | eb86b70 | 2017-06-07 11:38:31 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 85 | ~PathGeoBuilder() { |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 86 | this->createMeshAndPutBackReserve(); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Path verbs |
| 91 | */ |
| 92 | void moveTo(const SkPoint& p) { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 93 | if (!this->ensureSpace(1)) { |
| 94 | return; |
| 95 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 96 | |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 97 | if (!this->isHairline()) { |
| 98 | fSubpathIndexStart = this->currentIndex(); |
| 99 | fSubpathStartPoint = p; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 100 | } |
Greg Daniel | 30b355a | 2021-02-03 16:22:49 +0000 | [diff] [blame] | 101 | *(fCurVert++) = p; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 104 | void addLine(const SkPoint pts[]) { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 105 | if (!this->ensureSpace(1, this->indexScale(), &pts[0])) { |
| 106 | return; |
| 107 | } |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 108 | |
| 109 | if (this->isIndexed()) { |
| 110 | uint16_t prevIdx = this->currentIndex() - 1; |
| 111 | this->appendCountourEdgeIndices(prevIdx); |
| 112 | } |
| 113 | *(fCurVert++) = pts[1]; |
| 114 | } |
| 115 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 116 | void addQuad(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 117 | if (!this->ensureSpace(GrPathUtils::kMaxPointsPerCurve, |
| 118 | GrPathUtils::kMaxPointsPerCurve * this->indexScale(), |
| 119 | &pts[0])) { |
| 120 | return; |
| 121 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 122 | |
| 123 | // First pt of quad is the pt we ended on in previous step |
| 124 | uint16_t firstQPtIdx = this->currentIndex() - 1; |
| 125 | uint16_t numPts = (uint16_t)GrPathUtils::generateQuadraticPoints( |
| 126 | pts[0], pts[1], pts[2], srcSpaceTolSqd, &fCurVert, |
| 127 | GrPathUtils::quadraticPointCount(pts, srcSpaceTol)); |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 128 | if (this->isIndexed()) { |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 129 | for (uint16_t i = 0; i < numPts; ++i) { |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 130 | this->appendCountourEdgeIndices(firstQPtIdx + i); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 131 | } |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 132 | } |
| 133 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 134 | |
| 135 | void addConic(SkScalar weight, const SkPoint pts[], SkScalar srcSpaceTolSqd, |
| 136 | SkScalar srcSpaceTol) { |
| 137 | SkAutoConicToQuads converter; |
| 138 | const SkPoint* quadPts = converter.computeQuads(pts, weight, srcSpaceTol); |
| 139 | for (int i = 0; i < converter.countQuads(); ++i) { |
| 140 | this->addQuad(quadPts + i * 2, srcSpaceTolSqd, srcSpaceTol); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void addCubic(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 145 | if (!this->ensureSpace(GrPathUtils::kMaxPointsPerCurve, |
| 146 | GrPathUtils::kMaxPointsPerCurve * this->indexScale(), |
| 147 | &pts[0])) { |
| 148 | return; |
| 149 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 150 | |
| 151 | // First pt of cubic is the pt we ended on in previous step |
| 152 | uint16_t firstCPtIdx = this->currentIndex() - 1; |
| 153 | uint16_t numPts = (uint16_t) GrPathUtils::generateCubicPoints( |
| 154 | pts[0], pts[1], pts[2], pts[3], srcSpaceTolSqd, &fCurVert, |
| 155 | GrPathUtils::cubicPointCount(pts, srcSpaceTol)); |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 156 | if (this->isIndexed()) { |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 157 | for (uint16_t i = 0; i < numPts; ++i) { |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 158 | this->appendCountourEdgeIndices(firstCPtIdx + i); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void addPath(const SkPath& path, SkScalar srcSpaceTol) { |
| 164 | SkScalar srcSpaceTolSqd = srcSpaceTol * srcSpaceTol; |
| 165 | |
| 166 | SkPath::Iter iter(path, false); |
| 167 | SkPoint pts[4]; |
| 168 | |
| 169 | bool done = false; |
| 170 | while (!done) { |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 171 | SkPath::Verb verb = iter.next(pts); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 172 | switch (verb) { |
| 173 | case SkPath::kMove_Verb: |
| 174 | this->moveTo(pts[0]); |
| 175 | break; |
| 176 | case SkPath::kLine_Verb: |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 177 | this->addLine(pts); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 178 | break; |
| 179 | case SkPath::kConic_Verb: |
| 180 | this->addConic(iter.conicWeight(), pts, srcSpaceTolSqd, srcSpaceTol); |
| 181 | break; |
| 182 | case SkPath::kQuad_Verb: |
| 183 | this->addQuad(pts, srcSpaceTolSqd, srcSpaceTol); |
| 184 | break; |
| 185 | case SkPath::kCubic_Verb: |
| 186 | this->addCubic(pts, srcSpaceTolSqd, srcSpaceTol); |
| 187 | break; |
| 188 | case SkPath::kClose_Verb: |
| 189 | break; |
| 190 | case SkPath::kDone_Verb: |
| 191 | done = true; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | static bool PathHasMultipleSubpaths(const SkPath& path) { |
| 197 | bool first = true; |
| 198 | |
| 199 | SkPath::Iter iter(path, false); |
| 200 | SkPath::Verb verb; |
| 201 | |
| 202 | SkPoint pts[4]; |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 203 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 204 | if (SkPath::kMove_Verb == verb && !first) { |
| 205 | return true; |
| 206 | } |
| 207 | first = false; |
| 208 | } |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | private: |
| 213 | /** |
| 214 | * Derived properties |
| 215 | * TODO: Cache some of these for better performance, rather than re-computing? |
| 216 | */ |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 217 | bool isIndexed() const { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 218 | return GrPrimitiveType::kLines == fPrimitiveType || |
| 219 | GrPrimitiveType::kTriangles == fPrimitiveType; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 220 | } |
| 221 | bool isHairline() const { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 222 | return GrPrimitiveType::kLines == fPrimitiveType || |
| 223 | GrPrimitiveType::kLineStrip == fPrimitiveType; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 224 | } |
| 225 | int indexScale() const { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 226 | switch (fPrimitiveType) { |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 227 | case GrPrimitiveType::kLines: |
| 228 | return 2; |
| 229 | case GrPrimitiveType::kTriangles: |
| 230 | return 3; |
| 231 | default: |
| 232 | return 0; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | uint16_t currentIndex() const { return fCurVert - fVertices; } |
| 237 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 238 | // Allocate vertex and (possibly) index buffers |
| 239 | void allocNewBuffers() { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 240 | SkASSERT(fValid); |
| 241 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 242 | // Ensure that we always get enough verts for a worst-case quad/cubic, plus leftover points |
| 243 | // from previous mesh piece (up to two verts to continue fanning). If we can't get that |
| 244 | // many, ask for a much larger number. This needs to be fairly big to handle quads/cubics, |
| 245 | // which have a worst-case of 1k points. |
| 246 | static const int kMinVerticesPerChunk = GrPathUtils::kMaxPointsPerCurve + 2; |
| 247 | static const int kFallbackVerticesPerChunk = 16384; |
| 248 | |
| 249 | fVertices = static_cast<SkPoint*>(fTarget->makeVertexSpaceAtLeast(fVertexStride, |
| 250 | kMinVerticesPerChunk, |
| 251 | kFallbackVerticesPerChunk, |
| 252 | &fVertexBuffer, |
| 253 | &fFirstVertex, |
| 254 | &fVerticesInChunk)); |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 255 | if (!fVertices) { |
| 256 | SkDebugf("WARNING: Failed to allocate vertex buffer for GrDefaultPathRenderer.\n"); |
| 257 | fCurVert = nullptr; |
| 258 | fCurIdx = fIndices = nullptr; |
| 259 | fSubpathIndexStart = 0; |
| 260 | fValid = false; |
| 261 | return; |
| 262 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 263 | |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 264 | if (this->isIndexed()) { |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 265 | // Similar to above: Ensure we get enough indices for one worst-case quad/cubic. |
| 266 | // No extra indices are needed for stitching, though. If we can't get that many, ask |
| 267 | // for enough to match our large vertex request. |
| 268 | const int kMinIndicesPerChunk = GrPathUtils::kMaxPointsPerCurve * this->indexScale(); |
| 269 | const int kFallbackIndicesPerChunk = kFallbackVerticesPerChunk * this->indexScale(); |
| 270 | |
| 271 | fIndices = fTarget->makeIndexSpaceAtLeast(kMinIndicesPerChunk, kFallbackIndicesPerChunk, |
| 272 | &fIndexBuffer, &fFirstIndex, |
| 273 | &fIndicesInChunk); |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 274 | if (!fIndices) { |
| 275 | SkDebugf("WARNING: Failed to allocate index buffer for GrDefaultPathRenderer.\n"); |
| 276 | fVertices = nullptr; |
| 277 | fValid = false; |
| 278 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 279 | } |
Brian Osman | 3902d40 | 2017-06-20 15:36:31 -0400 | [diff] [blame] | 280 | |
| 281 | fCurVert = fVertices; |
| 282 | fCurIdx = fIndices; |
| 283 | fSubpathIndexStart = 0; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void appendCountourEdgeIndices(uint16_t edgeV0Idx) { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 287 | SkASSERT(fCurIdx); |
| 288 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 289 | // When drawing lines we're appending line segments along the countour. When applying the |
| 290 | // other fill rules we're drawing triangle fans around the start of the current (sub)path. |
| 291 | if (!this->isHairline()) { |
| 292 | *(fCurIdx++) = fSubpathIndexStart; |
| 293 | } |
| 294 | *(fCurIdx++) = edgeV0Idx; |
| 295 | *(fCurIdx++) = edgeV0Idx + 1; |
| 296 | } |
| 297 | |
| 298 | // Emits a single draw with all accumulated vertex/index data |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 299 | void createMeshAndPutBackReserve() { |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 300 | if (!fValid) { |
| 301 | return; |
| 302 | } |
| 303 | |
Brian Osman | 3902d40 | 2017-06-20 15:36:31 -0400 | [diff] [blame] | 304 | int vertexCount = fCurVert - fVertices; |
| 305 | int indexCount = fCurIdx - fIndices; |
| 306 | SkASSERT(vertexCount <= fVerticesInChunk); |
| 307 | SkASSERT(indexCount <= fIndicesInChunk); |
| 308 | |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 309 | GrSimpleMesh* mesh = nullptr; |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 310 | if (this->isIndexed() ? SkToBool(indexCount) : SkToBool(vertexCount)) { |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 311 | mesh = fTarget->allocMesh(); |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 312 | if (!this->isIndexed()) { |
Chris Dalton | 37c7bdd | 2020-03-13 09:21:12 -0600 | [diff] [blame] | 313 | mesh->set(std::move(fVertexBuffer), vertexCount, fFirstVertex); |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 314 | } else { |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 315 | mesh->setIndexed(std::move(fIndexBuffer), indexCount, fFirstIndex, 0, |
Chris Dalton | 37c7bdd | 2020-03-13 09:21:12 -0600 | [diff] [blame] | 316 | vertexCount - 1, GrPrimitiveRestart::kNo, std::move(fVertexBuffer), |
| 317 | fFirstVertex); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 318 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 319 | } |
Brian Osman | 3902d40 | 2017-06-20 15:36:31 -0400 | [diff] [blame] | 320 | |
| 321 | fTarget->putBackIndices((size_t)(fIndicesInChunk - indexCount)); |
| 322 | fTarget->putBackVertices((size_t)(fVerticesInChunk - vertexCount), fVertexStride); |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 323 | |
| 324 | if (mesh) { |
| 325 | fMeshes->push_back(mesh); |
| 326 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 327 | } |
| 328 | |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 329 | bool ensureSpace(int vertsNeeded, int indicesNeeded = 0, const SkPoint* lastPoint = nullptr) { |
| 330 | if (!fValid) { |
| 331 | return false; |
| 332 | } |
| 333 | |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 334 | if (fCurVert + vertsNeeded > fVertices + fVerticesInChunk || |
| 335 | fCurIdx + indicesNeeded > fIndices + fIndicesInChunk) { |
| 336 | // We are about to run out of space (possibly) |
| 337 | |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 338 | #ifdef SK_DEBUG |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 339 | // To maintain continuity, we need to remember one or two points from the current mesh. |
| 340 | // Lines only need the last point, fills need the first point from the current contour. |
| 341 | // We always grab both here, and append the ones we need at the end of this process. |
Brian Osman | 3902d40 | 2017-06-20 15:36:31 -0400 | [diff] [blame] | 342 | SkASSERT(fSubpathIndexStart < fVerticesInChunk); |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 343 | // This assert is reading from the gpu buffer fVertices and will be slow, but for debug |
| 344 | // that is okay. |
| 345 | if (!this->isHairline()) { |
| 346 | SkASSERT(fSubpathStartPoint == fVertices[fSubpathIndexStart]); |
| 347 | } |
| 348 | if (lastPoint) { |
| 349 | SkASSERT(*(fCurVert - 1) == *lastPoint); |
| 350 | } |
| 351 | #endif |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 352 | |
Brian Osman | 3902d40 | 2017-06-20 15:36:31 -0400 | [diff] [blame] | 353 | // Draw the mesh we've accumulated, and put back any unused space |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 354 | this->createMeshAndPutBackReserve(); |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 355 | |
Brian Osman | 3902d40 | 2017-06-20 15:36:31 -0400 | [diff] [blame] | 356 | // Get new buffers |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 357 | this->allocNewBuffers(); |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 358 | if (!fValid) { |
| 359 | return false; |
| 360 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 361 | |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 362 | // On moves we don't need to copy over any points to the new buffer and we pass in a |
| 363 | // null lastPoint. |
| 364 | if (lastPoint) { |
| 365 | // Append copies of the points we saved so the two meshes will weld properly |
| 366 | if (!this->isHairline()) { |
| 367 | *(fCurVert++) = fSubpathStartPoint; |
| 368 | } |
| 369 | *(fCurVert++) = *lastPoint; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 370 | } |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 371 | } |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 372 | |
| 373 | return true; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 376 | GrPrimitiveType fPrimitiveType; |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 377 | GrMeshDrawTarget* fTarget; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 378 | size_t fVertexStride; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 379 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 380 | sk_sp<const GrBuffer> fVertexBuffer; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 381 | int fFirstVertex; |
| 382 | int fVerticesInChunk; |
| 383 | SkPoint* fVertices; |
| 384 | SkPoint* fCurVert; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 385 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 386 | sk_sp<const GrBuffer> fIndexBuffer; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 387 | int fFirstIndex; |
| 388 | int fIndicesInChunk; |
| 389 | uint16_t* fIndices; |
| 390 | uint16_t* fCurIdx; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 391 | uint16_t fSubpathIndexStart; |
Greg Daniel | 733ab11 | 2021-02-03 12:16:32 -0500 | [diff] [blame] | 392 | SkPoint fSubpathStartPoint; |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 393 | |
Robert Phillips | d1285c6 | 2021-06-29 07:29:58 -0400 | [diff] [blame] | 394 | bool fValid = true; |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 395 | SkTDArray<GrSimpleMesh*>* fMeshes; |
Brian Osman | 49b7b6f | 2017-06-20 14:43:58 -0400 | [diff] [blame] | 396 | }; |
egdaniel | af18a09 | 2015-01-05 10:22:28 -0800 | [diff] [blame] | 397 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 398 | class DefaultPathOp final : public GrMeshDrawOp { |
| 399 | private: |
| 400 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 401 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 402 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 403 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 404 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 405 | static GrOp::Owner Make(GrRecordingContext* context, |
| 406 | GrPaint&& paint, |
| 407 | const SkPath& path, |
| 408 | SkScalar tolerance, |
| 409 | uint8_t coverage, |
| 410 | const SkMatrix& viewMatrix, |
| 411 | bool isHairline, |
| 412 | GrAAType aaType, |
| 413 | const SkRect& devBounds, |
| 414 | const GrUserStencilSettings* stencilSettings) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 415 | return Helper::FactoryHelper<DefaultPathOp>(context, std::move(paint), path, tolerance, |
| 416 | coverage, viewMatrix, isHairline, aaType, |
| 417 | devBounds, stencilSettings); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 420 | const char* name() const override { return "DefaultPathOp"; } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 421 | |
Robert Phillips | 294723d | 2021-06-17 09:23:58 -0400 | [diff] [blame] | 422 | void visitProxies(const GrVisitProxyFunc& func) const override { |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 423 | if (fProgramInfo) { |
Chris Dalton | be45742 | 2020-03-16 18:05:03 -0600 | [diff] [blame] | 424 | fProgramInfo->visitFPProxies(func); |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 425 | } else { |
| 426 | fHelper.visitProxies(func); |
| 427 | } |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 430 | DefaultPathOp(GrProcessorSet* processorSet, const SkPMColor4f& color, const SkPath& path, |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 431 | SkScalar tolerance, uint8_t coverage, const SkMatrix& viewMatrix, bool isHairline, |
| 432 | GrAAType aaType, const SkRect& devBounds, |
| 433 | const GrUserStencilSettings* stencilSettings) |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 434 | : INHERITED(ClassID()) |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 435 | , fHelper(processorSet, aaType, stencilSettings) |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 436 | , fColor(color) |
| 437 | , fCoverage(coverage) |
| 438 | , fViewMatrix(viewMatrix) |
| 439 | , fIsHairline(isHairline) { |
| 440 | fPaths.emplace_back(PathData{path, tolerance}); |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 441 | |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 442 | HasAABloat aaBloat = (aaType == GrAAType::kNone) ? HasAABloat ::kNo : HasAABloat::kYes; |
| 443 | this->setBounds(devBounds, aaBloat, |
| 444 | isHairline ? IsHairline::kYes : IsHairline::kNo); |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 445 | } |
| 446 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 447 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 448 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 449 | GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip, |
| 450 | GrClampType clampType) override { |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 451 | GrProcessorAnalysisCoverage gpCoverage = |
| 452 | this->coverage() == 0xFF ? GrProcessorAnalysisCoverage::kNone |
| 453 | : GrProcessorAnalysisCoverage::kSingleChannel; |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 454 | // This Op uses uniform (not vertex) color, so doesn't need to track wide color. |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame] | 455 | return fHelper.finalizeProcessors(caps, clip, clampType, gpCoverage, &fColor, nullptr); |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 456 | } |
| 457 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 458 | private: |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 459 | GrPrimitiveType primType() const { |
| 460 | if (this->isHairline()) { |
| 461 | int instanceCount = fPaths.count(); |
| 462 | |
| 463 | // We avoid indices when we have a single hairline contour. |
| 464 | bool isIndexed = instanceCount > 1 || |
| 465 | PathGeoBuilder::PathHasMultipleSubpaths(fPaths[0].fPath); |
| 466 | |
| 467 | return isIndexed ? GrPrimitiveType::kLines : GrPrimitiveType::kLineStrip; |
| 468 | } |
| 469 | |
| 470 | return GrPrimitiveType::kTriangles; |
| 471 | } |
| 472 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 473 | GrProgramInfo* programInfo() override { return fProgramInfo; } |
| 474 | |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 475 | void onCreateProgramInfo(const GrCaps* caps, |
| 476 | SkArenaAlloc* arena, |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 477 | const GrSurfaceProxyView& writeView, |
Chris Dalton | 6aaf00f | 2021-07-13 13:26:39 -0600 | [diff] [blame] | 478 | bool usesMSAASurface, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 479 | GrAppliedClip&& appliedClip, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 480 | const GrDstProxyView& dstProxyView, |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 481 | GrXferBarrierFlags renderPassXferBarriers, |
| 482 | GrLoadOp colorLoadOp) override { |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 483 | GrGeometryProcessor* gp; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 484 | { |
| 485 | using namespace GrDefaultGeoProcFactory; |
| 486 | Color color(this->color()); |
| 487 | Coverage coverage(this->coverage()); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 488 | LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type |
| 489 | : LocalCoords::kUnused_Type); |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 490 | gp = GrDefaultGeoProcFactory::Make(arena, |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 491 | color, |
| 492 | coverage, |
| 493 | localCoords, |
| 494 | this->viewMatrix()); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 495 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 496 | |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 497 | SkASSERT(gp->vertexStride() == sizeof(SkPoint)); |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 498 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 499 | fProgramInfo = fHelper.createProgramInfoWithStencil(caps, arena, writeView, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 500 | std::move(appliedClip), |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 501 | dstProxyView, gp, this->primType(), |
Greg Daniel | 42dbca5 | 2020-11-20 10:22:43 -0500 | [diff] [blame] | 502 | renderPassXferBarriers, colorLoadOp); |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 503 | |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 504 | } |
Brian Osman | 7f95dfc | 2017-06-09 14:43:49 +0000 | [diff] [blame] | 505 | |
Robert Phillips | 7114395 | 2021-06-17 14:55:07 -0400 | [diff] [blame] | 506 | void onPrepareDraws(GrMeshDrawTarget* target) override { |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 507 | PathGeoBuilder pathGeoBuilder(this->primType(), target, &fMeshes); |
Brian Osman | 7f95dfc | 2017-06-09 14:43:49 +0000 | [diff] [blame] | 508 | |
| 509 | // fill buffers |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 510 | for (int i = 0; i < fPaths.count(); i++) { |
Brian Salomon | 763abf0 | 2018-05-01 18:49:38 +0000 | [diff] [blame] | 511 | const PathData& args = fPaths[i]; |
| 512 | pathGeoBuilder.addPath(args.fPath, args.fTolerance); |
Brian Osman | 7f95dfc | 2017-06-09 14:43:49 +0000 | [diff] [blame] | 513 | } |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 516 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 517 | if (!fProgramInfo) { |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 518 | this->createProgramInfo(flushState); |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 519 | } |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 520 | |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 521 | if (!fProgramInfo || !fMeshes.count()) { |
| 522 | return; |
| 523 | } |
| 524 | |
Chris Dalton | 765ed36 | 2020-03-16 17:34:44 -0600 | [diff] [blame] | 525 | flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds); |
Robert Phillips | 787fd9d | 2021-03-22 14:48:09 -0400 | [diff] [blame] | 526 | flushState->bindTextures(fProgramInfo->geomProc(), nullptr, fProgramInfo->pipeline()); |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 527 | for (int i = 0; i < fMeshes.count(); ++i) { |
Chris Dalton | 765ed36 | 2020-03-16 17:34:44 -0600 | [diff] [blame] | 528 | flushState->drawMesh(*fMeshes[i]); |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 529 | } |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 532 | CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override { |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 533 | DefaultPathOp* that = t->cast<DefaultPathOp>(); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 534 | if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 535 | return CombineResult::kCannotCombine; |
joshualitt | 8cab9a7 | 2015-07-16 09:13:50 -0700 | [diff] [blame] | 536 | } |
| 537 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 538 | if (this->color() != that->color()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 539 | return CombineResult::kCannotCombine; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | if (this->coverage() != that->coverage()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 543 | return CombineResult::kCannotCombine; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Mike Reed | 2c38315 | 2019-12-18 16:47:47 -0500 | [diff] [blame] | 546 | if (!SkMatrixPriv::CheapEqual(this->viewMatrix(), that->viewMatrix())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 547 | return CombineResult::kCannotCombine; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | if (this->isHairline() != that->isHairline()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 551 | return CombineResult::kCannotCombine; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 554 | fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 555 | return CombineResult::kMerged; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 556 | } |
| 557 | |
John Stiles | af36652 | 2020-08-13 09:57:34 -0400 | [diff] [blame] | 558 | #if GR_TEST_UTILS |
| 559 | SkString onDumpInfo() const override { |
| 560 | SkString string = SkStringPrintf("Color: 0x%08x Count: %d\n", |
| 561 | fColor.toBytes_RGBA(), fPaths.count()); |
| 562 | for (const auto& path : fPaths) { |
| 563 | string.appendf("Tolerance: %.2f\n", path.fTolerance); |
| 564 | } |
| 565 | string += fHelper.dumpInfo(); |
| 566 | return string; |
| 567 | } |
| 568 | #endif |
| 569 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 570 | const SkPMColor4f& color() const { return fColor; } |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 571 | uint8_t coverage() const { return fCoverage; } |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 572 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
| 573 | bool isHairline() const { return fIsHairline; } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 574 | |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 575 | struct PathData { |
bsalomon | 0432dd6 | 2016-06-30 07:19:27 -0700 | [diff] [blame] | 576 | SkPath fPath; |
| 577 | SkScalar fTolerance; |
| 578 | }; |
| 579 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 580 | SkSTArray<1, PathData, true> fPaths; |
| 581 | Helper fHelper; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 582 | SkPMColor4f fColor; |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 583 | uint8_t fCoverage; |
| 584 | SkMatrix fViewMatrix; |
Brian Salomon | 780dad1 | 2016-12-15 18:08:40 -0500 | [diff] [blame] | 585 | bool fIsHairline; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 586 | |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 587 | SkTDArray<GrSimpleMesh*> fMeshes; |
| 588 | GrProgramInfo* fProgramInfo = nullptr; |
Robert Phillips | 9028bac | 2020-03-10 16:19:27 -0400 | [diff] [blame] | 589 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 590 | using INHERITED = GrMeshDrawOp; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 591 | }; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 592 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 593 | } // anonymous namespace |
| 594 | |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame^] | 595 | bool GrDefaultPathRenderer::internalDrawPath(skgpu::v1::SurfaceDrawContext* sdc, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 596 | GrPaint&& paint, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 597 | GrAAType aaType, |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 598 | const GrUserStencilSettings& userStencilSettings, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 599 | const GrClip* clip, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 600 | const SkMatrix& viewMatrix, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 601 | const GrStyledShape& shape, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 602 | bool stencilOnly) { |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame^] | 603 | auto context = sdc->recordingContext(); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 604 | |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 605 | SkASSERT(GrAAType::kCoverage != aaType); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 606 | SkPath path; |
| 607 | shape.asPath(&path); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 608 | |
| 609 | SkScalar hairlineCoverage; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 610 | uint8_t newCoverage = 0xff; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 611 | bool isHairline = false; |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 612 | if (GrIsStrokeHairlineOrEquivalent(shape.style(), viewMatrix, &hairlineCoverage)) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 613 | newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 614 | isHairline = true; |
| 615 | } else { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 616 | SkASSERT(shape.style().isSimpleFill()); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 617 | } |
| 618 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 619 | int passCount = 0; |
Brian Salomon | f086167 | 2017-05-08 11:10:10 -0400 | [diff] [blame] | 620 | const GrUserStencilSettings* passes[2]; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 621 | bool reverse = false; |
| 622 | bool lastPassIsBounds; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 623 | |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 624 | if (isHairline) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 625 | passCount = 1; |
| 626 | if (stencilOnly) { |
| 627 | passes[0] = &gDirectToStencil; |
| 628 | } else { |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 629 | passes[0] = &userStencilSettings; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 630 | } |
| 631 | lastPassIsBounds = false; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 632 | } else { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 633 | if (single_pass_shape(shape)) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 634 | passCount = 1; |
| 635 | if (stencilOnly) { |
| 636 | passes[0] = &gDirectToStencil; |
| 637 | } else { |
robertphillips | d2b6d64 | 2016-07-21 08:55:08 -0700 | [diff] [blame] | 638 | passes[0] = &userStencilSettings; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 639 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 640 | lastPassIsBounds = false; |
| 641 | } else { |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 642 | switch (path.getFillType()) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 643 | case SkPathFillType::kInverseEvenOdd: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 644 | reverse = true; |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 645 | [[fallthrough]]; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 646 | case SkPathFillType::kEvenOdd: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 647 | passes[0] = &gEOStencilPass; |
| 648 | if (stencilOnly) { |
| 649 | passCount = 1; |
| 650 | lastPassIsBounds = false; |
| 651 | } else { |
| 652 | passCount = 2; |
| 653 | lastPassIsBounds = true; |
| 654 | if (reverse) { |
| 655 | passes[1] = &gInvEOColorPass; |
| 656 | } else { |
| 657 | passes[1] = &gEOColorPass; |
| 658 | } |
| 659 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 660 | break; |
| 661 | |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 662 | case SkPathFillType::kInverseWinding: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 663 | reverse = true; |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 664 | [[fallthrough]]; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 665 | case SkPathFillType::kWinding: |
Brian Salomon | 15b2509 | 2017-05-08 11:10:53 -0400 | [diff] [blame] | 666 | passes[0] = &gWindStencilPass; |
Brian Salomon | f086167 | 2017-05-08 11:10:10 -0400 | [diff] [blame] | 667 | passCount = 2; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 668 | if (stencilOnly) { |
| 669 | lastPassIsBounds = false; |
| 670 | --passCount; |
| 671 | } else { |
| 672 | lastPassIsBounds = true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 673 | if (reverse) { |
| 674 | passes[passCount-1] = &gInvWindColorPass; |
| 675 | } else { |
| 676 | passes[passCount-1] = &gWindColorPass; |
| 677 | } |
| 678 | } |
| 679 | break; |
| 680 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 681 | SkDEBUGFAIL("Unknown path fFill!"); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 682 | return false; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
senorblanco | 2b4bb07 | 2015-04-22 13:45:18 -0700 | [diff] [blame] | 687 | SkScalar tol = GrPathUtils::kDefaultTolerance; |
joshualitt | 332c729 | 2015-02-23 08:44:31 -0800 | [diff] [blame] | 688 | SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds()); |
| 689 | |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 690 | SkRect devBounds; |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame^] | 691 | GetPathDevBounds(path, sdc->asRenderTargetProxy()->backingStoreDimensions(), |
Robert Phillips | ec32534 | 2017-10-30 18:02:48 +0000 | [diff] [blame] | 692 | viewMatrix, &devBounds); |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 693 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 694 | for (int p = 0; p < passCount; ++p) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 695 | if (lastPassIsBounds && (p == passCount-1)) { |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 696 | SkRect bounds; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 697 | SkMatrix localMatrix = SkMatrix::I(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 698 | if (reverse) { |
bsalomon@google.com | 1dd9baa | 2013-05-20 16:49:06 +0000 | [diff] [blame] | 699 | // draw over the dev bounds (which will be the whole dst surface for inv fill). |
| 700 | bounds = devBounds; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 701 | SkMatrix vmi; |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 702 | // mapRect through persp matrix may not be correct |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 703 | if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 704 | vmi.mapRect(&bounds); |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 705 | } else { |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 706 | if (!viewMatrix.invert(&localMatrix)) { |
| 707 | return false; |
| 708 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 709 | } |
| 710 | } else { |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 711 | bounds = path.getBounds(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 712 | } |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 713 | const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() : |
| 714 | viewMatrix; |
Michael Ludwig | 72ab346 | 2018-12-10 12:43:36 -0500 | [diff] [blame] | 715 | // This is a non-coverage aa rect op since we assert aaType != kCoverage at the start |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 716 | assert_alive(paint); |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame^] | 717 | sdc->stencilRect(clip, passes[p], std::move(paint), |
| 718 | GrAA(aaType == GrAAType::kMSAA), viewM, bounds, |
| 719 | &localMatrix); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 720 | } else { |
Brian Salomon | d4652ca | 2017-01-13 12:11:36 -0500 | [diff] [blame] | 721 | bool stencilPass = stencilOnly || passCount > 1; |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 722 | GrOp::Owner op; |
Brian Salomon | d4652ca | 2017-01-13 12:11:36 -0500 | [diff] [blame] | 723 | if (stencilPass) { |
Brian Salomon | b74ef03 | 2017-08-10 12:46:01 -0400 | [diff] [blame] | 724 | GrPaint stencilPaint; |
| 725 | stencilPaint.setXPFactory(GrDisableColorXPFactory::Get()); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 726 | op = DefaultPathOp::Make(context, std::move(stencilPaint), path, srcSpaceTol, |
| 727 | newCoverage, viewMatrix, isHairline, aaType, devBounds, |
| 728 | passes[p]); |
Brian Salomon | b74ef03 | 2017-08-10 12:46:01 -0400 | [diff] [blame] | 729 | } else { |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 730 | assert_alive(paint); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 731 | op = DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, newCoverage, |
Brian Salomon | b74ef03 | 2017-08-10 12:46:01 -0400 | [diff] [blame] | 732 | viewMatrix, isHairline, aaType, devBounds, passes[p]); |
Brian Salomon | d4652ca | 2017-01-13 12:11:36 -0500 | [diff] [blame] | 733 | } |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame^] | 734 | sdc->addDrawOp(clip, std::move(op)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 735 | } |
| 736 | } |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 737 | return true; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 740 | GrPathRenderer::CanDrawPath |
| 741 | GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Robert Phillips | 62214f7 | 2021-06-15 10:12:51 -0400 | [diff] [blame] | 742 | bool isHairline = GrIsStrokeHairlineOrEquivalent( |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 743 | args.fShape->style(), *args.fViewMatrix, nullptr); |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 744 | // If we aren't a single_pass_shape or hairline, we require stencil buffers. |
Greg Daniel | be7fc46 | 2019-01-03 16:40:42 -0500 | [diff] [blame] | 745 | if (!(single_pass_shape(*args.fShape) || isHairline) && |
Chris Dalton | 537293bf | 2021-05-03 15:54:24 -0600 | [diff] [blame] | 746 | !args.fProxy->canUseStencil(*args.fCaps)) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 747 | return CanDrawPath::kNo; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 748 | } |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 749 | // If antialiasing is required, we only support MSAA. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 750 | if (GrAAType::kNone != args.fAAType && GrAAType::kMSAA != args.fAAType) { |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 751 | return CanDrawPath::kNo; |
| 752 | } |
| 753 | // This can draw any path with any simple fill style. |
| 754 | if (!args.fShape->style().isSimpleFill() && !isHairline) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 755 | return CanDrawPath::kNo; |
| 756 | } |
| 757 | // This is the fallback renderer for when a path is too complicated for the others to draw. |
| 758 | return CanDrawPath::kAsBackup; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 759 | } |
| 760 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 761 | bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Robert Phillips | a92913e | 2021-07-12 16:31:52 -0400 | [diff] [blame] | 762 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 763 | "GrDefaultPathRenderer::onDrawPath"); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 764 | GrAAType aaType = (GrAAType::kNone != args.fAAType) ? GrAAType::kMSAA : GrAAType::kNone; |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 765 | |
| 766 | return this->internalDrawPath( |
John Stiles | 0fbc6a3 | 2021-06-04 14:40:57 -0400 | [diff] [blame] | 767 | args.fSurfaceDrawContext, std::move(args.fPaint), aaType, *args.fUserStencilSettings, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 768 | args.fClip, *args.fViewMatrix, *args.fShape, false); |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 769 | } |
| 770 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 771 | void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) { |
Robert Phillips | a92913e | 2021-07-12 16:31:52 -0400 | [diff] [blame] | 772 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 773 | "GrDefaultPathRenderer::onStencilPath"); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 774 | SkASSERT(!args.fShape->inverseFilled()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 775 | |
| 776 | GrPaint paint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 777 | paint.setXPFactory(GrDisableColorXPFactory::Get()); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 778 | |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 779 | auto aaType = (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone; |
| 780 | |
| 781 | this->internalDrawPath( |
John Stiles | 0fbc6a3 | 2021-06-04 14:40:57 -0400 | [diff] [blame] | 782 | args.fSurfaceDrawContext, std::move(paint), aaType, GrUserStencilSettings::kUnused, |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 783 | args.fClip, *args.fViewMatrix, *args.fShape, true); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 784 | } |
joshualitt | 622d3ad | 2015-05-07 08:13:11 -0700 | [diff] [blame] | 785 | |
| 786 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 787 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 788 | #if GR_TEST_UTILS |
joshualitt | 622d3ad | 2015-05-07 08:13:11 -0700 | [diff] [blame] | 789 | |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 790 | GR_DRAW_OP_TEST_DEFINE(DefaultPathOp) { |
joshualitt | 622d3ad | 2015-05-07 08:13:11 -0700 | [diff] [blame] | 791 | SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 792 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 793 | // For now just hairlines because the other types of draws require two ops. |
| 794 | // TODO we should figure out a way to combine the stencil and cover steps into one op. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 795 | GrStyle style(SkStrokeRec::kHairline_InitStyle); |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 796 | const SkPath& path = GrTest::TestPath(random); |
joshualitt | 622d3ad | 2015-05-07 08:13:11 -0700 | [diff] [blame] | 797 | |
| 798 | // Compute srcSpaceTol |
| 799 | SkRect bounds = path.getBounds(); |
| 800 | SkScalar tol = GrPathUtils::kDefaultTolerance; |
| 801 | SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds); |
| 802 | |
joshualitt | 622d3ad | 2015-05-07 08:13:11 -0700 | [diff] [blame] | 803 | viewMatrix.mapRect(&bounds); |
| 804 | uint8_t coverage = GrRandomCoverage(random); |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 805 | GrAAType aaType = GrAAType::kNone; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 806 | if (numSamples > 1 && random->nextBool()) { |
Brian Salomon | ee3e0ba | 2017-07-13 16:40:46 -0400 | [diff] [blame] | 807 | aaType = GrAAType::kMSAA; |
| 808 | } |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 809 | return DefaultPathOp::Make(context, std::move(paint), path, srcSpaceTol, coverage, viewMatrix, |
| 810 | true, aaType, bounds, GrGetRandomStencil(random, context)); |
joshualitt | 622d3ad | 2015-05-07 08:13:11 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | #endif |