2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkPath_DEFINED
|
|
|
|
#define SkPath_DEFINED
|
|
|
|
|
2012-08-14 13:15:44 +00:00
|
|
|
#include "SkInstCnt.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkMatrix.h"
|
2013-09-26 12:18:23 +00:00
|
|
|
#include "SkPathRef.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkTDArray.h"
|
2012-10-03 13:46:20 +00:00
|
|
|
#include "SkRefCnt.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-25 19:04:27 +00:00
|
|
|
class SkReader32;
|
|
|
|
class SkWriter32;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkAutoPathBoundsUpdate;
|
|
|
|
class SkString;
|
2012-12-12 20:48:18 +00:00
|
|
|
class SkRRect;
|
2014-06-24 15:30:15 +00:00
|
|
|
class SkWStream;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** \class SkPath
|
|
|
|
|
|
|
|
The SkPath class encapsulates compound (multiple contour) geometric paths
|
|
|
|
consisting of straight line segments, quadratic curves, and cubic curves.
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkPath {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2015-01-13 16:22:43 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkPath);
|
2012-08-14 13:15:44 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPath();
|
2013-10-30 18:57:55 +00:00
|
|
|
SkPath(const SkPath&);
|
2008-12-17 15:59:43 +00:00
|
|
|
~SkPath();
|
|
|
|
|
2013-10-30 18:57:55 +00:00
|
|
|
SkPath& operator=(const SkPath&);
|
2012-09-07 13:32:37 +00:00
|
|
|
friend SK_API bool operator==(const SkPath&, const SkPath&);
|
2009-03-02 05:36:20 +00:00
|
|
|
friend bool operator!=(const SkPath& a, const SkPath& b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
enum FillType {
|
|
|
|
/** Specifies that "inside" is computed by a non-zero sum of signed
|
|
|
|
edge crossings
|
|
|
|
*/
|
|
|
|
kWinding_FillType,
|
|
|
|
/** Specifies that "inside" is computed by an odd number of edge
|
|
|
|
crossings
|
|
|
|
*/
|
|
|
|
kEvenOdd_FillType,
|
|
|
|
/** Same as Winding, but draws outside of the path, rather than inside
|
|
|
|
*/
|
|
|
|
kInverseWinding_FillType,
|
|
|
|
/** Same as EvenOdd, but draws outside of the path, rather than inside
|
|
|
|
*/
|
|
|
|
kInverseEvenOdd_FillType
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Return the path's fill type. This is used to define how "inside" is
|
|
|
|
computed. The default value is kWinding_FillType.
|
|
|
|
|
|
|
|
@return the path's fill type
|
|
|
|
*/
|
|
|
|
FillType getFillType() const { return (FillType)fFillType; }
|
|
|
|
|
|
|
|
/** Set the path's fill type. This is used to define how "inside" is
|
|
|
|
computed. The default value is kWinding_FillType.
|
2011-12-21 20:43:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param ft The new fill type for this path
|
|
|
|
*/
|
2011-04-15 13:41:26 +00:00
|
|
|
void setFillType(FillType ft) {
|
|
|
|
fFillType = SkToU8(ft);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Returns true if the filltype is one of the Inverse variants */
|
2012-12-17 21:16:45 +00:00
|
|
|
bool isInverseFillType() const { return IsInverseFillType((FillType)fFillType); }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-05-16 14:16:04 +00:00
|
|
|
/**
|
|
|
|
* Toggle between inverse and normal filltypes. This reverse the return
|
|
|
|
* value of isInverseFillType()
|
|
|
|
*/
|
2011-04-15 13:41:26 +00:00
|
|
|
void toggleInverseFillType() {
|
|
|
|
fFillType ^= 2;
|
2013-12-12 23:03:51 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-05-15 04:08:24 +00:00
|
|
|
enum Convexity {
|
|
|
|
kUnknown_Convexity,
|
|
|
|
kConvex_Convexity,
|
|
|
|
kConcave_Convexity
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-11-13 14:36:42 +00:00
|
|
|
* Return the path's convexity, as stored in the path. If it is currently unknown,
|
|
|
|
* then this function will attempt to compute the convexity (and cache the result).
|
2011-05-16 14:16:04 +00:00
|
|
|
*/
|
|
|
|
Convexity getConvexity() const {
|
2012-11-13 14:36:42 +00:00
|
|
|
if (kUnknown_Convexity != fConvexity) {
|
|
|
|
return static_cast<Convexity>(fConvexity);
|
|
|
|
} else {
|
|
|
|
return this->internalGetConvexity();
|
2011-05-16 14:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the currently cached value for convexity, even if that is set to
|
|
|
|
* kUnknown_Convexity. Note: getConvexity() will automatically call
|
|
|
|
* ComputeConvexity and cache its return value if the current setting is
|
|
|
|
* kUnknown.
|
2011-05-15 04:08:24 +00:00
|
|
|
*/
|
2011-05-16 14:16:04 +00:00
|
|
|
Convexity getConvexityOrUnknown() const { return (Convexity)fConvexity; }
|
2011-05-15 04:08:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a convexity setting in the path. There is no automatic check to
|
2012-11-13 14:36:42 +00:00
|
|
|
* see if this value actually agrees with the return value that would be
|
|
|
|
* computed by getConvexity().
|
2011-05-16 14:16:04 +00:00
|
|
|
*
|
|
|
|
* Note: even if this is set to a "known" value, if the path is later
|
|
|
|
* changed (e.g. lineTo(), addRect(), etc.) then the cached value will be
|
|
|
|
* reset to kUnknown_Convexity.
|
2011-05-15 04:08:24 +00:00
|
|
|
*/
|
|
|
|
void setConvexity(Convexity);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the path is flagged as being convex. This is not a
|
|
|
|
* confirmed by any analysis, it is just the value set earlier.
|
|
|
|
*/
|
|
|
|
bool isConvex() const {
|
|
|
|
return kConvex_Convexity == this->getConvexity();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the isConvex flag to true or false. Convex paths may draw faster if
|
|
|
|
* this flag is set, though setting this to true on a path that is in fact
|
|
|
|
* not convex can give undefined results when drawn. Paths default to
|
|
|
|
* isConvex == false
|
2009-06-03 02:35:01 +00:00
|
|
|
*/
|
2013-10-31 17:28:30 +00:00
|
|
|
SK_ATTR_DEPRECATED("use setConvexity")
|
2011-04-15 13:41:26 +00:00
|
|
|
void setIsConvex(bool isConvex) {
|
2011-05-15 04:08:24 +00:00
|
|
|
this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity);
|
2011-04-15 13:41:26 +00:00
|
|
|
}
|
2009-06-03 02:35:01 +00:00
|
|
|
|
2012-04-18 13:29:52 +00:00
|
|
|
/** Returns true if the path is an oval.
|
|
|
|
*
|
|
|
|
* @param rect returns the bounding rect of this oval. It's a circle
|
|
|
|
* if the height and width are the same.
|
|
|
|
*
|
|
|
|
* @return true if this path is an oval.
|
|
|
|
* Tracking whether a path is an oval is considered an
|
|
|
|
* optimization for performance and so some paths that are in
|
|
|
|
* fact ovals can report false.
|
|
|
|
*/
|
2013-12-03 16:43:54 +00:00
|
|
|
bool isOval(SkRect* rect) const { return fPathRef->isOval(rect); }
|
2012-04-18 13:29:52 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Clear any lines and curves from the path, making it empty. This frees up
|
|
|
|
internal storage associated with those segments.
|
2013-08-15 21:14:51 +00:00
|
|
|
On Android, does not change fSourcePath.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void reset();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Similar to reset(), in that all lines and curves are removed from the
|
|
|
|
path. However, any internal storage for those lines/curves is retained,
|
|
|
|
making reuse of the path potentially faster.
|
2013-08-15 21:14:51 +00:00
|
|
|
On Android, does not change fSourcePath.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void rewind();
|
|
|
|
|
|
|
|
/** Returns true if the path is empty (contains no lines or curves)
|
|
|
|
|
|
|
|
@return true if the path is empty (contains no lines or curves)
|
|
|
|
*/
|
2013-09-26 12:18:23 +00:00
|
|
|
bool isEmpty() const {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
return 0 == fPathRef->countVerbs();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-07-26 15:20:36 +00:00
|
|
|
/**
|
|
|
|
* Returns true if all of the points in this path are finite, meaning there
|
|
|
|
* are no infinities and no NaNs.
|
|
|
|
*/
|
|
|
|
bool isFinite() const {
|
2013-09-26 12:18:23 +00:00
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
return fPathRef->isFinite();
|
2012-07-26 15:20:36 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 14:12:51 +00:00
|
|
|
/** Returns true if the path is volatile (i.e. should not be cached by devices.)
|
|
|
|
*/
|
|
|
|
bool isVolatile() const {
|
|
|
|
return SkToBool(fIsVolatile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Specify whether this path is volatile. Paths are not volatile by
|
|
|
|
default. Temporary paths that are discarded or modified after use should be
|
|
|
|
marked as volatile. This provides a hint to the device that the path
|
|
|
|
should not be cached. Providing this hint when appropriate can
|
|
|
|
improve performance by avoiding unnecessary overhead and resource
|
|
|
|
consumption on the device.
|
|
|
|
*/
|
|
|
|
void setIsVolatile(bool isVolatile) {
|
|
|
|
fIsVolatile = isVolatile;
|
|
|
|
}
|
|
|
|
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
/** Test a line for zero length
|
|
|
|
|
|
|
|
@return true if the line is of zero length; otherwise false.
|
|
|
|
*/
|
|
|
|
static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) {
|
2012-04-11 17:51:01 +00:00
|
|
|
return p1.equalsWithinTolerance(p2);
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Test a quad for zero length
|
|
|
|
|
|
|
|
@return true if the quad is of zero length; otherwise false.
|
|
|
|
*/
|
|
|
|
static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
|
|
|
|
const SkPoint& p3) {
|
2012-04-11 17:51:01 +00:00
|
|
|
return p1.equalsWithinTolerance(p2) &&
|
|
|
|
p2.equalsWithinTolerance(p3);
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Test a cubic curve for zero length
|
|
|
|
|
|
|
|
@return true if the cubic is of zero length; otherwise false.
|
|
|
|
*/
|
|
|
|
static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
|
|
|
|
const SkPoint& p3, const SkPoint& p4) {
|
2012-04-11 17:51:01 +00:00
|
|
|
return p1.equalsWithinTolerance(p2) &&
|
|
|
|
p2.equalsWithinTolerance(p3) &&
|
|
|
|
p3.equalsWithinTolerance(p4);
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-10 14:05:43 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the path specifies a single line (i.e. it contains just
|
|
|
|
* a moveTo and a lineTo). If so, and line[] is not null, it sets the 2
|
|
|
|
* points in line[] to the end-points of the line. If the path is not a
|
|
|
|
* line, returns false and ignores line[].
|
|
|
|
*/
|
|
|
|
bool isLine(SkPoint line[2]) const;
|
|
|
|
|
2010-02-09 16:38:45 +00:00
|
|
|
/** Return the number of points in the path
|
|
|
|
*/
|
2012-10-03 13:46:20 +00:00
|
|
|
int countPoints() const;
|
2010-02-09 16:38:45 +00:00
|
|
|
|
|
|
|
/** Return the point at the specified index. If the index is out of range
|
|
|
|
(i.e. is not 0 <= index < countPoints()) then the returned coordinates
|
|
|
|
will be (0,0)
|
|
|
|
*/
|
|
|
|
SkPoint getPoint(int index) const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns the number of points in the path. Up to max points are copied.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param points If not null, receives up to max points
|
|
|
|
@param max The maximum number of points to copy into points
|
|
|
|
@return the actual number of points in the path
|
|
|
|
*/
|
|
|
|
int getPoints(SkPoint points[], int max) const;
|
|
|
|
|
2012-06-07 21:43:15 +00:00
|
|
|
/** Return the number of verbs in the path
|
|
|
|
*/
|
2012-10-03 13:46:20 +00:00
|
|
|
int countVerbs() const;
|
2012-06-07 21:43:15 +00:00
|
|
|
|
|
|
|
/** Returns the number of verbs in the path. Up to max verbs are copied. The
|
|
|
|
verbs are copied as one byte per verb.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-06-07 21:43:15 +00:00
|
|
|
@param verbs If not null, receives up to max verbs
|
|
|
|
@param max The maximum number of verbs to copy into verbs
|
|
|
|
@return the actual number of verbs in the path
|
|
|
|
*/
|
|
|
|
int getVerbs(uint8_t verbs[], int max) const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
//! Swap contents of this and other. Guaranteed not to throw
|
|
|
|
void swap(SkPath& other);
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
/** Returns the bounds of the path's points. If the path contains 0 or 1
|
|
|
|
points, the bounds is set to (0,0,0,0), and isEmpty() will return true.
|
|
|
|
Note: this bounds may be larger than the actual shape, since curves
|
2015-01-05 18:13:46 +00:00
|
|
|
do not extend as far as their control points. Additionally this bound
|
|
|
|
can contain trailing MoveTo points (cf. isRect).
|
2009-04-01 18:31:44 +00:00
|
|
|
*/
|
|
|
|
const SkRect& getBounds() const {
|
2013-09-26 12:18:23 +00:00
|
|
|
return fPathRef->getBounds();
|
2009-04-01 18:31:44 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Calling this will, if the internal cache of the bounds is out of date,
|
2012-11-13 21:51:38 +00:00
|
|
|
update it so that subsequent calls to getBounds will be instantaneous.
|
2008-12-17 15:59:43 +00:00
|
|
|
This also means that any copies or simple transformations of the path
|
|
|
|
will inherit the cached bounds.
|
2009-04-01 18:31:44 +00:00
|
|
|
*/
|
|
|
|
void updateBoundsCache() const {
|
|
|
|
// for now, just calling getBounds() is sufficient
|
|
|
|
this->getBounds();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-11-13 21:51:38 +00:00
|
|
|
/**
|
|
|
|
* Does a conservative test to see whether a rectangle is inside a path. Currently it only
|
|
|
|
* will ever return true for single convex contour paths. The empty-status of the rect is not
|
|
|
|
* considered (e.g. a rect that is a point can be inside a path). Points or line segments where
|
|
|
|
* the rect edge touches the path border are not considered containment violations.
|
|
|
|
*/
|
|
|
|
bool conservativelyContainsRect(const SkRect& rect) const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// Construction methods
|
|
|
|
|
|
|
|
/** Hint to the path to prepare for adding more points. This can allow the
|
|
|
|
path to more efficiently grow its storage.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param extraPtCount The number of extra points the path should
|
|
|
|
preallocate for.
|
|
|
|
*/
|
|
|
|
void incReserve(unsigned extraPtCount);
|
|
|
|
|
|
|
|
/** Set the beginning of the next contour to the point (x,y).
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param x The x-coordinate of the start of a new contour
|
|
|
|
@param y The y-coordinate of the start of a new contour
|
|
|
|
*/
|
|
|
|
void moveTo(SkScalar x, SkScalar y);
|
|
|
|
|
|
|
|
/** Set the beginning of the next contour to the point
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param p The start of a new contour
|
|
|
|
*/
|
|
|
|
void moveTo(const SkPoint& p) {
|
|
|
|
this->moveTo(p.fX, p.fY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the beginning of the next contour relative to the last point on the
|
|
|
|
previous contour. If there is no previous contour, this is treated the
|
|
|
|
same as moveTo().
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param dx The amount to add to the x-coordinate of the end of the
|
|
|
|
previous contour, to specify the start of a new contour
|
|
|
|
@param dy The amount to add to the y-coordinate of the end of the
|
|
|
|
previous contour, to specify the start of a new contour
|
|
|
|
*/
|
|
|
|
void rMoveTo(SkScalar dx, SkScalar dy);
|
|
|
|
|
|
|
|
/** Add a line from the last point to the specified point (x,y). If no
|
|
|
|
moveTo() call has been made for this contour, the first point is
|
|
|
|
automatically set to (0,0).
|
|
|
|
|
|
|
|
@param x The x-coordinate of the end of a line
|
|
|
|
@param y The y-coordinate of the end of a line
|
|
|
|
*/
|
|
|
|
void lineTo(SkScalar x, SkScalar y);
|
|
|
|
|
|
|
|
/** Add a line from the last point to the specified point. If no moveTo()
|
|
|
|
call has been made for this contour, the first point is automatically
|
|
|
|
set to (0,0).
|
|
|
|
|
|
|
|
@param p The end of a line
|
|
|
|
*/
|
|
|
|
void lineTo(const SkPoint& p) {
|
|
|
|
this->lineTo(p.fX, p.fY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as lineTo, but the coordinates are considered relative to the last
|
|
|
|
point on this contour. If there is no previous point, then a moveTo(0,0)
|
|
|
|
is inserted automatically.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param dx The amount to add to the x-coordinate of the previous point
|
|
|
|
on this contour, to specify a line
|
|
|
|
@param dy The amount to add to the y-coordinate of the previous point
|
|
|
|
on this contour, to specify a line
|
|
|
|
*/
|
|
|
|
void rLineTo(SkScalar dx, SkScalar dy);
|
|
|
|
|
|
|
|
/** Add a quadratic bezier from the last point, approaching control point
|
|
|
|
(x1,y1), and ending at (x2,y2). If no moveTo() call has been made for
|
|
|
|
this contour, the first point is automatically set to (0,0).
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param x1 The x-coordinate of the control point on a quadratic curve
|
|
|
|
@param y1 The y-coordinate of the control point on a quadratic curve
|
|
|
|
@param x2 The x-coordinate of the end point on a quadratic curve
|
|
|
|
@param y2 The y-coordinate of the end point on a quadratic curve
|
|
|
|
*/
|
|
|
|
void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2);
|
|
|
|
|
|
|
|
/** Add a quadratic bezier from the last point, approaching control point
|
|
|
|
p1, and ending at p2. If no moveTo() call has been made for this
|
|
|
|
contour, the first point is automatically set to (0,0).
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param p1 The control point on a quadratic curve
|
|
|
|
@param p2 The end point on a quadratic curve
|
|
|
|
*/
|
|
|
|
void quadTo(const SkPoint& p1, const SkPoint& p2) {
|
|
|
|
this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as quadTo, but the coordinates are considered relative to the last
|
|
|
|
point on this contour. If there is no previous point, then a moveTo(0,0)
|
|
|
|
is inserted automatically.
|
|
|
|
|
|
|
|
@param dx1 The amount to add to the x-coordinate of the last point on
|
|
|
|
this contour, to specify the control point of a quadratic curve
|
|
|
|
@param dy1 The amount to add to the y-coordinate of the last point on
|
|
|
|
this contour, to specify the control point of a quadratic curve
|
|
|
|
@param dx2 The amount to add to the x-coordinate of the last point on
|
|
|
|
this contour, to specify the end point of a quadratic curve
|
|
|
|
@param dy2 The amount to add to the y-coordinate of the last point on
|
|
|
|
this contour, to specify the end point of a quadratic curve
|
|
|
|
*/
|
|
|
|
void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2);
|
|
|
|
|
2013-05-31 15:17:50 +00:00
|
|
|
void conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
|
|
|
SkScalar w);
|
|
|
|
void conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) {
|
|
|
|
this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w);
|
|
|
|
}
|
|
|
|
void rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2,
|
|
|
|
SkScalar w);
|
2013-06-01 07:01:39 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add a cubic bezier from the last point, approaching control points
|
|
|
|
(x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been
|
|
|
|
made for this contour, the first point is automatically set to (0,0).
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param x1 The x-coordinate of the 1st control point on a cubic curve
|
|
|
|
@param y1 The y-coordinate of the 1st control point on a cubic curve
|
|
|
|
@param x2 The x-coordinate of the 2nd control point on a cubic curve
|
|
|
|
@param y2 The y-coordinate of the 2nd control point on a cubic curve
|
|
|
|
@param x3 The x-coordinate of the end point on a cubic curve
|
|
|
|
@param y3 The y-coordinate of the end point on a cubic curve
|
|
|
|
*/
|
|
|
|
void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
|
|
|
SkScalar x3, SkScalar y3);
|
|
|
|
|
|
|
|
/** Add a cubic bezier from the last point, approaching control points p1
|
|
|
|
and p2, and ending at p3. If no moveTo() call has been made for this
|
|
|
|
contour, the first point is automatically set to (0,0).
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param p1 The 1st control point on a cubic curve
|
|
|
|
@param p2 The 2nd control point on a cubic curve
|
|
|
|
@param p3 The end point on a cubic curve
|
|
|
|
*/
|
|
|
|
void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) {
|
|
|
|
this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Same as cubicTo, but the coordinates are considered relative to the
|
|
|
|
current point on this contour. If there is no previous point, then a
|
|
|
|
moveTo(0,0) is inserted automatically.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param dx1 The amount to add to the x-coordinate of the last point on
|
|
|
|
this contour, to specify the 1st control point of a cubic curve
|
|
|
|
@param dy1 The amount to add to the y-coordinate of the last point on
|
|
|
|
this contour, to specify the 1st control point of a cubic curve
|
|
|
|
@param dx2 The amount to add to the x-coordinate of the last point on
|
|
|
|
this contour, to specify the 2nd control point of a cubic curve
|
|
|
|
@param dy2 The amount to add to the y-coordinate of the last point on
|
|
|
|
this contour, to specify the 2nd control point of a cubic curve
|
|
|
|
@param dx3 The amount to add to the x-coordinate of the last point on
|
|
|
|
this contour, to specify the end point of a cubic curve
|
|
|
|
@param dy3 The amount to add to the y-coordinate of the last point on
|
|
|
|
this contour, to specify the end point of a cubic curve
|
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
void rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2,
|
|
|
|
SkScalar x3, SkScalar y3);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-01-29 20:59:11 +00:00
|
|
|
/**
|
|
|
|
* Append the specified arc to the path. If the start of the arc is different from the path's
|
|
|
|
* current last point, then an automatic lineTo() is added to connect the current contour
|
|
|
|
* to the start of the arc. However, if the path is empty, then we call moveTo() with
|
|
|
|
* the first point of the arc. The sweep angle is treated mod 360.
|
|
|
|
*
|
|
|
|
* @param oval The bounding oval defining the shape and size of the arc
|
|
|
|
* @param startAngle Starting angle (in degrees) where the arc begins
|
|
|
|
* @param sweepAngle Sweep angle (in degrees) measured clockwise. This is treated mod 360.
|
|
|
|
* @param forceMoveTo If true, always begin a new contour with the arc
|
|
|
|
*/
|
|
|
|
void arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-01-29 20:59:11 +00:00
|
|
|
/**
|
|
|
|
* Append a line and arc to the current path. This is the same as the PostScript call "arct".
|
|
|
|
*/
|
|
|
|
void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Append a line and arc to the current path. This is the same as the
|
|
|
|
PostScript call "arct".
|
|
|
|
*/
|
|
|
|
void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
|
|
|
|
this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Close the current contour. If the current point is not equal to the
|
|
|
|
first point of the contour, a line segment is automatically added.
|
|
|
|
*/
|
|
|
|
void close();
|
|
|
|
|
2013-06-25 15:39:58 +00:00
|
|
|
enum Direction {
|
|
|
|
/** Direction either has not been or could not be computed */
|
|
|
|
kUnknown_Direction,
|
|
|
|
/** clockwise direction for adding closed contours */
|
|
|
|
kCW_Direction,
|
|
|
|
/** counter-clockwise direction for adding closed contours */
|
|
|
|
kCCW_Direction,
|
|
|
|
};
|
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Return the opposite of the specified direction. kUnknown is its own
|
|
|
|
* opposite.
|
|
|
|
*/
|
2012-11-13 14:36:42 +00:00
|
|
|
static Direction OppositeDirection(Direction dir) {
|
2012-11-26 18:16:27 +00:00
|
|
|
static const Direction gOppositeDir[] = {
|
|
|
|
kUnknown_Direction, kCCW_Direction, kCW_Direction
|
|
|
|
};
|
|
|
|
return gOppositeDir[dir];
|
2012-11-13 14:36:42 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 20:13:11 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not a fill type is inverted
|
2012-12-17 21:16:45 +00:00
|
|
|
*
|
|
|
|
* kWinding_FillType -> false
|
|
|
|
* kEvenOdd_FillType -> false
|
|
|
|
* kInverseWinding_FillType -> true
|
|
|
|
* kInverseEvenOdd_FillType -> true
|
2012-12-06 20:13:11 +00:00
|
|
|
*/
|
2012-12-17 21:16:45 +00:00
|
|
|
static bool IsInverseFillType(FillType fill) {
|
2012-12-06 20:13:11 +00:00
|
|
|
SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch);
|
|
|
|
SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch);
|
|
|
|
SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch);
|
|
|
|
SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch);
|
|
|
|
return (fill & 2) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the equivalent non-inverted fill type to the given fill type
|
2012-12-17 21:16:45 +00:00
|
|
|
*
|
|
|
|
* kWinding_FillType -> kWinding_FillType
|
|
|
|
* kEvenOdd_FillType -> kEvenOdd_FillType
|
|
|
|
* kInverseWinding_FillType -> kWinding_FillType
|
|
|
|
* kInverseEvenOdd_FillType -> kEvenOdd_FillType
|
2012-12-06 20:13:11 +00:00
|
|
|
*/
|
2012-12-17 21:16:45 +00:00
|
|
|
static FillType ConvertToNonInverseFillType(FillType fill) {
|
2012-12-06 20:13:11 +00:00
|
|
|
SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch);
|
|
|
|
SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch);
|
|
|
|
SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch);
|
|
|
|
SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch);
|
|
|
|
return (FillType)(fill & 1);
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:00:10 +00:00
|
|
|
/**
|
|
|
|
* Tries to quickly compute the direction of the first non-degenerate
|
|
|
|
* contour. If it can be computed, return true and set dir to that
|
|
|
|
* direction. If it cannot be (quickly) determined, return false and ignore
|
2012-11-13 14:36:42 +00:00
|
|
|
* the dir parameter. If the direction was determined, it is cached to make
|
|
|
|
* subsequent calls return quickly.
|
2012-01-10 18:00:10 +00:00
|
|
|
*/
|
|
|
|
bool cheapComputeDirection(Direction* dir) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the path's direction can be computed via
|
|
|
|
* cheapComputDirection() and if that computed direction matches the
|
2012-11-26 18:16:27 +00:00
|
|
|
* specified direction. If dir is kUnknown, returns true if the direction
|
|
|
|
* cannot be computed.
|
2012-01-10 18:00:10 +00:00
|
|
|
*/
|
|
|
|
bool cheapIsDirection(Direction dir) const {
|
2012-11-26 18:16:27 +00:00
|
|
|
Direction computedDir = kUnknown_Direction;
|
|
|
|
(void)this->cheapComputeDirection(&computedDir);
|
|
|
|
return computedDir == dir;
|
2012-01-10 18:00:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 22:06:51 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the path specifies a rectangle.
|
|
|
|
*
|
|
|
|
* If this returns false, then all output parameters are ignored, and left
|
|
|
|
* unchanged. If this returns true, then each of the output parameters
|
|
|
|
* are checked for NULL. If they are not, they return their value.
|
|
|
|
*
|
2015-01-05 18:13:46 +00:00
|
|
|
* @param rect If not null, set to the bounds of the rectangle.
|
|
|
|
* Note : this bounds may be smaller than the path's bounds, since it is just
|
|
|
|
* the bounds of the "drawable" parts of the path. e.g. a trailing MoveTo would
|
|
|
|
* be ignored in this rect, but not by the path's bounds
|
2014-12-29 22:06:51 +00:00
|
|
|
* @param isClosed If not null, set to true if the path is closed
|
|
|
|
* @param direction If not null, set to the rectangle's direction
|
|
|
|
* @return true if the path specifies a rectangle
|
|
|
|
*/
|
2015-01-05 18:13:46 +00:00
|
|
|
bool isRect(SkRect* rect, bool* isClosed = NULL, Direction* direction = NULL) const;
|
2013-06-25 15:39:58 +00:00
|
|
|
|
|
|
|
/** Returns true if the path specifies a pair of nested rectangles. If so, and if
|
|
|
|
rect is not null, set rect[0] to the outer rectangle and rect[1] to the inner
|
|
|
|
rectangle. If so, and dirs is not null, set dirs[0] to the direction of
|
|
|
|
the outer rectangle and dirs[1] to the direction of the inner rectangle. If
|
|
|
|
the path does not specify a pair of nested rectangles, return
|
|
|
|
false and ignore rect and dirs.
|
|
|
|
|
|
|
|
@param rect If not null, returns the path as a pair of nested rectangles
|
|
|
|
@param dirs If not null, returns the direction of the rects
|
|
|
|
@return true if the path describes a pair of nested rectangles
|
|
|
|
*/
|
|
|
|
bool isNestedRects(SkRect rect[2], Direction dirs[2] = NULL) const;
|
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Add a closed rectangle contour to the path
|
|
|
|
* @param rect The rectangle to add as a closed contour to the path
|
|
|
|
* @param dir The direction to wind the rectangle's contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
|
|
|
*/
|
2013-09-26 12:18:23 +00:00
|
|
|
void addRect(const SkRect& rect, Direction dir = kCW_Direction);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Add a closed rectangle contour to the path
|
|
|
|
*
|
|
|
|
* @param left The left side of a rectangle to add as a closed contour
|
|
|
|
* to the path
|
|
|
|
* @param top The top of a rectangle to add as a closed contour to the
|
|
|
|
* path
|
|
|
|
* @param right The right side of a rectangle to add as a closed contour
|
|
|
|
* to the path
|
|
|
|
* @param bottom The bottom of a rectangle to add as a closed contour to
|
|
|
|
* the path
|
|
|
|
* @param dir The direction to wind the rectangle's contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
|
|
|
|
Direction dir = kCW_Direction);
|
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Add a closed oval contour to the path
|
|
|
|
*
|
|
|
|
* @param oval The bounding oval to add as a closed contour to the path
|
|
|
|
* @param dir The direction to wind the oval's contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void addOval(const SkRect& oval, Direction dir = kCW_Direction);
|
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Add a closed circle contour to the path
|
|
|
|
*
|
|
|
|
* @param x The x-coordinate of the center of a circle to add as a
|
|
|
|
* closed contour to the path
|
|
|
|
* @param y The y-coordinate of the center of a circle to add as a
|
|
|
|
* closed contour to the path
|
|
|
|
* @param radius The radius of a circle to add as a closed contour to the
|
|
|
|
* path
|
|
|
|
* @param dir The direction to wind the circle's contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void addCircle(SkScalar x, SkScalar y, SkScalar radius,
|
|
|
|
Direction dir = kCW_Direction);
|
|
|
|
|
|
|
|
/** Add the specified arc to the path as a new contour.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param oval The bounds of oval used to define the size of the arc
|
|
|
|
@param startAngle Starting angle (in degrees) where the arc begins
|
|
|
|
@param sweepAngle Sweep angle (in degrees) measured clockwise
|
|
|
|
*/
|
|
|
|
void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle);
|
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Add a closed round-rectangle contour to the path
|
|
|
|
* @param rect The bounds of a round-rectangle to add as a closed contour
|
|
|
|
* @param rx The x-radius of the rounded corners on the round-rectangle
|
|
|
|
* @param ry The y-radius of the rounded corners on the round-rectangle
|
|
|
|
* @param dir The direction to wind the rectangle's contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
|
|
|
*/
|
2013-09-26 12:18:23 +00:00
|
|
|
void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,
|
|
|
|
Direction dir = kCW_Direction);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-11-26 18:16:27 +00:00
|
|
|
/**
|
|
|
|
* Add a closed round-rectangle contour to the path. Each corner receives
|
|
|
|
* two radius values [X, Y]. The corners are ordered top-left, top-right,
|
|
|
|
* bottom-right, bottom-left.
|
|
|
|
* @param rect The bounds of a round-rectangle to add as a closed contour
|
|
|
|
* @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner
|
|
|
|
* @param dir The direction to wind the rectangle's contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
2012-12-17 21:48:19 +00:00
|
|
|
* Note: The radii here now go through the same constraint handling as the
|
|
|
|
* SkRRect radii (i.e., either radii at a corner being 0 implies a
|
|
|
|
* sqaure corner and oversized radii are proportionally scaled down).
|
2012-11-26 18:16:27 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void addRoundRect(const SkRect& rect, const SkScalar radii[],
|
|
|
|
Direction dir = kCW_Direction);
|
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
/**
|
2012-12-17 21:48:19 +00:00
|
|
|
* Add an SkRRect contour to the path
|
|
|
|
* @param rrect The rounded rect to add as a closed contour
|
|
|
|
* @param dir The winding direction for the new contour. Cannot be
|
|
|
|
* kUnknown_Direction.
|
2012-12-12 20:48:18 +00:00
|
|
|
*/
|
2012-12-17 21:48:19 +00:00
|
|
|
void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction);
|
2012-12-12 20:48:18 +00:00
|
|
|
|
2012-05-29 19:54:52 +00:00
|
|
|
/**
|
|
|
|
* Add a new contour made of just lines. This is just a fast version of
|
|
|
|
* the following:
|
|
|
|
* this->moveTo(pts[0]);
|
|
|
|
* for (int i = 1; i < count; ++i) {
|
|
|
|
* this->lineTo(pts[i]);
|
|
|
|
* }
|
|
|
|
* if (close) {
|
|
|
|
* this->close();
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
void addPoly(const SkPoint pts[], int count, bool close);
|
|
|
|
|
2014-02-11 21:16:29 +00:00
|
|
|
enum AddPathMode {
|
|
|
|
/** Source path contours are added as new contours.
|
|
|
|
*/
|
|
|
|
kAppend_AddPathMode,
|
|
|
|
/** Path is added by extending the last contour of the destination path
|
|
|
|
with the first contour of the source path. If the last contour of
|
2014-02-12 03:02:04 +00:00
|
|
|
the destination path is closed, then it will not be extended.
|
2014-02-11 21:16:29 +00:00
|
|
|
Instead, the start of source path will be extended by a straight
|
|
|
|
line to the end point of the destination path.
|
|
|
|
*/
|
2014-02-12 03:02:04 +00:00
|
|
|
kExtend_AddPathMode
|
2014-02-11 21:16:29 +00:00
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Add a copy of src to the path, offset by (dx,dy)
|
|
|
|
@param src The path to add as a new contour
|
|
|
|
@param dx The amount to translate the path in X as it is added
|
|
|
|
@param dx The amount to translate the path in Y as it is added
|
|
|
|
*/
|
2014-02-11 21:16:29 +00:00
|
|
|
void addPath(const SkPath& src, SkScalar dx, SkScalar dy,
|
|
|
|
AddPathMode mode = kAppend_AddPathMode);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Add a copy of src to the path
|
|
|
|
*/
|
2014-02-11 21:16:29 +00:00
|
|
|
void addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
2014-02-11 21:16:29 +00:00
|
|
|
this->addPath(src, m, mode);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Add a copy of src to the path, transformed by matrix
|
|
|
|
@param src The path to add as a new contour
|
2014-02-11 21:16:29 +00:00
|
|
|
@param matrix Transform applied to src
|
|
|
|
@param mode Determines how path is added
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2014-02-11 21:16:29 +00:00
|
|
|
void addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend_AddPathMode);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-01-10 15:33:12 +00:00
|
|
|
/**
|
|
|
|
* Same as addPath(), but reverses the src input
|
|
|
|
*/
|
|
|
|
void reverseAddPath(const SkPath& src);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Offset the path by (dx,dy), returning true on success
|
2012-08-23 18:09:54 +00:00
|
|
|
|
|
|
|
@param dx The amount in the X direction to offset the entire path
|
|
|
|
@param dy The amount in the Y direction to offset the entire path
|
2008-12-17 15:59:43 +00:00
|
|
|
@param dst The translated path is written here
|
|
|
|
*/
|
|
|
|
void offset(SkScalar dx, SkScalar dy, SkPath* dst) const;
|
|
|
|
|
|
|
|
/** Offset the path by (dx,dy), returning true on success
|
2012-08-23 18:09:54 +00:00
|
|
|
|
|
|
|
@param dx The amount in the X direction to offset the entire path
|
|
|
|
@param dy The amount in the Y direction to offset the entire path
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void offset(SkScalar dx, SkScalar dy) {
|
|
|
|
this->offset(dx, dy, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Transform the points in this path by matrix, and write the answer into
|
|
|
|
dst.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param matrix The matrix to apply to the path
|
|
|
|
@param dst The transformed path is written here
|
|
|
|
*/
|
|
|
|
void transform(const SkMatrix& matrix, SkPath* dst) const;
|
|
|
|
|
|
|
|
/** Transform the points in this path by matrix
|
|
|
|
|
|
|
|
@param matrix The matrix to apply to the path
|
|
|
|
*/
|
|
|
|
void transform(const SkMatrix& matrix) {
|
|
|
|
this->transform(matrix, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the last point on the path. If no points have been added, (0,0)
|
2011-10-11 11:58:32 +00:00
|
|
|
is returned. If there are no points, this returns false, otherwise it
|
|
|
|
returns true.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param lastPt The last point on the path is returned here
|
|
|
|
*/
|
2011-10-11 11:58:32 +00:00
|
|
|
bool getLastPt(SkPoint* lastPt) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Set the last point on the path. If no points have been added,
|
|
|
|
moveTo(x,y) is automatically called.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param x The new x-coordinate for the last point
|
|
|
|
@param y The new y-coordinate for the last point
|
|
|
|
*/
|
|
|
|
void setLastPt(SkScalar x, SkScalar y);
|
|
|
|
|
|
|
|
/** Set the last point on the path. If no points have been added, moveTo(p)
|
|
|
|
is automatically called.
|
|
|
|
|
|
|
|
@param p The new location for the last point
|
|
|
|
*/
|
|
|
|
void setLastPt(const SkPoint& p) {
|
|
|
|
this->setLastPt(p.fX, p.fY);
|
|
|
|
}
|
|
|
|
|
2011-09-21 12:29:05 +00:00
|
|
|
enum SegmentMask {
|
|
|
|
kLine_SegmentMask = 1 << 0,
|
|
|
|
kQuad_SegmentMask = 1 << 1,
|
2013-05-31 15:17:50 +00:00
|
|
|
kConic_SegmentMask = 1 << 2,
|
|
|
|
kCubic_SegmentMask = 1 << 3,
|
2011-09-21 12:29:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a mask, where each bit corresponding to a SegmentMask is
|
|
|
|
* set if the path contains 1 or more segments of that type.
|
|
|
|
* Returns 0 for an empty path (no segments).
|
|
|
|
*/
|
2013-12-12 23:03:51 +00:00
|
|
|
uint32_t getSegmentMasks() const { return fPathRef->getSegmentMasks(); }
|
2011-09-21 12:29:05 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
enum Verb {
|
|
|
|
kMove_Verb, //!< iter.next returns 1 point
|
|
|
|
kLine_Verb, //!< iter.next returns 2 points
|
|
|
|
kQuad_Verb, //!< iter.next returns 3 points
|
2013-05-31 15:17:50 +00:00
|
|
|
kConic_Verb, //!< iter.next returns 3 points + iter.conicWeight()
|
2008-12-17 15:59:43 +00:00
|
|
|
kCubic_Verb, //!< iter.next returns 4 points
|
2011-07-13 17:44:36 +00:00
|
|
|
kClose_Verb, //!< iter.next returns 1 point (contour's moveTo pt)
|
2013-05-31 15:17:50 +00:00
|
|
|
kDone_Verb, //!< iter.next returns 0 points
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Iterate through all of the segments (lines, quadratics, cubics) of
|
|
|
|
each contours in a path.
|
2011-12-29 21:03:28 +00:00
|
|
|
|
|
|
|
The iterator cleans up the segments along the way, removing degenerate
|
|
|
|
segments and adding close verbs where necessary. When the forceClose
|
|
|
|
argument is provided, each contour (as defined by a new starting
|
|
|
|
move command) will be completed with a close verb regardless of the
|
|
|
|
contour's contents.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API Iter {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2011-12-29 21:03:28 +00:00
|
|
|
Iter();
|
|
|
|
Iter(const SkPath&, bool forceClose);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
void setPath(const SkPath&, bool forceClose);
|
|
|
|
|
|
|
|
/** Return the next verb in this iteration of the path. When all
|
|
|
|
segments have been visited, return kDone_Verb.
|
2011-12-21 20:43:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param pts The points representing the current verb and/or segment
|
2012-05-16 17:16:46 +00:00
|
|
|
@param doConsumeDegerates If true, first scan for segments that are
|
|
|
|
deemed degenerate (too short) and skip those.
|
2008-12-17 15:59:43 +00:00
|
|
|
@return The verb for the current segment
|
|
|
|
*/
|
2012-05-16 17:16:46 +00:00
|
|
|
Verb next(SkPoint pts[4], bool doConsumeDegerates = true) {
|
|
|
|
if (doConsumeDegerates) {
|
|
|
|
this->consumeDegenerateSegments();
|
|
|
|
}
|
|
|
|
return this->doNext(pts);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-05-31 15:17:50 +00:00
|
|
|
/**
|
|
|
|
* Return the weight for the current conic. Only valid if the current
|
|
|
|
* segment return by next() was a conic.
|
|
|
|
*/
|
|
|
|
SkScalar conicWeight() const { return *fConicWeights; }
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** If next() returns kLine_Verb, then this query returns true if the
|
|
|
|
line was the result of a close() command (i.e. the end point is the
|
|
|
|
initial moveto for this contour). If next() returned a different
|
|
|
|
verb, this returns an undefined value.
|
2011-12-21 20:43:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@return If the last call to next() returned kLine_Verb, return true
|
|
|
|
if it was the result of an explicit close command.
|
|
|
|
*/
|
|
|
|
bool isCloseLine() const { return SkToBool(fCloseLine); }
|
2011-12-21 20:43:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Returns true if the current contour is closed (has a kClose_Verb)
|
|
|
|
@return true if the current contour is closed (has a kClose_Verb)
|
|
|
|
*/
|
|
|
|
bool isClosedContour() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const SkPoint* fPts;
|
|
|
|
const uint8_t* fVerbs;
|
|
|
|
const uint8_t* fVerbStop;
|
2013-05-31 15:17:50 +00:00
|
|
|
const SkScalar* fConicWeights;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPoint fMoveTo;
|
|
|
|
SkPoint fLastPt;
|
|
|
|
SkBool8 fForceClose;
|
|
|
|
SkBool8 fNeedClose;
|
|
|
|
SkBool8 fCloseLine;
|
2011-12-21 20:43:13 +00:00
|
|
|
SkBool8 fSegmentState;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-05-15 17:05:38 +00:00
|
|
|
inline const SkPoint& cons_moveTo();
|
2008-12-17 15:59:43 +00:00
|
|
|
Verb autoClose(SkPoint pts[2]);
|
Modifying SkPath to store all verbs provided by the user, and to give
correct results for all stroke and fill modes even on the various types
of degenerate paths.
The goals of this patch include:
1. Have Skia store all of the verbs implied by path construction methods, even
if those define degenerate paths. The SVG implementation in WebKit, which is
backed by Skia, needs to know about all elements of the path, even degenerate
ones, for the correct drawing of markers and line caps. For example, in SVG you
should be able to draw a scatter plot by specifying a marker for vertices and
then giving a sequence of moveTo commands. Skia will not store the moveTos,
requiring a different storage mechanism.
2. Assuming 1, maintain the current Skia behavior. That is, make Skia robust to
degenerate paths.
3. Fix an existing bug in Skia where a degenerate moveTo-lineTo pair spits out
warnings from rasterization and produces incorrect results in inverse-fill
renderings.
4. Adds extensive testing for degenerate paths and path rendering in general.
To meet these goals, the patch I am proposing will result in minor additional
storage for degenerate paths (a few bytes per degenerate path, only if the user
defines such paths). There is also some additional overhead in the iteration
code, with the path now cleaned to remove degenerate segments as part of the
iteration process. I suspect this will also fix issues with computing normal
vectors to degenerate segments. Benchmarking suggests that this change may
result in slightly (< 1%) slower path drawing due to the checks for
degeneracy. This overhead could be removed (in fact, a significant speedup
could occur) if the results of iterating to clean up the path were cached.
This would cost memory, of course, and quite a bit of it.
BUG=398
TEST=tests/PathTest.cpp
gm/cubicpaths.cpp
gm/degeneratesegments.cpp
gm/movepaths.cpp
gm/linepaths.cpp
gm/quadpaths.cpp
Review URL: http://codereview.appspot.com/5482051
git-svn-id: http://skia.googlecode.com/svn/trunk@2901 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-12-20 15:14:18 +00:00
|
|
|
void consumeDegenerateSegments();
|
2012-05-16 17:16:46 +00:00
|
|
|
Verb doNext(SkPoint pts[4]);
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
/** Iterate through the verbs in the path, providing the associated points.
|
|
|
|
*/
|
|
|
|
class SK_API RawIter {
|
|
|
|
public:
|
|
|
|
RawIter();
|
|
|
|
RawIter(const SkPath&);
|
|
|
|
|
|
|
|
void setPath(const SkPath&);
|
|
|
|
|
|
|
|
/** Return the next verb in this iteration of the path. When all
|
|
|
|
segments have been visited, return kDone_Verb.
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
@param pts The points representing the current verb and/or segment
|
2012-06-07 17:47:33 +00:00
|
|
|
This must not be NULL.
|
2012-01-04 21:05:51 +00:00
|
|
|
@return The verb for the current segment
|
|
|
|
*/
|
|
|
|
Verb next(SkPoint pts[4]);
|
|
|
|
|
2013-05-31 15:17:50 +00:00
|
|
|
SkScalar conicWeight() const { return *fConicWeights; }
|
|
|
|
|
2012-01-04 21:05:51 +00:00
|
|
|
private:
|
|
|
|
const SkPoint* fPts;
|
|
|
|
const uint8_t* fVerbs;
|
|
|
|
const uint8_t* fVerbStop;
|
2013-05-31 15:17:50 +00:00
|
|
|
const SkScalar* fConicWeights;
|
2012-01-04 21:05:51 +00:00
|
|
|
SkPoint fMoveTo;
|
|
|
|
SkPoint fLastPt;
|
|
|
|
};
|
|
|
|
|
2012-07-11 01:51:33 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the point { x, y } is contained by the path, taking into
|
|
|
|
* account the FillType.
|
|
|
|
*/
|
|
|
|
bool contains(SkScalar x, SkScalar y) const;
|
|
|
|
|
2014-09-15 16:26:09 +00:00
|
|
|
void dump(SkWStream* , bool forceClose, bool dumpAsHex) const;
|
2009-11-23 20:10:41 +00:00
|
|
|
void dump() const;
|
2014-09-15 16:26:09 +00:00
|
|
|
void dumpHex() const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-06-08 18:30:46 +00:00
|
|
|
/**
|
2013-11-05 15:46:56 +00:00
|
|
|
* Write the path to the buffer, and return the number of bytes written.
|
2012-06-08 18:30:46 +00:00
|
|
|
* If buffer is NULL, it still returns the number of bytes.
|
|
|
|
*/
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t writeToMemory(void* buffer) const;
|
2012-06-08 18:30:46 +00:00
|
|
|
/**
|
2013-11-05 15:46:56 +00:00
|
|
|
* Initializes the path from the buffer
|
|
|
|
*
|
|
|
|
* @param buffer Memory to read from
|
|
|
|
* @param length Amount of memory available in the buffer
|
|
|
|
* @return number of bytes read (must be a multiple of 4) or
|
|
|
|
* 0 if there was not enough memory available
|
2012-06-08 18:30:46 +00:00
|
|
|
*/
|
2013-11-05 15:46:56 +00:00
|
|
|
size_t readFromMemory(const void* buffer, size_t length);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-10-30 18:57:55 +00:00
|
|
|
/** Returns a non-zero, globally unique value corresponding to the set of verbs
|
|
|
|
and points in the path (but not the fill type [except on Android skbug.com/1762]).
|
2013-10-31 07:01:53 +00:00
|
|
|
Each time the path is modified, a different generation ID will be returned.
|
2013-10-30 18:57:55 +00:00
|
|
|
*/
|
2013-10-29 22:45:37 +00:00
|
|
|
uint32_t getGenerationID() const;
|
2013-10-30 18:57:55 +00:00
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
|
|
|
static const int kPathRefGenIDBitCnt = 30; // leave room for the fill type (skbug.com/1762)
|
2012-03-21 15:39:03 +00:00
|
|
|
const SkPath* getSourcePath() const;
|
|
|
|
void setSourcePath(const SkPath* path);
|
2013-10-30 18:57:55 +00:00
|
|
|
#else
|
|
|
|
static const int kPathRefGenIDBitCnt = 32;
|
2011-04-15 13:41:26 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDEBUGCODE(void validate() const;)
|
|
|
|
|
|
|
|
private:
|
2012-08-17 10:58:49 +00:00
|
|
|
enum SerializationOffsets {
|
2014-01-23 15:16:05 +00:00
|
|
|
// 1 free bit at 29
|
2013-12-03 19:46:58 +00:00
|
|
|
kUnused1_SerializationShift = 28, // 1 free bit
|
2012-11-13 14:36:42 +00:00
|
|
|
kDirection_SerializationShift = 26, // requires 2 bits
|
2014-10-24 14:12:51 +00:00
|
|
|
kIsVolatile_SerializationShift = 25, // requires 1 bit
|
2014-01-23 15:16:05 +00:00
|
|
|
// 1 free bit at 24
|
2013-09-26 12:18:23 +00:00
|
|
|
kConvexity_SerializationShift = 16, // requires 8 bits
|
|
|
|
kFillType_SerializationShift = 8, // requires 8 bits
|
2014-01-23 15:16:05 +00:00
|
|
|
// 8 free bits at 0
|
2012-08-17 10:58:49 +00:00
|
|
|
};
|
|
|
|
|
2012-10-03 19:57:01 +00:00
|
|
|
SkAutoTUnref<SkPathRef> fPathRef;
|
|
|
|
|
2014-02-12 17:44:30 +00:00
|
|
|
int fLastMoveToIndex;
|
2008-12-17 15:59:43 +00:00
|
|
|
uint8_t fFillType;
|
2011-05-16 14:16:04 +00:00
|
|
|
mutable uint8_t fConvexity;
|
2012-11-13 14:36:42 +00:00
|
|
|
mutable uint8_t fDirection;
|
2014-10-24 14:12:51 +00:00
|
|
|
mutable SkBool8 fIsVolatile;
|
2011-11-08 19:00:26 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
2012-03-21 15:39:03 +00:00
|
|
|
const SkPath* fSourcePath;
|
2011-04-15 13:41:26 +00:00
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-06-21 15:13:34 +00:00
|
|
|
/** Resets all fields other than fPathRef to their initial 'empty' values.
|
|
|
|
* Assumes the caller has already emptied fPathRef.
|
|
|
|
* On Android increments fGenerationID without reseting it.
|
|
|
|
*/
|
|
|
|
void resetFields();
|
|
|
|
|
|
|
|
/** Sets all fields other than fPathRef to the values in 'that'.
|
|
|
|
* Assumes the caller has already set fPathRef.
|
2013-08-07 19:17:53 +00:00
|
|
|
* Doesn't change fGenerationID or fSourcePath on Android.
|
2013-06-21 15:13:34 +00:00
|
|
|
*/
|
|
|
|
void copyFields(const SkPath& that);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
friend class Iter;
|
|
|
|
|
|
|
|
friend class SkPathStroker;
|
|
|
|
|
|
|
|
/* Append, in reverse order, the first contour of path, ignoring path's
|
|
|
|
last point. If no moveTo() call has been made for this contour, the
|
|
|
|
first point is automatically set to (0,0).
|
|
|
|
*/
|
|
|
|
void reversePathTo(const SkPath&);
|
|
|
|
|
2012-01-12 18:17:11 +00:00
|
|
|
// called before we add points for lineTo, quadTo, cubicTo, checking to see
|
|
|
|
// if we need to inject a leading moveTo first
|
|
|
|
//
|
|
|
|
// SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0)
|
|
|
|
// SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo)
|
|
|
|
//
|
2014-02-12 17:44:30 +00:00
|
|
|
inline void injectMoveToIfNeeded();
|
2012-01-12 18:17:11 +00:00
|
|
|
|
2012-04-18 13:29:52 +00:00
|
|
|
inline bool hasOnlyMoveTos() const;
|
|
|
|
|
2012-11-13 14:36:42 +00:00
|
|
|
Convexity internalGetConvexity() const;
|
2012-11-20 02:01:23 +00:00
|
|
|
|
2012-11-21 15:18:06 +00:00
|
|
|
bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts,
|
|
|
|
bool* isClosed, Direction* direction) const;
|
2012-11-13 14:36:42 +00:00
|
|
|
|
2013-09-26 12:18:23 +00:00
|
|
|
/** Returns if the path can return a bound at no cost (true) or will have to
|
|
|
|
perform some computation (false).
|
|
|
|
*/
|
|
|
|
bool hasComputedBounds() const {
|
|
|
|
SkDEBUGCODE(this->validate();)
|
|
|
|
return fPathRef->hasComputedBounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 'rect' needs to be sorted
|
|
|
|
void setBounds(const SkRect& rect) {
|
2013-12-13 19:36:25 +00:00
|
|
|
SkPathRef::Editor ed(&fPathRef);
|
|
|
|
|
|
|
|
ed.setBounds(rect);
|
2013-09-26 12:18:23 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
friend class SkAutoPathBoundsUpdate;
|
2012-04-18 13:29:52 +00:00
|
|
|
friend class SkAutoDisableOvalCheck;
|
2012-11-13 14:36:42 +00:00
|
|
|
friend class SkAutoDisableDirectionCheck;
|
2013-11-14 16:53:22 +00:00
|
|
|
friend class SkBench_AddPathTest; // perf test reversePathTo
|
|
|
|
friend class PathTest_Private; // unit test reversePathTo
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|