Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPathUtils.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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
9
12#include "include/core/SkPath.h"
16
17namespace skpathutils {
18
19bool FillPathWithPaint(const SkPath& src, const SkPaint& paint, SkPath* dst) {
20 return skpathutils::FillPathWithPaint(src, paint, dst, nullptr, 1);
21}
22
23bool FillPathWithPaint(const SkPath& src, const SkPaint& paint, SkPath* dst,
24 const SkRect* cullRect, SkScalar resScale) {
25 return skpathutils::FillPathWithPaint(src, paint, dst, cullRect,
26 SkMatrix::Scale(resScale, resScale));
27}
28
29bool FillPathWithPaint(const SkPath& src, const SkPaint& paint, SkPath* dst,
30 const SkRect* cullRect, const SkMatrix& ctm) {
31 if (!src.isFinite()) {
32 dst->reset();
33 return false;
34 }
35
37 SkStrokeRec rec(paint, resScale);
38
39#if defined(SK_BUILD_FOR_FUZZER)
40 // Prevent lines with small widths from timing out.
41 if (rec.getStyle() == SkStrokeRec::Style::kStroke_Style && rec.getWidth() < 0.001) {
42 return false;
43 }
44#endif
45
46 const SkPath* srcPtr = &src;
47 SkPath tmpPath;
48
49 SkPathEffect* pe = paint.getPathEffect();
50 if (pe && pe->filterPath(&tmpPath, src, &rec, cullRect, ctm)) {
51 srcPtr = &tmpPath;
52 }
53
54 if (!rec.applyToPath(dst, *srcPtr)) {
55 if (srcPtr == &tmpPath) {
56 // If path's were copy-on-write, this trick would not be needed.
57 // As it is, we want to save making a deep-copy from tmpPath -> dst
58 // since we know we're just going to delete tmpPath when we return,
59 // so the swap saves that copy.
60 dst->swap(tmpPath);
61 } else {
62 *dst = *srcPtr;
63 }
64 }
65
66 if (!dst->isFinite()) {
67 dst->reset();
68 return false;
69 }
70 return !rec.isHairlineStyle();
71}
72
73} // namespace skpathutils
74
75bool FillPathWithPaint(const SkPath& src,
76 const SkPaint& paint,
77 SkPath* dst,
78 const SkRect* cullRect,
79 SkScalar resScale) {
80 return skpathutils::FillPathWithPaint(src, paint, dst, cullRect, resScale);
81}
82
83bool FillPathWithPaint(const SkPath& src,
84 const SkPaint& paint,
85 SkPath* dst,
86 const SkRect* cullRect,
87 const SkMatrix& ctm) {
88 return skpathutils::FillPathWithPaint(src, paint, dst, cullRect, ctm);
89}
90
91bool FillPathWithPaint(const SkPath& src, const SkPaint& paint, SkPath* dst) {
92 return skpathutils::FillPathWithPaint(src, paint, dst);
93}
bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale)
static SkScalar ComputeResScaleForStroking(const SkMatrix &matrix)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
bool filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *, const SkRect *cullR) const
Style getStyle() const
bool isHairlineStyle() const
Definition SkStrokeRec.h:47
bool applyToPath(SkPath *dst, const SkPath &src) const
SkScalar getWidth() const
Definition SkStrokeRec.h:42
const Paint & paint
float SkScalar
Definition extension.cpp:12
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)