SkPath.h revision 6b8dbb668f1f069270d35a47cfe98decd059c625
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPath_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPath_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1365a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com#include "SkInstCnt.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h"
15ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com#include "SkPathRef.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDArray.h"
171dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com#include "SkRefCnt.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
19739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkReader32;
20739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkWriter32;
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoPathBoundsUpdate;
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkString;
234ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect;
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkPath
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    The SkPath class encapsulates compound (multiple contour) geometric paths
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    consisting of straight line segments, quadratic curves, and cubic curves.
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
307ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkPath {
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
3265a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com    SK_DECLARE_INST_COUNT_ROOT(SkPath);
3365a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPath();
351ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org    SkPath(const SkPath&);
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkPath();
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
381ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org    SkPath& operator=(const SkPath&);
395e728450247c677343e072f37150967b36892573bsalomon@google.com    friend  SK_API bool operator==(const SkPath&, const SkPath&);
403abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com    friend bool operator!=(const SkPath& a, const SkPath& b) {
413abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com        return !(a == b);
423abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com    }
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum FillType {
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Specifies that "inside" is computed by a non-zero sum of signed
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            edge crossings
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kWinding_FillType,
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Specifies that "inside" is computed by an odd number of edge
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            crossings
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kEvenOdd_FillType,
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Same as Winding, but draws outside of the path, rather than inside
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kInverseWinding_FillType,
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Same as EvenOdd, but draws outside of the path, rather than inside
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com         */
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kInverseEvenOdd_FillType
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the path's fill type. This is used to define how "inside" is
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        computed. The default value is kWinding_FillType.
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the path's fill type
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    FillType getFillType() const { return (FillType)fFillType; }
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the path's fill type. This is used to define how "inside" is
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        computed. The default value is kWinding_FillType.
70b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param ft The new fill type for this path
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
73f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    void setFillType(FillType ft) {
74f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com        fFillType = SkToU8(ft);
75f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    }
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the filltype is one of the Inverse variants */
785f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com    bool isInverseFillType() const { return IsInverseFillType((FillType)fFillType); }
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
80b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    /**
81b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Toggle between inverse and normal filltypes. This reverse the return
82b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  value of isInverseFillType()
83b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     */
84f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    void toggleInverseFillType() {
85f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com        fFillType ^= 2;
866b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com    }
878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    enum Convexity {
8904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        kUnknown_Convexity,
9004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        kConvex_Convexity,
9104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        kConcave_Convexity
9204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    };
9304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
9404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
9530c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com     *  Return the path's convexity, as stored in the path. If it is currently unknown,
9630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com     *  then this function will attempt to compute the convexity (and cache the result).
97b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     */
98b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    Convexity getConvexity() const {
9930c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com        if (kUnknown_Convexity != fConvexity) {
10030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com            return static_cast<Convexity>(fConvexity);
10130c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com        } else {
10230c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com            return this->internalGetConvexity();
103b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com        }
104b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    }
105b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com
106b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    /**
107b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Return the currently cached value for convexity, even if that is set to
108b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  kUnknown_Convexity. Note: getConvexity() will automatically call
109b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  ComputeConvexity and cache its return value if the current setting is
110b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  kUnknown.
11104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     */
112b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    Convexity getConvexityOrUnknown() const { return (Convexity)fConvexity; }
11304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
11404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
11504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Store a convexity setting in the path. There is no automatic check to
11630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com     *  see if this value actually agrees with the return value that would be
11730c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com     *  computed by getConvexity().
118b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *
119b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  Note: even if this is set to a "known" value, if the path is later
120b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  changed (e.g. lineTo(), addRect(), etc.) then the cached value will be
121b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com     *  reset to kUnknown_Convexity.
12204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     */
12304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    void setConvexity(Convexity);
12404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
12504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
12604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Returns true if the path is flagged as being convex. This is not a
12704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  confirmed by any analysis, it is just the value set earlier.
12804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     */
12904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    bool isConvex() const {
13004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        return kConvex_Convexity == this->getConvexity();
13104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    }
13204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com
13304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com    /**
13404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  Set the isConvex flag to true or false. Convex paths may draw faster if
13504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  this flag is set, though setting this to true on a path that is in fact
13604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  not convex can give undefined results when drawn. Paths default to
13704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com     *  isConvex == false
1386b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com     */
1394469938e92d779dff05e745559e67907bbf21e78reed@google.com    SK_ATTR_DEPRECATED("use setConvexity")
140f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    void setIsConvex(bool isConvex) {
14104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com        this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity);
142f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com    }
1436b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com
1446aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    /** Returns true if the path is an oval.
1456aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *
1466aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     * @param rect      returns the bounding rect of this oval. It's a circle
1476aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *                  if the height and width are the same.
1486aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *
1496aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     * @return true if this path is an oval.
1506aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *              Tracking whether a path is an oval is considered an
1516aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *              optimization for performance and so some paths that are in
1526aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     *              fact ovals can report false.
1536aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com     */
154466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com    bool isOval(SkRect* rect) const { return fPathRef->isOval(rect); }
1556aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com
1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Clear any lines and curves from the path, making it empty. This frees up
1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        internal storage associated with those segments.
158cb8b0eeacfc2ff79a2b9721e3ef21d1efb507dc8mtklein@google.com        On Android, does not change fSourcePath.
1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void reset();
161fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Similar to reset(), in that all lines and curves are removed from the
1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path. However, any internal storage for those lines/curves is retained,
1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        making reuse of the path potentially faster.
165cb8b0eeacfc2ff79a2b9721e3ef21d1efb507dc8mtklein@google.com        On Android, does not change fSourcePath.
1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rewind();
1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the path is empty (contains no lines or curves)
1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path is empty (contains no lines or curves)
1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
173ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    bool isEmpty() const {
174ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        SkDEBUGCODE(this->validate();)
175ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        return 0 == fPathRef->countVerbs();
176ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    }
1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1780bb18bb264b26afca45452910437c09445e23a3creed@google.com    /**
1790bb18bb264b26afca45452910437c09445e23a3creed@google.com     *  Returns true if all of the points in this path are finite, meaning there
1800bb18bb264b26afca45452910437c09445e23a3creed@google.com     *  are no infinities and no NaNs.
1810bb18bb264b26afca45452910437c09445e23a3creed@google.com     */
1820bb18bb264b26afca45452910437c09445e23a3creed@google.com    bool isFinite() const {
183ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        SkDEBUGCODE(this->validate();)
184ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        return fPathRef->isFinite();
1850bb18bb264b26afca45452910437c09445e23a3creed@google.com    }
1860bb18bb264b26afca45452910437c09445e23a3creed@google.com
1874da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    /** Test a line for zero length
1884da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
1894da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        @return true if the line is of zero length; otherwise false.
1904da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    */
1914da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) {
19294fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com        return p1.equalsWithinTolerance(p2);
1934da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    }
1944da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
1954da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    /** Test a quad for zero length
1964da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
1974da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        @return true if the quad is of zero length; otherwise false.
1984da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    */
1994da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
2004da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org                                 const SkPoint& p3) {
20194fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com        return p1.equalsWithinTolerance(p2) &&
20294fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com               p2.equalsWithinTolerance(p3);
2034da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    }
2044da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2054da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    /** Test a cubic curve for zero length
2064da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2074da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        @return true if the cubic is of zero length; otherwise false.
2084da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    */
2094da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
2104da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org                                  const SkPoint& p3, const SkPoint& p4) {
21194fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com        return p1.equalsWithinTolerance(p2) &&
21294fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com               p2.equalsWithinTolerance(p3) &&
21394fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com               p3.equalsWithinTolerance(p4);
2144da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org    }
2154da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org
2167e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com    /**
2177e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  Returns true if the path specifies a single line (i.e. it contains just
2187e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  a moveTo and a lineTo). If so, and line[] is not null, it sets the 2
2197e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  points in line[] to the end-points of the line. If the path is not a
2207e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     *  line, returns false and ignores line[].
2217e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com     */
2227e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com    bool isLine(SkPoint line[2]) const;
2237e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com
2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if the path specifies a rectangle. If so, and if rect is
2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        not null, set rect to the bounds of the path. If the path does not
2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        specify a rectangle, return false and ignore rect.
227fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param rect If not null, returns the bounds of the path if it specifies
2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    a rectangle
2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return true if the path specifies a rectangle
2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2328fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    bool isRect(SkRect* rect) const;
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
234d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    /** Return the number of points in the path
235d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com     */
2361dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com    int countPoints() const;
237d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com
238d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    /** Return the point at the specified index. If the index is out of range
239d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com         (i.e. is not 0 <= index < countPoints()) then the returned coordinates
240d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com         will be (0,0)
241d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com     */
242d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com    SkPoint getPoint(int index) const;
243d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com
2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the number of points in the path. Up to max points are copied.
245fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param points If not null, receives up to max points
2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param max The maximum number of points to copy into points
2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return the actual number of points in the path
2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int getPoints(SkPoint points[], int max) const;
2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
252df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com    /** Return the number of verbs in the path
253df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com     */
2541dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com    int countVerbs() const;
255df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com
256df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com    /** Returns the number of verbs in the path. Up to max verbs are copied. The
257df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com        verbs are copied as one byte per verb.
258fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
259df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com        @param verbs If not null, receives up to max verbs
260df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com        @param max The maximum number of verbs to copy into verbs
261df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com        @return the actual number of verbs in the path
262df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com    */
263df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com    int getVerbs(uint8_t verbs[], int max) const;
264df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com
2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //! Swap contents of this and other. Guaranteed not to throw
2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void swap(SkPath& other);
2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
268d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    /** Returns the bounds of the path's points. If the path contains 0 or 1
269d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        points, the bounds is set to (0,0,0,0), and isEmpty() will return true.
270d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        Note: this bounds may be larger than the actual shape, since curves
271d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        do not extend as far as their control points.
272d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    */
273d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    const SkRect& getBounds() const {
274ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        return fPathRef->getBounds();
275d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    }
2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Calling this will, if the internal cache of the bounds is out of date,
2789bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com        update it so that subsequent calls to getBounds will be instantaneous.
2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This also means that any copies or simple transformations of the path
2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        will inherit the cached bounds.
281d252db03d9650013b545ef9781fe993c07f8f314reed@android.com     */
282d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    void updateBoundsCache() const {
283d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        // for now, just calling getBounds() is sufficient
284d252db03d9650013b545ef9781fe993c07f8f314reed@android.com        this->getBounds();
285d252db03d9650013b545ef9781fe993c07f8f314reed@android.com    }
2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2879bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com    /**
2889bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com     * Does a conservative test to see whether a rectangle is inside a path. Currently it only
2899bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com     * will ever return true for single convex contour paths. The empty-status of the rect is not
2909bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com     * considered (e.g. a rect that is a point can be inside a path). Points or line segments where
2919bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com     * the rect edge touches the path border are not considered containment violations.
2929bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com     */
2939bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com    bool conservativelyContainsRect(const SkRect& rect) const;
2949bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com
2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    //  Construction methods
2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Hint to the path to prepare for adding more points. This can allow the
2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        path to more efficiently grow its storage.
299fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param extraPtCount The number of extra points the path should
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                            preallocate for.
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void incReserve(unsigned extraPtCount);
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the beginning of the next contour to the point (x,y).
306fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x    The x-coordinate of the start of a new contour
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y    The y-coordinate of the start of a new contour
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void moveTo(SkScalar x, SkScalar y);
3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the beginning of the next contour to the point
313fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p    The start of a new contour
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void moveTo(const SkPoint& p) {
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->moveTo(p.fX, p.fY);
3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the beginning of the next contour relative to the last point on the
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        previous contour. If there is no previous contour, this is treated the
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        same as moveTo().
323fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to add to the x-coordinate of the end of the
3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    previous contour, to specify the start of a new contour
3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The amount to add to the y-coordinate of the end of the
3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    previous contour, to specify the start of a new contour
3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rMoveTo(SkScalar dx, SkScalar dy);
3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a line from the last point to the specified point (x,y). If no
3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo() call has been made for this contour, the first point is
3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        automatically set to (0,0).
3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x    The x-coordinate of the end of a line
3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y    The y-coordinate of the end of a line
3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void lineTo(SkScalar x, SkScalar y);
3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a line from the last point to the specified point. If no moveTo()
3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call has been made for this contour, the first point is automatically
3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        set to (0,0).
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p    The end of a line
3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void lineTo(const SkPoint& p) {
3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->lineTo(p.fX, p.fY);
3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Same as lineTo, but the coordinates are considered relative to the last
3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        point on this contour. If there is no previous point, then a moveTo(0,0)
3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        is inserted automatically.
353fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to add to the x-coordinate of the previous point
3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    on this contour, to specify a line
3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy   The amount to add to the y-coordinate of the previous point
3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    on this contour, to specify a line
3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rLineTo(SkScalar dx, SkScalar dy);
3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a quadratic bezier from the last point, approaching control point
3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for
3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this contour, the first point is automatically set to (0,0).
364fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1   The x-coordinate of the control point on a quadratic curve
3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1   The y-coordinate of the control point on a quadratic curve
3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x2   The x-coordinate of the end point on a quadratic curve
3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y2   The y-coordinate of the end point on a quadratic curve
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2);
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a quadratic bezier from the last point, approaching control point
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        p1, and ending at p2. If no moveTo() call has been made for this
3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contour, the first point is automatically set to (0,0).
375fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p1   The control point on a quadratic curve
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p2   The end point on a quadratic curve
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void quadTo(const SkPoint& p1, const SkPoint& p2) {
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY);
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Same as quadTo, but the coordinates are considered relative to the last
3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        point on this contour. If there is no previous point, then a moveTo(0,0)
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        is inserted automatically.
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx1   The amount to add to the x-coordinate of the last point on
3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the control point of a quadratic curve
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy1   The amount to add to the y-coordinate of the last point on
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the control point of a quadratic curve
3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx2   The amount to add to the x-coordinate of the last point on
3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a quadratic curve
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy2   The amount to add to the y-coordinate of the last point on
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a quadratic curve
3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2);
3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
398277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com    void conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
399277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com                 SkScalar w);
400277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com    void conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) {
401277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w);
402277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com    }
403277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com    void rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2,
404277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com                  SkScalar w);
40526da7f00aedba107d4b3e382283034e265db09b6skia.committer@gmail.com
4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a cubic bezier from the last point, approaching control points
4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been
4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        made for this contour, the first point is automatically set to (0,0).
409fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x1   The x-coordinate of the 1st control point on a cubic curve
4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y1   The y-coordinate of the 1st control point on a cubic curve
4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x2   The x-coordinate of the 2nd control point on a cubic curve
4138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y2   The y-coordinate of the 2nd control point on a cubic curve
4148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x3   The x-coordinate of the end point on a cubic curve
4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y3   The y-coordinate of the end point on a cubic curve
4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 SkScalar x3, SkScalar y3);
4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a cubic bezier from the last point, approaching control points p1
4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        and p2, and ending at p3. If no moveTo() call has been made for this
4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        contour, the first point is automatically set to (0,0).
423fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p1   The 1st control point on a cubic curve
4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p2   The 2nd control point on a cubic curve
4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p3   The end point on a cubic curve
4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) {
4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY);
4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Same as cubicTo, but the coordinates are considered relative to the
4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        current point on this contour. If there is no previous point, then a
4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo(0,0) is inserted automatically.
435fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx1   The amount to add to the x-coordinate of the last point on
4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 1st control point of a cubic curve
4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy1   The amount to add to the y-coordinate of the last point on
4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 1st control point of a cubic curve
4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx2   The amount to add to the x-coordinate of the last point on
4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 2nd control point of a cubic curve
4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy2   The amount to add to the y-coordinate of the last point on
4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                this contour, to specify the 2nd control point of a cubic curve
4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx3   The amount to add to the x-coordinate of the last point on
4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a cubic curve
4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dy3   The amount to add to the y-coordinate of the last point on
4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                     this contour, to specify the end point of a cubic curve
4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4496b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com    void rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
4506b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com                  SkScalar x3, SkScalar y3);
4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Append the specified arc to the path as a new contour. If the start of
4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the path is different from the path's current last point, then an
4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        automatic lineTo() is added to connect the current contour to the start
4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        of the arc. However, if the path is empty, then we call moveTo() with
4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the first point of the arc. The sweep angle is treated mod 360.
457fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounding oval defining the shape and size of the arc
4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise. This is
4618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                          treated mod 360.
4628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param forceMoveTo If true, always begin a new contour with the arc
4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4646b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com    void arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
4656b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com               bool forceMoveTo);
4668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Append a line and arc to the current path. This is the same as the
4688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        PostScript call "arct".
4698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
4718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com               SkScalar radius);
4728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Append a line and arc to the current path. This is the same as the
4748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        PostScript call "arct".
4758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
4778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Close the current contour. If the current point is not equal to the
4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        first point of the contour, a line segment is automatically added.
4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void close();
4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
4858fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    enum Direction {
4868fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        /** Direction either has not been or could not be computed */
4878fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        kUnknown_Direction,
4888fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        /** clockwise direction for adding closed contours */
4898fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        kCW_Direction,
4908fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        /** counter-clockwise direction for adding closed contours */
4918fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        kCCW_Direction,
4928fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    };
4938fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com
494a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
495a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Return the opposite of the specified direction. kUnknown is its own
496a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  opposite.
497a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
49830c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com    static Direction OppositeDirection(Direction dir) {
499a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com        static const Direction gOppositeDir[] = {
500a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com            kUnknown_Direction, kCCW_Direction, kCW_Direction
501a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com        };
502a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com        return gOppositeDir[dir];
50330c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com    }
50430c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com
50569a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    /**
50612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com     *  Returns whether or not a fill type is inverted
5075f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *
5085f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kWinding_FillType        -> false
5095f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kEvenOdd_FillType        -> false
5105f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kInverseWinding_FillType -> true
5115f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kInverseEvenOdd_FillType -> true
51212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com     */
5135f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com    static bool IsInverseFillType(FillType fill) {
51412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch);
51512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch);
51612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch);
51712b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch);
51812b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        return (fill & 2) != 0;
51912b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com    }
52012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com
52112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com    /**
52212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com     *  Returns the equivalent non-inverted fill type to the given fill type
5235f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *
5245f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kWinding_FillType        -> kWinding_FillType
5255f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kEvenOdd_FillType        -> kEvenOdd_FillType
5265f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kInverseWinding_FillType -> kWinding_FillType
5275f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com     *  kInverseEvenOdd_FillType -> kEvenOdd_FillType
52812b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com     */
5295f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com    static FillType ConvertToNonInverseFillType(FillType fill) {
53012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch);
53112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch);
53212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch);
53312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch);
53412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com        return (FillType)(fill & 1);
53512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com    }
53612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com
53712b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com    /**
53869a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  Tries to quickly compute the direction of the first non-degenerate
53969a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  contour. If it can be computed, return true and set dir to that
54069a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  direction. If it cannot be (quickly) determined, return false and ignore
54130c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com     *  the dir parameter. If the direction was determined, it is cached to make
54230c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com     *  subsequent calls return quickly.
54369a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     */
54469a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    bool cheapComputeDirection(Direction* dir) const;
54569a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com
54669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    /**
54769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  Returns true if the path's direction can be computed via
54869a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     *  cheapComputDirection() and if that computed direction matches the
549a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  specified direction. If dir is kUnknown, returns true if the direction
550a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  cannot be computed.
55169a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com     */
55269a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    bool cheapIsDirection(Direction dir) const {
553a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com        Direction computedDir = kUnknown_Direction;
554a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com        (void)this->cheapComputeDirection(&computedDir);
555a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com        return computedDir == dir;
55669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com    }
55769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com
5588fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    /** Returns true if the path specifies a rectangle. If so, and if isClosed is
5598fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        not null, set isClosed to true if the path is closed. Also, if returning true
5608fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        and direction is not null, return the rect direction. If the path does not
5618fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        specify a rectangle, return false and ignore isClosed and direction.
5628fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com
5638fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        @param isClosed If not null, set to true if the path is closed
5648fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        @param direction If not null, set to the rectangle's direction
5658fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        @return true if the path specifies a rectangle
5668fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    */
5678fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    bool isRect(bool* isClosed, Direction* direction) const;
5688fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com
5698fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    /** Returns true if the path specifies a pair of nested rectangles. If so, and if
5708fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        rect is not null, set rect[0] to the outer rectangle and rect[1] to the inner
5718fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        rectangle. If so, and dirs is not null, set dirs[0] to the direction of
5728fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        the outer rectangle and dirs[1] to the direction of the inner rectangle. If
5738fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        the path does not specify a pair of nested rectangles, return
5748fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        false and ignore rect and dirs.
5758fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com
5768fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        @param rect If not null, returns the path as a pair of nested rectangles
5778fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        @param dirs If not null, returns the direction of the rects
5788fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com        @return true if the path describes a pair of nested rectangles
5798fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    */
5808fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com    bool isNestedRects(SkRect rect[2], Direction dirs[2] = NULL) const;
5818fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com
582a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
583a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Add a closed rectangle contour to the path
584a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param rect The rectangle to add as a closed contour to the path
585a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param dir  The direction to wind the rectangle's contour. Cannot be
586a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *              kUnknown_Direction.
587a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
588ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    void addRect(const SkRect& rect, Direction dir = kCW_Direction);
5898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
590a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
591a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Add a closed rectangle contour to the path
592a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *
593a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param left     The left side of a rectangle to add as a closed contour
594a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  to the path
595a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param top      The top of a rectangle to add as a closed contour to the
596a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  path
597a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param right    The right side of a rectangle to add as a closed contour
598a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  to the path
599a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param bottom   The bottom of a rectangle to add as a closed contour to
600a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  the path
601a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param dir  The direction to wind the rectangle's contour. Cannot be
602a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *              kUnknown_Direction.
603a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
6048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                 Direction dir = kCW_Direction);
6068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
607a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
608a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Add a closed oval contour to the path
609a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *
610a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param oval The bounding oval to add as a closed contour to the path
611a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param dir  The direction to wind the oval's contour. Cannot be
612a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *              kUnknown_Direction.
613a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
6148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addOval(const SkRect& oval, Direction dir = kCW_Direction);
6158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
616a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
617a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Add a closed circle contour to the path
618a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *
619a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param x        The x-coordinate of the center of a circle to add as a
620a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  closed contour to the path
621a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param y        The y-coordinate of the center of a circle to add as a
622a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  closed contour to the path
623a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param radius   The radius of a circle to add as a closed contour to the
624a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *                  path
625a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param dir  The direction to wind the circle's contour. Cannot be
626a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *              kUnknown_Direction.
627a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
6288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addCircle(SkScalar x, SkScalar y, SkScalar radius,
6298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                   Direction dir = kCW_Direction);
6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add the specified arc to the path as a new contour.
632fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
6338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param oval The bounds of oval used to define the size of the arc
6348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param startAngle Starting angle (in degrees) where the arc begins
6358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param sweepAngle Sweep angle (in degrees) measured clockwise
6368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle);
6388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
639a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
640a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Add a closed round-rectangle contour to the path
641a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param rect The bounds of a round-rectangle to add as a closed contour
642a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param rx   The x-radius of the rounded corners on the round-rectangle
643a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param ry   The y-radius of the rounded corners on the round-rectangle
644a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param dir  The direction to wind the rectangle's contour. Cannot be
645a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *              kUnknown_Direction.
646a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
647ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
648ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com                      Direction dir = kCW_Direction);
6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
650a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com    /**
651a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  Add a closed round-rectangle contour to the path. Each corner receives
652a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  two radius values [X, Y]. The corners are ordered top-left, top-right,
653a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  bottom-right, bottom-left.
654a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param rect The bounds of a round-rectangle to add as a closed contour
655a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner
656a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *  @param dir  The direction to wind the rectangle's contour. Cannot be
657a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     *              kUnknown_Direction.
6584e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     * Note: The radii here now go through the same constraint handling as the
6594e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     *       SkRRect radii (i.e., either radii at a corner being 0 implies a
6604e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     *       sqaure corner and oversized radii are proportionally scaled down).
661a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com     */
6628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addRoundRect(const SkRect& rect, const SkScalar radii[],
6638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                      Direction dir = kCW_Direction);
6648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
665744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com    /**
6664e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     *  Add an SkRRect contour to the path
6674e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     *  @param rrect The rounded rect to add as a closed contour
6684e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     *  @param dir   The winding direction for the new contour. Cannot be
6694e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com     *               kUnknown_Direction.
6704ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com     */
6714e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com    void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction);
6724ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com
6734ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com    /**
674744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *  Add a new contour made of just lines. This is just a fast version of
675744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *  the following:
676744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *      this->moveTo(pts[0]);
677744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *      for (int i = 1; i < count; ++i) {
678744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *          this->lineTo(pts[i]);
679744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *      }
680744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *      if (close) {
681744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *          this->close();
682744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     *      }
683744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com     */
684744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com    void addPoly(const SkPoint pts[], int count, bool close);
685744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com
6868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a copy of src to the path, offset by (dx,dy)
6878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src  The path to add as a new contour
6888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to translate the path in X as it is added
6898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dx   The amount to translate the path in Y as it is added
6908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
69163d73749fbe36491403ea521005fd298dc70a94creed@google.com    void addPath(const SkPath& src, SkScalar dx, SkScalar dy);
6928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
6938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a copy of src to the path
6948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
6958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addPath(const SkPath& src) {
6968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkMatrix m;
6978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        m.reset();
6988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->addPath(src, m);
6998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Add a copy of src to the path, transformed by matrix
7028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param src  The path to add as a new contour
7038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void addPath(const SkPath& src, const SkMatrix& matrix);
7058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
70663d73749fbe36491403ea521005fd298dc70a94creed@google.com    /**
70763d73749fbe36491403ea521005fd298dc70a94creed@google.com     *  Same as addPath(), but reverses the src input
70863d73749fbe36491403ea521005fd298dc70a94creed@google.com     */
70963d73749fbe36491403ea521005fd298dc70a94creed@google.com    void reverseAddPath(const SkPath& src);
71063d73749fbe36491403ea521005fd298dc70a94creed@google.com
7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Offset the path by (dx,dy), returning true on success
712fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
713fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com        @param dx   The amount in the X direction to offset the entire path
714fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com        @param dy   The amount in the Y direction to offset the entire path
7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst  The translated path is written here
7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void offset(SkScalar dx, SkScalar dy, SkPath* dst) const;
7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Offset the path by (dx,dy), returning true on success
720fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
721fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com        @param dx   The amount in the X direction to offset the entire path
722fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com        @param dy   The amount in the Y direction to offset the entire path
7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void offset(SkScalar dx, SkScalar dy) {
7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->offset(dx, dy, this);
7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Transform the points in this path by matrix, and write the answer into
7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        dst.
730fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix   The matrix to apply to the path
7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param dst      The transformed path is written here
7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void transform(const SkMatrix& matrix, SkPath* dst) const;
7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Transform the points in this path by matrix
7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param matrix The matrix to apply to the path
7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void transform(const SkMatrix& matrix) {
7418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->transform(matrix, this);
7428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the last point on the path. If no points have been added, (0,0)
745294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com        is returned. If there are no points, this returns false, otherwise it
746294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com        returns true.
747fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param lastPt   The last point on the path is returned here
7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
750294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com    bool getLastPt(SkPoint* lastPt) const;
7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the last point on the path. If no points have been added,
7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        moveTo(x,y) is automatically called.
754fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param x    The new x-coordinate for the last point
7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param y    The new y-coordinate for the last point
7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setLastPt(SkScalar x, SkScalar y);
7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Set the last point on the path. If no points have been added, moveTo(p)
7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        is automatically called.
7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param p    The new location for the last point
7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setLastPt(const SkPoint& p) {
7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this->setLastPt(p.fX, p.fY);
7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
76910296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    enum SegmentMask {
77010296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com        kLine_SegmentMask   = 1 << 0,
77110296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com        kQuad_SegmentMask   = 1 << 1,
772277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        kConic_SegmentMask  = 1 << 2,
773277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        kCubic_SegmentMask  = 1 << 3,
77410296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    };
77510296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com
77610296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com    /**
77710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     *  Returns a mask, where each bit corresponding to a SegmentMask is
77810296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     *  set if the path contains 1 or more segments of that type.
77910296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     *  Returns 0 for an empty path (no segments).
78010296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com     */
7816b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com    uint32_t getSegmentMasks() const { return fPathRef->getSegmentMasks(); }
78210296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com
7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum Verb {
7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kMove_Verb,     //!< iter.next returns 1 point
7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kLine_Verb,     //!< iter.next returns 2 points
7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kQuad_Verb,     //!< iter.next returns 3 points
787277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        kConic_Verb,    //!< iter.next returns 3 points + iter.conicWeight()
7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kCubic_Verb,    //!< iter.next returns 4 points
789b3b8dfa31326c51dab8b5ed569e19ee715582d1bbsalomon@google.com        kClose_Verb,    //!< iter.next returns 1 point (contour's moveTo pt)
790277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        kDone_Verb,     //!< iter.next returns 0 points
7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Iterate through all of the segments (lines, quadratics, cubics) of
7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        each contours in a path.
79572785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org
79672785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        The iterator cleans up the segments along the way, removing degenerate
79772785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        segments and adding close verbs where necessary. When the forceClose
79872785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        argument is provided, each contour (as defined by a new starting
79972785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        move command) will be completed with a close verb regardless of the
80072785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        contour's contents.
8018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
8027ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org    class SK_API Iter {
8038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
80472785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        Iter();
80572785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org        Iter(const SkPath&, bool forceClose);
8068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void setPath(const SkPath&, bool forceClose);
8088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Return the next verb in this iteration of the path. When all
8108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            segments have been visited, return kDone_Verb.
811b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @param  pts The points representing the current verb and/or segment
8134a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com            @param doConsumeDegerates If true, first scan for segments that are
8144a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com                   deemed degenerate (too short) and skip those.
8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @return The verb for the current segment
8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
8174a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com        Verb next(SkPoint pts[4], bool doConsumeDegerates = true) {
8184a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com            if (doConsumeDegerates) {
8194a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com                this->consumeDegenerateSegments();
8204a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com            }
8214a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com            return this->doNext(pts);
8224a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com        }
8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
824277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        /**
825277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com         *  Return the weight for the current conic. Only valid if the current
826277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com         *  segment return by next() was a conic.
827277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com         */
828277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        SkScalar conicWeight() const { return *fConicWeights; }
829277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com
8308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** If next() returns kLine_Verb, then this query returns true if the
8318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            line was the result of a close() command (i.e. the end point is the
8328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            initial moveto for this contour). If next() returned a different
8338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            verb, this returns an undefined value.
834b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
8358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @return If the last call to next() returned kLine_Verb, return true
8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                    if it was the result of an explicit close command.
8378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
8388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool isCloseLine() const { return SkToBool(fCloseLine); }
839b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org
8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        /** Returns true if the current contour is closed (has a kClose_Verb)
8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            @return true if the current contour is closed (has a kClose_Verb)
8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        */
8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        bool isClosedContour() const;
8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
8468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const SkPoint*  fPts;
8478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const uint8_t*  fVerbs;
8488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        const uint8_t*  fVerbStop;
849277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        const SkScalar* fConicWeights;
8508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPoint         fMoveTo;
8518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPoint         fLastPt;
8528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkBool8         fForceClose;
8538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkBool8         fNeedClose;
8548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkBool8         fCloseLine;
855b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org        SkBool8         fSegmentState;
8568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8579e25dbf589539dd44244bc2581590bd7591e17a2reed@google.com        inline const SkPoint& cons_moveTo();
8588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Verb autoClose(SkPoint pts[2]);
8594da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org        void consumeDegenerateSegments();
8604a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com        Verb doNext(SkPoint pts[4]);
8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
8636630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    /** Iterate through the verbs in the path, providing the associated points.
8646630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    */
8656630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    class SK_API RawIter {
8666630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    public:
8676630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        RawIter();
8686630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        RawIter(const SkPath&);
8696630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
8706630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        void setPath(const SkPath&);
8716630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
8726630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        /** Return the next verb in this iteration of the path. When all
8736630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org            segments have been visited, return kDone_Verb.
874fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
8756630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org            @param  pts The points representing the current verb and/or segment
876f6d3c5aa5f93e4c3cc7a7aebf014e960cf837783bsalomon@google.com                        This must not be NULL.
8776630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org            @return The verb for the current segment
8786630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        */
8796630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        Verb next(SkPoint pts[4]);
8806630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
881277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        SkScalar conicWeight() const { return *fConicWeights; }
882277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com
8836630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    private:
8846630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        const SkPoint*  fPts;
8856630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        const uint8_t*  fVerbs;
8866630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        const uint8_t*  fVerbStop;
887277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com        const SkScalar* fConicWeights;
8886630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        SkPoint         fMoveTo;
8896630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org        SkPoint         fLastPt;
8906630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org    };
8916630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org
892bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org    /**
893bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org     *  Returns true if the point { x, y } is contained by the path, taking into
894bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org     *  account the FillType.
895bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org     */
896bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org    bool contains(SkScalar x, SkScalar y) const;
897bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org
8988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void dump(bool forceClose, const char title[] = NULL) const;
899e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com    void dump() const;
9008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
90194e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com    /**
9024faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     *  Write the path to the buffer, and return the number of bytes written.
90394e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com     *  If buffer is NULL, it still returns the number of bytes.
90494e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com     */
9054faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org    size_t writeToMemory(void* buffer) const;
90694e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com    /**
9074faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     * Initializes the path from the buffer
9084faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     *
9094faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     * @param buffer Memory to read from
9104faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     * @param length Amount of memory available in the buffer
9114faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     * @return number of bytes read (must be a multiple of 4) or
9124faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org     *         0 if there was not enough memory available
91394e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com     */
9144faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org    size_t readFromMemory(const void* buffer, size_t length);
9158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9161ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org    /** Returns a non-zero, globally unique value corresponding to the set of verbs
9171ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org        and points in the path (but not the fill type [except on Android skbug.com/1762]).
9187ed98df9ba14bdb58e381508eb0505c963a4b6dbskia.committer@gmail.com        Each time the path is modified, a different generation ID will be returned.
9191ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org    */
9207101abe5b37d82ea222e971a42615a97a2419edbrobertphillips@google.com    uint32_t getGenerationID() const;
9211ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org
9221ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org#ifdef SK_BUILD_FOR_ANDROID
9231ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org    static const int kPathRefGenIDBitCnt = 30; // leave room for the fill type (skbug.com/1762)
924e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com    const SkPath* getSourcePath() const;
925e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com    void setSourcePath(const SkPath* path);
9261ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org#else
9271ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org    static const int kPathRefGenIDBitCnt = 32;
928f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif
929f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com
9308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDEBUGCODE(void validate() const;)
9318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
93301ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com    enum SerializationOffsets {
934466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
93511e055518a0cbe5329232a55fe2cd177e83836d8robertphillips@google.com        kNewFormat_SerializationShift = 29, // requires 1 bit
936ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com#endif
93711e055518a0cbe5329232a55fe2cd177e83836d8robertphillips@google.com        kUnused1_SerializationShift = 28,    // 1 free bit
93830c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com        kDirection_SerializationShift = 26, // requires 2 bits
93911e055518a0cbe5329232a55fe2cd177e83836d8robertphillips@google.com        kUnused2_SerializationShift = 25,    // 1 free bit
940466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
941466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com        kOldIsOval_SerializationShift = 24,    // requires 1 bit
942466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com#endif
943ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        kConvexity_SerializationShift = 16, // requires 8 bits
944ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        kFillType_SerializationShift = 8,   // requires 8 bits
9456b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
9466b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com        kOldSegmentMask_SerializationShift = 0 // requires 4 bits
9476b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com#endif
94801ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com    };
94901ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com
950ae09f2dc3fb1e8a8db99b214c8a71d0b9613a856bsalomon@google.com    SkAutoTUnref<SkPathRef> fPathRef;
951ae09f2dc3fb1e8a8db99b214c8a71d0b9613a856bsalomon@google.com
952d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    int                 fLastMoveToIndex;
9538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint8_t             fFillType;
954b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com    mutable uint8_t     fConvexity;
95530c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com    mutable uint8_t     fDirection;
95656c69773aea56c6c6bd47bc7e7970dd081205184djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID
957e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com    const SkPath*       fSourcePath;
958f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif
9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
960a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com    /** Resets all fields other than fPathRef to their initial 'empty' values.
961a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com     *  Assumes the caller has already emptied fPathRef.
962a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com     *  On Android increments fGenerationID without reseting it.
963a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com     */
964a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com    void resetFields();
965a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com
966a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com    /** Sets all fields other than fPathRef to the values in 'that'.
967a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com     *  Assumes the caller has already set fPathRef.
9689c9d4a70028ef8dc33a46cfc0b22e254443effe3mtklein@google.com     *  Doesn't change fGenerationID or fSourcePath on Android.
969a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com     */
970a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com    void copyFields(const SkPath& that);
971a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com
9728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class Iter;
9738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkPathStroker;
9758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /*  Append, in reverse order, the first contour of path, ignoring path's
9778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        last point. If no moveTo() call has been made for this contour, the
9788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        first point is automatically set to (0,0).
9798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
9808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void reversePathTo(const SkPath&);
9818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
982d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    // called before we add points for lineTo, quadTo, cubicTo, checking to see
983d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    // if we need to inject a leading moveTo first
984d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    //
985d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    //  SkPath path; path.lineTo(...);   <--- need a leading moveTo(0, 0)
986d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo)
987d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    //
988d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com    inline void injectMoveToIfNeeded();
989d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com
9906aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    inline bool hasOnlyMoveTos() const;
9916aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com
99230c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com    Convexity internalGetConvexity() const;
9933458716b52aa25dcd1b270141c7628c380696e35skia.committer@gmail.com
994f68154a3cf43eb22d45be11f3b09e25440c366a6caryclark@google.com    bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts,
995f68154a3cf43eb22d45be11f3b09e25440c366a6caryclark@google.com                       bool* isClosed, Direction* direction) const;
99630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com
997ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    /** Returns if the path can return a bound at no cost (true) or will have to
998ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        perform some computation (false).
999ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com     */
1000ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    bool hasComputedBounds() const {
1001ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        SkDEBUGCODE(this->validate();)
1002ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        return fPathRef->hasComputedBounds();
1003ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    }
1004ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com
1005ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com
1006ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    // 'rect' needs to be sorted
1007ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    void setBounds(const SkRect& rect) {
1008ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com        fPathRef->setBounds(rect);
1009ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    }
1010ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com
1011466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com#ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO
1012ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com    friend class SkPathRef;     // just for SerializationOffsets
1013ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com#endif
10148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkAutoPathBoundsUpdate;
10156aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com    friend class SkAutoDisableOvalCheck;
101630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com    friend class SkAutoDisableDirectionCheck;
1017a1a097ee814d05a92487d85db8ad02e1d852fd6fcommit-bot@chromium.org    friend class SkBench_AddPathTest; // perf test reversePathTo
1018a1a097ee814d05a92487d85db8ad02e1d852fd6fcommit-bot@chromium.org    friend class PathTest_Private; // unit test reversePathTo
10198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
10208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
10218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1022