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