Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 "GrCCPathParser.h" |
| 9 | |
| 10 | #include "GrCaps.h" |
| 11 | #include "GrGpuCommandBuffer.h" |
| 12 | #include "GrOnFlushResourceProvider.h" |
| 13 | #include "GrOpFlushState.h" |
| 14 | #include "SkMathPriv.h" |
| 15 | #include "SkPath.h" |
| 16 | #include "SkPathPriv.h" |
| 17 | #include "SkPoint.h" |
| 18 | #include "ccpr/GrCCGeometry.h" |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 19 | #include <stdlib.h> |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 20 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 21 | using TriPointInstance = GrCCCoverageProcessor::TriPointInstance; |
| 22 | using QuadPointInstance = GrCCCoverageProcessor::QuadPointInstance; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 23 | |
Chris Dalton | 3917b1e | 2018-05-09 00:40:52 -0600 | [diff] [blame] | 24 | GrCCPathParser::GrCCPathParser(int numPaths, const PathStats& pathStats) |
| 25 | // Overallocate by one point to accomodate for overflow with Sk4f. (See parsePath.) |
| 26 | : fLocalDevPtsBuffer(pathStats.fMaxPointsPerPath + 1) |
| 27 | , fGeometry(pathStats.fNumTotalSkPoints, pathStats.fNumTotalSkVerbs, |
| 28 | pathStats.fNumTotalConicWeights) |
| 29 | , fPathsInfo(numPaths) |
| 30 | , fScissorSubBatches(numPaths) |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 31 | , fTotalPrimitiveCounts{PrimitiveTallies(), PrimitiveTallies()} { |
| 32 | // Batches decide what to draw by looking where the previous one ended. Define initial batches |
| 33 | // that "end" at the beginning of the data. These will not be drawn, but will only be be read by |
| 34 | // the first actual batch. |
| 35 | fScissorSubBatches.push_back() = {PrimitiveTallies(), SkIRect::MakeEmpty()}; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 36 | fCoverageCountBatches.push_back() = {PrimitiveTallies(), fScissorSubBatches.count(), |
| 37 | PrimitiveTallies()}; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void GrCCPathParser::parsePath(const SkMatrix& m, const SkPath& path, SkRect* devBounds, |
| 41 | SkRect* devBounds45) { |
| 42 | const SkPoint* pts = SkPathPriv::PointData(path); |
| 43 | int numPts = path.countPoints(); |
| 44 | SkASSERT(numPts + 1 <= fLocalDevPtsBuffer.count()); |
| 45 | |
| 46 | if (!numPts) { |
| 47 | devBounds->setEmpty(); |
| 48 | devBounds45->setEmpty(); |
| 49 | this->parsePath(path, nullptr); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // m45 transforms path points into "45 degree" device space. A bounding box in this space gives |
| 54 | // the circumscribing octagon's diagonals. We could use SK_ScalarRoot2Over2, but an orthonormal |
| 55 | // transform is not necessary as long as the shader uses the correct inverse. |
| 56 | SkMatrix m45; |
| 57 | m45.setSinCos(1, 1); |
| 58 | m45.preConcat(m); |
| 59 | |
| 60 | // X,Y,T are two parallel view matrices that accumulate two bounding boxes as they map points: |
| 61 | // device-space bounds and "45 degree" device-space bounds (| 1 -1 | * devCoords). |
| 62 | // | 1 1 | |
| 63 | Sk4f X = Sk4f(m.getScaleX(), m.getSkewY(), m45.getScaleX(), m45.getSkewY()); |
| 64 | Sk4f Y = Sk4f(m.getSkewX(), m.getScaleY(), m45.getSkewX(), m45.getScaleY()); |
| 65 | Sk4f T = Sk4f(m.getTranslateX(), m.getTranslateY(), m45.getTranslateX(), m45.getTranslateY()); |
| 66 | |
| 67 | // Map the path's points to device space and accumulate bounding boxes. |
| 68 | Sk4f devPt = SkNx_fma(Y, Sk4f(pts[0].y()), T); |
| 69 | devPt = SkNx_fma(X, Sk4f(pts[0].x()), devPt); |
| 70 | Sk4f topLeft = devPt; |
| 71 | Sk4f bottomRight = devPt; |
| 72 | |
| 73 | // Store all 4 values [dev.x, dev.y, dev45.x, dev45.y]. We are only interested in the first two, |
| 74 | // and will overwrite [dev45.x, dev45.y] with the next point. This is why the dst buffer must |
| 75 | // be at least one larger than the number of points. |
| 76 | devPt.store(&fLocalDevPtsBuffer[0]); |
| 77 | |
| 78 | for (int i = 1; i < numPts; ++i) { |
| 79 | devPt = SkNx_fma(Y, Sk4f(pts[i].y()), T); |
| 80 | devPt = SkNx_fma(X, Sk4f(pts[i].x()), devPt); |
| 81 | topLeft = Sk4f::Min(topLeft, devPt); |
| 82 | bottomRight = Sk4f::Max(bottomRight, devPt); |
| 83 | devPt.store(&fLocalDevPtsBuffer[i]); |
| 84 | } |
| 85 | |
| 86 | SkPoint topLeftPts[2], bottomRightPts[2]; |
| 87 | topLeft.store(topLeftPts); |
| 88 | bottomRight.store(bottomRightPts); |
| 89 | devBounds->setLTRB(topLeftPts[0].x(), topLeftPts[0].y(), bottomRightPts[0].x(), |
| 90 | bottomRightPts[0].y()); |
| 91 | devBounds45->setLTRB(topLeftPts[1].x(), topLeftPts[1].y(), bottomRightPts[1].x(), |
| 92 | bottomRightPts[1].y()); |
| 93 | |
| 94 | this->parsePath(path, fLocalDevPtsBuffer.get()); |
| 95 | } |
| 96 | |
| 97 | void GrCCPathParser::parseDeviceSpacePath(const SkPath& deviceSpacePath) { |
| 98 | this->parsePath(deviceSpacePath, SkPathPriv::PointData(deviceSpacePath)); |
| 99 | } |
| 100 | |
| 101 | void GrCCPathParser::parsePath(const SkPath& path, const SkPoint* deviceSpacePts) { |
| 102 | SkASSERT(!fInstanceBuffer); // Can't call after finalize(). |
| 103 | SkASSERT(!fParsingPath); // Call saveParsedPath() or discardParsedPath() for the last one first. |
| 104 | SkDEBUGCODE(fParsingPath = true); |
| 105 | SkASSERT(path.isEmpty() || deviceSpacePts); |
| 106 | |
| 107 | fCurrPathPointsIdx = fGeometry.points().count(); |
| 108 | fCurrPathVerbsIdx = fGeometry.verbs().count(); |
| 109 | fCurrPathPrimitiveCounts = PrimitiveTallies(); |
| 110 | |
| 111 | fGeometry.beginPath(); |
| 112 | |
| 113 | if (path.isEmpty()) { |
| 114 | return; |
| 115 | } |
| 116 | |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 117 | const float* conicWeights = SkPathPriv::ConicWeightData(path); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 118 | int ptsIdx = 0; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 119 | int conicWeightsIdx = 0; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 120 | bool insideContour = false; |
| 121 | |
| 122 | for (SkPath::Verb verb : SkPathPriv::Verbs(path)) { |
| 123 | switch (verb) { |
| 124 | case SkPath::kMove_Verb: |
| 125 | this->endContourIfNeeded(insideContour); |
| 126 | fGeometry.beginContour(deviceSpacePts[ptsIdx]); |
| 127 | ++ptsIdx; |
| 128 | insideContour = true; |
| 129 | continue; |
| 130 | case SkPath::kClose_Verb: |
| 131 | this->endContourIfNeeded(insideContour); |
| 132 | insideContour = false; |
| 133 | continue; |
| 134 | case SkPath::kLine_Verb: |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 135 | fGeometry.lineTo(&deviceSpacePts[ptsIdx - 1]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 136 | ++ptsIdx; |
| 137 | continue; |
| 138 | case SkPath::kQuad_Verb: |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 139 | fGeometry.quadraticTo(&deviceSpacePts[ptsIdx - 1]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 140 | ptsIdx += 2; |
| 141 | continue; |
| 142 | case SkPath::kCubic_Verb: |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 143 | fGeometry.cubicTo(&deviceSpacePts[ptsIdx - 1]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 144 | ptsIdx += 3; |
| 145 | continue; |
| 146 | case SkPath::kConic_Verb: |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 147 | fGeometry.conicTo(&deviceSpacePts[ptsIdx - 1], conicWeights[conicWeightsIdx]); |
| 148 | ptsIdx += 2; |
| 149 | ++conicWeightsIdx; |
| 150 | continue; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 151 | default: |
| 152 | SK_ABORT("Unexpected path verb."); |
| 153 | } |
| 154 | } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 155 | SkASSERT(ptsIdx == path.countPoints()); |
| 156 | SkASSERT(conicWeightsIdx == SkPathPriv::ConicWeightCnt(path)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 157 | |
| 158 | this->endContourIfNeeded(insideContour); |
| 159 | } |
| 160 | |
| 161 | void GrCCPathParser::endContourIfNeeded(bool insideContour) { |
| 162 | if (insideContour) { |
| 163 | fCurrPathPrimitiveCounts += fGeometry.endContour(); |
| 164 | } |
| 165 | } |
| 166 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 167 | void GrCCPathParser::saveParsedPath(GrScissorTest scissorTest, const SkIRect& clippedDevIBounds, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 168 | const SkIVector& devToAtlasOffset) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 169 | SkASSERT(fParsingPath); |
| 170 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 171 | fPathsInfo.emplace_back(scissorTest, devToAtlasOffset); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 172 | |
| 173 | // Tessellate fans from very large and/or simple paths, in order to reduce overdraw. |
| 174 | int numVerbs = fGeometry.verbs().count() - fCurrPathVerbsIdx - 1; |
| 175 | int64_t tessellationWork = (int64_t)numVerbs * (32 - SkCLZ(numVerbs)); // N log N. |
| 176 | int64_t fanningWork = (int64_t)clippedDevIBounds.height() * clippedDevIBounds.width(); |
| 177 | if (tessellationWork * (50*50) + (100*100) < fanningWork) { // Don't tessellate under 100x100. |
| 178 | fCurrPathPrimitiveCounts.fTriangles = |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 179 | fCurrPathPrimitiveCounts.fWeightedTriangles = 0; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 180 | |
| 181 | const SkTArray<GrCCGeometry::Verb, true>& verbs = fGeometry.verbs(); |
| 182 | const SkTArray<SkPoint, true>& pts = fGeometry.points(); |
| 183 | int ptsIdx = fCurrPathPointsIdx; |
| 184 | |
Chris Dalton | 45e4660 | 2018-02-15 12:27:29 -0700 | [diff] [blame] | 185 | // Build an SkPath of the Redbook fan. We use "winding" fill type right now because we are |
| 186 | // producing a coverage count, and must fill in every region that has non-zero wind. The |
| 187 | // path processor will convert coverage count to the appropriate fill type later. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 188 | SkPath fan; |
Chris Dalton | 45e4660 | 2018-02-15 12:27:29 -0700 | [diff] [blame] | 189 | fan.setFillType(SkPath::kWinding_FillType); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 190 | SkASSERT(GrCCGeometry::Verb::kBeginPath == verbs[fCurrPathVerbsIdx]); |
| 191 | for (int i = fCurrPathVerbsIdx + 1; i < fGeometry.verbs().count(); ++i) { |
| 192 | switch (verbs[i]) { |
| 193 | case GrCCGeometry::Verb::kBeginPath: |
| 194 | SK_ABORT("Invalid GrCCGeometry"); |
| 195 | continue; |
| 196 | |
| 197 | case GrCCGeometry::Verb::kBeginContour: |
| 198 | fan.moveTo(pts[ptsIdx++]); |
| 199 | continue; |
| 200 | |
| 201 | case GrCCGeometry::Verb::kLineTo: |
| 202 | fan.lineTo(pts[ptsIdx++]); |
| 203 | continue; |
| 204 | |
| 205 | case GrCCGeometry::Verb::kMonotonicQuadraticTo: |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 206 | case GrCCGeometry::Verb::kMonotonicConicTo: |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 207 | fan.lineTo(pts[ptsIdx + 1]); |
| 208 | ptsIdx += 2; |
| 209 | continue; |
| 210 | |
| 211 | case GrCCGeometry::Verb::kMonotonicCubicTo: |
| 212 | fan.lineTo(pts[ptsIdx + 2]); |
| 213 | ptsIdx += 3; |
| 214 | continue; |
| 215 | |
| 216 | case GrCCGeometry::Verb::kEndClosedContour: |
| 217 | case GrCCGeometry::Verb::kEndOpenContour: |
| 218 | fan.close(); |
| 219 | continue; |
| 220 | } |
| 221 | } |
| 222 | GrTessellator::WindingVertex* vertices = nullptr; |
| 223 | int count = GrTessellator::PathToVertices(fan, std::numeric_limits<float>::infinity(), |
| 224 | SkRect::Make(clippedDevIBounds), &vertices); |
| 225 | SkASSERT(0 == count % 3); |
| 226 | for (int i = 0; i < count; i += 3) { |
Chris Dalton | 45e4660 | 2018-02-15 12:27:29 -0700 | [diff] [blame] | 227 | int tessWinding = vertices[i].fWinding; |
| 228 | SkASSERT(tessWinding == vertices[i + 1].fWinding); |
| 229 | SkASSERT(tessWinding == vertices[i + 2].fWinding); |
| 230 | |
| 231 | // Ensure this triangle's points actually wind in the same direction as tessWinding. |
| 232 | // CCPR shaders use the sign of wind to determine which direction to bloat, so even for |
| 233 | // "wound" triangles the winding sign and point ordering need to agree. |
| 234 | float ax = vertices[i].fPos.fX - vertices[i + 1].fPos.fX; |
| 235 | float ay = vertices[i].fPos.fY - vertices[i + 1].fPos.fY; |
| 236 | float bx = vertices[i].fPos.fX - vertices[i + 2].fPos.fX; |
| 237 | float by = vertices[i].fPos.fY - vertices[i + 2].fPos.fY; |
| 238 | float wind = ax*by - ay*bx; |
| 239 | if ((wind > 0) != (-tessWinding > 0)) { // Tessellator has opposite winding sense. |
| 240 | std::swap(vertices[i + 1].fPos, vertices[i + 2].fPos); |
| 241 | } |
| 242 | |
| 243 | if (1 == abs(tessWinding)) { |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 244 | ++fCurrPathPrimitiveCounts.fTriangles; |
| 245 | } else { |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 246 | ++fCurrPathPrimitiveCounts.fWeightedTriangles; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Chris Dalton | ad06544 | 2018-03-08 22:41:33 -0700 | [diff] [blame] | 250 | fPathsInfo.back().adoptFanTessellation(vertices, count); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 253 | fTotalPrimitiveCounts[(int)scissorTest] += fCurrPathPrimitiveCounts; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 254 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 255 | if (GrScissorTest::kEnabled == scissorTest) { |
| 256 | fScissorSubBatches.push_back() = {fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled], |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 257 | clippedDevIBounds.makeOffset(devToAtlasOffset.fX, |
| 258 | devToAtlasOffset.fY)}; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | SkDEBUGCODE(fParsingPath = false); |
| 262 | } |
| 263 | |
| 264 | void GrCCPathParser::discardParsedPath() { |
| 265 | SkASSERT(fParsingPath); |
| 266 | fGeometry.resize_back(fCurrPathPointsIdx, fCurrPathVerbsIdx); |
| 267 | SkDEBUGCODE(fParsingPath = false); |
| 268 | } |
| 269 | |
| 270 | GrCCPathParser::CoverageCountBatchID GrCCPathParser::closeCurrentBatch() { |
| 271 | SkASSERT(!fInstanceBuffer); |
| 272 | SkASSERT(!fCoverageCountBatches.empty()); |
| 273 | |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 274 | const auto& lastBatch = fCoverageCountBatches.back(); |
| 275 | int maxMeshes = 1 + fScissorSubBatches.count() - lastBatch.fEndScissorSubBatchIdx; |
| 276 | fMaxMeshesPerDraw = SkTMax(fMaxMeshesPerDraw, maxMeshes); |
| 277 | |
| 278 | const auto& lastScissorSubBatch = fScissorSubBatches[lastBatch.fEndScissorSubBatchIdx - 1]; |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 279 | PrimitiveTallies batchTotalCounts = fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled] - |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 280 | lastBatch.fEndNonScissorIndices; |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 281 | batchTotalCounts += fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled] - |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 282 | lastScissorSubBatch.fEndPrimitiveIndices; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 283 | |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 284 | // This will invalidate lastBatch. |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 285 | fCoverageCountBatches.push_back() = { |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 286 | fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled], |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 287 | fScissorSubBatches.count(), |
| 288 | batchTotalCounts |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 289 | }; |
| 290 | return fCoverageCountBatches.count() - 1; |
| 291 | } |
| 292 | |
| 293 | // Emits a contour's triangle fan. |
| 294 | // |
| 295 | // Classic Redbook fanning would be the triangles: [0 1 2], [0 2 3], ..., [0 n-2 n-1]. |
| 296 | // |
| 297 | // This function emits the triangle: [0 n/3 n*2/3], and then recurses on all three sides. The |
| 298 | // advantage to this approach is that for a convex-ish contour, it generates larger triangles. |
| 299 | // Classic fanning tends to generate long, skinny triangles, which are expensive to draw since they |
| 300 | // have a longer perimeter to rasterize and antialias. |
| 301 | // |
| 302 | // The indices array indexes the fan's points (think: glDrawElements), and must have at least log3 |
| 303 | // elements past the end for this method to use as scratch space. |
| 304 | // |
| 305 | // Returns the next triangle instance after the final one emitted. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 306 | static TriPointInstance* emit_recursive_fan(const SkTArray<SkPoint, true>& pts, |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 307 | SkTArray<int32_t, true>& indices, int firstIndex, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 308 | int indexCount, const Sk2f& devToAtlasOffset, |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 309 | TriPointInstance out[]) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 310 | if (indexCount < 3) { |
| 311 | return out; |
| 312 | } |
| 313 | |
| 314 | int32_t oneThirdCount = indexCount / 3; |
| 315 | int32_t twoThirdsCount = (2 * indexCount) / 3; |
| 316 | out++->set(pts[indices[firstIndex]], pts[indices[firstIndex + oneThirdCount]], |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 317 | pts[indices[firstIndex + twoThirdsCount]], devToAtlasOffset); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 318 | |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 319 | out = emit_recursive_fan(pts, indices, firstIndex, oneThirdCount + 1, devToAtlasOffset, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 320 | out = emit_recursive_fan(pts, indices, firstIndex + oneThirdCount, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 321 | twoThirdsCount - oneThirdCount + 1, devToAtlasOffset, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 322 | |
| 323 | int endIndex = firstIndex + indexCount; |
| 324 | int32_t oldValue = indices[endIndex]; |
| 325 | indices[endIndex] = indices[firstIndex]; |
| 326 | out = emit_recursive_fan(pts, indices, firstIndex + twoThirdsCount, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 327 | indexCount - twoThirdsCount + 1, devToAtlasOffset, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 328 | indices[endIndex] = oldValue; |
| 329 | |
| 330 | return out; |
| 331 | } |
| 332 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 333 | static void emit_tessellated_fan(const GrTessellator::WindingVertex* vertices, int numVertices, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 334 | const Sk2f& devToAtlasOffset, |
| 335 | TriPointInstance* triPointInstanceData, |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 336 | QuadPointInstance* quadPointInstanceData, |
| 337 | GrCCGeometry::PrimitiveTallies* indices) { |
| 338 | for (int i = 0; i < numVertices; i += 3) { |
| 339 | if (1 == abs(vertices[i].fWinding)) { |
| 340 | triPointInstanceData[indices->fTriangles++].set(vertices[i].fPos, vertices[i + 1].fPos, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 341 | vertices[i + 2].fPos, devToAtlasOffset); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 342 | } else { |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 343 | quadPointInstanceData[indices->fWeightedTriangles++].setW( |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 344 | vertices[i].fPos, vertices[i+1].fPos, vertices[i + 2].fPos, devToAtlasOffset, |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 345 | static_cast<float>(abs(vertices[i].fWinding))); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 350 | bool GrCCPathParser::finalize(GrOnFlushResourceProvider* onFlushRP) { |
| 351 | SkASSERT(!fParsingPath); // Call saveParsedPath() or discardParsedPath(). |
| 352 | SkASSERT(fCoverageCountBatches.back().fEndNonScissorIndices == // Call closeCurrentBatch(). |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 353 | fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 354 | SkASSERT(fCoverageCountBatches.back().fEndScissorSubBatchIdx == fScissorSubBatches.count()); |
| 355 | |
| 356 | // Here we build a single instance buffer to share with every internal batch. |
| 357 | // |
| 358 | // CCPR processs 3 different types of primitives: triangles, quadratics, cubics. Each primitive |
| 359 | // type is further divided into instances that require a scissor and those that don't. This |
| 360 | // leaves us with 3*2 = 6 independent instance arrays to build for the GPU. |
| 361 | // |
| 362 | // Rather than place each instance array in its own GPU buffer, we allocate a single |
| 363 | // megabuffer and lay them all out side-by-side. We can offset the "baseInstance" parameter in |
| 364 | // our draw calls to direct the GPU to the applicable elements within a given array. |
| 365 | // |
| 366 | // We already know how big to make each of the 6 arrays from fTotalPrimitiveCounts, so layout is |
| 367 | // straightforward. Start with triangles and quadratics. They both view the instance buffer as |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 368 | // an array of TriPointInstance[], so we can begin at zero and lay them out one after the other. |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 369 | fBaseInstances[0].fTriangles = 0; |
| 370 | fBaseInstances[1].fTriangles = fBaseInstances[0].fTriangles + |
| 371 | fTotalPrimitiveCounts[0].fTriangles; |
| 372 | fBaseInstances[0].fQuadratics = fBaseInstances[1].fTriangles + |
| 373 | fTotalPrimitiveCounts[1].fTriangles; |
| 374 | fBaseInstances[1].fQuadratics = fBaseInstances[0].fQuadratics + |
| 375 | fTotalPrimitiveCounts[0].fQuadratics; |
| 376 | int triEndIdx = fBaseInstances[1].fQuadratics + fTotalPrimitiveCounts[1].fQuadratics; |
| 377 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 378 | // Wound triangles and cubics both view the same instance buffer as an array of |
| 379 | // QuadPointInstance[]. So, reinterpreting the instance data as QuadPointInstance[], we start |
| 380 | // them on the first index that will not overwrite previous TriPointInstance data. |
| 381 | int quadBaseIdx = |
| 382 | GR_CT_DIV_ROUND_UP(triEndIdx * sizeof(TriPointInstance), sizeof(QuadPointInstance)); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 383 | fBaseInstances[0].fWeightedTriangles = quadBaseIdx; |
| 384 | fBaseInstances[1].fWeightedTriangles = fBaseInstances[0].fWeightedTriangles + |
| 385 | fTotalPrimitiveCounts[0].fWeightedTriangles; |
| 386 | fBaseInstances[0].fCubics = fBaseInstances[1].fWeightedTriangles + |
| 387 | fTotalPrimitiveCounts[1].fWeightedTriangles; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 388 | fBaseInstances[1].fCubics = fBaseInstances[0].fCubics + fTotalPrimitiveCounts[0].fCubics; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 389 | fBaseInstances[0].fConics = fBaseInstances[1].fCubics + fTotalPrimitiveCounts[1].fCubics; |
| 390 | fBaseInstances[1].fConics = fBaseInstances[0].fConics + fTotalPrimitiveCounts[0].fConics; |
| 391 | int quadEndIdx = fBaseInstances[1].fConics + fTotalPrimitiveCounts[1].fConics; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 392 | |
| 393 | fInstanceBuffer = onFlushRP->makeBuffer(kVertex_GrBufferType, |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 394 | quadEndIdx * sizeof(QuadPointInstance)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 395 | if (!fInstanceBuffer) { |
| 396 | return false; |
| 397 | } |
| 398 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 399 | TriPointInstance* triPointInstanceData = static_cast<TriPointInstance*>(fInstanceBuffer->map()); |
| 400 | QuadPointInstance* quadPointInstanceData = |
| 401 | reinterpret_cast<QuadPointInstance*>(triPointInstanceData); |
| 402 | SkASSERT(quadPointInstanceData); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 403 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 404 | PathInfo* nextPathInfo = fPathsInfo.begin(); |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 405 | Sk2f devToAtlasOffset; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 406 | PrimitiveTallies instanceIndices[2] = {fBaseInstances[0], fBaseInstances[1]}; |
| 407 | PrimitiveTallies* currIndices = nullptr; |
| 408 | SkSTArray<256, int32_t, true> currFan; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 409 | bool currFanIsTessellated = false; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 410 | |
| 411 | const SkTArray<SkPoint, true>& pts = fGeometry.points(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 412 | int ptsIdx = -1; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 413 | int nextConicWeightIdx = 0; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 414 | |
| 415 | // Expand the ccpr verbs into GPU instance buffers. |
| 416 | for (GrCCGeometry::Verb verb : fGeometry.verbs()) { |
| 417 | switch (verb) { |
| 418 | case GrCCGeometry::Verb::kBeginPath: |
| 419 | SkASSERT(currFan.empty()); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 420 | currIndices = &instanceIndices[(int)nextPathInfo->scissorTest()]; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 421 | devToAtlasOffset = Sk2f(static_cast<float>(nextPathInfo->devToAtlasOffset().fX), |
| 422 | static_cast<float>(nextPathInfo->devToAtlasOffset().fY)); |
Chris Dalton | ad06544 | 2018-03-08 22:41:33 -0700 | [diff] [blame] | 423 | currFanIsTessellated = nextPathInfo->hasFanTessellation(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 424 | if (currFanIsTessellated) { |
Chris Dalton | ad06544 | 2018-03-08 22:41:33 -0700 | [diff] [blame] | 425 | emit_tessellated_fan(nextPathInfo->fanTessellation(), |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 426 | nextPathInfo->fanTessellationCount(), devToAtlasOffset, |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 427 | triPointInstanceData, quadPointInstanceData, currIndices); |
| 428 | } |
| 429 | ++nextPathInfo; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 430 | continue; |
| 431 | |
| 432 | case GrCCGeometry::Verb::kBeginContour: |
| 433 | SkASSERT(currFan.empty()); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 434 | ++ptsIdx; |
| 435 | if (!currFanIsTessellated) { |
| 436 | currFan.push_back(ptsIdx); |
| 437 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 438 | continue; |
| 439 | |
| 440 | case GrCCGeometry::Verb::kLineTo: |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 441 | ++ptsIdx; |
| 442 | if (!currFanIsTessellated) { |
| 443 | SkASSERT(!currFan.empty()); |
| 444 | currFan.push_back(ptsIdx); |
| 445 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 446 | continue; |
| 447 | |
| 448 | case GrCCGeometry::Verb::kMonotonicQuadraticTo: |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 449 | triPointInstanceData[currIndices->fQuadratics++].set(&pts[ptsIdx], |
| 450 | devToAtlasOffset); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 451 | ptsIdx += 2; |
| 452 | if (!currFanIsTessellated) { |
| 453 | SkASSERT(!currFan.empty()); |
| 454 | currFan.push_back(ptsIdx); |
| 455 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 456 | continue; |
| 457 | |
| 458 | case GrCCGeometry::Verb::kMonotonicCubicTo: |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 459 | quadPointInstanceData[currIndices->fCubics++].set(&pts[ptsIdx], devToAtlasOffset[0], |
| 460 | devToAtlasOffset[1]); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 461 | ptsIdx += 3; |
| 462 | if (!currFanIsTessellated) { |
| 463 | SkASSERT(!currFan.empty()); |
| 464 | currFan.push_back(ptsIdx); |
| 465 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 466 | continue; |
| 467 | |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 468 | case GrCCGeometry::Verb::kMonotonicConicTo: |
| 469 | quadPointInstanceData[currIndices->fConics++].setW( |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 470 | &pts[ptsIdx], devToAtlasOffset, |
| 471 | fGeometry.getConicWeight(nextConicWeightIdx)); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 472 | ptsIdx += 2; |
| 473 | ++nextConicWeightIdx; |
| 474 | if (!currFanIsTessellated) { |
| 475 | SkASSERT(!currFan.empty()); |
| 476 | currFan.push_back(ptsIdx); |
| 477 | } |
| 478 | continue; |
| 479 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 480 | case GrCCGeometry::Verb::kEndClosedContour: // endPt == startPt. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 481 | if (!currFanIsTessellated) { |
| 482 | SkASSERT(!currFan.empty()); |
| 483 | currFan.pop_back(); |
| 484 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 485 | // fallthru. |
| 486 | case GrCCGeometry::Verb::kEndOpenContour: // endPt != startPt. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 487 | SkASSERT(!currFanIsTessellated || currFan.empty()); |
| 488 | if (!currFanIsTessellated && currFan.count() >= 3) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 489 | int fanSize = currFan.count(); |
| 490 | // Reserve space for emit_recursive_fan. Technically this can grow to |
| 491 | // fanSize + log3(fanSize), but we approximate with log2. |
| 492 | currFan.push_back_n(SkNextLog2(fanSize)); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 493 | SkDEBUGCODE(TriPointInstance* end =) |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 494 | emit_recursive_fan(pts, currFan, 0, fanSize, devToAtlasOffset, |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 495 | triPointInstanceData + currIndices->fTriangles); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 496 | currIndices->fTriangles += fanSize - 2; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 497 | SkASSERT(triPointInstanceData + currIndices->fTriangles == end); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 498 | } |
| 499 | currFan.reset(); |
| 500 | continue; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | fInstanceBuffer->unmap(); |
| 505 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 506 | SkASSERT(nextPathInfo == fPathsInfo.end()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 507 | SkASSERT(ptsIdx == pts.count() - 1); |
| 508 | SkASSERT(instanceIndices[0].fTriangles == fBaseInstances[1].fTriangles); |
| 509 | SkASSERT(instanceIndices[1].fTriangles == fBaseInstances[0].fQuadratics); |
| 510 | SkASSERT(instanceIndices[0].fQuadratics == fBaseInstances[1].fQuadratics); |
| 511 | SkASSERT(instanceIndices[1].fQuadratics == triEndIdx); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 512 | SkASSERT(instanceIndices[0].fWeightedTriangles == fBaseInstances[1].fWeightedTriangles); |
| 513 | SkASSERT(instanceIndices[1].fWeightedTriangles == fBaseInstances[0].fCubics); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 514 | SkASSERT(instanceIndices[0].fCubics == fBaseInstances[1].fCubics); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 515 | SkASSERT(instanceIndices[1].fCubics == fBaseInstances[0].fConics); |
| 516 | SkASSERT(instanceIndices[0].fConics == fBaseInstances[1].fConics); |
| 517 | SkASSERT(instanceIndices[1].fConics == quadEndIdx); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 518 | |
| 519 | fMeshesScratchBuffer.reserve(fMaxMeshesPerDraw); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 520 | fScissorRectScratchBuffer.reserve(fMaxMeshesPerDraw); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 521 | |
| 522 | return true; |
| 523 | } |
| 524 | |
| 525 | void GrCCPathParser::drawCoverageCount(GrOpFlushState* flushState, CoverageCountBatchID batchID, |
| 526 | const SkIRect& drawBounds) const { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 527 | using PrimitiveType = GrCCCoverageProcessor::PrimitiveType; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 528 | |
| 529 | SkASSERT(fInstanceBuffer); |
| 530 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 531 | const PrimitiveTallies& batchTotalCounts = fCoverageCountBatches[batchID].fTotalPrimitiveCounts; |
| 532 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 533 | GrPipeline pipeline(flushState->drawOpArgs().fProxy, GrScissorTest::kEnabled, |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 534 | SkBlendMode::kPlus); |
| 535 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 536 | if (batchTotalCounts.fTriangles) { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 537 | this->drawPrimitives(flushState, pipeline, batchID, PrimitiveType::kTriangles, |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 538 | &PrimitiveTallies::fTriangles, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 539 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 540 | |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 541 | if (batchTotalCounts.fWeightedTriangles) { |
| 542 | this->drawPrimitives(flushState, pipeline, batchID, PrimitiveType::kWeightedTriangles, |
| 543 | &PrimitiveTallies::fWeightedTriangles, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 544 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 545 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 546 | if (batchTotalCounts.fQuadratics) { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 547 | this->drawPrimitives(flushState, pipeline, batchID, PrimitiveType::kQuadratics, |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 548 | &PrimitiveTallies::fQuadratics, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | if (batchTotalCounts.fCubics) { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 552 | this->drawPrimitives(flushState, pipeline, batchID, PrimitiveType::kCubics, |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 553 | &PrimitiveTallies::fCubics, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 554 | } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 555 | |
| 556 | if (batchTotalCounts.fConics) { |
| 557 | this->drawPrimitives(flushState, pipeline, batchID, PrimitiveType::kConics, |
| 558 | &PrimitiveTallies::fConics, drawBounds); |
| 559 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 562 | void GrCCPathParser::drawPrimitives(GrOpFlushState* flushState, const GrPipeline& pipeline, |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 563 | CoverageCountBatchID batchID, |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 564 | GrCCCoverageProcessor::PrimitiveType primitiveType, |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 565 | int PrimitiveTallies::*instanceType, |
| 566 | const SkIRect& drawBounds) const { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 567 | SkASSERT(pipeline.isScissorEnabled()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 568 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 569 | // Don't call reset(), as that also resets the reserve count. |
| 570 | fMeshesScratchBuffer.pop_back_n(fMeshesScratchBuffer.count()); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 571 | fScissorRectScratchBuffer.pop_back_n(fScissorRectScratchBuffer.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 572 | |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 573 | GrCCCoverageProcessor proc(flushState->resourceProvider(), primitiveType); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 574 | |
| 575 | SkASSERT(batchID > 0); |
| 576 | SkASSERT(batchID < fCoverageCountBatches.count()); |
| 577 | const CoverageCountBatch& previousBatch = fCoverageCountBatches[batchID - 1]; |
| 578 | const CoverageCountBatch& batch = fCoverageCountBatches[batchID]; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 579 | SkDEBUGCODE(int totalInstanceCount = 0); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 580 | |
| 581 | if (int instanceCount = batch.fEndNonScissorIndices.*instanceType - |
| 582 | previousBatch.fEndNonScissorIndices.*instanceType) { |
| 583 | SkASSERT(instanceCount > 0); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 584 | int baseInstance = fBaseInstances[(int)GrScissorTest::kDisabled].*instanceType + |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 585 | previousBatch.fEndNonScissorIndices.*instanceType; |
| 586 | proc.appendMesh(fInstanceBuffer.get(), instanceCount, baseInstance, &fMeshesScratchBuffer); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 587 | fScissorRectScratchBuffer.push_back().setXYWH(0, 0, drawBounds.width(), |
| 588 | drawBounds.height()); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 589 | SkDEBUGCODE(totalInstanceCount += instanceCount); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | SkASSERT(previousBatch.fEndScissorSubBatchIdx > 0); |
| 593 | SkASSERT(batch.fEndScissorSubBatchIdx <= fScissorSubBatches.count()); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame^] | 594 | int baseScissorInstance = fBaseInstances[(int)GrScissorTest::kEnabled].*instanceType; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 595 | for (int i = previousBatch.fEndScissorSubBatchIdx; i < batch.fEndScissorSubBatchIdx; ++i) { |
| 596 | const ScissorSubBatch& previousSubBatch = fScissorSubBatches[i - 1]; |
| 597 | const ScissorSubBatch& scissorSubBatch = fScissorSubBatches[i]; |
| 598 | int startIndex = previousSubBatch.fEndPrimitiveIndices.*instanceType; |
| 599 | int instanceCount = scissorSubBatch.fEndPrimitiveIndices.*instanceType - startIndex; |
| 600 | if (!instanceCount) { |
| 601 | continue; |
| 602 | } |
| 603 | SkASSERT(instanceCount > 0); |
| 604 | proc.appendMesh(fInstanceBuffer.get(), instanceCount, |
| 605 | baseScissorInstance + startIndex, &fMeshesScratchBuffer); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 606 | fScissorRectScratchBuffer.push_back() = scissorSubBatch.fScissor; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 607 | SkDEBUGCODE(totalInstanceCount += instanceCount); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 610 | SkASSERT(fMeshesScratchBuffer.count() == fScissorRectScratchBuffer.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 611 | SkASSERT(fMeshesScratchBuffer.count() <= fMaxMeshesPerDraw); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 612 | SkASSERT(totalInstanceCount == batch.fTotalPrimitiveCounts.*instanceType); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 613 | |
| 614 | if (!fMeshesScratchBuffer.empty()) { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 615 | proc.draw(flushState, pipeline, fScissorRectScratchBuffer.begin(), |
| 616 | fMeshesScratchBuffer.begin(), fMeshesScratchBuffer.count(), |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 617 | SkRect::Make(drawBounds)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 618 | } |
| 619 | } |