Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkQuadClipper_DEFINED
     18 #define SkQuadClipper_DEFINED
     19 
     20 #include "SkPath.h"
     21 
     22 /** This class is initialized with a clip rectangle, and then can be fed quads,
     23     which must already be monotonic in Y.
     24 
     25     In the future, it might return a series of segments, allowing it to clip
     26     also in X, to ensure that all segments fit in a finite coordinate system.
     27  */
     28 class SkQuadClipper {
     29 public:
     30     SkQuadClipper();
     31 
     32     void setClip(const SkIRect& clip);
     33 
     34     bool clipQuad(const SkPoint src[3], SkPoint dst[3]);
     35 
     36 private:
     37     SkRect      fClip;
     38 };
     39 
     40 /** Iterator that returns the clipped segements of a quad clipped to a rect.
     41     The segments will be either lines or quads (based on SkPath::Verb), and
     42     will all be monotonic in Y
     43  */
     44 class SkQuadClipper2 {
     45 public:
     46     bool clipQuad(const SkPoint pts[3], const SkRect& clip);
     47     bool clipCubic(const SkPoint pts[4], const SkRect& clip);
     48 
     49     SkPath::Verb next(SkPoint pts[]);
     50 
     51 private:
     52     SkPoint*        fCurrPoint;
     53     SkPath::Verb*   fCurrVerb;
     54 
     55     enum {
     56         kMaxVerbs = 13,
     57         kMaxPoints = 32
     58     };
     59     SkPoint         fPoints[kMaxPoints];
     60     SkPath::Verb    fVerbs[kMaxVerbs];
     61 
     62     void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
     63     void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
     64     void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
     65     void appendQuad(const SkPoint pts[3], bool reverse);
     66     void appendCubic(const SkPoint pts[4], bool reverse);
     67 };
     68 
     69 #ifdef SK_DEBUG
     70     void sk_assert_monotonic_x(const SkPoint pts[], int count);
     71     void sk_assert_monotonic_y(const SkPoint pts[], int count);
     72 #else
     73     #define sk_assert_monotonic_x(pts, count)
     74     #define sk_assert_monotonic_y(pts, count)
     75 #endif
     76 
     77 #endif
     78