| 1 |
/* |
| 2 |
* Copyright 2009 The Android Open Source Project |
| 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 |
|
| 9 |
#ifndef SkEdgeClipper_DEFINED |
| 10 |
#define SkEdgeClipper_DEFINED |
| 11 |
|
| 12 |
#include "include/core/SkPathTypes.h" |
| 13 |
#include "include/core/SkPoint.h" |
| 14 |
#include "include/core/SkScalar.h" |
| 15 |
#include "include/private/base/SkDebug.h" |
| 16 |
|
| 17 |
#include <optional> |
| 18 |
|
| 19 |
struct SkPathRaw; |
| 20 |
struct SkRect; |
| 21 |
|
| 22 |
/** This is basically an iterator. It is initialized with an edge and a clip, |
| 23 |
and then next() is called until it returns kDone_Verb. |
| 24 |
*/ |
| 25 |
class SkEdgeClipper { |
| 26 |
public: |
| 27 |
explicit SkEdgeClipper(bool canCullToTheRight) : fCanCullToTheRight(canCullToTheRight) {} |
| 28 |
|
| 29 |
bool clipLine(SkPoint p0, SkPoint p1, const SkRect& clip); |
| 30 |
bool clipQuad(const SkPoint pts[3], const SkRect& clip); |
| 31 |
bool clipCubic(const SkPoint pts[4], const SkRect& clip); |
| 32 |
|
| 33 |
std::optional<SkPathVerb> next(SkPoint pts[]); |
| 34 |
|
| 35 |
bool canCullToTheRight() const { return fCanCullToTheRight; } |
| 36 |
|
| 37 |
/** |
| 38 |
* Clips each segment from the path, and passes the result (in a clipper) to the |
| 39 |
* consume proc. |
| 40 |
*/ |
| 41 |
static void ClipPath(const SkPathRaw&, const SkRect& clip, bool canCullToTheRight, |
| 42 |
void (*consume)(SkEdgeClipper*, bool newCtr, void* ctx), void* ctx); |
| 43 |
|
| 44 |
private: |
| 45 |
SkPoint* fCurrPoint; |
| 46 |
SkPathVerb* fCurrVerb, *fCurrVerbStop; |
| 47 |
const bool fCanCullToTheRight; |
| 48 |
|
| 49 |
enum { |
| 50 |
kMaxVerbs = 18, // max curvature in X and Y split cubic into 9 pieces, * (line + cubic) |
| 51 |
kMaxPoints = 54 // 2 lines + 1 cubic require 6 points; times 9 pieces |
| 52 |
}; |
| 53 |
SkPoint fPoints[kMaxPoints]; |
| 54 |
SkPathVerb fVerbs[kMaxVerbs]; |
| 55 |
|
| 56 |
void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip); |
| 57 |
void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip); |
| 58 |
void appendLine(SkPoint p0, SkPoint p1); |
| 59 |
void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse); |
| 60 |
void appendQuad(const SkPoint pts[3], bool reverse); |
| 61 |
void appendCubic(const SkPoint pts[4], bool reverse); |
| 62 |
}; |
| 63 |
|
| 64 |
#ifdef SK_DEBUG |
| 65 |
void sk_assert_monotonic_x(const SkPoint pts[], int count); |
| 66 |
void sk_assert_monotonic_y(const SkPoint pts[], int count); |
| 67 |
#else |
| 68 |
#define sk_assert_monotonic_x(pts, count) |
| 69 |
#define sk_assert_monotonic_y(pts, count) |
| 70 |
#endif |
| 71 |
|
| 72 |
#endif |