blob: c0b8695c916c95658d70a5305d81db69be20a19b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.comc07d23a2009-02-06 13:30:58 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2009 The Android Open Source Project
reed@android.comc07d23a2009-02-06 13:30:58 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.comc07d23a2009-02-06 13:30:58 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.comc07d23a2009-02-06 13:30:58 +000010#ifndef SkQuadClipper_DEFINED
11#define SkQuadClipper_DEFINED
12
reed@android.com77f0ef72009-11-17 18:47:52 +000013#include "SkPath.h"
reed@android.comc07d23a2009-02-06 13:30:58 +000014
15/** This class is initialized with a clip rectangle, and then can be fed quads,
16 which must already be monotonic in Y.
rmistry@google.comfbfcd562012-08-23 18:09:54 +000017
reed@android.comc07d23a2009-02-06 13:30:58 +000018 In the future, it might return a series of segments, allowing it to clip
19 also in X, to ensure that all segments fit in a finite coordinate system.
20 */
21class SkQuadClipper {
22public:
23 SkQuadClipper();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000024
reed@android.comc07d23a2009-02-06 13:30:58 +000025 void setClip(const SkIRect& clip);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000026
reed@android.com77f0ef72009-11-17 18:47:52 +000027 bool clipQuad(const SkPoint src[3], SkPoint dst[3]);
28
reed@android.comc07d23a2009-02-06 13:30:58 +000029private:
30 SkRect fClip;
31};
32
reed@android.com77f0ef72009-11-17 18:47:52 +000033/** Iterator that returns the clipped segements of a quad clipped to a rect.
34 The segments will be either lines or quads (based on SkPath::Verb), and
35 will all be monotonic in Y
36 */
37class SkQuadClipper2 {
38public:
39 bool clipQuad(const SkPoint pts[3], const SkRect& clip);
reed@android.com3a0cd7f2009-11-17 19:39:51 +000040 bool clipCubic(const SkPoint pts[4], const SkRect& clip);
reed@android.com77f0ef72009-11-17 18:47:52 +000041
42 SkPath::Verb next(SkPoint pts[]);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000043
reed@android.com77f0ef72009-11-17 18:47:52 +000044private:
45 SkPoint* fCurrPoint;
46 SkPath::Verb* fCurrVerb;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000047
reed@android.com77f0ef72009-11-17 18:47:52 +000048 enum {
reed@android.combb135862009-11-18 13:47:40 +000049 kMaxVerbs = 13,
50 kMaxPoints = 32
reed@android.com77f0ef72009-11-17 18:47:52 +000051 };
52 SkPoint fPoints[kMaxPoints];
53 SkPath::Verb fVerbs[kMaxVerbs];
54
55 void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
reed@android.combb135862009-11-18 13:47:40 +000056 void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
reed@android.com77f0ef72009-11-17 18:47:52 +000057 void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
58 void appendQuad(const SkPoint pts[3], bool reverse);
reed@android.com3a0cd7f2009-11-17 19:39:51 +000059 void appendCubic(const SkPoint pts[4], bool reverse);
reed@android.com77f0ef72009-11-17 18:47:52 +000060};
61
reed@android.combb135862009-11-18 13:47:40 +000062#ifdef SK_DEBUG
63 void sk_assert_monotonic_x(const SkPoint pts[], int count);
64 void sk_assert_monotonic_y(const SkPoint pts[], int count);
65#else
66 #define sk_assert_monotonic_x(pts, count)
67 #define sk_assert_monotonic_y(pts, count)
68#endif
69
reed@android.comc07d23a2009-02-06 13:30:58 +000070#endif