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" |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 12 | #include "GrProxyProvider.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 13 | #include "SkMakeUnique.h" |
Chris Dalton | a039d3b | 2017-09-28 11:16:36 -0600 | [diff] [blame] | 14 | #include "SkPathOps.h" |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 15 | #include "ccpr/GrCCClipProcessor.h" |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 16 | #include "ccpr/GrCCDrawPathsOp.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 17 | #include "ccpr/GrCCPathParser.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 18 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 19 | using PathInstance = GrCCPathProcessor::Instance; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 20 | |
| 21 | // If a path spans more pixels than this, we need to crop it or else analytic AA can run out of fp32 |
| 22 | // precision. |
| 23 | static constexpr float kPathCropThreshold = 1 << 16; |
| 24 | |
| 25 | static void crop_path(const SkPath& path, const SkIRect& cropbox, SkPath* out) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 26 | SkPath cropboxPath; |
| 27 | cropboxPath.addRect(SkRect::Make(cropbox)); |
| 28 | if (!Op(cropboxPath, path, kIntersect_SkPathOp, out)) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 29 | // This can fail if the PathOps encounter NaN or infinities. |
| 30 | out->reset(); |
| 31 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 32 | out->setIsVolatile(true); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 33 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 34 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 35 | |
| 36 | GrCCPerOpListPaths::~GrCCPerOpListPaths() { |
| 37 | // Ensure there are no surviving DrawPathsOps with a dangling pointer into this class. |
| 38 | if (!fDrawOps.isEmpty()) { |
| 39 | SK_ABORT("GrCCDrawPathsOp(s) not deleted during flush"); |
| 40 | } |
| 41 | // Clip lazy proxies also reference this class from their callbacks, but those callbacks |
| 42 | // are only invoked at flush time while we are still alive. (Unlike DrawPathsOps, that |
| 43 | // unregister themselves upon destruction.) So it shouldn't matter if any clip proxies |
| 44 | // are still around. |
| 45 | } |
| 46 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 47 | bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps) { |
| 48 | const GrShaderCaps& shaderCaps = *caps.shaderCaps(); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 49 | return shaderCaps.integerSupport() && shaderCaps.flatInterpolationSupport() && |
| 50 | caps.instanceAttribSupport() && GrCaps::kNone_MapFlags != caps.mapBufferFlags() && |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 51 | caps.isConfigTexturable(kAlpha_half_GrPixelConfig) && |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 52 | caps.isConfigRenderable(kAlpha_half_GrPixelConfig) && |
Chris Dalton | e4679fa | 2017-09-29 13:58:26 -0600 | [diff] [blame] | 53 | !caps.blacklistCoverageCounting(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 54 | } |
| 55 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 56 | sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported( |
| 57 | const GrCaps& caps, bool drawCachablePaths) { |
Chris Dalton | a2ac30d | 2017-10-17 10:40:01 -0600 | [diff] [blame] | 58 | auto ccpr = IsSupported(caps) ? new GrCoverageCountingPathRenderer(drawCachablePaths) : nullptr; |
| 59 | return sk_sp<GrCoverageCountingPathRenderer>(ccpr); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 60 | } |
| 61 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 62 | GrCCPerOpListPaths* GrCoverageCountingPathRenderer::lookupPendingPaths(uint32_t opListID) { |
| 63 | auto it = fPendingPaths.find(opListID); |
| 64 | if (fPendingPaths.end() == it) { |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 65 | sk_sp<GrCCPerOpListPaths> paths = sk_make_sp<GrCCPerOpListPaths>(); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 66 | it = fPendingPaths.insert(std::make_pair(opListID, std::move(paths))).first; |
| 67 | } |
| 68 | return it->second.get(); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 69 | } |
| 70 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 71 | GrPathRenderer::CanDrawPath GrCoverageCountingPathRenderer::onCanDrawPath( |
| 72 | const CanDrawPathArgs& args) const { |
Chris Dalton | a2ac30d | 2017-10-17 10:40:01 -0600 | [diff] [blame] | 73 | if (args.fShape->hasUnstyledKey() && !fDrawCachablePaths) { |
| 74 | return CanDrawPath::kNo; |
| 75 | } |
| 76 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 77 | if (!args.fShape->style().isSimpleFill() || args.fShape->inverseFilled() || |
| 78 | args.fViewMatrix->hasPerspective() || GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 79 | return CanDrawPath::kNo; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | SkPath path; |
| 83 | args.fShape->asPath(&path); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 84 | SkRect devBounds; |
| 85 | SkIRect devIBounds; |
| 86 | args.fViewMatrix->mapRect(&devBounds, path.getBounds()); |
| 87 | devBounds.roundOut(&devIBounds); |
| 88 | if (!devIBounds.intersect(*args.fClipConservativeBounds)) { |
| 89 | // Path is completely clipped away. Our code will eventually notice this before doing any |
| 90 | // real work. |
| 91 | return CanDrawPath::kYes; |
| 92 | } |
| 93 | |
| 94 | if (devIBounds.height() * devIBounds.width() > 256 * 256) { |
| 95 | // Large paths can blow up the atlas fast. And they are not ideal for a two-pass rendering |
| 96 | // algorithm. Give the simpler direct renderers a chance before we commit to drawing it. |
| 97 | return CanDrawPath::kAsBackup; |
| 98 | } |
| 99 | |
| 100 | if (args.fShape->hasUnstyledKey() && path.countVerbs() > 50) { |
| 101 | // Complex paths do better cached in an SDF, if the renderer will accept them. |
| 102 | return CanDrawPath::kAsBackup; |
| 103 | } |
| 104 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 105 | return CanDrawPath::kYes; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | bool GrCoverageCountingPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 109 | SkASSERT(!fFlushing); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 110 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 111 | SkIRect clipIBounds; |
| 112 | GrRenderTargetContext* rtc = args.fRenderTargetContext; |
| 113 | args.fClip->getConservativeBounds(rtc->width(), rtc->height(), &clipIBounds, nullptr); |
| 114 | |
| 115 | SkPath path; |
| 116 | args.fShape->asPath(&path); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 117 | |
| 118 | SkRect devBounds; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 119 | args.fViewMatrix->mapRect(&devBounds, path.getBounds()); |
| 120 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 121 | std::unique_ptr<GrCCDrawPathsOp> op; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 122 | if (SkTMax(devBounds.height(), devBounds.width()) > kPathCropThreshold) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 123 | // The path is too large. Crop it or analytic AA can run out of fp32 precision. |
| 124 | SkPath croppedPath; |
| 125 | path.transform(*args.fViewMatrix, &croppedPath); |
| 126 | crop_path(croppedPath, clipIBounds, &croppedPath); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 127 | // FIXME: This breaks local coords: http://skbug.com/8003 |
| 128 | op = GrCCDrawPathsOp::Make(args.fContext, clipIBounds, SkMatrix::I(), croppedPath, |
| 129 | croppedPath.getBounds(), std::move(args.fPaint)); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 130 | } else { |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 131 | op = GrCCDrawPathsOp::Make(args.fContext, clipIBounds, *args.fViewMatrix, path, devBounds, |
| 132 | std::move(args.fPaint)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 135 | this->recordOp(std::move(op), args); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 136 | return true; |
| 137 | } |
| 138 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 139 | void GrCoverageCountingPathRenderer::recordOp(std::unique_ptr<GrCCDrawPathsOp> opHolder, |
| 140 | const DrawPathArgs& args) { |
| 141 | if (GrCCDrawPathsOp* op = opHolder.get()) { |
| 142 | GrRenderTargetContext* rtc = args.fRenderTargetContext; |
| 143 | if (uint32_t opListID = rtc->addDrawOp(*args.fClip, std::move(opHolder))) { |
| 144 | op->wasRecorded(this->lookupPendingPaths(opListID)); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 149 | std::unique_ptr<GrFragmentProcessor> GrCoverageCountingPathRenderer::makeClipProcessor( |
Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 150 | GrProxyProvider* proxyProvider, |
| 151 | uint32_t opListID, const SkPath& deviceSpacePath, const SkIRect& accessRect, |
| 152 | int rtWidth, int rtHeight) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 153 | using MustCheckBounds = GrCCClipProcessor::MustCheckBounds; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 154 | |
| 155 | SkASSERT(!fFlushing); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 156 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 157 | GrCCClipPath& clipPath = |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 158 | this->lookupPendingPaths(opListID)->fClipPaths[deviceSpacePath.getGenerationID()]; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 159 | if (!clipPath.isInitialized()) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 160 | // This ClipPath was just created during lookup. Initialize it. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 161 | const SkRect& pathDevBounds = deviceSpacePath.getBounds(); |
| 162 | if (SkTMax(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) { |
| 163 | // The path is too large. Crop it or analytic AA can run out of fp32 precision. |
| 164 | SkPath croppedPath; |
| 165 | int maxRTSize = proxyProvider->caps()->maxRenderTargetSize(); |
| 166 | crop_path(deviceSpacePath, SkIRect::MakeWH(maxRTSize, maxRTSize), &croppedPath); |
| 167 | clipPath.init(proxyProvider, croppedPath, accessRect, rtWidth, rtHeight); |
| 168 | } else { |
| 169 | clipPath.init(proxyProvider, deviceSpacePath, accessRect, rtWidth, rtHeight); |
| 170 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 171 | } else { |
| 172 | clipPath.addAccess(accessRect); |
| 173 | } |
| 174 | |
| 175 | bool mustCheckBounds = !clipPath.pathDevIBounds().contains(accessRect); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 176 | return skstd::make_unique<GrCCClipProcessor>(&clipPath, MustCheckBounds(mustCheckBounds), |
| 177 | deviceSpacePath.getFillType()); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 180 | void GrCoverageCountingPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP, |
| 181 | const uint32_t* opListIDs, int numOpListIDs, |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 182 | SkTArray<sk_sp<GrRenderTargetContext>>* atlasDraws) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 183 | SkASSERT(!fFlushing); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 184 | SkASSERT(fFlushingPaths.empty()); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 185 | SkDEBUGCODE(fFlushing = true); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 186 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 187 | if (fPendingPaths.empty()) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 188 | return; // Nothing to draw. |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 189 | } |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 190 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 191 | GrCCPerFlushResourceSpecs resourceSpecs; |
| 192 | int maxPreferredRTSize = onFlushRP->caps()->maxPreferredRenderTargetSize(); |
| 193 | resourceSpecs.fAtlasSpecs.fMaxPreferredTextureSize = maxPreferredRTSize; |
| 194 | resourceSpecs.fAtlasSpecs.fMinTextureSize = SkTMin(1024, maxPreferredRTSize); |
| 195 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 196 | // Move the per-opList paths that are about to be flushed from fPendingPaths to fFlushingPaths, |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 197 | // and count them up so we can preallocate buffers. |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 198 | fFlushingPaths.reserve(numOpListIDs); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 199 | for (int i = 0; i < numOpListIDs; ++i) { |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 200 | auto iter = fPendingPaths.find(opListIDs[i]); |
| 201 | if (fPendingPaths.end() == iter) { |
| 202 | continue; // No paths on this opList. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 203 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 204 | |
tzik | bdb4956 | 2018-05-28 14:58:00 +0900 | [diff] [blame] | 205 | fFlushingPaths.push_back(std::move(iter->second)); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 206 | fPendingPaths.erase(iter); |
| 207 | |
| 208 | for (const GrCCDrawPathsOp* op : fFlushingPaths.back()->fDrawOps) { |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 209 | op->accountForOwnPaths(&resourceSpecs); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 210 | } |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 211 | for (const auto& clipsIter : fFlushingPaths.back()->fClipPaths) { |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 212 | clipsIter.second.accountForOwnPath(&resourceSpecs); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 213 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 214 | } |
| 215 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 216 | if (resourceSpecs.isEmpty()) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 217 | return; // Nothing to draw. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 218 | } |
| 219 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 220 | auto resources = sk_make_sp<GrCCPerFlushResources>(onFlushRP, resourceSpecs); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 221 | if (!resources->isMapped()) { |
| 222 | return; // Some allocation failed. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 223 | } |
| 224 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 225 | // Layout atlas(es) and parse paths. |
Chris Dalton | 3917b1e | 2018-05-09 00:40:52 -0600 | [diff] [blame] | 226 | SkDEBUGCODE(int numSkippedPaths = 0); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 227 | for (const auto& flushingPaths : fFlushingPaths) { |
| 228 | for (GrCCDrawPathsOp* op : flushingPaths->fDrawOps) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 229 | op->setupResources(resources.get(), onFlushRP); |
Chris Dalton | 3917b1e | 2018-05-09 00:40:52 -0600 | [diff] [blame] | 230 | SkDEBUGCODE(numSkippedPaths += op->numSkippedInstances_debugOnly()); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 231 | } |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 232 | for (auto& clipsIter : flushingPaths->fClipPaths) { |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 233 | clipsIter.second.renderPathInAtlas(resources.get(), onFlushRP); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 234 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 235 | } |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame^] | 236 | SkASSERT(resources->nextPathInstanceIdx() == resourceSpecs.fNumRenderedPaths - numSkippedPaths); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 237 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 238 | // Allocate the atlases and create instance buffers to draw them. |
| 239 | if (!resources->finalize(onFlushRP, atlasDraws)) { |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 240 | return; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 243 | // Commit flushing paths to the resources once they are successfully completed. |
| 244 | for (auto& flushingPaths : fFlushingPaths) { |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 245 | SkASSERT(!flushingPaths->fFlushResources); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 246 | flushingPaths->fFlushResources = resources; |
| 247 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 248 | } |
| 249 | |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 250 | void GrCoverageCountingPathRenderer::postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, |
| 251 | int numOpListIDs) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 252 | SkASSERT(fFlushing); |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 253 | |
| 254 | // In DDL mode these aren't guaranteed to be deleted so we must clear out the perFlush |
| 255 | // resources manually. |
| 256 | for (auto& flushingPaths : fFlushingPaths) { |
| 257 | flushingPaths->fFlushResources = nullptr; |
| 258 | } |
| 259 | |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 260 | // We wait to erase these until after flush, once Ops and FPs are done accessing their data. |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 261 | fFlushingPaths.reset(); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 262 | SkDEBUGCODE(fFlushing = false); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 263 | } |