blob: 1a12c1e81a7b0282a34fd1891f441339603d5bde [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
Mike Reed5baafa82017-01-26 14:21:26 -050021 bool clipLine(SkPoint p0, SkPoint p1, const SkRect& clip);
reed@android.com909994f2009-11-18 16:09:51 +000022 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[]);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000026
reed31223e02015-02-09 08:33:07 -080027 bool canCullToTheRight() const { return fCanCullToTheRight; }
28
reed@android.com909994f2009-11-18 16:09:51 +000029private:
30 SkPoint* fCurrPoint;
31 SkPath::Verb* fCurrVerb;
reed31223e02015-02-09 08:33:07 -080032 const bool fCanCullToTheRight;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000033
reed@android.com909994f2009-11-18 16:09:51 +000034 enum {
Cary Clark44c1b112017-03-21 16:11:54 -040035 kMaxVerbs = 18, // max curvature in X and Y split cubic into 9 pieces, * (line + cubic)
36 kMaxPoints = 54 // 2 lines + 1 cubic require 6 points; times 9 pieces
reed@android.com909994f2009-11-18 16:09:51 +000037 };
38 SkPoint fPoints[kMaxPoints];
39 SkPath::Verb fVerbs[kMaxVerbs];
40
41 void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
42 void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
Mike Reed5baafa82017-01-26 14:21:26 -050043 void appendLine(SkPoint p0, SkPoint p1);
reed@android.com909994f2009-11-18 16:09:51 +000044 void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
45 void appendQuad(const SkPoint pts[3], bool reverse);
46 void appendCubic(const SkPoint pts[4], bool reverse);
47};
48
49#ifdef SK_DEBUG
50 void sk_assert_monotonic_x(const SkPoint pts[], int count);
51 void sk_assert_monotonic_y(const SkPoint pts[], int count);
52#else
53 #define sk_assert_monotonic_x(pts, count)
54 #define sk_assert_monotonic_y(pts, count)
55#endif
56
57#endif