180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2009 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkQuadClipper_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkQuadClipper_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPath.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** This class is initialized with a clip rectangle, and then can be fed quads,
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    which must already be monotonic in Y.
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    In the future, it might return a series of segments, allowing it to clip
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    also in X, to ensure that all segments fit in a finite coordinate system.
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkQuadClipper {
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkQuadClipper();
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setClip(const SkIRect& clip);
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool clipQuad(const SkPoint src[3], SkPoint dst[3]);
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkRect      fClip;
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** Iterator that returns the clipped segements of a quad clipped to a rect.
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    The segments will be either lines or quads (based on SkPath::Verb), and
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    will all be monotonic in Y
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkQuadClipper2 {
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool clipQuad(const SkPoint pts[3], const SkRect& clip);
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool clipCubic(const SkPoint pts[4], const SkRect& clip);
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkPath::Verb next(SkPoint pts[]);
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkPoint*        fCurrPoint;
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkPath::Verb*   fCurrVerb;
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum {
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kMaxVerbs = 13,
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kMaxPoints = 32
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkPoint         fPoints[kMaxPoints];
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkPath::Verb    fVerbs[kMaxVerbs];
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip);
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip);
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse);
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void appendQuad(const SkPoint pts[3], bool reverse);
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void appendCubic(const SkPoint pts[4], bool reverse);
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DEBUG
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void sk_assert_monotonic_x(const SkPoint pts[], int count);
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void sk_assert_monotonic_y(const SkPoint pts[], int count);
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#else
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    #define sk_assert_monotonic_x(pts, count)
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    #define sk_assert_monotonic_y(pts, count)
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
71