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