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