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], |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 113 | clippedDevIBounds.makeOffset(devToAtlasOffset.fX, |
| 114 | devToAtlasOffset.fY)}; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 115 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 118 | void GrCCFiller::PathInfo::tessellateFan( |
| 119 | Algorithm algorithm, const SkPath& originalPath, const GrCCFillGeometry& geometry, |
| 120 | int verbsIdx, int ptsIdx, const SkIRect& clippedDevIBounds, |
| 121 | PrimitiveTallies* newTriangleCounts) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 122 | using Verb = GrCCFillGeometry::Verb; |
| 123 | SkASSERT(-1 == fFanTessellationCount); |
| 124 | SkASSERT(!fFanTessellation); |
| 125 | |
| 126 | const SkTArray<Verb, true>& verbs = geometry.verbs(); |
| 127 | const SkTArray<SkPoint, true>& pts = geometry.points(); |
| 128 | |
| 129 | newTriangleCounts->fTriangles = |
| 130 | newTriangleCounts->fWeightedTriangles = 0; |
| 131 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 132 | // Build an SkPath of the Redbook fan. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 133 | SkPath fan; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 134 | if (Algorithm::kCoverageCount == algorithm) { |
| 135 | // We use "winding" fill type right now because we are producing a coverage count, and must |
| 136 | // fill in every region that has non-zero wind. The path processor will convert coverage |
| 137 | // count to the appropriate fill type later. |
Mike Reed | 4241f5e | 2019-09-14 19:13:23 +0000 | [diff] [blame] | 138 | fan.setFillType(SkPath::kWinding_FillType); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 139 | } else { |
| 140 | // When counting winding numbers in the stencil buffer, it works to just tessellate the |
| 141 | // Redbook fan with the same fill type as the path. |
| 142 | fan.setFillType(originalPath.getFillType()); |
| 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; |
| 178 | fFanTessellationCount = |
| 179 | GrTessellator::PathToVertices(fan, std::numeric_limits<float>::infinity(), |
| 180 | SkRect::Make(clippedDevIBounds), &vertices); |
| 181 | if (fFanTessellationCount <= 0) { |
| 182 | SkASSERT(0 == fFanTessellationCount); |
| 183 | SkASSERT(nullptr == vertices); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | SkASSERT(0 == fFanTessellationCount % 3); |
| 188 | for (int i = 0; i < fFanTessellationCount; i += 3) { |
| 189 | int tessWinding = vertices[i].fWinding; |
| 190 | SkASSERT(tessWinding == vertices[i + 1].fWinding); |
| 191 | SkASSERT(tessWinding == vertices[i + 2].fWinding); |
| 192 | |
| 193 | // Ensure this triangle's points actually wind in the same direction as tessWinding. |
| 194 | // CCPR shaders use the sign of wind to determine which direction to bloat, so even for |
| 195 | // "wound" triangles the winding sign and point ordering need to agree. |
| 196 | float ax = vertices[i].fPos.fX - vertices[i + 1].fPos.fX; |
| 197 | float ay = vertices[i].fPos.fY - vertices[i + 1].fPos.fY; |
| 198 | float bx = vertices[i].fPos.fX - vertices[i + 2].fPos.fX; |
| 199 | float by = vertices[i].fPos.fY - vertices[i + 2].fPos.fY; |
| 200 | float wind = ax*by - ay*bx; |
| 201 | if ((wind > 0) != (-tessWinding > 0)) { // Tessellator has opposite winding sense. |
| 202 | std::swap(vertices[i + 1].fPos, vertices[i + 2].fPos); |
| 203 | } |
| 204 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 205 | int weight = abs(tessWinding); |
| 206 | SkASSERT(SkPath::kEvenOdd_FillType != fan.getFillType() || weight == 1); |
| 207 | if (weight > 1 && Algorithm::kCoverageCount == algorithm) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 208 | ++newTriangleCounts->fWeightedTriangles; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 209 | } else { |
| 210 | newTriangleCounts->fTriangles += weight; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
| 214 | fFanTessellation.reset(vertices); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 217 | GrCCFiller::BatchID GrCCFiller::closeCurrentBatch() { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 218 | SkASSERT(!fInstanceBuffer); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 219 | SkASSERT(!fBatches.empty()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 220 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 221 | const auto& lastBatch = fBatches.back(); |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 222 | int maxMeshes = 1 + fScissorSubBatches.count() - lastBatch.fEndScissorSubBatchIdx; |
| 223 | fMaxMeshesPerDraw = SkTMax(fMaxMeshesPerDraw, maxMeshes); |
| 224 | |
| 225 | const auto& lastScissorSubBatch = fScissorSubBatches[lastBatch.fEndScissorSubBatchIdx - 1]; |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 226 | PrimitiveTallies batchTotalCounts = fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled] - |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 227 | lastBatch.fEndNonScissorIndices; |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 228 | batchTotalCounts += fTotalPrimitiveCounts[(int)GrScissorTest::kEnabled] - |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 229 | lastScissorSubBatch.fEndPrimitiveIndices; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 230 | |
Chris Dalton | a883aca | 2018-03-08 23:05:30 -0700 | [diff] [blame] | 231 | // This will invalidate lastBatch. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 232 | fBatches.push_back() = { |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 233 | fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled], |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 234 | fScissorSubBatches.count(), |
| 235 | batchTotalCounts |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 236 | }; |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 237 | return fBatches.count() - 1; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // Emits a contour's triangle fan. |
| 241 | // |
| 242 | // Classic Redbook fanning would be the triangles: [0 1 2], [0 2 3], ..., [0 n-2 n-1]. |
| 243 | // |
| 244 | // This function emits the triangle: [0 n/3 n*2/3], and then recurses on all three sides. The |
| 245 | // advantage to this approach is that for a convex-ish contour, it generates larger triangles. |
| 246 | // Classic fanning tends to generate long, skinny triangles, which are expensive to draw since they |
| 247 | // have a longer perimeter to rasterize and antialias. |
| 248 | // |
| 249 | // The indices array indexes the fan's points (think: glDrawElements), and must have at least log3 |
| 250 | // elements past the end for this method to use as scratch space. |
| 251 | // |
| 252 | // Returns the next triangle instance after the final one emitted. |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 253 | static TriPointInstance* emit_recursive_fan( |
| 254 | const SkTArray<SkPoint, true>& pts, SkTArray<int32_t, true>& indices, int firstIndex, |
| 255 | int indexCount, const Sk2f& devToAtlasOffset, TriPointInstance::Ordering ordering, |
| 256 | TriPointInstance out[]) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 257 | if (indexCount < 3) { |
| 258 | return out; |
| 259 | } |
| 260 | |
| 261 | int32_t oneThirdCount = indexCount / 3; |
| 262 | int32_t twoThirdsCount = (2 * indexCount) / 3; |
| 263 | out++->set(pts[indices[firstIndex]], pts[indices[firstIndex + oneThirdCount]], |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 264 | pts[indices[firstIndex + twoThirdsCount]], devToAtlasOffset, ordering); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 265 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 266 | out = emit_recursive_fan( |
| 267 | pts, indices, firstIndex, oneThirdCount + 1, devToAtlasOffset, ordering, out); |
| 268 | out = emit_recursive_fan( |
| 269 | pts, indices, firstIndex + oneThirdCount, twoThirdsCount - oneThirdCount + 1, |
| 270 | devToAtlasOffset, ordering, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 271 | |
| 272 | int endIndex = firstIndex + indexCount; |
| 273 | int32_t oldValue = indices[endIndex]; |
| 274 | indices[endIndex] = indices[firstIndex]; |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 275 | out = emit_recursive_fan( |
| 276 | pts, indices, firstIndex + twoThirdsCount, indexCount - twoThirdsCount + 1, |
| 277 | devToAtlasOffset, ordering, out); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 278 | indices[endIndex] = oldValue; |
| 279 | |
| 280 | return out; |
| 281 | } |
| 282 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 283 | void GrCCFiller::emitTessellatedFan( |
| 284 | const GrTessellator::WindingVertex* vertices, int numVertices, const Sk2f& devToAtlasOffset, |
| 285 | TriPointInstance::Ordering ordering, TriPointInstance* triPointInstanceData, |
| 286 | QuadPointInstance* quadPointInstanceData, GrCCFillGeometry::PrimitiveTallies* indices) { |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 287 | for (int i = 0; i < numVertices; i += 3) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 288 | int weight = abs(vertices[i].fWinding); |
| 289 | SkASSERT(weight >= 1); |
| 290 | if (weight > 1 && Algorithm::kStencilWindingCount != fAlgorithm) { |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 291 | quadPointInstanceData[indices->fWeightedTriangles++].setW( |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 292 | vertices[i].fPos, vertices[i+1].fPos, vertices[i + 2].fPos, devToAtlasOffset, |
Chris Dalton | 6f5e77a | 2018-04-23 21:14:42 -0600 | [diff] [blame] | 293 | static_cast<float>(abs(vertices[i].fWinding))); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 294 | } else for (int j = 0; j < weight; ++j) { |
| 295 | // Unfortunately, there is not a way to increment stencil values by an amount larger |
| 296 | // than 1. Instead we draw the triangle 'weight' times. |
| 297 | triPointInstanceData[indices->fTriangles++].set( |
| 298 | vertices[i].fPos, vertices[i + 1].fPos, vertices[i + 2].fPos, devToAtlasOffset, |
| 299 | ordering); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 304 | bool GrCCFiller::prepareToDraw(GrOnFlushResourceProvider* onFlushRP) { |
| 305 | using Verb = GrCCFillGeometry::Verb; |
| 306 | SkASSERT(!fInstanceBuffer); |
| 307 | SkASSERT(fBatches.back().fEndNonScissorIndices == // Call closeCurrentBatch(). |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 308 | fTotalPrimitiveCounts[(int)GrScissorTest::kDisabled]); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 309 | SkASSERT(fBatches.back().fEndScissorSubBatchIdx == fScissorSubBatches.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 310 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 311 | auto triangleOrdering = (Algorithm::kCoverageCount == fAlgorithm) |
| 312 | ? TriPointInstance::Ordering::kXYTransposed |
| 313 | : TriPointInstance::Ordering::kXYInterleaved; |
| 314 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 315 | // Here we build a single instance buffer to share with every internal batch. |
| 316 | // |
| 317 | // CCPR processs 3 different types of primitives: triangles, quadratics, cubics. Each primitive |
| 318 | // type is further divided into instances that require a scissor and those that don't. This |
| 319 | // leaves us with 3*2 = 6 independent instance arrays to build for the GPU. |
| 320 | // |
| 321 | // Rather than place each instance array in its own GPU buffer, we allocate a single |
| 322 | // megabuffer and lay them all out side-by-side. We can offset the "baseInstance" parameter in |
| 323 | // our draw calls to direct the GPU to the applicable elements within a given array. |
| 324 | // |
| 325 | // We already know how big to make each of the 6 arrays from fTotalPrimitiveCounts, so layout is |
| 326 | // 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] | 327 | // 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] | 328 | fBaseInstances[0].fTriangles = 0; |
| 329 | fBaseInstances[1].fTriangles = fBaseInstances[0].fTriangles + |
| 330 | fTotalPrimitiveCounts[0].fTriangles; |
| 331 | fBaseInstances[0].fQuadratics = fBaseInstances[1].fTriangles + |
| 332 | fTotalPrimitiveCounts[1].fTriangles; |
| 333 | fBaseInstances[1].fQuadratics = fBaseInstances[0].fQuadratics + |
| 334 | fTotalPrimitiveCounts[0].fQuadratics; |
| 335 | int triEndIdx = fBaseInstances[1].fQuadratics + fTotalPrimitiveCounts[1].fQuadratics; |
| 336 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 337 | // Wound triangles and cubics both view the same instance buffer as an array of |
| 338 | // QuadPointInstance[]. So, reinterpreting the instance data as QuadPointInstance[], we start |
| 339 | // them on the first index that will not overwrite previous TriPointInstance data. |
| 340 | int quadBaseIdx = |
Brian Salomon | 24d377e | 2019-04-23 15:24:31 -0400 | [diff] [blame] | 341 | GrSizeDivRoundUp(triEndIdx * sizeof(TriPointInstance), sizeof(QuadPointInstance)); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 342 | fBaseInstances[0].fWeightedTriangles = quadBaseIdx; |
| 343 | fBaseInstances[1].fWeightedTriangles = fBaseInstances[0].fWeightedTriangles + |
| 344 | fTotalPrimitiveCounts[0].fWeightedTriangles; |
| 345 | fBaseInstances[0].fCubics = fBaseInstances[1].fWeightedTriangles + |
| 346 | fTotalPrimitiveCounts[1].fWeightedTriangles; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 347 | fBaseInstances[1].fCubics = fBaseInstances[0].fCubics + fTotalPrimitiveCounts[0].fCubics; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 348 | fBaseInstances[0].fConics = fBaseInstances[1].fCubics + fTotalPrimitiveCounts[1].fCubics; |
| 349 | fBaseInstances[1].fConics = fBaseInstances[0].fConics + fTotalPrimitiveCounts[0].fConics; |
| 350 | int quadEndIdx = fBaseInstances[1].fConics + fTotalPrimitiveCounts[1].fConics; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 351 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 352 | fInstanceBuffer = |
| 353 | onFlushRP->makeBuffer(GrGpuBufferType::kVertex, quadEndIdx * sizeof(QuadPointInstance)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 354 | if (!fInstanceBuffer) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 355 | SkDebugf("WARNING: failed to allocate CCPR fill instance buffer.\n"); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 356 | return false; |
| 357 | } |
| 358 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 359 | TriPointInstance* triPointInstanceData = static_cast<TriPointInstance*>(fInstanceBuffer->map()); |
| 360 | QuadPointInstance* quadPointInstanceData = |
| 361 | reinterpret_cast<QuadPointInstance*>(triPointInstanceData); |
| 362 | SkASSERT(quadPointInstanceData); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 363 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 364 | PathInfo* nextPathInfo = fPathInfos.begin(); |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 365 | Sk2f devToAtlasOffset; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 366 | PrimitiveTallies instanceIndices[2] = {fBaseInstances[0], fBaseInstances[1]}; |
| 367 | PrimitiveTallies* currIndices = nullptr; |
| 368 | SkSTArray<256, int32_t, true> currFan; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 369 | bool currFanIsTessellated = false; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 370 | |
| 371 | const SkTArray<SkPoint, true>& pts = fGeometry.points(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 372 | int ptsIdx = -1; |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 373 | int nextConicWeightIdx = 0; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 374 | |
| 375 | // Expand the ccpr verbs into GPU instance buffers. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 376 | for (Verb verb : fGeometry.verbs()) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 377 | switch (verb) { |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 378 | case Verb::kBeginPath: |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 379 | SkASSERT(currFan.empty()); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 380 | currIndices = &instanceIndices[(int)nextPathInfo->scissorTest()]; |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 381 | devToAtlasOffset = Sk2f(static_cast<float>(nextPathInfo->devToAtlasOffset().fX), |
| 382 | static_cast<float>(nextPathInfo->devToAtlasOffset().fY)); |
Chris Dalton | ad06544 | 2018-03-08 22:41:33 -0700 | [diff] [blame] | 383 | currFanIsTessellated = nextPathInfo->hasFanTessellation(); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 384 | if (currFanIsTessellated) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 385 | this->emitTessellatedFan( |
| 386 | nextPathInfo->fanTessellation(), nextPathInfo->fanTessellationCount(), |
| 387 | devToAtlasOffset, triangleOrdering, triPointInstanceData, |
| 388 | quadPointInstanceData, currIndices); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 389 | } |
| 390 | ++nextPathInfo; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 391 | continue; |
| 392 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 393 | case Verb::kBeginContour: |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 394 | SkASSERT(currFan.empty()); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 395 | ++ptsIdx; |
| 396 | if (!currFanIsTessellated) { |
| 397 | currFan.push_back(ptsIdx); |
| 398 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 399 | continue; |
| 400 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 401 | case Verb::kLineTo: |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 402 | ++ptsIdx; |
| 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::kMonotonicQuadraticTo: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 410 | triPointInstanceData[currIndices->fQuadratics++].set( |
| 411 | &pts[ptsIdx], devToAtlasOffset, TriPointInstance::Ordering::kXYTransposed); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 412 | ptsIdx += 2; |
| 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::kMonotonicCubicTo: |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 420 | quadPointInstanceData[currIndices->fCubics++].set( |
| 421 | &pts[ptsIdx], devToAtlasOffset[0], devToAtlasOffset[1]); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 422 | ptsIdx += 3; |
| 423 | if (!currFanIsTessellated) { |
| 424 | SkASSERT(!currFan.empty()); |
| 425 | currFan.push_back(ptsIdx); |
| 426 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 427 | continue; |
| 428 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 429 | case Verb::kMonotonicConicTo: |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 430 | quadPointInstanceData[currIndices->fConics++].setW( |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 431 | &pts[ptsIdx], devToAtlasOffset, |
| 432 | fGeometry.getConicWeight(nextConicWeightIdx)); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 433 | ptsIdx += 2; |
| 434 | ++nextConicWeightIdx; |
| 435 | if (!currFanIsTessellated) { |
| 436 | SkASSERT(!currFan.empty()); |
| 437 | currFan.push_back(ptsIdx); |
| 438 | } |
| 439 | continue; |
| 440 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 441 | case Verb::kEndClosedContour: // endPt == startPt. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 442 | if (!currFanIsTessellated) { |
| 443 | SkASSERT(!currFan.empty()); |
| 444 | currFan.pop_back(); |
| 445 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 446 | // fallthru. |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 447 | case Verb::kEndOpenContour: // endPt != startPt. |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 448 | SkASSERT(!currFanIsTessellated || currFan.empty()); |
| 449 | if (!currFanIsTessellated && currFan.count() >= 3) { |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 450 | int fanSize = currFan.count(); |
| 451 | // Reserve space for emit_recursive_fan. Technically this can grow to |
| 452 | // fanSize + log3(fanSize), but we approximate with log2. |
| 453 | currFan.push_back_n(SkNextLog2(fanSize)); |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 454 | SkDEBUGCODE(TriPointInstance* end =) emit_recursive_fan( |
| 455 | pts, currFan, 0, fanSize, devToAtlasOffset, triangleOrdering, |
| 456 | triPointInstanceData + currIndices->fTriangles); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 457 | currIndices->fTriangles += fanSize - 2; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 458 | SkASSERT(triPointInstanceData + currIndices->fTriangles == end); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 459 | } |
| 460 | currFan.reset(); |
| 461 | continue; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | fInstanceBuffer->unmap(); |
| 466 | |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 467 | SkASSERT(nextPathInfo == fPathInfos.end()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 468 | SkASSERT(ptsIdx == pts.count() - 1); |
| 469 | SkASSERT(instanceIndices[0].fTriangles == fBaseInstances[1].fTriangles); |
| 470 | SkASSERT(instanceIndices[1].fTriangles == fBaseInstances[0].fQuadratics); |
| 471 | SkASSERT(instanceIndices[0].fQuadratics == fBaseInstances[1].fQuadratics); |
| 472 | SkASSERT(instanceIndices[1].fQuadratics == triEndIdx); |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 473 | SkASSERT(instanceIndices[0].fWeightedTriangles == fBaseInstances[1].fWeightedTriangles); |
| 474 | SkASSERT(instanceIndices[1].fWeightedTriangles == fBaseInstances[0].fCubics); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 475 | SkASSERT(instanceIndices[0].fCubics == fBaseInstances[1].fCubics); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 476 | SkASSERT(instanceIndices[1].fCubics == fBaseInstances[0].fConics); |
| 477 | SkASSERT(instanceIndices[0].fConics == fBaseInstances[1].fConics); |
| 478 | SkASSERT(instanceIndices[1].fConics == quadEndIdx); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 479 | |
| 480 | fMeshesScratchBuffer.reserve(fMaxMeshesPerDraw); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 481 | fScissorRectScratchBuffer.reserve(fMaxMeshesPerDraw); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 482 | |
| 483 | return true; |
| 484 | } |
| 485 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 486 | void GrCCFiller::drawFills( |
| 487 | GrOpFlushState* flushState, GrCCCoverageProcessor* proc, const GrPipeline& pipeline, |
| 488 | BatchID batchID, const SkIRect& drawBounds) const { |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 489 | using PrimitiveType = GrCCCoverageProcessor::PrimitiveType; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 490 | |
| 491 | SkASSERT(fInstanceBuffer); |
| 492 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 493 | GrResourceProvider* rp = flushState->resourceProvider(); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 494 | const PrimitiveTallies& batchTotalCounts = fBatches[batchID].fTotalPrimitiveCounts; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 495 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 496 | if (batchTotalCounts.fTriangles) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 497 | proc->reset(PrimitiveType::kTriangles, rp); |
| 498 | this->drawPrimitives( |
| 499 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fTriangles, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 500 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 501 | |
Chris Dalton | 703b476 | 2018-04-06 16:11:48 -0600 | [diff] [blame] | 502 | if (batchTotalCounts.fWeightedTriangles) { |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 503 | SkASSERT(Algorithm::kStencilWindingCount != fAlgorithm); |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 504 | proc->reset(PrimitiveType::kWeightedTriangles, rp); |
| 505 | this->drawPrimitives( |
| 506 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fWeightedTriangles, |
| 507 | drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 508 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 509 | |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 510 | if (batchTotalCounts.fQuadratics) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 511 | proc->reset(PrimitiveType::kQuadratics, rp); |
| 512 | this->drawPrimitives( |
| 513 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fQuadratics, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | if (batchTotalCounts.fCubics) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 517 | proc->reset(PrimitiveType::kCubics, rp); |
| 518 | this->drawPrimitives( |
| 519 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fCubics, drawBounds); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 520 | } |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 521 | |
| 522 | if (batchTotalCounts.fConics) { |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 523 | proc->reset(PrimitiveType::kConics, rp); |
| 524 | this->drawPrimitives( |
| 525 | flushState, *proc, pipeline, batchID, &PrimitiveTallies::fConics, drawBounds); |
Chris Dalton | 9f2dab0 | 2018-04-18 14:07:03 -0600 | [diff] [blame] | 526 | } |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Chris Dalton | 2c5e011 | 2019-03-29 13:14:18 -0500 | [diff] [blame] | 529 | void GrCCFiller::drawPrimitives( |
| 530 | GrOpFlushState* flushState, const GrCCCoverageProcessor& proc, const GrPipeline& pipeline, |
| 531 | BatchID batchID, int PrimitiveTallies::*instanceType, const SkIRect& drawBounds) const { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 532 | SkASSERT(pipeline.isScissorEnabled()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 533 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 534 | // Don't call reset(), as that also resets the reserve count. |
| 535 | fMeshesScratchBuffer.pop_back_n(fMeshesScratchBuffer.count()); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 536 | fScissorRectScratchBuffer.pop_back_n(fScissorRectScratchBuffer.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 537 | |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 538 | SkASSERT(batchID > 0); |
Chris Dalton | e163969 | 2018-08-20 14:00:30 -0600 | [diff] [blame] | 539 | SkASSERT(batchID < fBatches.count()); |
| 540 | const Batch& previousBatch = fBatches[batchID - 1]; |
| 541 | const Batch& batch = fBatches[batchID]; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 542 | SkDEBUGCODE(int totalInstanceCount = 0); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 543 | |
| 544 | if (int instanceCount = batch.fEndNonScissorIndices.*instanceType - |
| 545 | previousBatch.fEndNonScissorIndices.*instanceType) { |
| 546 | SkASSERT(instanceCount > 0); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 547 | int baseInstance = fBaseInstances[(int)GrScissorTest::kDisabled].*instanceType + |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 548 | previousBatch.fEndNonScissorIndices.*instanceType; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 549 | proc.appendMesh(fInstanceBuffer, instanceCount, baseInstance, &fMeshesScratchBuffer); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 550 | fScissorRectScratchBuffer.push_back().setXYWH(0, 0, drawBounds.width(), |
| 551 | drawBounds.height()); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 552 | SkDEBUGCODE(totalInstanceCount += instanceCount); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | SkASSERT(previousBatch.fEndScissorSubBatchIdx > 0); |
| 556 | SkASSERT(batch.fEndScissorSubBatchIdx <= fScissorSubBatches.count()); |
Chris Dalton | 916c498 | 2018-08-15 00:53:25 -0600 | [diff] [blame] | 557 | int baseScissorInstance = fBaseInstances[(int)GrScissorTest::kEnabled].*instanceType; |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 558 | for (int i = previousBatch.fEndScissorSubBatchIdx; i < batch.fEndScissorSubBatchIdx; ++i) { |
| 559 | const ScissorSubBatch& previousSubBatch = fScissorSubBatches[i - 1]; |
| 560 | const ScissorSubBatch& scissorSubBatch = fScissorSubBatches[i]; |
| 561 | int startIndex = previousSubBatch.fEndPrimitiveIndices.*instanceType; |
| 562 | int instanceCount = scissorSubBatch.fEndPrimitiveIndices.*instanceType - startIndex; |
| 563 | if (!instanceCount) { |
| 564 | continue; |
| 565 | } |
| 566 | SkASSERT(instanceCount > 0); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 567 | proc.appendMesh(fInstanceBuffer, instanceCount, baseScissorInstance + startIndex, |
| 568 | &fMeshesScratchBuffer); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 569 | fScissorRectScratchBuffer.push_back() = scissorSubBatch.fScissor; |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 570 | SkDEBUGCODE(totalInstanceCount += instanceCount); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 573 | SkASSERT(fMeshesScratchBuffer.count() == fScissorRectScratchBuffer.count()); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 574 | SkASSERT(fMeshesScratchBuffer.count() <= fMaxMeshesPerDraw); |
Chris Dalton | 84403d7 | 2018-02-13 21:46:17 -0500 | [diff] [blame] | 575 | SkASSERT(totalInstanceCount == batch.fTotalPrimitiveCounts.*instanceType); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 576 | |
| 577 | if (!fMeshesScratchBuffer.empty()) { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 578 | proc.draw(flushState, pipeline, fScissorRectScratchBuffer.begin(), |
| 579 | fMeshesScratchBuffer.begin(), fMeshesScratchBuffer.count(), |
Chris Dalton | 8dfc70f | 2018-03-26 19:15:22 -0600 | [diff] [blame] | 580 | SkRect::Make(drawBounds)); |
Chris Dalton | 9ca2784 | 2018-01-18 12:24:50 -0700 | [diff] [blame] | 581 | } |
| 582 | } |