blob: e460c1cd879aae548f2d67ec72690844c9bd666e [file] [log] [blame]
reed@android.com909994f2009-11-18 16:09:51 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2009 The Android Open Source Project
reed@android.com909994f2009-11-18 16:09:51 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com909994f2009-11-18 16:09:51 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@android.com909994f2009-11-18 16:09:51 +00009#ifndef SkEdgeClipper_DEFINED
10#define SkEdgeClipper_DEFINED
11
12#include "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 */
17class SkEdgeClipper {
18public:
reed31223e02015-02-09 08:33:07 -080019 SkEdgeClipper(bool canCullToTheRight) : fCanCullToTheRight(canCullToTheRight) {}
20
reed@android.com909994f2009-11-18 16:09:51 +000021 bool clipQuad(const SkPoint pts[3], const SkRect& clip);
22 bool clipCubic(const SkPoint pts[4], const SkRect& clip);
23
24 SkPath::Verb next(SkPoint pts[]);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000025
reed31223e02015-02-09 08:33:07 -080026 bool canCullToTheRight() const { return fCanCullToTheRight; }
27
reed@android.com909994f2009-11-18 16:09:51 +000028private:
29 SkPoint* fCurrPoint;
30 SkPath::Verb* fCurrVerb;
reed31223e02015-02-09 08:33:07 -080031 const bool fCanCullToTheRight;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000032
reed@android.com909994f2009-11-18 16:09:51 +000033 enum {
34 kMaxVerbs = 13,
35 kMaxPoints = 32
36 };
37 SkPoint fPoints[kMaxPoints];
38 SkPath::Verb fVerbs[kMaxVerbs];
39
40 void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
41 void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
42 void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
43 void appendQuad(const SkPoint pts[3], bool reverse);
44 void appendCubic(const SkPoint pts[4], bool reverse);
45};
46
47#ifdef SK_DEBUG
48 void sk_assert_monotonic_x(const SkPoint pts[], int count);
49 void sk_assert_monotonic_y(const SkPoint pts[], int count);
50#else
51 #define sk_assert_monotonic_x(pts, count)
52 #define sk_assert_monotonic_y(pts, count)
53#endif
54
55#endif