blob: 1dd8576b0a02fff7229aae79f30f32380524f1d6 [file] [log] [blame]
reed@android.comc07d23a2009-02-06 13:30:58 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2009 The Android Open Source Project
reed@android.comc07d23a2009-02-06 13:30:58 +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.comc07d23a2009-02-06 13:30:58 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@android.comc07d23a2009-02-06 13:30:58 +00009#ifndef SkQuadClipper_DEFINED
10#define SkQuadClipper_DEFINED
11
reed@android.com77f0ef72009-11-17 18:47:52 +000012#include "SkPath.h"
reed@android.comc07d23a2009-02-06 13:30:58 +000013
14/** This class is initialized with a clip rectangle, and then can be fed quads,
15 which must already be monotonic in Y.
rmistry@google.comfbfcd562012-08-23 18:09:54 +000016
reed@android.comc07d23a2009-02-06 13:30:58 +000017 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 */
20class SkQuadClipper {
21public:
22 SkQuadClipper();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000023
reed@android.comc07d23a2009-02-06 13:30:58 +000024 void setClip(const SkIRect& clip);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000025
reed@android.com77f0ef72009-11-17 18:47:52 +000026 bool clipQuad(const SkPoint src[3], SkPoint dst[3]);
27
reed@android.comc07d23a2009-02-06 13:30:58 +000028private:
29 SkRect fClip;
30};
31
reed@android.com77f0ef72009-11-17 18:47:52 +000032/** 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 */
36class SkQuadClipper2 {
37public:
38 bool clipQuad(const SkPoint pts[3], const SkRect& clip);
reed@android.com3a0cd7f2009-11-17 19:39:51 +000039 bool clipCubic(const SkPoint pts[4], const SkRect& clip);
reed@android.com77f0ef72009-11-17 18:47:52 +000040
41 SkPath::Verb next(SkPoint pts[]);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000042
reed@android.com77f0ef72009-11-17 18:47:52 +000043private:
44 SkPoint* fCurrPoint;
45 SkPath::Verb* fCurrVerb;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000046
reed@android.com77f0ef72009-11-17 18:47:52 +000047 enum {
reed@android.combb135862009-11-18 13:47:40 +000048 kMaxVerbs = 13,
49 kMaxPoints = 32
reed@android.com77f0ef72009-11-17 18:47:52 +000050 };
51 SkPoint fPoints[kMaxPoints];
52 SkPath::Verb fVerbs[kMaxVerbs];
53
54 void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
reed@android.combb135862009-11-18 13:47:40 +000055 void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
reed@android.com77f0ef72009-11-17 18:47:52 +000056 void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
57 void appendQuad(const SkPoint pts[3], bool reverse);
reed@android.com3a0cd7f2009-11-17 19:39:51 +000058 void appendCubic(const SkPoint pts[4], bool reverse);
reed@android.com77f0ef72009-11-17 18:47:52 +000059};
60
reed@android.combb135862009-11-18 13:47:40 +000061#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
reed@android.comc07d23a2009-02-06 13:30:58 +000069#endif