Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [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 "GrCoverageCountingPathRenderer.h" |
| 9 | |
| 10 | #include "GrCaps.h" |
| 11 | #include "GrClip.h" |
| 12 | #include "GrGpu.h" |
| 13 | #include "GrGpuCommandBuffer.h" |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 14 | #include "GrOpFlushState.h" |
| 15 | #include "GrRenderTargetOpList.h" |
| 16 | #include "GrStyle.h" |
| 17 | #include "GrTexture.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 18 | #include "SkMakeUnique.h" |
| 19 | #include "SkMatrix.h" |
Chris Dalton | a039d3b | 2017-09-28 11:16:36 -0600 | [diff] [blame] | 20 | #include "SkPathOps.h" |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 21 | #include "ccpr/GrCCClipProcessor.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 22 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 23 | // Shorthand for keeping line lengths under control with nested classes... |
| 24 | using CCPR = GrCoverageCountingPathRenderer; |
| 25 | |
| 26 | // If a path spans more pixels than this, we need to crop it or else analytic AA can run out of fp32 |
| 27 | // precision. |
| 28 | static constexpr float kPathCropThreshold = 1 << 16; |
| 29 | |
| 30 | static void crop_path(const SkPath& path, const SkIRect& cropbox, SkPath* out) { |
| 31 | SkPath cropPath; |
| 32 | cropPath.addRect(SkRect::Make(cropbox)); |
| 33 | if (!Op(cropPath, path, kIntersect_SkPathOp, out)) { |
| 34 | // This can fail if the PathOps encounter NaN or infinities. |
| 35 | out->reset(); |
| 36 | } |
| 37 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 38 | |
| 39 | bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps) { |
| 40 | const GrShaderCaps& shaderCaps = *caps.shaderCaps(); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 41 | return shaderCaps.integerSupport() && shaderCaps.flatInterpolationSupport() && |
| 42 | caps.instanceAttribSupport() && GrCaps::kNone_MapFlags != caps.mapBufferFlags() && |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 43 | caps.isConfigTexturable(kAlpha_half_GrPixelConfig) && |
Chris Dalton | e4679fa | 2017-09-29 13:58:26 -0600 | [diff] [blame] | 44 | caps.isConfigRenderable(kAlpha_half_GrPixelConfig, /*withMSAA=*/false) && |
| 45 | !caps.blacklistCoverageCounting(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 46 | } |
| 47 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 48 | sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported( |
| 49 | const GrCaps& caps, bool drawCachablePaths) { |
Chris Dalton | a2ac30d | 2017-10-17 10:40:01 -0600 | [diff] [blame] | 50 | auto ccpr = IsSupported(caps) ? new GrCoverageCountingPathRenderer(drawCachablePaths) : nullptr; |
| 51 | return sk_sp<GrCoverageCountingPathRenderer>(ccpr); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 52 | } |
| 53 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 54 | GrPathRenderer::CanDrawPath GrCoverageCountingPathRenderer::onCanDrawPath( |
| 55 | const CanDrawPathArgs& args) const { |
Chris Dalton | a2ac30d | 2017-10-17 10:40:01 -0600 | [diff] [blame] | 56 | if (args.fShape->hasUnstyledKey() && !fDrawCachablePaths) { |
| 57 | return CanDrawPath::kNo; |
| 58 | } |
| 59 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 60 | if (!args.fShape->style().isSimpleFill() || args.fShape->inverseFilled() || |
| 61 | args.fViewMatrix->hasPerspective() || GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 62 | return CanDrawPath::kNo; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | SkPath path; |
| 66 | args.fShape->asPath(&path); |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 67 | if (SkPathPriv::ConicWeightCnt(path)) { |
| 68 | return CanDrawPath::kNo; |
| 69 | } |
| 70 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 71 | SkRect devBounds; |
| 72 | SkIRect devIBounds; |
| 73 | args.fViewMatrix->mapRect(&devBounds, path.getBounds()); |
| 74 | devBounds.roundOut(&devIBounds); |
| 75 | if (!devIBounds.intersect(*args.fClipConservativeBounds)) { |
| 76 | // Path is completely clipped away. Our code will eventually notice this before doing any |
| 77 | // real work. |
| 78 | return CanDrawPath::kYes; |
| 79 | } |
| 80 | |
| 81 | if (devIBounds.height() * devIBounds.width() > 256 * 256) { |
| 82 | // Large paths can blow up the atlas fast. And they are not ideal for a two-pass rendering |
| 83 | // algorithm. Give the simpler direct renderers a chance before we commit to drawing it. |
| 84 | return CanDrawPath::kAsBackup; |
| 85 | } |
| 86 | |
| 87 | if (args.fShape->hasUnstyledKey() && path.countVerbs() > 50) { |
| 88 | // Complex paths do better cached in an SDF, if the renderer will accept them. |
| 89 | return CanDrawPath::kAsBackup; |
| 90 | } |
| 91 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 92 | return CanDrawPath::kYes; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | bool GrCoverageCountingPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 96 | SkASSERT(!fFlushing); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 97 | auto op = skstd::make_unique<DrawPathsOp>(this, args, args.fPaint.getColor()); |
| 98 | args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 102 | CCPR::DrawPathsOp::DrawPathsOp(GrCoverageCountingPathRenderer* ccpr, const DrawPathArgs& args, |
| 103 | GrColor color) |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 104 | : INHERITED(ClassID()) |
| 105 | , fCCPR(ccpr) |
| 106 | , fSRGBFlags(GrPipeline::SRGBFlagsFromPaint(args.fPaint)) |
| 107 | , fProcessors(std::move(args.fPaint)) |
| 108 | , fTailDraw(&fHeadDraw) |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 109 | , fOwningRTPendingPaths(nullptr) { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 110 | SkDEBUGCODE(++fCCPR->fPendingDrawOpsCount); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 111 | SkDEBUGCODE(fBaseInstance = -1); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 112 | SkDEBUGCODE(fInstanceCount = 1); |
| 113 | SkDEBUGCODE(fNumSkippedInstances = 0); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 114 | GrRenderTargetContext* const rtc = args.fRenderTargetContext; |
| 115 | |
| 116 | SkRect devBounds; |
| 117 | args.fViewMatrix->mapRect(&devBounds, args.fShape->bounds()); |
Chris Dalton | c9c97b7 | 2017-11-27 15:34:26 -0700 | [diff] [blame] | 118 | args.fClip->getConservativeBounds(rtc->width(), rtc->height(), &fHeadDraw.fClipIBounds, |
| 119 | nullptr); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 120 | if (SkTMax(devBounds.height(), devBounds.width()) > kPathCropThreshold) { |
| 121 | // The path is too large. We need to crop it or analytic AA can run out of fp32 precision. |
| 122 | SkPath path; |
Chris Dalton | a039d3b | 2017-09-28 11:16:36 -0600 | [diff] [blame] | 123 | args.fShape->asPath(&path); |
| 124 | path.transform(*args.fViewMatrix); |
| 125 | fHeadDraw.fMatrix.setIdentity(); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 126 | crop_path(path, fHeadDraw.fClipIBounds, &fHeadDraw.fPath); |
Chris Dalton | a039d3b | 2017-09-28 11:16:36 -0600 | [diff] [blame] | 127 | devBounds = fHeadDraw.fPath.getBounds(); |
Chris Dalton | a039d3b | 2017-09-28 11:16:36 -0600 | [diff] [blame] | 128 | } else { |
| 129 | fHeadDraw.fMatrix = *args.fViewMatrix; |
| 130 | args.fShape->asPath(&fHeadDraw.fPath); |
Chris Dalton | a039d3b | 2017-09-28 11:16:36 -0600 | [diff] [blame] | 131 | } |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 132 | fHeadDraw.fColor = color; // Can't call args.fPaint.getColor() because it has been std::move'd. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 133 | |
| 134 | // FIXME: intersect with clip bounds to (hopefully) improve batching. |
| 135 | // (This is nontrivial due to assumptions in generating the octagon cover geometry.) |
| 136 | this->setBounds(devBounds, GrOp::HasAABloat::kYes, GrOp::IsZeroArea::kNo); |
| 137 | } |
| 138 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 139 | CCPR::DrawPathsOp::~DrawPathsOp() { |
| 140 | if (fOwningRTPendingPaths) { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 141 | // Remove CCPR's dangling pointer to this Op before deleting it. |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 142 | fOwningRTPendingPaths->fDrawOps.remove(this); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 143 | } |
| 144 | SkDEBUGCODE(--fCCPR->fPendingDrawOpsCount); |
| 145 | } |
| 146 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 147 | GrDrawOp::RequiresDstTexture CCPR::DrawPathsOp::finalize(const GrCaps& caps, |
| 148 | const GrAppliedClip* clip, |
| 149 | GrPixelConfigIsClamped dstIsClamped) { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 150 | SkASSERT(!fCCPR->fFlushing); |
| 151 | // There should only be one single path draw in this Op right now. |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 152 | SkASSERT(1 == fInstanceCount); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 153 | SkASSERT(&fHeadDraw == fTailDraw); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 154 | GrProcessorSet::Analysis analysis = |
| 155 | fProcessors.finalize(fHeadDraw.fColor, GrProcessorAnalysisCoverage::kSingleChannel, |
| 156 | clip, false, caps, dstIsClamped, &fHeadDraw.fColor); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 157 | return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; |
| 158 | } |
| 159 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 160 | bool CCPR::DrawPathsOp::onCombineIfPossible(GrOp* op, const GrCaps& caps) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 161 | DrawPathsOp* that = op->cast<DrawPathsOp>(); |
| 162 | SkASSERT(fCCPR == that->fCCPR); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 163 | SkASSERT(!fCCPR->fFlushing); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 164 | SkASSERT(fOwningRTPendingPaths); |
| 165 | SkASSERT(fInstanceCount); |
| 166 | SkASSERT(!that->fOwningRTPendingPaths || that->fOwningRTPendingPaths == fOwningRTPendingPaths); |
| 167 | SkASSERT(that->fInstanceCount); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 168 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 169 | if (this->getFillType() != that->getFillType() || fSRGBFlags != that->fSRGBFlags || |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 170 | fProcessors != that->fProcessors) { |
| 171 | return false; |
| 172 | } |
| 173 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 174 | fTailDraw->fNext = &fOwningRTPendingPaths->fDrawsAllocator.push_back(that->fHeadDraw); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 175 | fTailDraw = (that->fTailDraw == &that->fHeadDraw) ? fTailDraw->fNext : that->fTailDraw; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 176 | |
| 177 | this->joinBounds(*that); |
| 178 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 179 | SkDEBUGCODE(fInstanceCount += that->fInstanceCount); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 180 | SkDEBUGCODE(that->fInstanceCount = 0); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 184 | void CCPR::DrawPathsOp::wasRecorded(GrRenderTargetOpList* opList) { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 185 | SkASSERT(!fCCPR->fFlushing); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 186 | SkASSERT(!fOwningRTPendingPaths); |
| 187 | fOwningRTPendingPaths = &fCCPR->fRTPendingPathsMap[opList->uniqueID()]; |
| 188 | fOwningRTPendingPaths->fDrawOps.addToTail(this); |
| 189 | } |
| 190 | |
| 191 | bool GrCoverageCountingPathRenderer::canMakeClipProcessor(const SkPath& deviceSpacePath) const { |
| 192 | if (!fDrawCachablePaths && !deviceSpacePath.isVolatile()) { |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | if (SkPathPriv::ConicWeightCnt(deviceSpacePath)) { |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | return true; |
| 201 | } |
| 202 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 203 | std::unique_ptr<GrFragmentProcessor> GrCoverageCountingPathRenderer::makeClipProcessor( |
| 204 | uint32_t opListID, const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth, |
| 205 | int rtHeight) { |
| 206 | using MustCheckBounds = GrCCClipProcessor::MustCheckBounds; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 207 | |
| 208 | SkASSERT(!fFlushing); |
| 209 | SkASSERT(this->canMakeClipProcessor(deviceSpacePath)); |
| 210 | |
| 211 | ClipPath& clipPath = fRTPendingPathsMap[opListID].fClipPaths[deviceSpacePath.getGenerationID()]; |
| 212 | if (clipPath.isUninitialized()) { |
| 213 | // This ClipPath was just created during lookup. Initialize it. |
| 214 | clipPath.init(deviceSpacePath, accessRect, rtWidth, rtHeight); |
| 215 | } else { |
| 216 | clipPath.addAccess(accessRect); |
| 217 | } |
| 218 | |
| 219 | bool mustCheckBounds = !clipPath.pathDevIBounds().contains(accessRect); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 220 | return skstd::make_unique<GrCCClipProcessor>(&clipPath, MustCheckBounds(mustCheckBounds), |
| 221 | deviceSpacePath.getFillType()); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void CCPR::ClipPath::init(const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth, |
| 225 | int rtHeight) { |
| 226 | SkASSERT(this->isUninitialized()); |
| 227 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 228 | fAtlasLazyProxy = GrSurfaceProxy::MakeLazy( |
| 229 | [this](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) { |
| 230 | SkASSERT(fHasAtlas); |
| 231 | SkASSERT(!fHasAtlasTransform); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 232 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 233 | GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr; |
| 234 | if (!textureProxy || !textureProxy->instantiate(resourceProvider)) { |
| 235 | fAtlasScale = fAtlasTranslate = {0, 0}; |
| 236 | SkDEBUGCODE(fHasAtlasTransform = true); |
| 237 | return sk_sp<GrTexture>(); |
| 238 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 239 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 240 | fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()}; |
| 241 | fAtlasTranslate = {fAtlasOffsetX * fAtlasScale.x(), |
| 242 | fAtlasOffsetY * fAtlasScale.y()}; |
| 243 | if (kBottomLeft_GrSurfaceOrigin == textureProxy->origin()) { |
| 244 | fAtlasScale.fY = -fAtlasScale.y(); |
| 245 | fAtlasTranslate.fY = 1 - fAtlasTranslate.y(); |
| 246 | } |
| 247 | SkDEBUGCODE(fHasAtlasTransform = true); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 248 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 249 | *outOrigin = textureProxy->origin(); |
| 250 | return sk_ref_sp(textureProxy->priv().peekTexture()); |
| 251 | }, |
| 252 | GrSurfaceProxy::Renderable::kYes, kAlpha_half_GrPixelConfig); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 253 | |
| 254 | const SkRect& pathDevBounds = deviceSpacePath.getBounds(); |
| 255 | if (SkTMax(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) { |
| 256 | // The path is too large. We need to crop it or analytic AA can run out of fp32 precision. |
| 257 | crop_path(deviceSpacePath, SkIRect::MakeWH(rtWidth, rtHeight), &fDeviceSpacePath); |
| 258 | } else { |
| 259 | fDeviceSpacePath = deviceSpacePath; |
| 260 | } |
| 261 | deviceSpacePath.getBounds().roundOut(&fPathDevIBounds); |
| 262 | fAccessRect = accessRect; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void GrCoverageCountingPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP, |
| 266 | const uint32_t* opListIDs, int numOpListIDs, |
| 267 | SkTArray<sk_sp<GrRenderTargetContext>>* results) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 268 | using PathInstance = GrCCPathProcessor::Instance; |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 269 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 270 | SkASSERT(!fFlushing); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 271 | SkASSERT(!fPerFlushIndexBuffer); |
| 272 | SkASSERT(!fPerFlushVertexBuffer); |
| 273 | SkASSERT(!fPerFlushInstanceBuffer); |
| 274 | SkASSERT(fPerFlushAtlases.empty()); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 275 | SkDEBUGCODE(fFlushing = true); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 276 | |
| 277 | if (fRTPendingPathsMap.empty()) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 278 | return; // Nothing to draw. |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 279 | } |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 280 | |
| 281 | fPerFlushResourcesAreValid = false; |
| 282 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 283 | // Count the paths that are being flushed. |
Chris Dalton | c9c97b7 | 2017-11-27 15:34:26 -0700 | [diff] [blame] | 284 | int maxTotalPaths = 0, maxPathPoints = 0, numSkPoints = 0, numSkVerbs = 0; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 285 | SkDEBUGCODE(int numClipPaths = 0); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 286 | for (int i = 0; i < numOpListIDs; ++i) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 287 | auto it = fRTPendingPathsMap.find(opListIDs[i]); |
| 288 | if (fRTPendingPathsMap.end() == it) { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 289 | continue; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 290 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 291 | const RTPendingPaths& rtPendingPaths = it->second; |
| 292 | |
| 293 | SkTInternalLList<DrawPathsOp>::Iter drawOpsIter; |
| 294 | drawOpsIter.init(rtPendingPaths.fDrawOps, |
| 295 | SkTInternalLList<DrawPathsOp>::Iter::kHead_IterStart); |
| 296 | while (DrawPathsOp* op = drawOpsIter.get()) { |
| 297 | for (const DrawPathsOp::SingleDraw* draw = op->head(); draw; draw = draw->fNext) { |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 298 | ++maxTotalPaths; |
Chris Dalton | c9c97b7 | 2017-11-27 15:34:26 -0700 | [diff] [blame] | 299 | maxPathPoints = SkTMax(draw->fPath.countPoints(), maxPathPoints); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 300 | numSkPoints += draw->fPath.countPoints(); |
| 301 | numSkVerbs += draw->fPath.countVerbs(); |
| 302 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 303 | drawOpsIter.next(); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 304 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 305 | |
| 306 | maxTotalPaths += rtPendingPaths.fClipPaths.size(); |
| 307 | SkDEBUGCODE(numClipPaths += rtPendingPaths.fClipPaths.size()); |
| 308 | for (const auto& clipsIter : rtPendingPaths.fClipPaths) { |
| 309 | const SkPath& path = clipsIter.second.deviceSpacePath(); |
| 310 | maxPathPoints = SkTMax(path.countPoints(), maxPathPoints); |
| 311 | numSkPoints += path.countPoints(); |
| 312 | numSkVerbs += path.countVerbs(); |
| 313 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 314 | } |
| 315 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 316 | if (!maxTotalPaths) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 317 | return; // Nothing to draw. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 318 | } |
| 319 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 320 | // Allocate GPU buffers. |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 321 | fPerFlushIndexBuffer = GrCCPathProcessor::FindIndexBuffer(onFlushRP); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 322 | if (!fPerFlushIndexBuffer) { |
| 323 | SkDebugf("WARNING: failed to allocate ccpr path index buffer.\n"); |
| 324 | return; |
| 325 | } |
| 326 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 327 | fPerFlushVertexBuffer = GrCCPathProcessor::FindVertexBuffer(onFlushRP); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 328 | if (!fPerFlushVertexBuffer) { |
| 329 | SkDebugf("WARNING: failed to allocate ccpr path vertex buffer.\n"); |
| 330 | return; |
| 331 | } |
| 332 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 333 | fPerFlushInstanceBuffer = |
| 334 | onFlushRP->makeBuffer(kVertex_GrBufferType, maxTotalPaths * sizeof(PathInstance)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 335 | if (!fPerFlushInstanceBuffer) { |
| 336 | SkDebugf("WARNING: failed to allocate path instance buffer. No paths will be drawn.\n"); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | PathInstance* pathInstanceData = static_cast<PathInstance*>(fPerFlushInstanceBuffer->map()); |
| 341 | SkASSERT(pathInstanceData); |
| 342 | int pathInstanceIdx = 0; |
| 343 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 344 | GrCCCoverageOpsBuilder atlasOpsBuilder(maxTotalPaths, maxPathPoints, numSkPoints, numSkVerbs); |
| 345 | SkDEBUGCODE(int skippedTotalPaths = 0); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 346 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 347 | // Allocate atlas(es) and fill out GPU instance buffers. |
| 348 | for (int i = 0; i < numOpListIDs; ++i) { |
| 349 | auto it = fRTPendingPathsMap.find(opListIDs[i]); |
| 350 | if (fRTPendingPathsMap.end() == it) { |
| 351 | continue; |
| 352 | } |
| 353 | RTPendingPaths& rtPendingPaths = it->second; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 354 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 355 | SkTInternalLList<DrawPathsOp>::Iter drawOpsIter; |
| 356 | drawOpsIter.init(rtPendingPaths.fDrawOps, |
| 357 | SkTInternalLList<DrawPathsOp>::Iter::kHead_IterStart); |
| 358 | while (DrawPathsOp* op = drawOpsIter.get()) { |
| 359 | pathInstanceIdx = op->setupResources(onFlushRP, &atlasOpsBuilder, pathInstanceData, |
| 360 | pathInstanceIdx); |
| 361 | drawOpsIter.next(); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 362 | SkDEBUGCODE(skippedTotalPaths += op->numSkippedInstances_debugOnly()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 363 | } |
| 364 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 365 | for (auto& clipsIter : rtPendingPaths.fClipPaths) { |
| 366 | clipsIter.second.placePathInAtlas(this, onFlushRP, &atlasOpsBuilder); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 367 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 368 | } |
| 369 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 370 | fPerFlushInstanceBuffer->unmap(); |
| 371 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 372 | SkASSERT(pathInstanceIdx == maxTotalPaths - skippedTotalPaths - numClipPaths); |
| 373 | |
| 374 | if (!fPerFlushAtlases.empty()) { |
| 375 | atlasOpsBuilder.emitOp(fPerFlushAtlases.back().drawBounds()); |
| 376 | } |
| 377 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 378 | SkSTArray<4, std::unique_ptr<GrCCCoverageOp>> atlasOps(fPerFlushAtlases.count()); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 379 | if (!atlasOpsBuilder.finalize(onFlushRP, &atlasOps)) { |
| 380 | SkDebugf("WARNING: failed to allocate ccpr atlas buffers. No paths will be drawn.\n"); |
| 381 | return; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 382 | } |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 383 | SkASSERT(atlasOps.count() == fPerFlushAtlases.count()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 384 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 385 | // Draw the coverage ops into their respective atlases. |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 386 | GrTAllocator<GrCCAtlas>::Iter atlasIter(&fPerFlushAtlases); |
| 387 | for (std::unique_ptr<GrCCCoverageOp>& atlasOp : atlasOps) { |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 388 | SkAssertResult(atlasIter.next()); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 389 | GrCCAtlas* atlas = atlasIter.get(); |
| 390 | SkASSERT(atlasOp->bounds() == |
| 391 | SkRect::MakeIWH(atlas->drawBounds().width(), atlas->drawBounds().height())); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 392 | if (auto rtc = atlas->finalize(onFlushRP, std::move(atlasOp))) { |
| 393 | results->push_back(std::move(rtc)); |
| 394 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 395 | } |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 396 | SkASSERT(!atlasIter.next()); |
| 397 | |
| 398 | fPerFlushResourcesAreValid = true; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 399 | } |
| 400 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 401 | int CCPR::DrawPathsOp::setupResources(GrOnFlushResourceProvider* onFlushRP, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 402 | GrCCCoverageOpsBuilder* atlasOpsBuilder, |
| 403 | GrCCPathProcessor::Instance* pathInstanceData, |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 404 | int pathInstanceIdx) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 405 | const GrCCAtlas* currentAtlas = nullptr; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 406 | SkASSERT(fInstanceCount > 0); |
| 407 | SkASSERT(-1 == fBaseInstance); |
| 408 | fBaseInstance = pathInstanceIdx; |
| 409 | |
| 410 | for (const SingleDraw* draw = this->head(); draw; draw = draw->fNext) { |
| 411 | // parsePath gives us two tight bounding boxes: one in device space, as well as a second |
| 412 | // one rotated an additional 45 degrees. The path vertex shader uses these two bounding |
| 413 | // boxes to generate an octagon that circumscribes the path. |
| 414 | SkRect devBounds, devBounds45; |
| 415 | atlasOpsBuilder->parsePath(draw->fMatrix, draw->fPath, &devBounds, &devBounds45); |
| 416 | |
| 417 | SkIRect devIBounds; |
| 418 | devBounds.roundOut(&devIBounds); |
| 419 | |
| 420 | int16_t offsetX, offsetY; |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 421 | GrCCAtlas* atlas = fCCPR->placeParsedPathInAtlas(onFlushRP, draw->fClipIBounds, devIBounds, |
| 422 | &offsetX, &offsetY, atlasOpsBuilder); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 423 | if (!atlas) { |
| 424 | SkDEBUGCODE(++fNumSkippedInstances); |
| 425 | continue; |
| 426 | } |
| 427 | if (currentAtlas != atlas) { |
| 428 | if (currentAtlas) { |
| 429 | this->addAtlasBatch(currentAtlas, pathInstanceIdx); |
| 430 | } |
| 431 | currentAtlas = atlas; |
| 432 | } |
| 433 | |
| 434 | const SkMatrix& m = draw->fMatrix; |
| 435 | pathInstanceData[pathInstanceIdx++] = { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 436 | devBounds, |
| 437 | devBounds45, |
| 438 | {{m.getScaleX(), m.getSkewY(), m.getSkewX(), m.getScaleY()}}, |
| 439 | {{m.getTranslateX(), m.getTranslateY()}}, |
| 440 | {{offsetX, offsetY}}, |
| 441 | draw->fColor}; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | SkASSERT(pathInstanceIdx == fBaseInstance + fInstanceCount - fNumSkippedInstances); |
| 445 | if (currentAtlas) { |
| 446 | this->addAtlasBatch(currentAtlas, pathInstanceIdx); |
| 447 | } |
| 448 | |
| 449 | return pathInstanceIdx; |
| 450 | } |
| 451 | |
| 452 | void CCPR::ClipPath::placePathInAtlas(GrCoverageCountingPathRenderer* ccpr, |
| 453 | GrOnFlushResourceProvider* onFlushRP, |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 454 | GrCCCoverageOpsBuilder* atlasOpsBuilder) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 455 | SkASSERT(!this->isUninitialized()); |
| 456 | SkASSERT(!fHasAtlas); |
| 457 | atlasOpsBuilder->parseDeviceSpacePath(fDeviceSpacePath); |
| 458 | fAtlas = ccpr->placeParsedPathInAtlas(onFlushRP, fAccessRect, fPathDevIBounds, &fAtlasOffsetX, |
| 459 | &fAtlasOffsetY, atlasOpsBuilder); |
| 460 | SkDEBUGCODE(fHasAtlas = true); |
| 461 | } |
| 462 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 463 | GrCCAtlas* GrCoverageCountingPathRenderer::placeParsedPathInAtlas( |
| 464 | GrOnFlushResourceProvider* onFlushRP, |
| 465 | const SkIRect& clipIBounds, |
| 466 | const SkIRect& pathIBounds, |
| 467 | int16_t* atlasOffsetX, |
| 468 | int16_t* atlasOffsetY, |
| 469 | GrCCCoverageOpsBuilder* atlasOpsBuilder) { |
| 470 | using ScissorMode = GrCCCoverageOpsBuilder::ScissorMode; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 471 | |
| 472 | ScissorMode scissorMode; |
| 473 | SkIRect clippedPathIBounds; |
| 474 | if (clipIBounds.contains(pathIBounds)) { |
| 475 | clippedPathIBounds = pathIBounds; |
| 476 | scissorMode = ScissorMode::kNonScissored; |
| 477 | } else if (clippedPathIBounds.intersect(clipIBounds, pathIBounds)) { |
| 478 | scissorMode = ScissorMode::kScissored; |
| 479 | } else { |
| 480 | atlasOpsBuilder->discardParsedPath(); |
| 481 | return nullptr; |
| 482 | } |
| 483 | |
| 484 | SkIPoint16 atlasLocation; |
| 485 | const int h = clippedPathIBounds.height(), w = clippedPathIBounds.width(); |
| 486 | if (fPerFlushAtlases.empty() || !fPerFlushAtlases.back().addRect(w, h, &atlasLocation)) { |
| 487 | if (!fPerFlushAtlases.empty()) { |
| 488 | // The atlas is out of room and can't grow any bigger. |
| 489 | atlasOpsBuilder->emitOp(fPerFlushAtlases.back().drawBounds()); |
| 490 | } |
| 491 | fPerFlushAtlases.emplace_back(*onFlushRP->caps(), w, h).addRect(w, h, &atlasLocation); |
| 492 | } |
| 493 | |
| 494 | *atlasOffsetX = atlasLocation.x() - static_cast<int16_t>(clippedPathIBounds.left()); |
| 495 | *atlasOffsetY = atlasLocation.y() - static_cast<int16_t>(clippedPathIBounds.top()); |
| 496 | atlasOpsBuilder->saveParsedPath(scissorMode, clippedPathIBounds, *atlasOffsetX, *atlasOffsetY); |
| 497 | |
| 498 | return &fPerFlushAtlases.back(); |
| 499 | } |
| 500 | |
| 501 | void CCPR::DrawPathsOp::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 502 | SkASSERT(fCCPR->fFlushing); |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 503 | SkASSERT(flushState->rtCommandBuffer()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 504 | |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 505 | if (!fCCPR->fPerFlushResourcesAreValid) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 506 | return; // Setup failed. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 507 | } |
| 508 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 509 | SkASSERT(fBaseInstance >= 0); // Make sure setupResources has been called. |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 510 | |
Chris Dalton | d151322 | 2017-10-06 08:30:46 -0600 | [diff] [blame] | 511 | GrPipeline::InitArgs initArgs; |
| 512 | initArgs.fFlags = fSRGBFlags; |
| 513 | initArgs.fProxy = flushState->drawOpArgs().fProxy; |
| 514 | initArgs.fCaps = &flushState->caps(); |
| 515 | initArgs.fResourceProvider = flushState->resourceProvider(); |
| 516 | initArgs.fDstProxy = flushState->drawOpArgs().fDstProxy; |
| 517 | GrPipeline pipeline(initArgs, std::move(fProcessors), flushState->detachAppliedClip()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 518 | |
| 519 | int baseInstance = fBaseInstance; |
| 520 | |
| 521 | for (int i = 0; i < fAtlasBatches.count(); baseInstance = fAtlasBatches[i++].fEndInstanceIdx) { |
| 522 | const AtlasBatch& batch = fAtlasBatches[i]; |
| 523 | SkASSERT(batch.fEndInstanceIdx > baseInstance); |
| 524 | |
| 525 | if (!batch.fAtlas->textureProxy()) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 526 | continue; // Atlas failed to allocate. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 527 | } |
| 528 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 529 | GrCCPathProcessor coverProc(flushState->resourceProvider(), |
| 530 | sk_ref_sp(batch.fAtlas->textureProxy()), this->getFillType(), |
| 531 | *flushState->gpu()->caps()->shaderCaps()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 532 | |
| 533 | GrMesh mesh(GrPrimitiveType::kTriangles); |
| 534 | mesh.setIndexedInstanced(fCCPR->fPerFlushIndexBuffer.get(), |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 535 | GrCCPathProcessor::kPerInstanceIndexCount, |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 536 | fCCPR->fPerFlushInstanceBuffer.get(), |
| 537 | batch.fEndInstanceIdx - baseInstance, baseInstance); |
| 538 | mesh.setVertexData(fCCPR->fPerFlushVertexBuffer.get()); |
| 539 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 540 | flushState->rtCommandBuffer()->draw(pipeline, coverProc, &mesh, nullptr, 1, this->bounds()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 541 | } |
| 542 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 543 | SkASSERT(baseInstance == fBaseInstance + fInstanceCount - fNumSkippedInstances); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 544 | } |
| 545 | |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 546 | void GrCoverageCountingPathRenderer::postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, |
| 547 | int numOpListIDs) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 548 | SkASSERT(fFlushing); |
| 549 | fPerFlushAtlases.reset(); |
| 550 | fPerFlushInstanceBuffer.reset(); |
| 551 | fPerFlushVertexBuffer.reset(); |
| 552 | fPerFlushIndexBuffer.reset(); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 553 | // We wait to erase these until after flush, once Ops and FPs are done accessing their data. |
| 554 | for (int i = 0; i < numOpListIDs; ++i) { |
| 555 | fRTPendingPathsMap.erase(opListIDs[i]); |
| 556 | } |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame^] | 557 | SkDEBUGCODE(fFlushing = false); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 558 | } |