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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/ccpr/GrCCFiller.h" |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkPath.h" |
| 11 | #include "include/core/SkPoint.h" |
| 12 | #include "src/core/SkMathPriv.h" |
| 13 | #include "src/core/SkPathPriv.h" |
| 14 | #include "src/gpu/GrCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 16 | #include "src/gpu/GrOpFlushState.h" |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 17 | #include <stdlib.h> |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 18 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 19 | using TriPointInstance = GrCCCoverageProcessor::TriPointInstance; |
| 20 | using QuadPointInstance = GrCCCoverageProcessor::QuadPointInstance; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 21 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 22 | GrCCFiller::GrCCFiller(Algorithm algorithm, int numPaths, int numSkPoints, int numSkVerbs, |
| 23 | int numConicWeights) |
| 24 | : fAlgorithm(algorithm) |
| 25 | , fGeometry(numSkPoints, numSkVerbs, numConicWeights) |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 26 | , fPathInfos(numPaths) |
Chris Dalton | 3917b1e | 2018-05-09 00:40:52 -0600 | [diff] [blame] | 27 | , fScissorSubBatches(numPaths) |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 28 | , fTotalPrimitiveCounts{PrimitiveTallies(), PrimitiveTallies()} { |
| 29 | // Batches decide what to draw by looking where the previous one ended. Define initial batches |
| 30 | // that "end" at the beginning of the data. These will not be drawn, but will only be be read by |
| 31 | // the first actual batch. |
| 32 | fScissorSubBatches.push_back() = {PrimitiveTallies(), SkIRect::MakeEmpty()}; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 33 | fBatches.push_back() = {PrimitiveTallies(), fScissorSubBatches.count(), PrimitiveTallies()}; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 36 | void GrCCFiller::parseDeviceSpaceFill(const SkPath& path, const SkPoint* deviceSpacePts, |
| 37 | GrScissorTest scissorTest, const SkIRect& clippedDevIBounds, |
| 38 | const SkIVector& devToAtlasOffset) { |
| 39 | SkASSERT(!fInstanceBuffer); // Can't call after prepareToDraw(). |
| 40 | SkASSERT(!path.isEmpty()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 41 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 42 | int currPathPointsIdx = fGeometry.points().count(); |
| 43 | int currPathVerbsIdx = fGeometry.verbs().count(); |
| 44 | PrimitiveTallies currPathPrimitiveCounts = PrimitiveTallies(); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 45 | |
| 46 | fGeometry.beginPath(); |
| 47 | |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 48 | const float* conicWeights = SkPathPriv::ConicWeightData(path); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 49 | int ptsIdx = 0; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 50 | int conicWeightsIdx = 0; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 51 | bool insideContour = false; |
| 52 | |
| 53 | for (SkPath::Verb verb : SkPathPriv::Verbs(path)) { |
| 54 | switch (verb) { |
| 55 | case SkPath::kMove_Verb: |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 56 | if (insideContour) { |
| 57 | currPathPrimitiveCounts += fGeometry.endContour(); |
| 58 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 59 | fGeometry.beginContour(deviceSpacePts[ptsIdx]); |
| 60 | ++ptsIdx; |
| 61 | insideContour = true; |
| 62 | continue; |
| 63 | case SkPath::kClose_Verb: |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 64 | if (insideContour) { |
| 65 | currPathPrimitiveCounts += fGeometry.endContour(); |
| 66 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 67 | insideContour = false; |
| 68 | continue; |
| 69 | case SkPath::kLine_Verb: |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 70 | fGeometry.lineTo(&deviceSpacePts[ptsIdx - 1]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 71 | ++ptsIdx; |
| 72 | continue; |
| 73 | case SkPath::kQuad_Verb: |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 74 | fGeometry.quadraticTo(&deviceSpacePts[ptsIdx - 1]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 75 | ptsIdx += 2; |
| 76 | continue; |
| 77 | case SkPath::kCubic_Verb: |
Chris Dalton | 7ca3b7b | 2018-04-10 00:21:19 -0600 | [diff] [blame] | 78 | fGeometry.cubicTo(&deviceSpacePts[ptsIdx - 1]); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 79 | ptsIdx += 3; |
| 80 | continue; |
| 81 | case SkPath::kConic_Verb: |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 82 | fGeometry.conicTo(&deviceSpacePts[ptsIdx - 1], conicWeights[conicWeightsIdx]); |
| 83 | ptsIdx += 2; |
| 84 | ++conicWeightsIdx; |
| 85 | continue; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 86 | default: |
| 87 | SK_ABORT("Unexpected path verb."); |
| 88 | } |
| 89 | } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 90 | SkASSERT(ptsIdx == path.countPoints()); |
| 91 | SkASSERT(conicWeightsIdx == SkPathPriv::ConicWeightCnt(path)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 92 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 93 | if (insideContour) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 94 | currPathPrimitiveCounts += fGeometry.endContour(); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 95 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 96 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 97 | fPathInfos.emplace_back(scissorTest, devToAtlasOffset); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 98 | |
| 99 | // Tessellate fans from very large and/or simple paths, in order to reduce overdraw. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 100 | int numVerbs = fGeometry.verbs().count() - currPathVerbsIdx - 1; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 101 | int64_t tessellationWork = (int64_t)numVerbs * (32 - SkCLZ(numVerbs)); // N log N. |
| 102 | int64_t fanningWork = (int64_t)clippedDevIBounds.height() * clippedDevIBounds.width(); |
| 103 | if (tessellationWork * (50*50) + (100*100) < fanningWork) { // Don't tessellate under 100x100. |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 104 | fPathInfos.back().tessellateFan( |
| 105 | fAlgorithm, path, fGeometry, currPathVerbsIdx, currPathPointsIdx, clippedDevIBounds, |
| 106 | &currPathPrimitiveCounts); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 109 | fTotalPrimitiveCounts[(int)scissorTest] += currPathPrimitiveCounts; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 110 | |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 111 | if (GrScissorTest::kEnabled == scissorTest) { |
| 112 | fScissorSubBatches.push_back() = {fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled], |
Brian Salomon | 9bd947d | 2019-10-03 14:57:07 -0400 | [diff] [blame] | 113 | clippedDevIBounds.makeOffset(devToAtlasOffset)}; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 114 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 117 | void GrCCFiller::PathInfo::tessellateFan( |
| 118 | Algorithm algorithm, const SkPath& originalPath, const GrCCFillGeometry& geometry, |
| 119 | int verbsIdx, int ptsIdx, const SkIRect& clippedDevIBounds, |
| 120 | PrimitiveTallies* newTriangleCounts) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 121 | using Verb = GrCCFillGeometry::Verb; |
| 122 | SkASSERT(-1 == fFanTessellationCount); |
| 123 | SkASSERT(!fFanTessellation); |
| 124 | |
| 125 | const SkTArray<Verb, true>& verbs = geometry.verbs(); |
| 126 | const SkTArray<SkPoint, true>& pts = geometry.points(); |
| 127 | |
| 128 | newTriangleCounts->fTriangles = |
| 129 | newTriangleCounts->fWeightedTriangles = 0; |
| 130 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 131 | // Build an SkPath of the Redbook fan. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 132 | SkPath fan; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 133 | if (Algorithm::kCoverageCount == algorithm) { |
| 134 | // We use "winding" fill type right now because we are producing a coverage count, and must |
| 135 | // fill in every region that has non-zero wind. The path processor will convert coverage |
| 136 | // count to the appropriate fill type later. |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 137 | fan.setFillType(SkPathFillType::kWinding); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 138 | } else { |
Chris Dalton | c096654 | 2019-09-23 20:16:03 -0600 | [diff] [blame] | 139 | // When counting winding numbers in the stencil buffer, it works to use even/odd for the fan |
| 140 | // tessellation (where applicable). But we need to strip out inverse fill info because |
| 141 | // inverse-ness gets accounted for later on. |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 142 | fan.setFillType(SkPathFillType_ConvertToNonInverse(originalPath.getFillType())); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 143 | } |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 144 | SkASSERT(Verb::kBeginPath == verbs[verbsIdx]); |
| 145 | for (int i = verbsIdx + 1; i < verbs.count(); ++i) { |
| 146 | switch (verbs[i]) { |
| 147 | case Verb::kBeginPath: |
| 148 | SK_ABORT("Invalid GrCCFillGeometry"); |
| 149 | continue; |
| 150 | |
| 151 | case Verb::kBeginContour: |
| 152 | fan.moveTo(pts[ptsIdx++]); |
| 153 | continue; |
| 154 | |
| 155 | case Verb::kLineTo: |
| 156 | fan.lineTo(pts[ptsIdx++]); |
| 157 | continue; |
| 158 | |
| 159 | case Verb::kMonotonicQuadraticTo: |
| 160 | case Verb::kMonotonicConicTo: |
| 161 | fan.lineTo(pts[ptsIdx + 1]); |
| 162 | ptsIdx += 2; |
| 163 | continue; |
| 164 | |
| 165 | case Verb::kMonotonicCubicTo: |
| 166 | fan.lineTo(pts[ptsIdx + 2]); |
| 167 | ptsIdx += 3; |
| 168 | continue; |
| 169 | |
| 170 | case Verb::kEndClosedContour: |
| 171 | case Verb::kEndOpenContour: |
| 172 | fan.close(); |
| 173 | continue; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | GrTessellator::WindingVertex* vertices = nullptr; |
Chris Dalton | c096654 | 2019-09-23 20:16:03 -0600 | [diff] [blame] | 178 | SkASSERT(!fan.isInverseFillType()); |
| 179 | fFanTessellationCount = GrTessellator::PathToVertices( |
| 180 | fan, std::numeric_limits<float>::infinity(), SkRect::Make(clippedDevIBounds), |
| 181 | &vertices); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 182 | if (fFanTessellationCount <= 0) { |
| 183 | SkASSERT(0 == fFanTessellationCount); |
| 184 | SkASSERT(nullptr == vertices); |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | SkASSERT(0 == fFanTessellationCount % 3); |
| 189 | for (int i = 0; i < fFanTessellationCount; i += 3) { |
Chris Dalton | 022bd3b | 2020-01-24 13:48:53 -0700 | [diff] [blame] | 190 | int weight = abs(vertices[i].fWinding); |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 191 | if (SkPathFillType::kEvenOdd == fan.getFillType()) { |
Chris Dalton | 022bd3b | 2020-01-24 13:48:53 -0700 | [diff] [blame] | 192 | // The tessellator doesn't wrap weights modulo 2 when we request even/odd fill type. |
| 193 | SkASSERT(weight & 1); |
| 194 | weight = 1; |
Chris Dalton | 9fdebfb | 2019-11-18 19:55:11 -0700 | [diff] [blame] | 195 | } |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 196 | if (weight > 1 && Algorithm::kCoverageCount == algorithm) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 197 | ++newTriangleCounts->fWeightedTriangles; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 198 | } else { |
| 199 | newTriangleCounts->fTriangles += weight; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 200 | } |
Chris Dalton | 9fdebfb | 2019-11-18 19:55:11 -0700 | [diff] [blame] | 201 | vertices[i].fWinding = weight; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | fFanTessellation.reset(vertices); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 207 | GrCCFiller::BatchID GrCCFiller::closeCurrentBatch() { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 208 | SkASSERT(!fInstanceBuffer); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 209 | SkASSERT(!fBatches.empty()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 210 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 211 | const auto& lastBatch = fBatches.back(); |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 212 | int maxMeshes = 1 + fScissorSubBatches.count() - lastBatch.fEndScissorSubBatchIdx; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 213 | fMaxMeshesPerDraw = std::max(fMaxMeshesPerDraw, maxMeshes); |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 214 | |
| 215 | const auto& lastScissorSubBatch = fScissorSubBatches[lastBatch.fEndScissorSubBatchIdx - 1]; |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 216 | PrimitiveTallies batchTotalCounts = fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled] - |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 217 | lastBatch.fEndNonScissorIndices; |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 218 | batchTotalCounts += fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled] - |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 219 | lastScissorSubBatch.fEndPrimitiveIndices; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 220 | |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 221 | // This will invalidate lastBatch. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 222 | fBatches.push_back() = { |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 223 | fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled], |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 224 | fScissorSubBatches.count(), |
| 225 | batchTotalCounts |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 226 | }; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 227 | return fBatches.count() - 1; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // Emits a contour's triangle fan. |
| 231 | // |
| 232 | // Classic Redbook fanning would be the triangles: [0 1 2], [0 2 3], ..., [0 n-2 n-1]. |
| 233 | // |
| 234 | // This function emits the triangle: [0 n/3 n*2/3], and then recurses on all three sides. The |
| 235 | // advantage to this approach is that for a convex-ish contour, it generates larger triangles. |
| 236 | // Classic fanning tends to generate long, skinny triangles, which are expensive to draw since they |
| 237 | // have a longer perimeter to rasterize and antialias. |
| 238 | // |
| 239 | // The indices array indexes the fan's points (think: glDrawElements), and must have at least log3 |
| 240 | // elements past the end for this method to use as scratch space. |
| 241 | // |
| 242 | // Returns the next triangle instance after the final one emitted. |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 243 | static TriPointInstance* emit_recursive_fan( |
| 244 | const SkTArray<SkPoint, true>& pts, SkTArray<int32_t, true>& indices, int firstIndex, |
| 245 | int indexCount, const Sk2f& devToAtlasOffset, TriPointInstance::Ordering ordering, |
| 246 | TriPointInstance out[]) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 247 | if (indexCount < 3) { |
| 248 | return out; |
| 249 | } |
| 250 | |
| 251 | int32_t oneThirdCount = indexCount / 3; |
| 252 | int32_t twoThirdsCount = (2 * indexCount) / 3; |
| 253 | out++->set(pts[indices[firstIndex]], pts[indices[firstIndex + oneThirdCount]], |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 254 | pts[indices[firstIndex + twoThirdsCount]], devToAtlasOffset, ordering); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 255 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 256 | out = emit_recursive_fan( |
| 257 | pts, indices, firstIndex, oneThirdCount + 1, devToAtlasOffset, ordering, out); |
| 258 | out = emit_recursive_fan( |
| 259 | pts, indices, firstIndex + oneThirdCount, twoThirdsCount - oneThirdCount + 1, |
| 260 | devToAtlasOffset, ordering, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 261 | |
| 262 | int endIndex = firstIndex + indexCount; |
| 263 | int32_t oldValue = indices[endIndex]; |
| 264 | indices[endIndex] = indices[firstIndex]; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 265 | out = emit_recursive_fan( |
| 266 | pts, indices, firstIndex + twoThirdsCount, indexCount - twoThirdsCount + 1, |
| 267 | devToAtlasOffset, ordering, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 268 | indices[endIndex] = oldValue; |
| 269 | |
| 270 | return out; |
| 271 | } |
| 272 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 273 | void GrCCFiller::emitTessellatedFan( |
| 274 | const GrTessellator::WindingVertex* vertices, int numVertices, const Sk2f& devToAtlasOffset, |
| 275 | TriPointInstance::Ordering ordering, TriPointInstance* triPointInstanceData, |
| 276 | QuadPointInstance* quadPointInstanceData, GrCCFillGeometry::PrimitiveTallies* indices) { |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 277 | for (int i = 0; i < numVertices; i += 3) { |
Chris Dalton | 9fdebfb | 2019-11-18 19:55:11 -0700 | [diff] [blame] | 278 | int weight = vertices[i].fWinding; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 279 | SkASSERT(weight >= 1); |
| 280 | if (weight > 1 && Algorithm::kStencilWindingCount != fAlgorithm) { |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 281 | quadPointInstanceData[indices->fWeightedTriangles++].setW( |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 282 | vertices[i].fPos, vertices[i+1].fPos, vertices[i + 2].fPos, devToAtlasOffset, |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 283 | static_cast<float>(abs(vertices[i].fWinding))); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 284 | } else for (int j = 0; j < weight; ++j) { |
| 285 | // Unfortunately, there is not a way to increment stencil values by an amount larger |
| 286 | // than 1. Instead we draw the triangle 'weight' times. |
| 287 | triPointInstanceData[indices->fTriangles++].set( |
| 288 | vertices[i].fPos, vertices[i + 1].fPos, vertices[i + 2].fPos, devToAtlasOffset, |
| 289 | ordering); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 294 | bool GrCCFiller::prepareToDraw(GrOnFlushResourceProvider* onFlushRP) { |
| 295 | using Verb = GrCCFillGeometry::Verb; |
| 296 | SkASSERT(!fInstanceBuffer); |
| 297 | SkASSERT(fBatches.back().fEndNonScissorIndices == // Call closeCurrentBatch(). |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 298 | fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled]); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 299 | SkASSERT(fBatches.back().fEndScissorSubBatchIdx == fScissorSubBatches.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 300 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 301 | auto triangleOrdering = (Algorithm::kCoverageCount == fAlgorithm) |
| 302 | ? TriPointInstance::Ordering::kXYTransposed |
| 303 | : TriPointInstance::Ordering::kXYInterleaved; |
| 304 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 305 | // Here we build a single instance buffer to share with every internal batch. |
| 306 | // |
| 307 | // CCPR processs 3 different types of primitives: triangles, quadratics, cubics. Each primitive |
| 308 | // type is further divided into instances that require a scissor and those that don't. This |
| 309 | // leaves us with 3*2 = 6 independent instance arrays to build for the GPU. |
| 310 | // |
| 311 | // Rather than place each instance array in its own GPU buffer, we allocate a single |
| 312 | // megabuffer and lay them all out side-by-side. We can offset the "baseInstance" parameter in |
| 313 | // our draw calls to direct the GPU to the applicable elements within a given array. |
| 314 | // |
| 315 | // We already know how big to make each of the 6 arrays from fTotalPrimitiveCounts, so layout is |
| 316 | // 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] | 317 | // 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] | 318 | fBaseInstances[0].fTriangles = 0; |
| 319 | fBaseInstances[1].fTriangles = fBaseInstances[0].fTriangles + |
| 320 | fTotalPrimitiveCounts[0].fTriangles; |
| 321 | fBaseInstances[0].fQuadratics = fBaseInstances[1].fTriangles + |
| 322 | fTotalPrimitiveCounts[1].fTriangles; |
| 323 | fBaseInstances[1].fQuadratics = fBaseInstances[0].fQuadratics + |
| 324 | fTotalPrimitiveCounts[0].fQuadratics; |
| 325 | int triEndIdx = fBaseInstances[1].fQuadratics + fTotalPrimitiveCounts[1].fQuadratics; |
| 326 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 327 | // Wound triangles and cubics both view the same instance buffer as an array of |
| 328 | // QuadPointInstance[]. So, reinterpreting the instance data as QuadPointInstance[], we start |
| 329 | // them on the first index that will not overwrite previous TriPointInstance data. |
| 330 | int quadBaseIdx = |
Brian Salomon | 24d377e | 2019-04-23 15:24:31 -0400 | [diff] [blame] | 331 | GrSizeDivRoundUp(triEndIdx * sizeof(TriPointInstance), sizeof(QuadPointInstance)); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 332 | fBaseInstances[0].fWeightedTriangles = quadBaseIdx; |
| 333 | fBaseInstances[1].fWeightedTriangles = fBaseInstances[0].fWeightedTriangles + |
| 334 | fTotalPrimitiveCounts[0].fWeightedTriangles; |
| 335 | fBaseInstances[0].fCubics = fBaseInstances[1].fWeightedTriangles + |
| 336 | fTotalPrimitiveCounts[1].fWeightedTriangles; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 337 | fBaseInstances[1].fCubics = fBaseInstances[0].fCubics + fTotalPrimitiveCounts[0].fCubics; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 338 | fBaseInstances[0].fConics = fBaseInstances[1].fCubics + fTotalPrimitiveCounts[1].fCubics; |
| 339 | fBaseInstances[1].fConics = fBaseInstances[0].fConics + fTotalPrimitiveCounts[0].fConics; |
| 340 | int quadEndIdx = fBaseInstances[1].fConics + fTotalPrimitiveCounts[1].fConics; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 341 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 342 | fInstanceBuffer = |
| 343 | onFlushRP->makeBuffer(GrGpuBufferType::kVertex, quadEndIdx * sizeof(QuadPointInstance)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 344 | if (!fInstanceBuffer) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 345 | SkDebugf("WARNING: failed to allocate CCPR fill instance buffer.\n"); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 349 | TriPointInstance* triPointInstanceData = static_cast<TriPointInstance*>(fInstanceBuffer->map()); |
| 350 | QuadPointInstance* quadPointInstanceData = |
| 351 | reinterpret_cast<QuadPointInstance*>(triPointInstanceData); |
| 352 | SkASSERT(quadPointInstanceData); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 353 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 354 | PathInfo* nextPathInfo = fPathInfos.begin(); |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 355 | Sk2f devToAtlasOffset; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 356 | PrimitiveTallies instanceIndices[2] = {fBaseInstances[0], fBaseInstances[1]}; |
| 357 | PrimitiveTallies* currIndices = nullptr; |
| 358 | SkSTArray<256, int32_t, true> currFan; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 359 | bool currFanIsTessellated = false; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 360 | |
| 361 | const SkTArray<SkPoint, true>& pts = fGeometry.points(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 362 | int ptsIdx = -1; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 363 | int nextConicWeightIdx = 0; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 364 | |
| 365 | // Expand the ccpr verbs into GPU instance buffers. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 366 | for (Verb verb : fGeometry.verbs()) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 367 | switch (verb) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 368 | case Verb::kBeginPath: |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 369 | SkASSERT(currFan.empty()); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 370 | currIndices = &instanceIndices[(int)nextPathInfo->scissorTest()]; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 371 | devToAtlasOffset = Sk2f(static_cast<float>(nextPathInfo->devToAtlasOffset().fX), |
| 372 | static_cast<float>(nextPathInfo->devToAtlasOffset().fY)); |
Chris Dalton | ad06544 | 2018-03-08 22:41:33 -0700 | [diff] [blame] | 373 | currFanIsTessellated = nextPathInfo->hasFanTessellation(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 374 | if (currFanIsTessellated) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 375 | this->emitTessellatedFan( |
| 376 | nextPathInfo->fanTessellation(), nextPathInfo->fanTessellationCount(), |
| 377 | devToAtlasOffset, triangleOrdering, triPointInstanceData, |
| 378 | quadPointInstanceData, currIndices); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 379 | } |
| 380 | ++nextPathInfo; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 381 | continue; |
| 382 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 383 | case Verb::kBeginContour: |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 384 | SkASSERT(currFan.empty()); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 385 | ++ptsIdx; |
| 386 | if (!currFanIsTessellated) { |
| 387 | currFan.push_back(ptsIdx); |
| 388 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 389 | continue; |
| 390 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 391 | case Verb::kLineTo: |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 392 | ++ptsIdx; |
| 393 | if (!currFanIsTessellated) { |
| 394 | SkASSERT(!currFan.empty()); |
| 395 | currFan.push_back(ptsIdx); |
| 396 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 397 | continue; |
| 398 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 399 | case Verb::kMonotonicQuadraticTo: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 400 | triPointInstanceData[currIndices->fQuadratics++].set( |
| 401 | &pts[ptsIdx], devToAtlasOffset, TriPointInstance::Ordering::kXYTransposed); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 402 | ptsIdx += 2; |
| 403 | if (!currFanIsTessellated) { |
| 404 | SkASSERT(!currFan.empty()); |
| 405 | currFan.push_back(ptsIdx); |
| 406 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 407 | continue; |
| 408 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 409 | case Verb::kMonotonicCubicTo: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 410 | quadPointInstanceData[currIndices->fCubics++].set( |
| 411 | &pts[ptsIdx], devToAtlasOffset[0], devToAtlasOffset[1]); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 412 | ptsIdx += 3; |
| 413 | if (!currFanIsTessellated) { |
| 414 | SkASSERT(!currFan.empty()); |
| 415 | currFan.push_back(ptsIdx); |
| 416 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 417 | continue; |
| 418 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 419 | case Verb::kMonotonicConicTo: |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 420 | quadPointInstanceData[currIndices->fConics++].setW( |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 421 | &pts[ptsIdx], devToAtlasOffset, |
| 422 | fGeometry.getConicWeight(nextConicWeightIdx)); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 423 | ptsIdx += 2; |
| 424 | ++nextConicWeightIdx; |
| 425 | if (!currFanIsTessellated) { |
| 426 | SkASSERT(!currFan.empty()); |
| 427 | currFan.push_back(ptsIdx); |
| 428 | } |
| 429 | continue; |
| 430 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 431 | case Verb::kEndClosedContour: // endPt == startPt. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 432 | if (!currFanIsTessellated) { |
| 433 | SkASSERT(!currFan.empty()); |
| 434 | currFan.pop_back(); |
| 435 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 436 | // fallthru. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 437 | case Verb::kEndOpenContour: // endPt != startPt. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 438 | SkASSERT(!currFanIsTessellated || currFan.empty()); |
| 439 | if (!currFanIsTessellated && currFan.count() >= 3) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 440 | int fanSize = currFan.count(); |
| 441 | // Reserve space for emit_recursive_fan. Technically this can grow to |
| 442 | // fanSize + log3(fanSize), but we approximate with log2. |
| 443 | currFan.push_back_n(SkNextLog2(fanSize)); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 444 | SkDEBUGCODE(TriPointInstance* end =) emit_recursive_fan( |
| 445 | pts, currFan, 0, fanSize, devToAtlasOffset, triangleOrdering, |
| 446 | triPointInstanceData + currIndices->fTriangles); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 447 | currIndices->fTriangles += fanSize - 2; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 448 | SkASSERT(triPointInstanceData + currIndices->fTriangles == end); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 449 | } |
| 450 | currFan.reset(); |
| 451 | continue; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | fInstanceBuffer->unmap(); |
| 456 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 457 | SkASSERT(nextPathInfo == fPathInfos.end()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 458 | SkASSERT(ptsIdx == pts.count() - 1); |
| 459 | SkASSERT(instanceIndices[0].fTriangles == fBaseInstances[1].fTriangles); |
| 460 | SkASSERT(instanceIndices[1].fTriangles == fBaseInstances[0].fQuadratics); |
| 461 | SkASSERT(instanceIndices[0].fQuadratics == fBaseInstances[1].fQuadratics); |
| 462 | SkASSERT(instanceIndices[1].fQuadratics == triEndIdx); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 463 | SkASSERT(instanceIndices[0].fWeightedTriangles == fBaseInstances[1].fWeightedTriangles); |
| 464 | SkASSERT(instanceIndices[1].fWeightedTriangles == fBaseInstances[0].fCubics); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 465 | SkASSERT(instanceIndices[0].fCubics == fBaseInstances[1].fCubics); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 466 | SkASSERT(instanceIndices[1].fCubics == fBaseInstances[0].fConics); |
| 467 | SkASSERT(instanceIndices[0].fConics == fBaseInstances[1].fConics); |
| 468 | SkASSERT(instanceIndices[1].fConics == quadEndIdx); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 469 | |
| 470 | fMeshesScratchBuffer.reserve(fMaxMeshesPerDraw); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 471 | fScissorRectScratchBuffer.reserve(fMaxMeshesPerDraw); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 472 | |
| 473 | return true; |
| 474 | } |
| 475 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 476 | void GrCCFiller::drawFills( |
| 477 | GrOpFlushState* flushState, GrCCCoverageProcessor* proc, const GrPipeline& pipeline, |
| 478 | BatchID batchID, const SkIRect& drawBounds) const { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 479 | using PrimitiveType = GrCCCoverageProcessor::PrimitiveType; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 480 | |
| 481 | SkASSERT(fInstanceBuffer); |
| 482 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 483 | GrResourceProvider* rp = flushState->resourceProvider(); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 484 | const PrimitiveTallies& batchTotalCounts = fBatches[batchID].fTotalPrimitiveCounts; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 485 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 486 | if (batchTotalCounts.fTriangles) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 487 | proc->reset(PrimitiveType::kTriangles, rp); |
| 488 | this->drawPrimitives( |
| 489 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fTriangles, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 490 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 491 | |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 492 | if (batchTotalCounts.fWeightedTriangles) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 493 | SkASSERT(Algorithm::kStencilWindingCount != fAlgorithm); |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 494 | proc->reset(PrimitiveType::kWeightedTriangles, rp); |
| 495 | this->drawPrimitives( |
| 496 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fWeightedTriangles, |
| 497 | drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 498 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 499 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 500 | if (batchTotalCounts.fQuadratics) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 501 | proc->reset(PrimitiveType::kQuadratics, rp); |
| 502 | this->drawPrimitives( |
| 503 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fQuadratics, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | if (batchTotalCounts.fCubics) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 507 | proc->reset(PrimitiveType::kCubics, rp); |
| 508 | this->drawPrimitives( |
| 509 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fCubics, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 510 | } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 511 | |
| 512 | if (batchTotalCounts.fConics) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 513 | proc->reset(PrimitiveType::kConics, rp); |
| 514 | this->drawPrimitives( |
| 515 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fConics, drawBounds); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 516 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 519 | void GrCCFiller::drawPrimitives( |
| 520 | GrOpFlushState* flushState, const GrCCCoverageProcessor& proc, const GrPipeline& pipeline, |
| 521 | BatchID batchID, int PrimitiveTallies::*instanceType, const SkIRect& drawBounds) const { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame^] | 522 | SkASSERT(pipeline.isScissorTestEnabled()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 523 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 524 | // Don't call reset(), as that also resets the reserve count. |
| 525 | fMeshesScratchBuffer.pop_back_n(fMeshesScratchBuffer.count()); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 526 | fScissorRectScratchBuffer.pop_back_n(fScissorRectScratchBuffer.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 527 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 528 | SkASSERT(batchID > 0); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 529 | SkASSERT(batchID < fBatches.count()); |
| 530 | const Batch& previousBatch = fBatches[batchID - 1]; |
| 531 | const Batch& batch = fBatches[batchID]; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 532 | SkDEBUGCODE(int totalInstanceCount = 0); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 533 | |
| 534 | if (int instanceCount = batch.fEndNonScissorIndices.*instanceType - |
| 535 | previousBatch.fEndNonScissorIndices.*instanceType) { |
| 536 | SkASSERT(instanceCount > 0); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 537 | int baseInstance = fBaseInstances[(int)GrScissorTest::kDisabled].*instanceType + |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 538 | previousBatch.fEndNonScissorIndices.*instanceType; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 539 | proc.appendMesh(fInstanceBuffer, instanceCount, baseInstance, &fMeshesScratchBuffer); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 540 | fScissorRectScratchBuffer.push_back().setXYWH(0, 0, drawBounds.width(), |
| 541 | drawBounds.height()); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 542 | SkDEBUGCODE(totalInstanceCount += instanceCount); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | SkASSERT(previousBatch.fEndScissorSubBatchIdx > 0); |
| 546 | SkASSERT(batch.fEndScissorSubBatchIdx <= fScissorSubBatches.count()); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 547 | int baseScissorInstance = fBaseInstances[(int)GrScissorTest::kEnabled].*instanceType; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 548 | for (int i = previousBatch.fEndScissorSubBatchIdx; i < batch.fEndScissorSubBatchIdx; ++i) { |
| 549 | const ScissorSubBatch& previousSubBatch = fScissorSubBatches[i - 1]; |
| 550 | const ScissorSubBatch& scissorSubBatch = fScissorSubBatches[i]; |
| 551 | int startIndex = previousSubBatch.fEndPrimitiveIndices.*instanceType; |
| 552 | int instanceCount = scissorSubBatch.fEndPrimitiveIndices.*instanceType - startIndex; |
| 553 | if (!instanceCount) { |
| 554 | continue; |
| 555 | } |
| 556 | SkASSERT(instanceCount > 0); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 557 | proc.appendMesh(fInstanceBuffer, instanceCount, baseScissorInstance + startIndex, |
| 558 | &fMeshesScratchBuffer); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 559 | fScissorRectScratchBuffer.push_back() = scissorSubBatch.fScissor; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 560 | SkDEBUGCODE(totalInstanceCount += instanceCount); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 563 | SkASSERT(fMeshesScratchBuffer.count() == fScissorRectScratchBuffer.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 564 | SkASSERT(fMeshesScratchBuffer.count() <= fMaxMeshesPerDraw); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 565 | SkASSERT(totalInstanceCount == batch.fTotalPrimitiveCounts.*instanceType); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 566 | |
| 567 | if (!fMeshesScratchBuffer.empty()) { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 568 | proc.draw(flushState, pipeline, fScissorRectScratchBuffer.begin(), |
| 569 | fMeshesScratchBuffer.begin(), fMeshesScratchBuffer.count(), |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 570 | SkRect::Make(drawBounds)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 571 | } |
| 572 | } |