| 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 |
|
| 8 |
#include "include/core/SkPathUtils.h" |
| 9 |
|
| 10 |
#include "include/core/SkMatrix.h" |
| 11 |
#include "include/core/SkPaint.h" |
| 12 |
#include "include/core/SkPath.h" |
| 13 |
#include "include/core/SkPathBuilder.h" |
| 14 |
#include "include/core/SkPathEffect.h" |
| 15 |
#include "include/core/SkScalar.h" |
| 16 |
#include "include/core/SkStrokeRec.h" |
| 17 |
#include "src/core/SkMatrixPriv.h" |
| 18 |
|
| 19 |
namespace skpathutils { |
| 20 |
|
| 21 |
bool FillPathWithPaint(const SkPath& origSrc, const SkPaint& paint, SkPathBuilder* builder, |
| 22 |
const SkRect* cullRect, const SkMatrix& ctm) { |
| 23 |
if (!origSrc.isFinite()) { |
| 24 |
builder->reset(); |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
const SkScalar resScale = SkMatrixPriv::ComputeResScaleForStroking(ctm); |
| 29 |
SkStrokeRec rec(paint, resScale); |
| 30 |
|
| 31 |
#if defined(SK_BUILD_FOR_FUZZER) |
| 32 |
// Prevent lines with small widths from timing out. |
| 33 |
if (rec.getStyle() == SkStrokeRec::Style::kStroke_Style && rec.getWidth() < 0.001) { |
| 34 |
return false; |
| 35 |
} |
| 36 |
#endif |
| 37 |
|
| 38 |
const SkPath* srcPtr = &origSrc; |
| 39 |
SkPath pathStorage; |
| 40 |
SkPathEffect* pe = paint.getPathEffect(); |
| 41 |
if (pe && pe->filterPath(builder, origSrc, &rec, cullRect, ctm)) { |
| 42 |
pathStorage = builder->detach(); |
| 43 |
srcPtr = &pathStorage; |
| 44 |
} |
| 45 |
if (!rec.applyToPath(builder, *srcPtr)) { |
| 46 |
*builder = *srcPtr; |
| 47 |
} |
| 48 |
|
| 49 |
if (!builder->isFinite()) { |
| 50 |
builder->reset(); |
| 51 |
} |
| 52 |
return !rec.isHairlineStyle(); |
| 53 |
} |
| 54 |
|
| 55 |
bool FillPathWithPaint(const SkPath& src, const SkPaint& paint, SkPathBuilder* dst) { |
| 56 |
return FillPathWithPaint(src, paint, dst, nullptr, SkMatrix::I()); |
| 57 |
} |
| 58 |
|
| 59 |
SkPath FillPathWithPaint(const SkPath& src, const SkPaint& paint, bool* isFillPtr) { |
| 60 |
SkPathBuilder builder; |
| 61 |
bool isFill = FillPathWithPaint(src, paint, &builder); |
| 62 |
if (isFillPtr) { |
| 63 |
*isFillPtr = isFill; |
| 64 |
} |
| 65 |
return builder.detach(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
} // namespace skpathutils |