When adding a convex shape to a path, mark path as convex if path is initially degenerate.

Review URL: http://codereview.appspot.com/5504073/



git-svn-id: http://skia.googlecode.com/svn/trunk@3124 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 72a7d68..322bd17 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -26,6 +26,12 @@
     dst->fBottom = SkMaxScalar(dst->fBottom, src.fBottom);
 }
 
+static bool is_degenerate(const SkPath& path) {
+    SkPath::Iter iter(path, false);
+    SkPoint pts[4];
+    return SkPath::kDone_Verb == iter.next(pts);
+}
+
 /*  This guy's constructor/destructor bracket a path editing operation. It is
     used when we know the bounds of the amount we are going to add to the path
     (usually a new contour, but not required).
@@ -34,8 +40,9 @@
     cached bounds), and the if it can, it updates the cache bounds explicitly,
     avoiding the need to revisit all of the points in getBounds().
 
-    It also notes if the path was originally empty, and if so, sets isConvex
-    to true. Thus it can only be used if the contour being added is convex.
+    It also notes if the path was originally degenerate, and if so, sets
+    isConvex to true. Thus it can only be used if the contour being added is
+    convex.
  */
 class SkAutoPathBoundsUpdate {
 public:
@@ -50,7 +57,7 @@
     }
 
     ~SkAutoPathBoundsUpdate() {
-        fPath->setIsConvex(fEmpty);
+        fPath->setIsConvex(fDegenerate);
         if (fEmpty) {
             fPath->fBounds = fRect;
             fPath->fBoundsIsDirty = false;
@@ -64,12 +71,14 @@
     SkPath* fPath;
     SkRect  fRect;
     bool    fDirty;
+    bool    fDegenerate;
     bool    fEmpty;
 
     // returns true if we should proceed
     void init(SkPath* path) {
         fPath = path;
         fDirty = SkToBool(path->fBoundsIsDirty);
+        fDegenerate = is_degenerate(*path);
         fEmpty = path->isEmpty();
         // Cannot use fRect for our bounds unless we know it is sorted
         fRect.sort();