aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/include
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-04 20:29:08 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-04 20:29:08 +0000
commit5aaa69e4339e229adfb05e96084a8ec0a590238b (patch)
tree0a4c274694b62f8e908d73adaa0d28215fd9fe7b /gpu/include
parentf7c2c4544f866ae65cd9a4eee4da563f6d653d20 (diff)
Fixups for clipstack, convexity test for paths.
Review URL http://codereview.appspot.com/4250056/ git-svn-id: http://skia.googlecode.com/svn/trunk@891 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/include')
-rw-r--r--gpu/include/GrClipIterator.h4
-rw-r--r--gpu/include/GrDrawTarget.h10
-rw-r--r--gpu/include/GrPath.h39
-rw-r--r--gpu/include/GrPathIter.h74
-rw-r--r--gpu/include/GrPoint.h49
-rw-r--r--gpu/include/GrRect.h14
-rw-r--r--gpu/include/GrStencil.h5
-rw-r--r--gpu/include/GrTypes.h111
8 files changed, 212 insertions, 94 deletions
diff --git a/gpu/include/GrClipIterator.h b/gpu/include/GrClipIterator.h
index abad619623..1fcbdd178a 100644
--- a/gpu/include/GrClipIterator.h
+++ b/gpu/include/GrClipIterator.h
@@ -68,8 +68,8 @@ public:
virtual GrSetOp getOp() const = 0;
/**
- * Call to move to the next rect in the set, previous path iter can be made
- * invalid.
+ * Call to move to the next element in the list, previous path iter can be
+ * made invalid.
*/
virtual void next() = 0;
};
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index 576bd7ae41..285665b0c8 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -106,6 +106,9 @@ public:
/**
* Sets the stencil settings to use for the next draw.
+ * Changing the clip has the side-effect of possibly zeroing
+ * out the client settable stencil bits. So multipass algorithms
+ * using stencil should not change the clip between passes.
* @param settings the stencil settings to use.
*/
void setStencil(const GrStencilSettings& settings) {
@@ -156,6 +159,8 @@ public:
* Sets the current clip to the region specified by clip. All draws will be
* clipped against this clip if kClip_StateBit is enabled.
*
+ * Setting the clip may (or may not) zero out the client's stencil bits.
+ *
* @param description of the clipping region
*/
void setClip(const GrClip& clip);
@@ -965,6 +970,8 @@ public:
vertexIndex * vertexSize);
}
+ static void VertexLayoutUnitTest();
+
protected:
// Helpers for GrDrawTarget subclasses that won't have private access to
@@ -1047,9 +1054,6 @@ protected:
AutoGeometrySrcRestore(const AutoGeometrySrcRestore&);
AutoGeometrySrcRestore& operator =(AutoGeometrySrcRestore&);
};
-
-private:
- void VertexLayoutUnitTest();
};
#endif
diff --git a/gpu/include/GrPath.h b/gpu/include/GrPath.h
index 23fc4a86b6..d70609ee6b 100644
--- a/gpu/include/GrPath.h
+++ b/gpu/include/GrPath.h
@@ -30,8 +30,8 @@ public:
explicit GrPath(GrPathIter&);
virtual ~GrPath();
- GrPathIter::ConvexHint getConvexHint() const { return fConvexHint; }
- void setConvexHint(GrPathIter::ConvexHint hint) { fConvexHint = hint; }
+ GrConvexHint getConvexHint() const { return fConvexHint; }
+ void setConvexHint(GrConvexHint hint) { fConvexHint = hint; }
void resetFromIter(GrPathIter*);
@@ -48,35 +48,44 @@ public:
class Iter : public GrPathIter {
public:
+ /**
+ * Creates an uninitialized iterator
+ */
+ Iter();
+
Iter(const GrPath& path);
// overrides from GrPathIter
- virtual Command next(GrPoint points[]);
- virtual ConvexHint convexHint() const;
- virtual Command next();
+ virtual GrPathCmd next(GrPoint points[]);
+ virtual GrConvexHint convexHint() const;
+ virtual GrPathCmd next();
virtual void rewind();
+
+ /**
+ * Sets iterator to begining of path
+ */
+ void reset(const GrPath& path);
private:
- const GrPath& fPath;
+ const GrPath* fPath;
GrPoint fLastPt;
- int fVerbIndex;
+ int fCmdIndex;
int fPtIndex;
};
+ static void ConvexUnitTest();
+
private:
- enum Verb {
- kMove, kLine, kQuad, kCubic, kClose
- };
- GrTDArray<uint8_t> fVerbs;
+ GrTDArray<GrPathCmd> fCmds;
GrTDArray<GrPoint> fPts;
- GrPathIter::ConvexHint fConvexHint;
+ GrConvexHint fConvexHint;
// this ensures we have a moveTo at the start of each contour
inline void ensureMoveTo();
- bool wasLastVerb(Verb verb) const {
- int count = fVerbs.count();
- return count > 0 && verb == fVerbs[count - 1];
+ bool wasLastVerb(GrPathCmd cmd) const {
+ int count = fCmds.count();
+ return count > 0 && cmd == fCmds[count - 1];
}
friend class Iter;
diff --git a/gpu/include/GrPathIter.h b/gpu/include/GrPathIter.h
index 140cbcba56..f310184bd7 100644
--- a/gpu/include/GrPathIter.h
+++ b/gpu/include/GrPathIter.h
@@ -29,76 +29,36 @@ struct GrPoint;
*/
class GrPathIter {
public:
- /**
- Returned by next(). Indicates the next piece of the path.
- */
- enum Command {
- kMove_Command, //!< next() returns 1 pt
- // Starts a new subpath at
- // at the returned point
- kLine_Command, //!< next() returns 2 pts
- // Adds a line segment
- kQuadratic_Command, //!< next() returns 3 pts
- // Adds a quadratic segment
- kCubic_Command, //!< next() returns 4 pts
- // Adds a cubic segment
- kClose_Command, //!< next() returns 0 pts
- kEnd_Command //!< next() returns 0 pts
- // Implictly closes the last
- // point
- };
-
- enum ConvexHint {
- kNone_ConvexHint, //<! No hint about convexity
- // of the path
- kConvex_ConvexHint, //<! Path is one convex piece
- kNonOverlappingConvexPieces_ConvexHint, //<! Multiple convex pieces,
- // pieces are known to be
- // disjoint
- kSameWindingConvexPieces_ConvexHint, //<! Multiple convex pieces,
- // may or may not intersect,
- // either all wind cw or all
- // wind ccw.
- kConcave_ConvexHint //<! Path is known to be
- // concave
- };
-
- static int NumCommandPoints(Command cmd) {
- static const int numPoints[] = {
- 1, 2, 3, 4, 0, 0
- };
- return numPoints[cmd];
- }
virtual ~GrPathIter() {};
/**
- Iterates through the path. Should not be called after
- kEnd_Command has been returned once. This version retrieves the
- points for the command.
- @param points The points relevant to returned commend. See Command
- enum for number of points valid for each command.
- @return The next command of the path.
+ * Iterates through the path. Should not be called after
+ * kEnd_Command has been returned once. This version retrieves the
+ * points for the command.
+ * @param points The points relevant to returned commend. See Command
+ * enum for number of points valid for each command.
+ * @return The next command of the path.
*/
- virtual Command next(GrPoint points[4]) = 0;
+ virtual GrPathCmd next(GrPoint points[4]) = 0;
/**
* If the host API has knowledge of the convexity of the path
- * it can be communicated by this hint. Ganesh can make these
- * determinations itself. So it is not necessary to compute
- * convexity status if it isn't already determined.
+ * it can be communicated by this hint. Gr can analyze the path
+ * as it is iterated. So it is not necessary to do additional work to
+ * compute convexity status if it isn't already determined.
*
* @return a hint about the convexity of the path.
*/
- virtual ConvexHint convexHint() const { return kNone_ConvexHint; }
+ virtual GrConvexHint convexHint() const { return kNone_ConvexHint; }
/**
- Iterates through the path. Should not be called after
- kEnd_Command has been returned once. This version does not retrieve the
- points for the command.
- @return The next command of the path.
- */
- virtual Command next() = 0;
+ * Iterates through the path. Should not be called after
+ * kEnd_Command has been returned once. This version does not retrieve the
+ * points for the command.
+ * @return The next command of the path.
+ */
+ virtual GrPathCmd next() = 0;
/**
Restarts iteration from the beginning.
diff --git a/gpu/include/GrPoint.h b/gpu/include/GrPoint.h
index bb24959c34..c07543bb30 100644
--- a/gpu/include/GrPoint.h
+++ b/gpu/include/GrPoint.h
@@ -161,7 +161,47 @@ public:
fX = b.fX - a.fX;
fY = b.fY - a.fY;
}
-
+
+ /**
+ * Make this vector be orthogonal to vec. Looking down vec the
+ * new vector will point left.
+ */
+ void setOrthogLeft(const GrVec& vec) {
+ // vec could be this
+ GrVec v = vec;
+ fX = -v.fY;
+ fY = v.fX;
+ }
+
+ /**
+ * Make this vector be orthogonal to vec. Looking down vec the
+ * new vector will point right.
+ */
+ void setOrthogRight(const GrVec& vec) {
+ // vec could be this
+ GrVec v = vec;
+ fX = v.fY;
+ fY = -v.fX;
+ }
+
+ /**
+ * set orthogonal to vec from a to b. Will be facing left relative to a,b
+ * vec
+ */
+ void setOrthogLeftToVecBetween(const GrPoint& a, const GrPoint& b) {
+ fX = a.fY - b.fY;
+ fY = b.fX - a.fX;
+ }
+
+ /**
+ * set orthogonal to vec from a to b. Will be facing right relative to a,b
+ * vec.
+ */
+ void setOrthogRightToVecBetween(const GrPoint& a, const GrPoint& b) {
+ fX = b.fY - a.fY;
+ fY = a.fX - b.fX;
+ }
+
/**
* length of the vector squared.
*/
@@ -201,6 +241,13 @@ public:
}
/**
+ * Dot product of this vec with vector from (0,0) to a pt.
+ */
+ GrScalar dotWithVecToPt(const GrPoint& pt) const {
+ return GrMul(pt.fX, fX) + GrMul(pt.fY, fY);
+ }
+
+ /**
* z-value of this cross vec.
*/
GrScalar cross(const GrVec& vec) const {
diff --git a/gpu/include/GrRect.h b/gpu/include/GrRect.h
index 96d302f53d..e0e53264fd 100644
--- a/gpu/include/GrRect.h
+++ b/gpu/include/GrRect.h
@@ -205,12 +205,26 @@ struct GrRect {
return (fLeft > fRight) || (fTop > fBottom);
}
+ /**
+ * Does this rect contain a point.
+ */
bool contains(const GrPoint& point) const {
return point.fX >= fLeft && point.fX < fRight &&
point.fY >= fTop && point.fY < fBottom;
}
/**
+ * Does this rect fully contain another rect.
+ */
+ bool contains(const GrRect& r) const {
+ return fLeft <= r.fLeft &&
+ fRight >= r.fRight &&
+ fTop <= r.fTop &&
+ fBottom >= r.fBottom;
+ }
+
+
+ /**
* Initialize a rectangle to a point.
* @param pt the point used to initialize the rectangle.
*/
diff --git a/gpu/include/GrStencil.h b/gpu/include/GrStencil.h
index be3e0f66fb..b014ee5586 100644
--- a/gpu/include/GrStencil.h
+++ b/gpu/include/GrStencil.h
@@ -190,8 +190,7 @@ private:
* existing clip
* @param stencilClipMask mask with just the stencil bit used for clipping
* enabled.
- * @param fill in: the fill rule of the element to draw.
- * out: the fill rule that should be used to draw
+ * @param invertedFill is this path inverted
* @param numPasses out: the number of passes needed to add the
* element to the clip.
* @param settings out: the stencil settings to use for each pass
@@ -203,7 +202,7 @@ private:
static bool GetClipPasses(GrSetOp op,
bool canBeDirect,
unsigned int stencilClipMask,
- GrPathFill* fill,
+ bool invertedFill,
int* numPasses,
GrStencilSettings settings[kMaxStencilClipPasses]);
};
diff --git a/gpu/include/GrTypes.h b/gpu/include/GrTypes.h
index 29e847fd09..f407e2f444 100644
--- a/gpu/include/GrTypes.h
+++ b/gpu/include/GrTypes.h
@@ -161,19 +161,6 @@ template <typename Dst, typename Src> Dst GrTCast(Src src) {
typedef uint16_t GrVertexLayout;
/**
- * Path filling rules
- */
-enum GrPathFill {
- kWinding_PathFill,
- kEvenOdd_PathFill,
- kInverseWinding_PathFill,
- kInverseEvenOdd_PathFill,
- kHairLine_PathFill,
-
- kPathFillCount
-};
-
-/**
* Geometric primitives used for drawing.
*/
enum GrPrimitiveType {
@@ -221,6 +208,104 @@ enum GrClipType {
kPath_ClipType
};
+/**
+ * Commands used to describe a path. Each command
+ * is accompanied by some number of points.
+ */
+enum GrPathCmd {
+ kMove_PathCmd, //!< Starts a new subpath at
+ // at the returned point
+ // 1 point
+ kLine_PathCmd, //!< Adds a line segment
+ // 2 points
+ kQuadratic_PathCmd, //!< Adds a quadratic segment
+ // 3 points
+ kCubic_PathCmd, //!< Adds a cubic segment
+ // 4 points
+ kClose_PathCmd, //!< Closes the current subpath
+ // by connecting a line to the
+ // starting point.
+ // 0 points
+ kEnd_PathCmd //!< Indicates the end of the last subpath
+ // when iterating
+ // 0 points.
+};
+
+/**
+ * Gets the number of points associated with a path command.
+ */
+static int inline NumPathCmdPoints(GrPathCmd cmd) {
+ static const int gNumPoints[] = {
+ 1, 2, 3, 4, 0, 0
+ };
+ return gNumPoints[cmd];
+}
+
+/**
+ * Path filling rules
+ */
+enum GrPathFill {
+ kWinding_PathFill,
+ kEvenOdd_PathFill,
+ kInverseWinding_PathFill,
+ kInverseEvenOdd_PathFill,
+ kHairLine_PathFill,
+
+ kPathFillCount
+};
+
+static inline GrPathFill NonInvertedFill(GrPathFill fill) {
+ static const GrPathFill gNonInvertedFills[] = {
+ kWinding_PathFill, // kWinding_PathFill
+ kEvenOdd_PathFill, // kEvenOdd_PathFill
+ kWinding_PathFill, // kInverseWinding_PathFill
+ kEvenOdd_PathFill, // kInverseEvenOdd_PathFill
+ kHairLine_PathFill,// kHairLine_PathFill
+ };
+ GR_STATIC_ASSERT(0 == kWinding_PathFill);
+ GR_STATIC_ASSERT(1 == kEvenOdd_PathFill);
+ GR_STATIC_ASSERT(2 == kInverseWinding_PathFill);
+ GR_STATIC_ASSERT(3 == kInverseEvenOdd_PathFill);
+ GR_STATIC_ASSERT(4 == kHairLine_PathFill);
+ GR_STATIC_ASSERT(5 == kPathFillCount);
+ return gNonInvertedFills[fill];
+}
+
+static inline bool IsFillInverted(GrPathFill fill) {
+ static const bool gIsFillInverted[] = {
+ false, // kWinding_PathFill
+ false, // kEvenOdd_PathFill
+ true, // kInverseWinding_PathFill
+ true, // kInverseEvenOdd_PathFill
+ false, // kHairLine_PathFill
+ };
+ GR_STATIC_ASSERT(0 == kWinding_PathFill);
+ GR_STATIC_ASSERT(1 == kEvenOdd_PathFill);
+ GR_STATIC_ASSERT(2 == kInverseWinding_PathFill);
+ GR_STATIC_ASSERT(3 == kInverseEvenOdd_PathFill);
+ GR_STATIC_ASSERT(4 == kHairLine_PathFill);
+ GR_STATIC_ASSERT(5 == kPathFillCount);
+ return gIsFillInverted[fill];
+}
+
+/**
+ * Hints provided about a path's convexity (or lack thereof).
+ */
+enum GrConvexHint {
+ kNone_ConvexHint, //<! No hint about convexity
+ // of the path
+ kConvex_ConvexHint, //<! Path is one convex piece
+ kNonOverlappingConvexPieces_ConvexHint, //<! Multiple convex pieces,
+ // pieces are known to be
+ // disjoint
+ kSameWindingConvexPieces_ConvexHint, //<! Multiple convex pieces,
+ // may or may not intersect,
+ // either all wind cw or all
+ // wind ccw.
+ kConcave_ConvexHint //<! Path is known to be
+ // concave
+};
+
///////////////////////////////////////////////////////////////////////////////
// this is included only to make it easy to use this debugging facility