epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2009 The Android Open Source Project |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 10 | #ifndef SkQuadClipper_DEFINED |
| 11 | #define SkQuadClipper_DEFINED |
| 12 | |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 13 | #include "SkPath.h" |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 14 | |
| 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 17 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 18 | 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 | */ |
| 21 | class SkQuadClipper { |
| 22 | public: |
| 23 | SkQuadClipper(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 24 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 25 | void setClip(const SkIRect& clip); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 26 | |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 27 | bool clipQuad(const SkPoint src[3], SkPoint dst[3]); |
| 28 | |
reed@android.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 29 | private: |
| 30 | SkRect fClip; |
| 31 | }; |
| 32 | |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 33 | /** 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 | */ |
| 37 | class SkQuadClipper2 { |
| 38 | public: |
| 39 | bool clipQuad(const SkPoint pts[3], const SkRect& clip); |
reed@android.com | 3a0cd7f | 2009-11-17 19:39:51 +0000 | [diff] [blame] | 40 | bool clipCubic(const SkPoint pts[4], const SkRect& clip); |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 41 | |
| 42 | SkPath::Verb next(SkPoint pts[]); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 43 | |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 44 | private: |
| 45 | SkPoint* fCurrPoint; |
| 46 | SkPath::Verb* fCurrVerb; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 47 | |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 48 | enum { |
reed@android.com | bb13586 | 2009-11-18 13:47:40 +0000 | [diff] [blame] | 49 | kMaxVerbs = 13, |
| 50 | kMaxPoints = 32 |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 51 | }; |
| 52 | SkPoint fPoints[kMaxPoints]; |
| 53 | SkPath::Verb fVerbs[kMaxVerbs]; |
| 54 | |
| 55 | void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip); |
reed@android.com | bb13586 | 2009-11-18 13:47:40 +0000 | [diff] [blame] | 56 | void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip); |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 57 | void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse); |
| 58 | void appendQuad(const SkPoint pts[3], bool reverse); |
reed@android.com | 3a0cd7f | 2009-11-17 19:39:51 +0000 | [diff] [blame] | 59 | void appendCubic(const SkPoint pts[4], bool reverse); |
reed@android.com | 77f0ef7 | 2009-11-17 18:47:52 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
reed@android.com | bb13586 | 2009-11-18 13:47:40 +0000 | [diff] [blame] | 62 | #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.com | c07d23a | 2009-02-06 13:30:58 +0000 | [diff] [blame] | 70 | #endif |