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 SkEdgeClipper_DEFINED
     18 #define SkEdgeClipper_DEFINED
     19 
     20 #include "SkPath.h"
     21 
     22 /** This is basically an iterator. It is initialized with an edge and a clip,
     23     and then next() is called until it returns kDone_Verb.
     24  */
     25 class SkEdgeClipper {
     26 public:
     27     bool clipQuad(const SkPoint pts[3], const SkRect& clip);
     28     bool clipCubic(const SkPoint pts[4], const SkRect& clip);
     29 
     30     SkPath::Verb next(SkPoint pts[]);
     31 
     32 private:
     33     SkPoint*        fCurrPoint;
     34     SkPath::Verb*   fCurrVerb;
     35 
     36     enum {
     37         kMaxVerbs = 13,
     38         kMaxPoints = 32
     39     };
     40     SkPoint         fPoints[kMaxPoints];
     41     SkPath::Verb    fVerbs[kMaxVerbs];
     42 
     43     void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
     44     void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
     45     void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
     46     void appendQuad(const SkPoint pts[3], bool reverse);
     47     void appendCubic(const SkPoint pts[4], bool reverse);
     48 };
     49 
     50 #ifdef SK_DEBUG
     51     void sk_assert_monotonic_x(const SkPoint pts[], int count);
     52     void sk_assert_monotonic_y(const SkPoint pts[], int count);
     53 #else
     54     #define sk_assert_monotonic_x(pts, count)
     55     #define sk_assert_monotonic_y(pts, count)
     56 #endif
     57 
     58 #endif
     59