| 1 | /* |
| 2 | * Copyright 2020 Google Inc. |
| 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 | #pragma once |
| 9 | |
| 10 | #include "include/core/SkPathTypes.h" |
| 11 | #include "include/core/SkPoint.h" |
| 12 | #include "include/core/SkRect.h" |
| 13 | #include "src/core/SkSpan.h" |
| 14 | |
| 15 | struct SkPathView { |
| 16 | SkPathView(SkSpan<const SkPoint> points, SkSpan<const uint8_t> verbs, SkSpan<const float> weights, |
| 17 | SkPathFillType ft, SkPathConvexityType ct, const SkRect& bounds, unsigned segmentMask, |
| 18 | bool isFinite) |
| 19 | : fPoints(points) |
| 20 | , fVerbs(verbs) |
| 21 | , fWeights(weights) |
| 22 | , fBounds(bounds) |
| 23 | , fFillType(ft) |
| 24 | , fConvexity(ct) |
| 25 | , fSegmentMask(segmentMask) |
| 26 | , fIsFinite(isFinite) |
| 27 | { |
| 28 | this->validate(); |
| 29 | } |
| 30 | |
| 31 | bool isInverseFillType() const { return SkPathFillType_IsInverse(fFillType); } |
| 32 | bool isConvex() const { return fConvexity == SkPathConvexityType::kConvex; } |
| 33 | |
| 34 | bool isEmpty() const { return fPoints.size() == 0; } |
| 35 | |
| 36 | bool isRect(SkRect*) const; |
| 37 | bool isFinite() const { return fIsFinite; } |
| 38 | |
| 39 | SkSpan<const SkPoint> fPoints; |
| 40 | SkSpan<const uint8_t> fVerbs; |
| 41 | SkSpan<const float> fWeights; |
| 42 | |
| 43 | SkRect fBounds; |
| 44 | |
| 45 | SkPathFillType fFillType; |
| 46 | SkPathConvexityType fConvexity; |
| 47 | uint8_t fSegmentMask; |
| 48 | bool fIsFinite; |
| 49 | |
| 50 | #ifdef SK_DEBUG |
| 51 | void validate() const; |
| 52 | #else |
| 53 | void validate() const {} |
| 54 | #endif |
| 55 | }; |
| 56 | |
| 57 | static inline SkPathView SkPathView_triangle(const SkPoint pts[3], const SkRect& bounds) { |
| 58 | static constexpr uint8_t verbs[] = { |
| 59 | (uint8_t)SkPathVerb::kMove, |
| 60 | (uint8_t)SkPathVerb::kLine, |
| 61 | (uint8_t)SkPathVerb::kLine, |
| 62 | }; |
| 63 | return SkPathView({pts, 3}, SkMakeSpan(verbs), {}, |
| 64 | SkPathFillType::kWinding, SkPathConvexityType::kConvex, |
| 65 | bounds, kLine_SkPathSegmentMask, true); |
| 66 | } |
| 67 | |
| 68 | static inline SkPathView SkPathView_quad(const SkPoint pts[4], const SkRect& bounds) { |
| 69 | static constexpr uint8_t verbs[] = { |
| 70 | (uint8_t)SkPathVerb::kMove, |
| 71 | (uint8_t)SkPathVerb::kLine, |
| 72 | (uint8_t)SkPathVerb::kLine, |
| 73 | (uint8_t)SkPathVerb::kLine, |
| 74 | }; |
| 75 | return SkPathView({pts, 4}, SkMakeSpan(verbs), {}, |
| 76 | SkPathFillType::kWinding, SkPathConvexityType::kConvex, |
| 77 | bounds, kLine_SkPathSegmentMask, true); |
| 78 | }; |
| 79 | |