Flutter Engine
The Flutter Engine
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
20 return skpathutils::FillPathWithPaint(src, paint, dst, nullptr, 1);
21}
22
24 const SkRect* cullRect, SkScalar resScale) {
26 SkMatrix::Scale(resScale, resScale));
27}
28
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
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
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
93}
bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale)
Definition: SkPathUtils.cpp:75
static SkScalar ComputeResScaleForStroking(const SkMatrix &matrix)
Definition: SkMatrix.cpp:1877
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
bool filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *, const SkRect *cullR) const
Definition: SkPath.h:59
Style getStyle() const
Definition: SkStrokeRec.cpp:71
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
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
dst
Definition: cp.py:12
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23