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 SkQuadClipper_DEFINED
10 #define SkQuadClipper_DEFINED
11 
12 #include "include/core/SkPath.h"
13 
14 /** This class is initialized with a clip rectangle, and then can be fed quads,
15     which must already be monotonic in Y.
16 
17     In the future, it might return a series of segments, allowing it to clip
18     also in X, to ensure that all segments fit in a finite coordinate system.
19  */
20 class SkQuadClipper {
21 public:
22     SkQuadClipper();
23 
24     void setClip(const SkIRect& clip);
25 
26     bool clipQuad(const SkPoint src[3], SkPoint dst[3]);
27 
28 private:
29     SkRect      fClip;
30 };
31 
32 /** Iterator that returns the clipped segements of a quad clipped to a rect.
33     The segments will be either lines or quads (based on SkPath::Verb), and
34     will all be monotonic in Y
35  */
36 class SkQuadClipper2 {
37 public:
38     bool clipQuad(const SkPoint pts[3], const SkRect& clip);
39     bool clipCubic(const SkPoint pts[4], const SkRect& clip);
40 
41     SkPath::Verb next(SkPoint pts[]);
42 
43 private:
44     SkPoint*        fCurrPoint;
45     SkPath::Verb*   fCurrVerb;
46 
47     enum {
48         kMaxVerbs = 13,
49         kMaxPoints = 32
50     };
51     SkPoint         fPoints[kMaxPoints];
52     SkPath::Verb    fVerbs[kMaxVerbs];
53 
54     void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
55     void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
56     void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
57     void appendQuad(const SkPoint pts[3], bool reverse);
58     void appendCubic(const SkPoint pts[4], bool reverse);
59 };
60 
61 #ifdef SK_DEBUG
62     void sk_assert_monotonic_x(const SkPoint pts[], int count);
63     void sk_assert_monotonic_y(const SkPoint pts[], int count);
64 #else
65     #define sk_assert_monotonic_x(pts, count)
66     #define sk_assert_monotonic_y(pts, count)
67 #endif
68 
69 #endif
70