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 | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 17 | #include "ccpr/GrCCPathCache.h" |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 18 | #include "ccpr/GrCCPathParser.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 19 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 20 | using PathInstance = GrCCPathProcessor::Instance; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 21 | |
| 22 | // If a path spans more pixels than this, we need to crop it or else analytic AA can run out of fp32 |
| 23 | // precision. |
| 24 | static constexpr float kPathCropThreshold = 1 << 16; |
| 25 | |
| 26 | static void crop_path(const SkPath& path, const SkIRect& cropbox, SkPath* out) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 27 | SkPath cropboxPath; |
| 28 | cropboxPath.addRect(SkRect::Make(cropbox)); |
| 29 | if (!Op(cropboxPath, path, kIntersect_SkPathOp, out)) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 30 | // This can fail if the PathOps encounter NaN or infinities. |
| 31 | out->reset(); |
| 32 | } |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 33 | out->setIsVolatile(true); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 34 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 35 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 36 | |
| 37 | GrCCPerOpListPaths::~GrCCPerOpListPaths() { |
| 38 | // Ensure there are no surviving DrawPathsOps with a dangling pointer into this class. |
| 39 | if (!fDrawOps.isEmpty()) { |
| 40 | SK_ABORT("GrCCDrawPathsOp(s) not deleted during flush"); |
| 41 | } |
| 42 | // Clip lazy proxies also reference this class from their callbacks, but those callbacks |
| 43 | // are only invoked at flush time while we are still alive. (Unlike DrawPathsOps, that |
| 44 | // unregister themselves upon destruction.) So it shouldn't matter if any clip proxies |
| 45 | // are still around. |
| 46 | } |
| 47 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 48 | bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps) { |
| 49 | const GrShaderCaps& shaderCaps = *caps.shaderCaps(); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 50 | return shaderCaps.integerSupport() && shaderCaps.flatInterpolationSupport() && |
| 51 | caps.instanceAttribSupport() && GrCaps::kNone_MapFlags != caps.mapBufferFlags() && |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 52 | caps.isConfigTexturable(kAlpha_half_GrPixelConfig) && |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 53 | caps.isConfigRenderable(kAlpha_half_GrPixelConfig) && |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 54 | caps.isConfigTexturable(kAlpha_8_GrPixelConfig) && |
| 55 | caps.isConfigRenderable(kAlpha_8_GrPixelConfig) && |
Chris Dalton | e4679fa | 2017-09-29 13:58:26 -0600 | [diff] [blame] | 56 | !caps.blacklistCoverageCounting(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 59 | sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported( |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 60 | const GrCaps& caps, AllowCaching allowCaching) { |
| 61 | return sk_sp<GrCoverageCountingPathRenderer>( |
| 62 | IsSupported(caps) ? new GrCoverageCountingPathRenderer(allowCaching) : nullptr); |
| 63 | } |
| 64 | |
| 65 | GrCoverageCountingPathRenderer::GrCoverageCountingPathRenderer(AllowCaching allowCaching) { |
| 66 | if (AllowCaching::kYes == allowCaching) { |
| 67 | fPathCache = skstd::make_unique<GrCCPathCache>(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | GrCoverageCountingPathRenderer::~GrCoverageCountingPathRenderer() { |
| 72 | // Ensure callers are actually flushing paths they record, not causing us to leak memory. |
| 73 | SkASSERT(fPendingPaths.empty()); |
| 74 | SkASSERT(!fFlushing); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 75 | } |
| 76 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 77 | GrCCPerOpListPaths* GrCoverageCountingPathRenderer::lookupPendingPaths(uint32_t opListID) { |
| 78 | auto it = fPendingPaths.find(opListID); |
| 79 | if (fPendingPaths.end() == it) { |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 80 | sk_sp<GrCCPerOpListPaths> paths = sk_make_sp<GrCCPerOpListPaths>(); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 81 | it = fPendingPaths.insert(std::make_pair(opListID, std::move(paths))).first; |
| 82 | } |
| 83 | return it->second.get(); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 84 | } |
| 85 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 86 | GrPathRenderer::CanDrawPath GrCoverageCountingPathRenderer::onCanDrawPath( |
| 87 | const CanDrawPathArgs& args) const { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 88 | if (!args.fShape->style().isSimpleFill() || args.fShape->inverseFilled() || |
| 89 | args.fViewMatrix->hasPerspective() || GrAAType::kCoverage != args.fAAType) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 90 | return CanDrawPath::kNo; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | SkPath path; |
| 94 | args.fShape->asPath(&path); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 95 | |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 96 | SkRect devBounds; |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 97 | args.fViewMatrix->mapRect(&devBounds, path.getBounds()); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 98 | |
| 99 | SkIRect clippedIBounds; |
| 100 | devBounds.roundOut(&clippedIBounds); |
| 101 | if (!clippedIBounds.intersect(*args.fClipConservativeBounds)) { |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 102 | // Path is completely clipped away. Our code will eventually notice this before doing any |
| 103 | // real work. |
| 104 | return CanDrawPath::kYes; |
| 105 | } |
| 106 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 107 | int64_t numPixels = sk_64_mul(clippedIBounds.height(), clippedIBounds.width()); |
| 108 | if (path.countVerbs() > 1000 && path.countPoints() > numPixels) { |
| 109 | // This is a complicated path that has more vertices than pixels! Let's let the SW renderer |
| 110 | // have this one: It will probably be faster and a bitmap will require less total memory on |
| 111 | // the GPU than CCPR instance buffers would for the raw path data. |
| 112 | return CanDrawPath::kNo; |
| 113 | } |
| 114 | |
| 115 | if (numPixels > 256 * 256) { |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 116 | // Large paths can blow up the atlas fast. And they are not ideal for a two-pass rendering |
| 117 | // algorithm. Give the simpler direct renderers a chance before we commit to drawing it. |
| 118 | return CanDrawPath::kAsBackup; |
| 119 | } |
| 120 | |
| 121 | if (args.fShape->hasUnstyledKey() && path.countVerbs() > 50) { |
| 122 | // Complex paths do better cached in an SDF, if the renderer will accept them. |
| 123 | return CanDrawPath::kAsBackup; |
| 124 | } |
| 125 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 126 | return CanDrawPath::kYes; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | bool GrCoverageCountingPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 130 | SkASSERT(!fFlushing); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 131 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 132 | SkIRect clipIBounds; |
| 133 | GrRenderTargetContext* rtc = args.fRenderTargetContext; |
| 134 | args.fClip->getConservativeBounds(rtc->width(), rtc->height(), &clipIBounds, nullptr); |
| 135 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 136 | SkRect devBounds; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 137 | args.fViewMatrix->mapRect(&devBounds, args.fShape->bounds()); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 138 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 139 | std::unique_ptr<GrCCDrawPathsOp> op; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 140 | if (SkTMax(devBounds.height(), devBounds.width()) > kPathCropThreshold) { |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 141 | // The path is too large. Crop it or analytic AA can run out of fp32 precision. |
| 142 | SkPath croppedPath; |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 143 | args.fShape->asPath(&croppedPath); |
| 144 | croppedPath.transform(*args.fViewMatrix, &croppedPath); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 145 | crop_path(croppedPath, clipIBounds, &croppedPath); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 146 | // FIXME: This breaks local coords: http://skbug.com/8003 |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 147 | op = GrCCDrawPathsOp::Make(args.fContext, clipIBounds, SkMatrix::I(), GrShape(croppedPath), |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 148 | croppedPath.getBounds(), std::move(args.fPaint)); |
Robert Phillips | 88a32ef | 2018-06-07 11:05:56 -0400 | [diff] [blame] | 149 | } else { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 150 | op = GrCCDrawPathsOp::Make(args.fContext, clipIBounds, *args.fViewMatrix, *args.fShape, |
| 151 | devBounds, std::move(args.fPaint)); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 152 | } |
| 153 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 154 | this->recordOp(std::move(op), args); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 155 | return true; |
| 156 | } |
| 157 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 158 | void GrCoverageCountingPathRenderer::recordOp(std::unique_ptr<GrCCDrawPathsOp> opHolder, |
| 159 | const DrawPathArgs& args) { |
| 160 | if (GrCCDrawPathsOp* op = opHolder.get()) { |
| 161 | GrRenderTargetContext* rtc = args.fRenderTargetContext; |
| 162 | if (uint32_t opListID = rtc->addDrawOp(*args.fClip, std::move(opHolder))) { |
| 163 | op->wasRecorded(this->lookupPendingPaths(opListID)); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 168 | std::unique_ptr<GrFragmentProcessor> GrCoverageCountingPathRenderer::makeClipProcessor( |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 169 | uint32_t opListID, const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth, |
| 170 | int rtHeight, const GrCaps& caps) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 171 | using MustCheckBounds = GrCCClipProcessor::MustCheckBounds; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 172 | |
| 173 | SkASSERT(!fFlushing); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 174 | |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 175 | GrCCClipPath& clipPath = |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 176 | this->lookupPendingPaths(opListID)->fClipPaths[deviceSpacePath.getGenerationID()]; |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 177 | if (!clipPath.isInitialized()) { |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 178 | // This ClipPath was just created during lookup. Initialize it. |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 179 | const SkRect& pathDevBounds = deviceSpacePath.getBounds(); |
| 180 | if (SkTMax(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) { |
| 181 | // The path is too large. Crop it or analytic AA can run out of fp32 precision. |
| 182 | SkPath croppedPath; |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 183 | int maxRTSize = caps.maxRenderTargetSize(); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 184 | crop_path(deviceSpacePath, SkIRect::MakeWH(maxRTSize, maxRTSize), &croppedPath); |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 185 | clipPath.init(croppedPath, accessRect, rtWidth, rtHeight, caps); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 186 | } else { |
Chris Dalton | 4c458b1 | 2018-06-16 17:22:59 -0600 | [diff] [blame] | 187 | clipPath.init(deviceSpacePath, accessRect, rtWidth, rtHeight, caps); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 188 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 189 | } else { |
| 190 | clipPath.addAccess(accessRect); |
| 191 | } |
| 192 | |
| 193 | bool mustCheckBounds = !clipPath.pathDevIBounds().contains(accessRect); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 194 | return skstd::make_unique<GrCCClipProcessor>(&clipPath, MustCheckBounds(mustCheckBounds), |
| 195 | deviceSpacePath.getFillType()); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 198 | void GrCoverageCountingPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP, |
| 199 | const uint32_t* opListIDs, int numOpListIDs, |
Chris Dalton | 9414c96 | 2018-06-14 10:14:50 -0600 | [diff] [blame] | 200 | SkTArray<sk_sp<GrRenderTargetContext>>* out) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 201 | using DoCopiesToCache = GrCCDrawPathsOp::DoCopiesToCache; |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 202 | SkASSERT(!fFlushing); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 203 | SkASSERT(fFlushingPaths.empty()); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 204 | SkDEBUGCODE(fFlushing = true); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 205 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 206 | // Dig up the stashed atlas from the previous flush (if any) so we can attempt to copy any |
| 207 | // reusable paths out of it and into the resource cache. We also need to clear its unique key. |
| 208 | sk_sp<GrTextureProxy> stashedAtlasProxy; |
| 209 | if (fStashedAtlasKey.isValid()) { |
| 210 | stashedAtlasProxy = onFlushRP->findOrCreateProxyByUniqueKey(fStashedAtlasKey, |
| 211 | GrCCAtlas::kTextureOrigin); |
| 212 | if (stashedAtlasProxy) { |
| 213 | // Instantiate the proxy so we can clear the underlying texture's unique key. |
| 214 | onFlushRP->instatiateProxy(stashedAtlasProxy.get()); |
| 215 | onFlushRP->removeUniqueKeyFromProxy(fStashedAtlasKey, stashedAtlasProxy.get()); |
| 216 | } else { |
| 217 | fStashedAtlasKey.reset(); // Indicate there is no stashed atlas to copy from. |
| 218 | } |
| 219 | } |
| 220 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 221 | if (fPendingPaths.empty()) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 222 | fStashedAtlasKey.reset(); |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 223 | return; // Nothing to draw. |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 224 | } |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 225 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 226 | GrCCPerFlushResourceSpecs specs; |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 227 | int maxPreferredRTSize = onFlushRP->caps()->maxPreferredRenderTargetSize(); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 228 | specs.fCopyAtlasSpecs.fMaxPreferredTextureSize = SkTMin(2048, maxPreferredRTSize); |
| 229 | SkASSERT(0 == specs.fCopyAtlasSpecs.fMinTextureSize); |
| 230 | specs.fRenderedAtlasSpecs.fMaxPreferredTextureSize = maxPreferredRTSize; |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 231 | specs.fRenderedAtlasSpecs.fMinTextureSize = SkTMin(512, maxPreferredRTSize); |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 232 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 233 | // 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] | 234 | // and count them up so we can preallocate buffers. |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 235 | fFlushingPaths.reserve(numOpListIDs); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 236 | for (int i = 0; i < numOpListIDs; ++i) { |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 237 | auto iter = fPendingPaths.find(opListIDs[i]); |
| 238 | if (fPendingPaths.end() == iter) { |
| 239 | continue; // No paths on this opList. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 240 | } |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 241 | |
tzik | bdb4956 | 2018-05-28 14:58:00 +0900 | [diff] [blame] | 242 | fFlushingPaths.push_back(std::move(iter->second)); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 243 | fPendingPaths.erase(iter); |
| 244 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 245 | for (GrCCDrawPathsOp* op : fFlushingPaths.back()->fDrawOps) { |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 246 | op->accountForOwnPaths(fPathCache.get(), onFlushRP, fStashedAtlasKey, &specs); |
Chris Dalton | 080baa4 | 2017-11-06 14:19:19 -0700 | [diff] [blame] | 247 | } |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 248 | for (const auto& clipsIter : fFlushingPaths.back()->fClipPaths) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 249 | clipsIter.second.accountForOwnPath(&specs); |
Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 250 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 251 | } |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 252 | fStashedAtlasKey.reset(); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 253 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 254 | if (specs.isEmpty()) { |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 255 | return; // Nothing to draw. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 256 | } |
| 257 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 258 | // Determine if there are enough reusable paths from last flush for it to be worth our time to |
| 259 | // copy them to cached atlas(es). |
| 260 | DoCopiesToCache doCopies = DoCopiesToCache(specs.fNumCopiedPaths > 100 || |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame^] | 261 | specs.fCopyAtlasSpecs.fApproxNumPixels > 256 * 256); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 262 | if (specs.fNumCopiedPaths && DoCopiesToCache::kNo == doCopies) { |
| 263 | specs.convertCopiesToRenders(); |
| 264 | SkASSERT(!specs.fNumCopiedPaths); |
| 265 | } |
| 266 | |
| 267 | auto resources = sk_make_sp<GrCCPerFlushResources>(onFlushRP, specs); |
Chris Dalton | 5ba36ba | 2018-05-09 01:08:38 -0600 | [diff] [blame] | 268 | if (!resources->isMapped()) { |
| 269 | return; // Some allocation failed. |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 270 | } |
| 271 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 272 | // Layout the atlas(es) and parse paths. |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 273 | for (const auto& flushingPaths : fFlushingPaths) { |
| 274 | for (GrCCDrawPathsOp* op : flushingPaths->fDrawOps) { |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 275 | op->setupResources(onFlushRP, resources.get(), doCopies); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 276 | } |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 277 | for (auto& clipsIter : flushingPaths->fClipPaths) { |
Chris Dalton | daef06a | 2018-05-23 17:11:09 -0600 | [diff] [blame] | 278 | clipsIter.second.renderPathInAtlas(resources.get(), onFlushRP); |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 279 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 280 | } |
| 281 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 282 | // Allocate resources and then render the atlas(es). |
| 283 | if (!resources->finalize(onFlushRP, std::move(stashedAtlasProxy), out)) { |
Chris Dalton | c1e5963 | 2017-09-05 00:30:07 -0600 | [diff] [blame] | 284 | return; |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 285 | } |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 286 | // Verify the stashed atlas got released so its texture could be recycled. |
| 287 | SkASSERT(!stashedAtlasProxy); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 288 | |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 289 | // Commit flushing paths to the resources once they are successfully completed. |
| 290 | for (auto& flushingPaths : fFlushingPaths) { |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 291 | SkASSERT(!flushingPaths->fFlushResources); |
Chris Dalton | d7e2227 | 2018-05-23 10:17:17 -0600 | [diff] [blame] | 292 | flushingPaths->fFlushResources = resources; |
| 293 | } |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 294 | } |
| 295 | |
Chris Dalton | 3968ff9 | 2017-11-27 12:26:31 -0700 | [diff] [blame] | 296 | void GrCoverageCountingPathRenderer::postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, |
| 297 | int numOpListIDs) { |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 298 | SkASSERT(fFlushing); |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 299 | SkASSERT(!fStashedAtlasKey.isValid()); // Should have been cleared in preFlush(). |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 300 | |
Chris Dalton | 4da7019 | 2018-06-18 09:51:36 -0600 | [diff] [blame] | 301 | if (!fFlushingPaths.empty()) { |
| 302 | // Note the stashed atlas's key for next flush, if any. |
| 303 | auto resources = fFlushingPaths.front()->fFlushResources.get(); |
| 304 | if (resources && resources->hasStashedAtlas()) { |
| 305 | fStashedAtlasKey = resources->stashedAtlasKey(); |
| 306 | } |
| 307 | |
| 308 | // In DDL mode these aren't guaranteed to be deleted so we must clear out the perFlush |
| 309 | // resources manually. |
| 310 | for (auto& flushingPaths : fFlushingPaths) { |
| 311 | flushingPaths->fFlushResources = nullptr; |
| 312 | } |
| 313 | |
| 314 | // We wait to erase these until after flush, once Ops and FPs are done accessing their data. |
| 315 | fFlushingPaths.reset(); |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Chris Dalton | 383a2ef | 2018-01-08 17:21:41 -0500 | [diff] [blame] | 318 | SkDEBUGCODE(fFlushing = false); |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 319 | } |