Skip to content

Commit 4eb7c23

Browse files
kcbannerSkia Commit-Bot
authored andcommitted
- GrGLPath: Fix hitting an assert when a style applies a path effect that results in an empty path
- Add rendering test for the empty path case Bug: skia:10909 Change-Id: I19188c58d4ee0841e441c33f4c1a5ed27dc2fd25 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332736 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
1 parent 1448eb9 commit 4eb7c23

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Amazon, Inc <*@amazon.com>
1717
Anthony Catel <paraboul@gmail.com>
1818
ARM <*@arm.com>
1919
Bharat Ahuja <ahujabharat93@gmail.com>
20+
Casey Banner <kcbanner@gmail.com>
2021
Dawson Coleman <dawsonmcoleman@gmail.com>
2122
Deepak Mohan <hop2deep@gmail.com>
2223
Ehsan Akhgari <ehsan.akhgari@gmail.com>

gm/dashing.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,28 @@ DEF_SIMPLE_GM(thin_aa_dash_lines, canvas, 330, 110) {
600600
}
601601
}
602602

603+
DEF_SIMPLE_GM(path_effect_empty_result, canvas, 100, 100) {
604+
SkPaint p;
605+
p.setStroke(true);
606+
p.setStrokeWidth(1);
607+
608+
SkPath path;
609+
float r = 70;
610+
float l = 70;
611+
float t = 70;
612+
float b = 70;
613+
path.moveTo(l, t);
614+
path.lineTo(r, t);
615+
path.lineTo(r, b);
616+
path.lineTo(l, b);
617+
path.close();
618+
619+
float dashes[] = {2.f, 2.f};
620+
p.setPathEffect(SkDashPathEffect::Make(dashes, 2, 0.f));
621+
622+
canvas->drawPath(path, p);
623+
}
624+
603625
//////////////////////////////////////////////////////////////////////////////
604626

605627
DEF_GM(return new DashingGM;)

src/gpu/gl/GrGLPath.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -286,36 +286,43 @@ GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStyle& style)
286286
stroke = style.strokeRec();
287287
}
288288

289-
bool didInit = false;
290-
if (stroke.needToApply() && stroke.getCap() != SkPaint::kButt_Cap) {
291-
// Skia stroking and NVPR stroking differ with respect to stroking
292-
// end caps of empty subpaths.
293-
// Convert stroke to fill if path contains empty subpaths.
294-
didInit = InitPathObjectPathDataCheckingDegenerates(gpu, fPathID, *skPath);
295-
if (!didInit) {
296-
if (!tmpPath.isValid()) {
297-
tmpPath.init();
289+
// applyPathEffectToPath could have generated an empty path
290+
if (skPath->isEmpty()) {
291+
InitPathObjectEmptyPath(gpu, fPathID);
292+
fShouldStroke = false;
293+
fShouldFill = false;
294+
} else {
295+
bool didInit = false;
296+
if (stroke.needToApply() && stroke.getCap() != SkPaint::kButt_Cap) {
297+
// Skia stroking and NVPR stroking differ with respect to stroking
298+
// end caps of empty subpaths.
299+
// Convert stroke to fill if path contains empty subpaths.
300+
didInit = InitPathObjectPathDataCheckingDegenerates(gpu, fPathID, *skPath);
301+
if (!didInit) {
302+
if (!tmpPath.isValid()) {
303+
tmpPath.init();
304+
}
305+
SkAssertResult(stroke.applyToPath(tmpPath.get(), *skPath));
306+
skPath = tmpPath.get();
307+
stroke.setFillStyle();
298308
}
299-
SkAssertResult(stroke.applyToPath(tmpPath.get(), *skPath));
300-
skPath = tmpPath.get();
301-
stroke.setFillStyle();
302309
}
303-
}
304310

305-
if (!didInit) {
306-
InitPathObjectPathData(gpu, fPathID, *skPath);
307-
}
311+
if (!didInit) {
312+
InitPathObjectPathData(gpu, fPathID, *skPath);
313+
}
308314

309-
fShouldStroke = stroke.needToApply();
310-
fShouldFill = stroke.isFillStyle() ||
315+
fShouldStroke = stroke.needToApply();
316+
fShouldFill = stroke.isFillStyle() ||
311317
stroke.getStyle() == SkStrokeRec::kStrokeAndFill_Style;
312318

313-
fFillType = convert_skpath_filltype(skPath->getFillType());
314-
fBounds = skPath->getBounds();
315-
SkScalar radius = stroke.getInflationRadius();
316-
fBounds.outset(radius, radius);
317-
if (fShouldStroke) {
318-
InitPathObjectStroke(gpu, fPathID, stroke);
319+
fFillType = convert_skpath_filltype(skPath->getFillType());
320+
fBounds = skPath->getBounds();
321+
SkScalar radius = stroke.getInflationRadius();
322+
fBounds.outset(radius, radius);
323+
if (fShouldStroke) {
324+
InitPathObjectStroke(gpu, fPathID, stroke);
325+
}
319326
}
320327
}
321328

0 commit comments

Comments
 (0)