blob: 5f66c6e442edc4bbead9ef8c418df8c41adfb704 [file] [log] [blame]
Chris Dalton1a325d22017-07-14 15:17:41 -06001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
Chris Dalton1a325d22017-07-14 15:17:41 -06009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/pathops/SkPathOps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrProxyProvider.h"
Michael Ludwig7c12e282020-05-29 09:54:07 -040013#include "src/gpu/GrRenderTargetContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/ccpr/GrCCClipProcessor.h"
15#include "src/gpu/ccpr/GrCCDrawPathsOp.h"
16#include "src/gpu/ccpr/GrCCPathCache.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060017
Chris Dalton5ba36ba2018-05-09 01:08:38 -060018using PathInstance = GrCCPathProcessor::Instance;
Chris Daltona32a3c32017-12-05 10:05:21 -070019
Chris Daltonc3318f02019-07-19 14:20:53 -060020bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps, CoverageType* coverageType) {
Chris Dalton1a325d22017-07-14 15:17:41 -060021 const GrShaderCaps& shaderCaps = *caps.shaderCaps();
Greg Daniel0258c902019-08-01 13:08:33 -040022 GrBackendFormat defaultA8Format = caps.getDefaultBackendFormat(GrColorType::kAlpha_8,
23 GrRenderable::kYes);
Chris Daltonc3318f02019-07-19 14:20:53 -060024 if (caps.driverBlacklistCCPR() || !shaderCaps.integerSupport() ||
Chris Daltona77cdee2020-04-03 14:50:43 -060025 !caps.drawInstancedSupport() || !shaderCaps.floatIs32Bits() ||
Greg Daniel0258c902019-08-01 13:08:33 -040026 !defaultA8Format.isValid() || // This checks both texturable and renderable
Chris Daltona8fbeba2019-03-30 00:31:23 -060027 !caps.halfFloatVertexAttributeSupport()) {
28 return false;
29 }
Chris Daltonc3318f02019-07-19 14:20:53 -060030
Greg Daniel0258c902019-08-01 13:08:33 -040031 GrBackendFormat defaultAHalfFormat = caps.getDefaultBackendFormat(GrColorType::kAlpha_F16,
32 GrRenderable::kYes);
Chris Daltonc3318f02019-07-19 14:20:53 -060033 if (caps.allowCoverageCounting() &&
Greg Daniel0258c902019-08-01 13:08:33 -040034 defaultAHalfFormat.isValid()) { // This checks both texturable and renderable
Chris Daltonc3318f02019-07-19 14:20:53 -060035 if (coverageType) {
36 *coverageType = CoverageType::kFP16_CoverageCount;
37 }
38 return true;
39 }
40
Chris Dalton7c012082019-07-22 00:45:52 -040041 if (!caps.driverBlacklistMSAACCPR() &&
Greg Danieleadfac92019-08-02 09:03:53 -040042 caps.internalMultisampleCount(defaultA8Format) > 1 &&
Chris Daltonc3318f02019-07-19 14:20:53 -060043 caps.sampleLocationsSupport() &&
Chris Dalton8a64a442019-10-29 18:54:58 -060044 shaderCaps.sampleMaskSupport()) {
Chris Daltonc3318f02019-07-19 14:20:53 -060045 if (coverageType) {
46 *coverageType = CoverageType::kA8_Multisample;
47 }
48 return true;
49 }
50
51 return false;
Chris Dalton1a325d22017-07-14 15:17:41 -060052}
53
Chris Dalton383a2ef2018-01-08 17:21:41 -050054sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton351e80c2019-01-06 22:51:00 -070055 const GrCaps& caps, AllowCaching allowCaching, uint32_t contextUniqueID) {
Chris Daltonc3318f02019-07-19 14:20:53 -060056 CoverageType coverageType;
57 if (IsSupported(caps, &coverageType)) {
58 return sk_sp<GrCoverageCountingPathRenderer>(new GrCoverageCountingPathRenderer(
59 coverageType, allowCaching, contextUniqueID));
60 }
61 return nullptr;
Chris Daltona2b5b642018-06-24 13:08:57 -060062}
63
Chris Daltonc3318f02019-07-19 14:20:53 -060064GrCoverageCountingPathRenderer::GrCoverageCountingPathRenderer(
65 CoverageType coverageType, AllowCaching allowCaching, uint32_t contextUniqueID)
66 : fCoverageType(coverageType) {
Chris Daltona2b5b642018-06-24 13:08:57 -060067 if (AllowCaching::kYes == allowCaching) {
Mike Kleinf46d5ca2019-12-11 10:45:01 -050068 fPathCache = std::make_unique<GrCCPathCache>(contextUniqueID);
Chris Daltona2b5b642018-06-24 13:08:57 -060069 }
70}
71
Greg Danielf41b2bd2019-08-22 16:19:24 -040072GrCCPerOpsTaskPaths* GrCoverageCountingPathRenderer::lookupPendingPaths(uint32_t opsTaskID) {
73 auto it = fPendingPaths.find(opsTaskID);
Chris Daltond7e22272018-05-23 10:17:17 -060074 if (fPendingPaths.end() == it) {
Greg Danielf41b2bd2019-08-22 16:19:24 -040075 sk_sp<GrCCPerOpsTaskPaths> paths = sk_make_sp<GrCCPerOpsTaskPaths>();
76 it = fPendingPaths.insert(std::make_pair(opsTaskID, std::move(paths))).first;
Chris Daltond7e22272018-05-23 10:17:17 -060077 }
78 return it->second.get();
Chris Dalton5ba36ba2018-05-09 01:08:38 -060079}
80
Chris Dalton383a2ef2018-01-08 17:21:41 -050081GrPathRenderer::CanDrawPath GrCoverageCountingPathRenderer::onCanDrawPath(
82 const CanDrawPathArgs& args) const {
Michael Ludwig2686d692020-04-17 20:21:37 +000083 const GrStyledShape& shape = *args.fShape;
Chris Daltonc3318f02019-07-19 14:20:53 -060084 // We use "kCoverage", or analytic AA, no mater what the coverage type of our atlas: Even if the
85 // atlas is multisampled, that resolves into analytic coverage before we draw the path to the
86 // main canvas.
Chris Dalton6ce447a2019-06-23 18:07:38 -060087 if (GrAAType::kCoverage != args.fAAType || shape.style().hasPathEffect() ||
Chris Dalton09a7bb22018-08-31 19:53:15 +080088 args.fViewMatrix->hasPerspective() || shape.inverseFilled()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060089 return CanDrawPath::kNo;
Chris Dalton1a325d22017-07-14 15:17:41 -060090 }
91
92 SkPath path;
Chris Dalton09a7bb22018-08-31 19:53:15 +080093 shape.asPath(&path);
Chris Daltona2b5b642018-06-24 13:08:57 -060094
Chris Dalton82de18f2018-09-12 17:24:09 -060095 const SkStrokeRec& stroke = shape.style().strokeRec();
96 switch (stroke.getStyle()) {
Chris Dalton09a7bb22018-08-31 19:53:15 +080097 case SkStrokeRec::kFill_Style: {
98 SkRect devBounds;
99 args.fViewMatrix->mapRect(&devBounds, path.getBounds());
Chris Daltona2b5b642018-06-24 13:08:57 -0600100
Chris Dalton09a7bb22018-08-31 19:53:15 +0800101 SkIRect clippedIBounds;
102 devBounds.roundOut(&clippedIBounds);
103 if (!clippedIBounds.intersect(*args.fClipConservativeBounds)) {
104 // The path is completely clipped away. Our code will eventually notice this before
105 // doing any real work.
106 return CanDrawPath::kYes;
107 }
108
109 int64_t numPixels = sk_64_mul(clippedIBounds.height(), clippedIBounds.width());
110 if (path.countVerbs() > 1000 && path.countPoints() > numPixels) {
111 // This is a complicated path that has more vertices than pixels! Let's let the SW
112 // renderer have this one: It will probably be faster and a bitmap will require less
113 // total memory on the GPU than CCPR instance buffers would for the raw path data.
114 return CanDrawPath::kNo;
115 }
116
117 if (numPixels > 256 * 256) {
118 // Large paths can blow up the atlas fast. And they are not ideal for a two-pass
119 // rendering algorithm. Give the simpler direct renderers a chance before we commit
120 // to drawing it.
121 return CanDrawPath::kAsBackup;
122 }
123
124 if (args.fShape->hasUnstyledKey() && path.countVerbs() > 50) {
125 // Complex paths do better cached in an SDF, if the renderer will accept them.
126 return CanDrawPath::kAsBackup;
127 }
128
129 return CanDrawPath::kYes;
130 }
131
132 case SkStrokeRec::kStroke_Style:
133 if (!args.fViewMatrix->isSimilarity()) {
134 // The stroker currently only supports rigid-body transfoms for the stroke lines
135 // themselves. This limitation doesn't affect hairlines since their stroke lines are
136 // defined relative to device space.
137 return CanDrawPath::kNo;
138 }
John Stiles30212b72020-06-11 17:55:07 -0400139 [[fallthrough]];
Chris Dalton82de18f2018-09-12 17:24:09 -0600140 case SkStrokeRec::kHairline_Style: {
Chris Daltonc3318f02019-07-19 14:20:53 -0600141 if (CoverageType::kFP16_CoverageCount != fCoverageType) {
142 // Stroking is not yet supported in MSAA atlas mode.
143 return CanDrawPath::kNo;
144 }
Chris Dalton82de18f2018-09-12 17:24:09 -0600145 float inflationRadius;
146 GetStrokeDevWidth(*args.fViewMatrix, stroke, &inflationRadius);
147 if (!(inflationRadius <= kMaxBoundsInflationFromStroke)) {
148 // Let extremely wide strokes be converted to fill paths and drawn by the CCPR
149 // filler instead. (Cast the logic negatively in order to also catch r=NaN.)
150 return CanDrawPath::kNo;
151 }
152 SkASSERT(!SkScalarIsNaN(inflationRadius));
153 if (SkPathPriv::ConicWeightCnt(path)) {
154 // The stroker does not support conics yet.
155 return CanDrawPath::kNo;
156 }
157 return CanDrawPath::kYes;
158 }
Chris Dalton09a7bb22018-08-31 19:53:15 +0800159
160 case SkStrokeRec::kStrokeAndFill_Style:
161 return CanDrawPath::kNo;
Chris Daltondb91c6e2017-09-08 16:25:08 -0600162 }
163
Chris Dalton09a7bb22018-08-31 19:53:15 +0800164 SK_ABORT("Invalid stroke style.");
Chris Dalton1a325d22017-07-14 15:17:41 -0600165}
166
167bool GrCoverageCountingPathRenderer::onDrawPath(const DrawPathArgs& args) {
168 SkASSERT(!fFlushing);
Chris Dalton1a325d22017-07-14 15:17:41 -0600169
Michael Ludwig7c12e282020-05-29 09:54:07 -0400170 auto op = GrCCDrawPathsOp::Make(args.fContext, *args.fClipConservativeBounds, *args.fViewMatrix,
171 *args.fShape, std::move(args.fPaint));
Chris Dalton42c21152018-06-13 15:28:19 -0600172 this->recordOp(std::move(op), args);
Chris Dalton1a325d22017-07-14 15:17:41 -0600173 return true;
174}
175
Brian Salomon348a0372018-10-31 10:42:18 -0400176void GrCoverageCountingPathRenderer::recordOp(std::unique_ptr<GrCCDrawPathsOp> op,
Chris Dalton42c21152018-06-13 15:28:19 -0600177 const DrawPathArgs& args) {
Brian Salomon348a0372018-10-31 10:42:18 -0400178 if (op) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400179 auto addToOwningPerOpsTaskPaths = [this](GrOp* op, uint32_t opsTaskID) {
180 op->cast<GrCCDrawPathsOp>()->addToOwningPerOpsTaskPaths(
181 sk_ref_sp(this->lookupPendingPaths(opsTaskID)));
Brian Salomon348a0372018-10-31 10:42:18 -0400182 };
Michael Ludwig7c12e282020-05-29 09:54:07 -0400183 args.fRenderTargetContext->addDrawOp(args.fClip, std::move(op),
Greg Danielf41b2bd2019-08-22 16:19:24 -0400184 addToOwningPerOpsTaskPaths);
Chris Dalton42c21152018-06-13 15:28:19 -0600185 }
186}
187
Chris Dalton383a2ef2018-01-08 17:21:41 -0500188std::unique_ptr<GrFragmentProcessor> GrCoverageCountingPathRenderer::makeClipProcessor(
John Stiles956ec8a2020-06-19 15:32:16 -0400189 std::unique_ptr<GrFragmentProcessor> inputFP, uint32_t opsTaskID,
190 const SkPath& deviceSpacePath, const SkIRect& accessRect, const GrCaps& caps) {
Chris Daltona32a3c32017-12-05 10:05:21 -0700191 SkASSERT(!fFlushing);
Chris Daltona32a3c32017-12-05 10:05:21 -0700192
Chris Daltonc3318f02019-07-19 14:20:53 -0600193 uint32_t key = deviceSpacePath.getGenerationID();
194 if (CoverageType::kA8_Multisample == fCoverageType) {
195 // We only need to consider fill rule in MSAA mode. In coverage count mode Even/Odd and
196 // Nonzero both reference the same coverage count mask.
197 key = (key << 1) | (uint32_t)GrFillRuleForSkPath(deviceSpacePath);
198 }
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600199 GrCCClipPath& clipPath =
Greg Danielf41b2bd2019-08-22 16:19:24 -0400200 this->lookupPendingPaths(opsTaskID)->fClipPaths[key];
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600201 if (!clipPath.isInitialized()) {
Chris Daltona32a3c32017-12-05 10:05:21 -0700202 // This ClipPath was just created during lookup. Initialize it.
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600203 const SkRect& pathDevBounds = deviceSpacePath.getBounds();
Brian Osman788b9162020-02-07 10:36:46 -0500204 if (std::max(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) {
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600205 // The path is too large. Crop it or analytic AA can run out of fp32 precision.
206 SkPath croppedPath;
Chris Dalton4c458b12018-06-16 17:22:59 -0600207 int maxRTSize = caps.maxRenderTargetSize();
Chris Dalton09a7bb22018-08-31 19:53:15 +0800208 CropPath(deviceSpacePath, SkIRect::MakeWH(maxRTSize, maxRTSize), &croppedPath);
Chris Daltonc3318f02019-07-19 14:20:53 -0600209 clipPath.init(croppedPath, accessRect, fCoverageType, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600210 } else {
Chris Daltonc3318f02019-07-19 14:20:53 -0600211 clipPath.init(deviceSpacePath, accessRect, fCoverageType, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600212 }
Chris Daltona32a3c32017-12-05 10:05:21 -0700213 } else {
214 clipPath.addAccess(accessRect);
215 }
216
Chris Daltonc3318f02019-07-19 14:20:53 -0600217 auto isCoverageCount = GrCCClipProcessor::IsCoverageCount(
218 CoverageType::kFP16_CoverageCount == fCoverageType);
219 auto mustCheckBounds = GrCCClipProcessor::MustCheckBounds(
220 !clipPath.pathDevIBounds().contains(accessRect));
John Stiles956ec8a2020-06-19 15:32:16 -0400221 return std::make_unique<GrCCClipProcessor>(
222 std::move(inputFP), caps, &clipPath, isCoverageCount, mustCheckBounds);
Chris Daltona32a3c32017-12-05 10:05:21 -0700223}
224
Brian Salomonbf6b9792019-08-21 09:38:10 -0400225void GrCoverageCountingPathRenderer::preFlush(
Chris Daltonc4b47352019-08-23 10:10:36 -0600226 GrOnFlushResourceProvider* onFlushRP, const uint32_t* opsTaskIDs, int numOpsTaskIDs) {
Chris Dalton351e80c2019-01-06 22:51:00 -0700227 using DoCopiesToA8Coverage = GrCCDrawPathsOp::DoCopiesToA8Coverage;
Chris Daltona32a3c32017-12-05 10:05:21 -0700228 SkASSERT(!fFlushing);
Chris Daltond7e22272018-05-23 10:17:17 -0600229 SkASSERT(fFlushingPaths.empty());
Chris Dalton383a2ef2018-01-08 17:21:41 -0500230 SkDEBUGCODE(fFlushing = true);
Chris Daltona32a3c32017-12-05 10:05:21 -0700231
Chris Dalton351e80c2019-01-06 22:51:00 -0700232 if (fPathCache) {
233 fPathCache->doPreFlushProcessing();
Chris Dalton4da70192018-06-18 09:51:36 -0600234 }
235
Chris Daltond7e22272018-05-23 10:17:17 -0600236 if (fPendingPaths.empty()) {
Chris Dalton383a2ef2018-01-08 17:21:41 -0500237 return; // Nothing to draw.
Chris Daltona32a3c32017-12-05 10:05:21 -0700238 }
Chris Daltonc1e59632017-09-05 00:30:07 -0600239
Chris Dalton4da70192018-06-18 09:51:36 -0600240 GrCCPerFlushResourceSpecs specs;
Chris Dalton42c21152018-06-13 15:28:19 -0600241 int maxPreferredRTSize = onFlushRP->caps()->maxPreferredRenderTargetSize();
Brian Osman788b9162020-02-07 10:36:46 -0500242 specs.fCopyAtlasSpecs.fMaxPreferredTextureSize = std::min(2048, maxPreferredRTSize);
Chris Dalton4da70192018-06-18 09:51:36 -0600243 SkASSERT(0 == specs.fCopyAtlasSpecs.fMinTextureSize);
244 specs.fRenderedAtlasSpecs.fMaxPreferredTextureSize = maxPreferredRTSize;
Brian Osman788b9162020-02-07 10:36:46 -0500245 specs.fRenderedAtlasSpecs.fMinTextureSize = std::min(512, maxPreferredRTSize);
Chris Dalton42c21152018-06-13 15:28:19 -0600246
Greg Danielf41b2bd2019-08-22 16:19:24 -0400247 // Move the per-opsTask paths that are about to be flushed from fPendingPaths to fFlushingPaths,
Chris Dalton42c21152018-06-13 15:28:19 -0600248 // and count them up so we can preallocate buffers.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400249 fFlushingPaths.reserve(numOpsTaskIDs);
250 for (int i = 0; i < numOpsTaskIDs; ++i) {
251 auto iter = fPendingPaths.find(opsTaskIDs[i]);
Chris Daltond7e22272018-05-23 10:17:17 -0600252 if (fPendingPaths.end() == iter) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400253 continue; // No paths on this opsTask.
Chris Dalton1a325d22017-07-14 15:17:41 -0600254 }
Chris Daltona32a3c32017-12-05 10:05:21 -0700255
tzikbdb49562018-05-28 14:58:00 +0900256 fFlushingPaths.push_back(std::move(iter->second));
Chris Daltond7e22272018-05-23 10:17:17 -0600257 fPendingPaths.erase(iter);
258
Chris Dalton4da70192018-06-18 09:51:36 -0600259 for (GrCCDrawPathsOp* op : fFlushingPaths.back()->fDrawOps) {
Chris Dalton351e80c2019-01-06 22:51:00 -0700260 op->accountForOwnPaths(fPathCache.get(), onFlushRP, &specs);
Chris Dalton080baa42017-11-06 14:19:19 -0700261 }
Chris Daltond7e22272018-05-23 10:17:17 -0600262 for (const auto& clipsIter : fFlushingPaths.back()->fClipPaths) {
Chris Dalton4da70192018-06-18 09:51:36 -0600263 clipsIter.second.accountForOwnPath(&specs);
Chris Daltona32a3c32017-12-05 10:05:21 -0700264 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600265 }
266
Chris Dalton4da70192018-06-18 09:51:36 -0600267 if (specs.isEmpty()) {
Chris Dalton383a2ef2018-01-08 17:21:41 -0500268 return; // Nothing to draw.
Chris Dalton1a325d22017-07-14 15:17:41 -0600269 }
270
Chris Dalton4da70192018-06-18 09:51:36 -0600271 // Determine if there are enough reusable paths from last flush for it to be worth our time to
272 // copy them to cached atlas(es).
Chris Dalton09a7bb22018-08-31 19:53:15 +0800273 int numCopies = specs.fNumCopiedPaths[GrCCPerFlushResourceSpecs::kFillIdx] +
274 specs.fNumCopiedPaths[GrCCPerFlushResourceSpecs::kStrokeIdx];
Chris Dalton351e80c2019-01-06 22:51:00 -0700275 auto doCopies = DoCopiesToA8Coverage(numCopies > 100 ||
276 specs.fCopyAtlasSpecs.fApproxNumPixels > 256 * 256);
277 if (numCopies && DoCopiesToA8Coverage::kNo == doCopies) {
278 specs.cancelCopies();
Chris Dalton4da70192018-06-18 09:51:36 -0600279 }
280
Chris Daltonc3318f02019-07-19 14:20:53 -0600281 auto resources = sk_make_sp<GrCCPerFlushResources>(onFlushRP, fCoverageType, specs);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600282 if (!resources->isMapped()) {
283 return; // Some allocation failed.
Chris Dalton1a325d22017-07-14 15:17:41 -0600284 }
285
Chris Dalton4da70192018-06-18 09:51:36 -0600286 // Layout the atlas(es) and parse paths.
Chris Daltond7e22272018-05-23 10:17:17 -0600287 for (const auto& flushingPaths : fFlushingPaths) {
288 for (GrCCDrawPathsOp* op : flushingPaths->fDrawOps) {
Chris Dalton351e80c2019-01-06 22:51:00 -0700289 op->setupResources(fPathCache.get(), onFlushRP, resources.get(), doCopies);
Chris Dalton1a325d22017-07-14 15:17:41 -0600290 }
Chris Daltond7e22272018-05-23 10:17:17 -0600291 for (auto& clipsIter : flushingPaths->fClipPaths) {
Chris Daltondaef06a2018-05-23 17:11:09 -0600292 clipsIter.second.renderPathInAtlas(resources.get(), onFlushRP);
Chris Daltonc1e59632017-09-05 00:30:07 -0600293 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600294 }
295
Chris Dalton351e80c2019-01-06 22:51:00 -0700296 if (fPathCache) {
297 // Purge invalidated textures from previous atlases *before* calling finalize(). That way,
298 // the underlying textures objects can be freed up and reused for the next atlases.
299 fPathCache->purgeInvalidatedAtlasTextures(onFlushRP);
Chris Daltond6fa4542019-01-04 13:23:51 -0700300 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600301
Chris Dalton351e80c2019-01-06 22:51:00 -0700302 // Allocate resources and then render the atlas(es).
Chris Daltonc4b47352019-08-23 10:10:36 -0600303 if (!resources->finalize(onFlushRP)) {
Chris Dalton351e80c2019-01-06 22:51:00 -0700304 return;
305 }
Chris Dalton2e825a32019-01-04 22:14:27 +0000306
Chris Daltond7e22272018-05-23 10:17:17 -0600307 // Commit flushing paths to the resources once they are successfully completed.
308 for (auto& flushingPaths : fFlushingPaths) {
Robert Phillips774168e2018-05-31 12:43:27 -0400309 SkASSERT(!flushingPaths->fFlushResources);
Chris Daltond7e22272018-05-23 10:17:17 -0600310 flushingPaths->fFlushResources = resources;
311 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600312}
313
Greg Danielf41b2bd2019-08-22 16:19:24 -0400314void GrCoverageCountingPathRenderer::postFlush(GrDeferredUploadToken, const uint32_t* opsTaskIDs,
315 int numOpsTaskIDs) {
Chris Dalton1a325d22017-07-14 15:17:41 -0600316 SkASSERT(fFlushing);
Robert Phillips774168e2018-05-31 12:43:27 -0400317
Chris Dalton4da70192018-06-18 09:51:36 -0600318 if (!fFlushingPaths.empty()) {
Chris Dalton4da70192018-06-18 09:51:36 -0600319 // In DDL mode these aren't guaranteed to be deleted so we must clear out the perFlush
320 // resources manually.
321 for (auto& flushingPaths : fFlushingPaths) {
322 flushingPaths->fFlushResources = nullptr;
323 }
324
325 // We wait to erase these until after flush, once Ops and FPs are done accessing their data.
326 fFlushingPaths.reset();
Robert Phillips774168e2018-05-31 12:43:27 -0400327 }
328
Chris Dalton383a2ef2018-01-08 17:21:41 -0500329 SkDEBUGCODE(fFlushing = false);
Chris Dalton1a325d22017-07-14 15:17:41 -0600330}
Chris Dalton09a7bb22018-08-31 19:53:15 +0800331
Chris Dalton6c3879d2018-11-01 11:13:19 -0600332void GrCoverageCountingPathRenderer::purgeCacheEntriesOlderThan(
Chris Dalton351e80c2019-01-06 22:51:00 -0700333 GrProxyProvider* proxyProvider, const GrStdSteadyClock::time_point& purgeTime) {
Chris Dalton6c3879d2018-11-01 11:13:19 -0600334 if (fPathCache) {
Chris Dalton351e80c2019-01-06 22:51:00 -0700335 fPathCache->purgeEntriesOlderThan(proxyProvider, purgeTime);
Chris Dalton6c3879d2018-11-01 11:13:19 -0600336 }
337}
338
Chris Dalton09a7bb22018-08-31 19:53:15 +0800339void GrCoverageCountingPathRenderer::CropPath(const SkPath& path, const SkIRect& cropbox,
340 SkPath* out) {
341 SkPath cropboxPath;
342 cropboxPath.addRect(SkRect::Make(cropbox));
343 if (!Op(cropboxPath, path, kIntersect_SkPathOp, out)) {
344 // This can fail if the PathOps encounter NaN or infinities.
345 out->reset();
346 }
347 out->setIsVolatile(true);
348}
Chris Dalton82de18f2018-09-12 17:24:09 -0600349
350float GrCoverageCountingPathRenderer::GetStrokeDevWidth(const SkMatrix& m,
351 const SkStrokeRec& stroke,
352 float* inflationRadius) {
353 float strokeDevWidth;
354 if (stroke.isHairlineStyle()) {
355 strokeDevWidth = 1;
356 } else {
357 SkASSERT(SkStrokeRec::kStroke_Style == stroke.getStyle());
358 SkASSERT(m.isSimilarity()); // Otherwise matrixScaleFactor = m.getMaxScale().
359 float matrixScaleFactor = SkVector::Length(m.getScaleX(), m.getSkewY());
360 strokeDevWidth = stroke.getWidth() * matrixScaleFactor;
361 }
362 if (inflationRadius) {
363 // Inflate for a minimum stroke width of 1. In some cases when the stroke is less than 1px
364 // wide, we may inflate it to 1px and instead reduce the opacity.
365 *inflationRadius = SkStrokeRec::GetInflationRadius(
Brian Osman788b9162020-02-07 10:36:46 -0500366 stroke.getJoin(), stroke.getMiter(), stroke.getCap(), std::max(strokeDevWidth, 1.f));
Chris Dalton82de18f2018-09-12 17:24:09 -0600367 }
368 return strokeDevWidth;
369}