1 2 /* 3 * Copyright 2009 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #ifndef SkQuadClipper_DEFINED 11 #define SkQuadClipper_DEFINED 12 13 #include "SkPath.h" 14 15 /** This class is initialized with a clip rectangle, and then can be fed quads, 16 which must already be monotonic in Y. 17 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(); 24 25 void setClip(const SkIRect& clip); 26 27 bool clipQuad(const SkPoint src[3], SkPoint dst[3]); 28 29 private: 30 SkRect fClip; 31 }; 32 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); 40 bool clipCubic(const SkPoint pts[4], const SkRect& clip); 41 42 SkPath::Verb next(SkPoint pts[]); 43 44 private: 45 SkPoint* fCurrPoint; 46 SkPath::Verb* fCurrVerb; 47 48 enum { 49 kMaxVerbs = 13, 50 kMaxPoints = 32 51 }; 52 SkPoint fPoints[kMaxPoints]; 53 SkPath::Verb fVerbs[kMaxVerbs]; 54 55 void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip); 56 void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip); 57 void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse); 58 void appendQuad(const SkPoint pts[3], bool reverse); 59 void appendCubic(const SkPoint pts[4], bool reverse); 60 }; 61 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 70 #endif 71