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