| 1 |
/* |
| 2 |
* Copyright 2025 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/SkPathTypes.h" |
| 9 |
#include "include/private/base/SkAssert.h" |
| 10 |
#include "src/core/SkPathPriv.h" |
| 11 |
#include "src/core/SkPathRaw.h" |
| 12 |
|
| 13 |
const uint8_t gVerbToSegmentMask[] = { |
| 14 |
0, // move |
| 15 |
kLine_SkPathSegmentMask, |
| 16 |
kQuad_SkPathSegmentMask, |
| 17 |
kConic_SkPathSegmentMask, |
| 18 |
kCubic_SkPathSegmentMask, |
| 19 |
0, // close |
| 20 |
}; |
| 21 |
|
| 22 |
uint8_t SkPathPriv::ComputeSegmentMask(SkSpan<const SkPathVerb> verbs) { |
| 23 |
unsigned mask = 0; |
| 24 |
for (auto v : verbs) { |
| 25 |
unsigned i = static_cast<unsigned>(v); |
| 26 |
SkASSERT(i < std::size(gVerbToSegmentMask)); |
| 27 |
mask |= gVerbToSegmentMask[i]; |
| 28 |
} |
| 29 |
return SkTo<uint8_t>(mask); |
| 30 |
} |
| 31 |
|
| 32 |
std::optional<SkRect> SkPathRaw::isRect() const { |
| 33 |
if (auto rc = SkPathPriv::IsRectContour(fPoints, fVerbs, fSegmentMask, false)) { |
| 34 |
return rc->fRect; |
| 35 |
} |
| 36 |
return {}; |
| 37 |
} |