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