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