blob: 69d7200cb4991058418b0cef2eeff081379920e0 [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
8#include "GrCoverageCountingPathRenderer.h"
9
10#include "GrCaps.h"
11#include "GrClip.h"
Robert Phillips777707b2018-01-17 11:40:14 -050012#include "GrProxyProvider.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060013#include "SkMakeUnique.h"
Chris Daltona039d3b2017-09-28 11:16:36 -060014#include "SkPathOps.h"
Chris Dalton383a2ef2018-01-08 17:21:41 -050015#include "ccpr/GrCCClipProcessor.h"
Chris Daltond7e22272018-05-23 10:17:17 -060016#include "ccpr/GrCCDrawPathsOp.h"
Chris Daltona2b5b642018-06-24 13:08:57 -060017#include "ccpr/GrCCPathCache.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060018
Chris Dalton5ba36ba2018-05-09 01:08:38 -060019using PathInstance = GrCCPathProcessor::Instance;
Chris Daltona32a3c32017-12-05 10:05:21 -070020
Chris Dalton1a325d22017-07-14 15:17:41 -060021bool GrCoverageCountingPathRenderer::IsSupported(const GrCaps& caps) {
22 const GrShaderCaps& shaderCaps = *caps.shaderCaps();
Chris Dalton383a2ef2018-01-08 17:21:41 -050023 return shaderCaps.integerSupport() && shaderCaps.flatInterpolationSupport() &&
24 caps.instanceAttribSupport() && GrCaps::kNone_MapFlags != caps.mapBufferFlags() &&
Chris Dalton1a325d22017-07-14 15:17:41 -060025 caps.isConfigTexturable(kAlpha_half_GrPixelConfig) &&
Brian Salomonbdecacf2018-02-02 20:32:49 -050026 caps.isConfigRenderable(kAlpha_half_GrPixelConfig) &&
Chris Dalton4da70192018-06-18 09:51:36 -060027 caps.isConfigTexturable(kAlpha_8_GrPixelConfig) &&
28 caps.isConfigRenderable(kAlpha_8_GrPixelConfig) &&
Chris Daltone4679fa2017-09-29 13:58:26 -060029 !caps.blacklistCoverageCounting();
Chris Dalton1a325d22017-07-14 15:17:41 -060030}
31
Chris Dalton383a2ef2018-01-08 17:21:41 -050032sk_sp<GrCoverageCountingPathRenderer> GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Daltona2b5b642018-06-24 13:08:57 -060033 const GrCaps& caps, AllowCaching allowCaching) {
34 return sk_sp<GrCoverageCountingPathRenderer>(
35 IsSupported(caps) ? new GrCoverageCountingPathRenderer(allowCaching) : nullptr);
36}
37
38GrCoverageCountingPathRenderer::GrCoverageCountingPathRenderer(AllowCaching allowCaching) {
39 if (AllowCaching::kYes == allowCaching) {
40 fPathCache = skstd::make_unique<GrCCPathCache>();
41 }
42}
43
Chris Daltond7e22272018-05-23 10:17:17 -060044GrCCPerOpListPaths* GrCoverageCountingPathRenderer::lookupPendingPaths(uint32_t opListID) {
45 auto it = fPendingPaths.find(opListID);
46 if (fPendingPaths.end() == it) {
Robert Phillips774168e2018-05-31 12:43:27 -040047 sk_sp<GrCCPerOpListPaths> paths = sk_make_sp<GrCCPerOpListPaths>();
Chris Daltond7e22272018-05-23 10:17:17 -060048 it = fPendingPaths.insert(std::make_pair(opListID, std::move(paths))).first;
49 }
50 return it->second.get();
Chris Dalton5ba36ba2018-05-09 01:08:38 -060051}
52
Chris Dalton383a2ef2018-01-08 17:21:41 -050053GrPathRenderer::CanDrawPath GrCoverageCountingPathRenderer::onCanDrawPath(
54 const CanDrawPathArgs& args) const {
Chris Dalton09a7bb22018-08-31 19:53:15 +080055 const GrShape& shape = *args.fShape;
56 if (GrAAType::kCoverage != args.fAAType || shape.style().hasPathEffect() ||
57 args.fViewMatrix->hasPerspective() || shape.inverseFilled()) {
Chris Dalton5ed44232017-09-07 13:22:46 -060058 return CanDrawPath::kNo;
Chris Dalton1a325d22017-07-14 15:17:41 -060059 }
60
61 SkPath path;
Chris Dalton09a7bb22018-08-31 19:53:15 +080062 shape.asPath(&path);
Chris Daltona2b5b642018-06-24 13:08:57 -060063
Chris Dalton82de18f2018-09-12 17:24:09 -060064 const SkStrokeRec& stroke = shape.style().strokeRec();
65 switch (stroke.getStyle()) {
Chris Dalton09a7bb22018-08-31 19:53:15 +080066 case SkStrokeRec::kFill_Style: {
67 SkRect devBounds;
68 args.fViewMatrix->mapRect(&devBounds, path.getBounds());
Chris Daltona2b5b642018-06-24 13:08:57 -060069
Chris Dalton09a7bb22018-08-31 19:53:15 +080070 SkIRect clippedIBounds;
71 devBounds.roundOut(&clippedIBounds);
72 if (!clippedIBounds.intersect(*args.fClipConservativeBounds)) {
73 // The path is completely clipped away. Our code will eventually notice this before
74 // doing any real work.
75 return CanDrawPath::kYes;
76 }
77
78 int64_t numPixels = sk_64_mul(clippedIBounds.height(), clippedIBounds.width());
79 if (path.countVerbs() > 1000 && path.countPoints() > numPixels) {
80 // This is a complicated path that has more vertices than pixels! Let's let the SW
81 // renderer have this one: It will probably be faster and a bitmap will require less
82 // total memory on the GPU than CCPR instance buffers would for the raw path data.
83 return CanDrawPath::kNo;
84 }
85
86 if (numPixels > 256 * 256) {
87 // Large paths can blow up the atlas fast. And they are not ideal for a two-pass
88 // rendering algorithm. Give the simpler direct renderers a chance before we commit
89 // to drawing it.
90 return CanDrawPath::kAsBackup;
91 }
92
93 if (args.fShape->hasUnstyledKey() && path.countVerbs() > 50) {
94 // Complex paths do better cached in an SDF, if the renderer will accept them.
95 return CanDrawPath::kAsBackup;
96 }
97
98 return CanDrawPath::kYes;
99 }
100
101 case SkStrokeRec::kStroke_Style:
102 if (!args.fViewMatrix->isSimilarity()) {
103 // The stroker currently only supports rigid-body transfoms for the stroke lines
104 // themselves. This limitation doesn't affect hairlines since their stroke lines are
105 // defined relative to device space.
106 return CanDrawPath::kNo;
107 }
108 // fallthru
Chris Dalton82de18f2018-09-12 17:24:09 -0600109 case SkStrokeRec::kHairline_Style: {
110 float inflationRadius;
111 GetStrokeDevWidth(*args.fViewMatrix, stroke, &inflationRadius);
112 if (!(inflationRadius <= kMaxBoundsInflationFromStroke)) {
113 // Let extremely wide strokes be converted to fill paths and drawn by the CCPR
114 // filler instead. (Cast the logic negatively in order to also catch r=NaN.)
115 return CanDrawPath::kNo;
116 }
117 SkASSERT(!SkScalarIsNaN(inflationRadius));
118 if (SkPathPriv::ConicWeightCnt(path)) {
119 // The stroker does not support conics yet.
120 return CanDrawPath::kNo;
121 }
122 return CanDrawPath::kYes;
123 }
Chris Dalton09a7bb22018-08-31 19:53:15 +0800124
125 case SkStrokeRec::kStrokeAndFill_Style:
126 return CanDrawPath::kNo;
Chris Daltondb91c6e2017-09-08 16:25:08 -0600127 }
128
Chris Dalton09a7bb22018-08-31 19:53:15 +0800129 SK_ABORT("Invalid stroke style.");
130 return CanDrawPath::kNo;
Chris Dalton1a325d22017-07-14 15:17:41 -0600131}
132
133bool GrCoverageCountingPathRenderer::onDrawPath(const DrawPathArgs& args) {
134 SkASSERT(!fFlushing);
Chris Dalton1a325d22017-07-14 15:17:41 -0600135
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600136 SkIRect clipIBounds;
137 GrRenderTargetContext* rtc = args.fRenderTargetContext;
138 args.fClip->getConservativeBounds(rtc->width(), rtc->height(), &clipIBounds, nullptr);
139
Chris Dalton09a7bb22018-08-31 19:53:15 +0800140 auto op = GrCCDrawPathsOp::Make(args.fContext, clipIBounds, *args.fViewMatrix, *args.fShape,
141 std::move(args.fPaint));
Chris Dalton42c21152018-06-13 15:28:19 -0600142 this->recordOp(std::move(op), args);
Chris Dalton1a325d22017-07-14 15:17:41 -0600143 return true;
144}
145
Chris Dalton42c21152018-06-13 15:28:19 -0600146void GrCoverageCountingPathRenderer::recordOp(std::unique_ptr<GrCCDrawPathsOp> opHolder,
147 const DrawPathArgs& args) {
148 if (GrCCDrawPathsOp* op = opHolder.get()) {
149 GrRenderTargetContext* rtc = args.fRenderTargetContext;
150 if (uint32_t opListID = rtc->addDrawOp(*args.fClip, std::move(opHolder))) {
Chris Daltonb68bcc42018-09-14 00:44:22 -0600151 op->wasRecorded(sk_ref_sp(this->lookupPendingPaths(opListID)));
Chris Dalton42c21152018-06-13 15:28:19 -0600152 }
153 }
154}
155
Chris Dalton383a2ef2018-01-08 17:21:41 -0500156std::unique_ptr<GrFragmentProcessor> GrCoverageCountingPathRenderer::makeClipProcessor(
Chris Dalton4c458b12018-06-16 17:22:59 -0600157 uint32_t opListID, const SkPath& deviceSpacePath, const SkIRect& accessRect, int rtWidth,
158 int rtHeight, const GrCaps& caps) {
Chris Dalton383a2ef2018-01-08 17:21:41 -0500159 using MustCheckBounds = GrCCClipProcessor::MustCheckBounds;
Chris Daltona32a3c32017-12-05 10:05:21 -0700160
161 SkASSERT(!fFlushing);
Chris Daltona32a3c32017-12-05 10:05:21 -0700162
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600163 GrCCClipPath& clipPath =
Chris Daltond7e22272018-05-23 10:17:17 -0600164 this->lookupPendingPaths(opListID)->fClipPaths[deviceSpacePath.getGenerationID()];
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600165 if (!clipPath.isInitialized()) {
Chris Daltona32a3c32017-12-05 10:05:21 -0700166 // This ClipPath was just created during lookup. Initialize it.
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600167 const SkRect& pathDevBounds = deviceSpacePath.getBounds();
168 if (SkTMax(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) {
169 // The path is too large. Crop it or analytic AA can run out of fp32 precision.
170 SkPath croppedPath;
Chris Dalton4c458b12018-06-16 17:22:59 -0600171 int maxRTSize = caps.maxRenderTargetSize();
Chris Dalton09a7bb22018-08-31 19:53:15 +0800172 CropPath(deviceSpacePath, SkIRect::MakeWH(maxRTSize, maxRTSize), &croppedPath);
Chris Dalton4c458b12018-06-16 17:22:59 -0600173 clipPath.init(croppedPath, accessRect, rtWidth, rtHeight, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600174 } else {
Chris Dalton4c458b12018-06-16 17:22:59 -0600175 clipPath.init(deviceSpacePath, accessRect, rtWidth, rtHeight, caps);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600176 }
Chris Daltona32a3c32017-12-05 10:05:21 -0700177 } else {
178 clipPath.addAccess(accessRect);
179 }
180
181 bool mustCheckBounds = !clipPath.pathDevIBounds().contains(accessRect);
Chris Dalton383a2ef2018-01-08 17:21:41 -0500182 return skstd::make_unique<GrCCClipProcessor>(&clipPath, MustCheckBounds(mustCheckBounds),
183 deviceSpacePath.getFillType());
Chris Daltona32a3c32017-12-05 10:05:21 -0700184}
185
Chris Dalton1a325d22017-07-14 15:17:41 -0600186void GrCoverageCountingPathRenderer::preFlush(GrOnFlushResourceProvider* onFlushRP,
187 const uint32_t* opListIDs, int numOpListIDs,
Chris Dalton9414c962018-06-14 10:14:50 -0600188 SkTArray<sk_sp<GrRenderTargetContext>>* out) {
Chris Dalton4da70192018-06-18 09:51:36 -0600189 using DoCopiesToCache = GrCCDrawPathsOp::DoCopiesToCache;
Chris Daltona32a3c32017-12-05 10:05:21 -0700190 SkASSERT(!fFlushing);
Chris Daltond7e22272018-05-23 10:17:17 -0600191 SkASSERT(fFlushingPaths.empty());
Chris Dalton383a2ef2018-01-08 17:21:41 -0500192 SkDEBUGCODE(fFlushing = true);
Chris Daltona32a3c32017-12-05 10:05:21 -0700193
Chris Dalton4da70192018-06-18 09:51:36 -0600194 // Dig up the stashed atlas from the previous flush (if any) so we can attempt to copy any
195 // reusable paths out of it and into the resource cache. We also need to clear its unique key.
196 sk_sp<GrTextureProxy> stashedAtlasProxy;
197 if (fStashedAtlasKey.isValid()) {
198 stashedAtlasProxy = onFlushRP->findOrCreateProxyByUniqueKey(fStashedAtlasKey,
199 GrCCAtlas::kTextureOrigin);
200 if (stashedAtlasProxy) {
201 // Instantiate the proxy so we can clear the underlying texture's unique key.
202 onFlushRP->instatiateProxy(stashedAtlasProxy.get());
203 onFlushRP->removeUniqueKeyFromProxy(fStashedAtlasKey, stashedAtlasProxy.get());
204 } else {
205 fStashedAtlasKey.reset(); // Indicate there is no stashed atlas to copy from.
206 }
207 }
208
Chris Daltond7e22272018-05-23 10:17:17 -0600209 if (fPendingPaths.empty()) {
Chris Dalton4da70192018-06-18 09:51:36 -0600210 fStashedAtlasKey.reset();
Chris Dalton383a2ef2018-01-08 17:21:41 -0500211 return; // Nothing to draw.
Chris Daltona32a3c32017-12-05 10:05:21 -0700212 }
Chris Daltonc1e59632017-09-05 00:30:07 -0600213
Chris Dalton4da70192018-06-18 09:51:36 -0600214 GrCCPerFlushResourceSpecs specs;
Chris Dalton42c21152018-06-13 15:28:19 -0600215 int maxPreferredRTSize = onFlushRP->caps()->maxPreferredRenderTargetSize();
Chris Dalton4da70192018-06-18 09:51:36 -0600216 specs.fCopyAtlasSpecs.fMaxPreferredTextureSize = SkTMin(2048, maxPreferredRTSize);
217 SkASSERT(0 == specs.fCopyAtlasSpecs.fMinTextureSize);
218 specs.fRenderedAtlasSpecs.fMaxPreferredTextureSize = maxPreferredRTSize;
Chris Daltona2b5b642018-06-24 13:08:57 -0600219 specs.fRenderedAtlasSpecs.fMinTextureSize = SkTMin(512, maxPreferredRTSize);
Chris Dalton42c21152018-06-13 15:28:19 -0600220
Chris Daltond7e22272018-05-23 10:17:17 -0600221 // Move the per-opList paths that are about to be flushed from fPendingPaths to fFlushingPaths,
Chris Dalton42c21152018-06-13 15:28:19 -0600222 // and count them up so we can preallocate buffers.
Chris Daltond7e22272018-05-23 10:17:17 -0600223 fFlushingPaths.reserve(numOpListIDs);
Chris Dalton1a325d22017-07-14 15:17:41 -0600224 for (int i = 0; i < numOpListIDs; ++i) {
Chris Daltond7e22272018-05-23 10:17:17 -0600225 auto iter = fPendingPaths.find(opListIDs[i]);
226 if (fPendingPaths.end() == iter) {
227 continue; // No paths on this opList.
Chris Dalton1a325d22017-07-14 15:17:41 -0600228 }
Chris Daltona32a3c32017-12-05 10:05:21 -0700229
tzikbdb49562018-05-28 14:58:00 +0900230 fFlushingPaths.push_back(std::move(iter->second));
Chris Daltond7e22272018-05-23 10:17:17 -0600231 fPendingPaths.erase(iter);
232
Chris Dalton4da70192018-06-18 09:51:36 -0600233 for (GrCCDrawPathsOp* op : fFlushingPaths.back()->fDrawOps) {
Chris Daltona2b5b642018-06-24 13:08:57 -0600234 op->accountForOwnPaths(fPathCache.get(), onFlushRP, fStashedAtlasKey, &specs);
Chris Dalton080baa42017-11-06 14:19:19 -0700235 }
Chris Daltond7e22272018-05-23 10:17:17 -0600236 for (const auto& clipsIter : fFlushingPaths.back()->fClipPaths) {
Chris Dalton4da70192018-06-18 09:51:36 -0600237 clipsIter.second.accountForOwnPath(&specs);
Chris Daltona32a3c32017-12-05 10:05:21 -0700238 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600239 }
Chris Dalton4da70192018-06-18 09:51:36 -0600240 fStashedAtlasKey.reset();
Chris Dalton1a325d22017-07-14 15:17:41 -0600241
Chris Dalton4da70192018-06-18 09:51:36 -0600242 if (specs.isEmpty()) {
Chris Dalton383a2ef2018-01-08 17:21:41 -0500243 return; // Nothing to draw.
Chris Dalton1a325d22017-07-14 15:17:41 -0600244 }
245
Chris Dalton4da70192018-06-18 09:51:36 -0600246 // Determine if there are enough reusable paths from last flush for it to be worth our time to
247 // copy them to cached atlas(es).
Chris Dalton09a7bb22018-08-31 19:53:15 +0800248 int numCopies = specs.fNumCopiedPaths[GrCCPerFlushResourceSpecs::kFillIdx] +
249 specs.fNumCopiedPaths[GrCCPerFlushResourceSpecs::kStrokeIdx];
250 DoCopiesToCache doCopies = DoCopiesToCache(numCopies > 100 ||
Chris Daltona2b5b642018-06-24 13:08:57 -0600251 specs.fCopyAtlasSpecs.fApproxNumPixels > 256 * 256);
Chris Dalton09a7bb22018-08-31 19:53:15 +0800252 if (numCopies && DoCopiesToCache::kNo == doCopies) {
Chris Dalton4da70192018-06-18 09:51:36 -0600253 specs.convertCopiesToRenders();
Chris Dalton09a7bb22018-08-31 19:53:15 +0800254 SkASSERT(!specs.fNumCopiedPaths[GrCCPerFlushResourceSpecs::kFillIdx]);
255 SkASSERT(!specs.fNumCopiedPaths[GrCCPerFlushResourceSpecs::kStrokeIdx]);
Chris Dalton4da70192018-06-18 09:51:36 -0600256 }
257
258 auto resources = sk_make_sp<GrCCPerFlushResources>(onFlushRP, specs);
Chris Dalton5ba36ba2018-05-09 01:08:38 -0600259 if (!resources->isMapped()) {
260 return; // Some allocation failed.
Chris Dalton1a325d22017-07-14 15:17:41 -0600261 }
262
Chris Dalton4da70192018-06-18 09:51:36 -0600263 // Layout the atlas(es) and parse paths.
Chris Daltond7e22272018-05-23 10:17:17 -0600264 for (const auto& flushingPaths : fFlushingPaths) {
265 for (GrCCDrawPathsOp* op : flushingPaths->fDrawOps) {
Chris Dalton4da70192018-06-18 09:51:36 -0600266 op->setupResources(onFlushRP, resources.get(), doCopies);
Chris Dalton1a325d22017-07-14 15:17:41 -0600267 }
Chris Daltond7e22272018-05-23 10:17:17 -0600268 for (auto& clipsIter : flushingPaths->fClipPaths) {
Chris Daltondaef06a2018-05-23 17:11:09 -0600269 clipsIter.second.renderPathInAtlas(resources.get(), onFlushRP);
Chris Daltonc1e59632017-09-05 00:30:07 -0600270 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600271 }
272
Chris Dalton4da70192018-06-18 09:51:36 -0600273 // Allocate resources and then render the atlas(es).
274 if (!resources->finalize(onFlushRP, std::move(stashedAtlasProxy), out)) {
Chris Daltonc1e59632017-09-05 00:30:07 -0600275 return;
Chris Dalton1a325d22017-07-14 15:17:41 -0600276 }
Chris Dalton4da70192018-06-18 09:51:36 -0600277 // Verify the stashed atlas got released so its texture could be recycled.
278 SkASSERT(!stashedAtlasProxy);
Chris Dalton1a325d22017-07-14 15:17:41 -0600279
Chris Daltond7e22272018-05-23 10:17:17 -0600280 // Commit flushing paths to the resources once they are successfully completed.
281 for (auto& flushingPaths : fFlushingPaths) {
Robert Phillips774168e2018-05-31 12:43:27 -0400282 SkASSERT(!flushingPaths->fFlushResources);
Chris Daltond7e22272018-05-23 10:17:17 -0600283 flushingPaths->fFlushResources = resources;
284 }
Chris Dalton1a325d22017-07-14 15:17:41 -0600285}
286
Chris Dalton3968ff92017-11-27 12:26:31 -0700287void GrCoverageCountingPathRenderer::postFlush(GrDeferredUploadToken, const uint32_t* opListIDs,
288 int numOpListIDs) {
Chris Dalton1a325d22017-07-14 15:17:41 -0600289 SkASSERT(fFlushing);
Chris Dalton4da70192018-06-18 09:51:36 -0600290 SkASSERT(!fStashedAtlasKey.isValid()); // Should have been cleared in preFlush().
Robert Phillips774168e2018-05-31 12:43:27 -0400291
Chris Dalton4da70192018-06-18 09:51:36 -0600292 if (!fFlushingPaths.empty()) {
293 // Note the stashed atlas's key for next flush, if any.
294 auto resources = fFlushingPaths.front()->fFlushResources.get();
295 if (resources && resources->hasStashedAtlas()) {
296 fStashedAtlasKey = resources->stashedAtlasKey();
297 }
298
299 // In DDL mode these aren't guaranteed to be deleted so we must clear out the perFlush
300 // resources manually.
301 for (auto& flushingPaths : fFlushingPaths) {
302 flushingPaths->fFlushResources = nullptr;
303 }
304
305 // We wait to erase these until after flush, once Ops and FPs are done accessing their data.
306 fFlushingPaths.reset();
Robert Phillips774168e2018-05-31 12:43:27 -0400307 }
308
Chris Dalton383a2ef2018-01-08 17:21:41 -0500309 SkDEBUGCODE(fFlushing = false);
Chris Dalton1a325d22017-07-14 15:17:41 -0600310}
Chris Dalton09a7bb22018-08-31 19:53:15 +0800311
312void GrCoverageCountingPathRenderer::CropPath(const SkPath& path, const SkIRect& cropbox,
313 SkPath* out) {
314 SkPath cropboxPath;
315 cropboxPath.addRect(SkRect::Make(cropbox));
316 if (!Op(cropboxPath, path, kIntersect_SkPathOp, out)) {
317 // This can fail if the PathOps encounter NaN or infinities.
318 out->reset();
319 }
320 out->setIsVolatile(true);
321}
Chris Dalton82de18f2018-09-12 17:24:09 -0600322
323float GrCoverageCountingPathRenderer::GetStrokeDevWidth(const SkMatrix& m,
324 const SkStrokeRec& stroke,
325 float* inflationRadius) {
326 float strokeDevWidth;
327 if (stroke.isHairlineStyle()) {
328 strokeDevWidth = 1;
329 } else {
330 SkASSERT(SkStrokeRec::kStroke_Style == stroke.getStyle());
331 SkASSERT(m.isSimilarity()); // Otherwise matrixScaleFactor = m.getMaxScale().
332 float matrixScaleFactor = SkVector::Length(m.getScaleX(), m.getSkewY());
333 strokeDevWidth = stroke.getWidth() * matrixScaleFactor;
334 }
335 if (inflationRadius) {
336 // Inflate for a minimum stroke width of 1. In some cases when the stroke is less than 1px
337 // wide, we may inflate it to 1px and instead reduce the opacity.
338 *inflationRadius = SkStrokeRec::GetInflationRadius(
339 stroke.getJoin(), stroke.getMiter(), stroke.getCap(), SkTMax(strokeDevWidth, 1.f));
340 }
341 return strokeDevWidth;
342}