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