add gm for reverseAddPath



git-svn-id: http://skia.googlecode.com/svn/trunk@3001 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/pathreverse.cpp b/gm/pathreverse.cpp
new file mode 100644
index 0000000..fc8028e
--- /dev/null
+++ b/gm/pathreverse.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
+#include "SkTypeface.h"
+
+static void test_path(SkCanvas* canvas, const SkPath& path) {
+    SkPaint paint;
+    paint.setAntiAlias(true);
+    canvas->drawPath(path, paint);
+    
+    paint.setStyle(SkPaint::kStroke_Style);
+    paint.setColor(SK_ColorRED);
+    canvas->drawPath(path, paint);
+}
+
+static void test_rev(SkCanvas* canvas, const SkPath& path) {
+    test_path(canvas, path);
+
+    SkPath rev;
+    rev.reverseAddPath(path);
+    canvas->save();
+    canvas->translate(150, 0);
+    test_path(canvas, rev);
+    canvas->restore();
+}
+
+static void test_rev(SkCanvas* canvas) {
+    SkRect r = { 10, 10, 100, 60 };
+
+    SkPath path;
+
+    path.addRect(r); test_rev(canvas, path);
+
+    canvas->translate(0, 100);
+    path.offset(20, 20);
+    path.addRect(r); test_rev(canvas, path);
+
+    canvas->translate(0, 100);
+    path.reset();
+    path.moveTo(10, 10); path.lineTo(30, 30);
+    path.addOval(r);
+    r.offset(50, 20);
+    path.addOval(r);
+    test_rev(canvas, path);
+
+    SkPaint paint;
+    paint.setTextSize(SkIntToScalar(100));
+    SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
+    SkSafeUnref(paint.setTypeface(hira));
+    path.reset();
+    paint.getTextPath("e", 1, 50, 50, &path);
+    canvas->translate(0, 100);
+    test_rev(canvas, path);
+}
+
+namespace skiagm {
+
+class PathReverseGM : public GM {
+public:
+    PathReverseGM() {
+
+    }
+
+protected:
+    virtual SkString onShortName() {
+        return SkString("path-reverse");
+    }
+
+    virtual SkISize onISize() {
+        return make_isize(640, 480);
+    }
+
+    virtual void onDraw(SkCanvas* canvas) {
+        SkRect r = { 10, 10, 100, 60 };
+        
+        SkPath path;
+        
+        path.addRect(r); test_rev(canvas, path);
+        
+        canvas->translate(0, 100);
+        path.offset(20, 20);
+        path.addRect(r); test_rev(canvas, path);
+        
+        canvas->translate(0, 100);
+        path.reset();
+        path.moveTo(10, 10); path.lineTo(30, 30);
+        path.addOval(r);
+        r.offset(50, 20);
+        path.addOval(r);
+        test_rev(canvas, path);
+        
+        SkPaint paint;
+        paint.setTextSize(SkIntToScalar(100));
+        SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal);
+        SkSafeUnref(paint.setTypeface(hira));
+        path.reset();
+        paint.getTextPath("e", 1, 50, 50, &path);
+        canvas->translate(0, 100);
+        test_rev(canvas, path);
+    }
+
+private:
+    typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new PathReverseGM; }
+static GMRegistry reg(MyFactory);
+
+}
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index c4f3899..66692d1 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -27,6 +27,7 @@
     '../gm/ninepatchstretch.cpp',
     '../gm/nocolorbleed.cpp',
     '../gm/pathfill.cpp',
+    '../gm/pathreverse.cpp',
     '../gm/points.cpp',
     '../gm/poly2poly.cpp',
     '../gm/quadpaths.cpp',
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 270fa68..a92d3e7 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -9,11 +9,57 @@
 #include "SkPaint.h"
 #include "SkPath.h"
 #include "SkParse.h"
+#include "SkParsePath.h"
 #include "SkRandom.h"
 #include "SkReader32.h"
 #include "SkSize.h"
 #include "SkWriter32.h"
 
+static void test_direction(skiatest::Reporter* reporter) {
+    size_t i;
+    SkPath path;
+    REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
+    REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
+    REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
+
+    static const char* gDegen[] = {
+        "M 10 10",
+        "M 10 10 M 20 20",
+        "M 10 10 L 20 20",
+        "M 10 10 L 10 10 L 10 10",
+        "M 10 10 Q 10 10 10 10",
+        "M 10 10 C 10 10 10 10 10 10",
+    };
+    for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
+        path.reset();
+        bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
+        REPORTER_ASSERT(reporter, valid);
+        REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
+    }
+    
+    static const char* gCW[] = {
+        "M 10 10 L 10 10 L 20 10 Q 20 20 30 30",
+        "M 10 10 C 20 10 20 20 20 20",
+    };
+    for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
+        path.reset();
+        bool valid = SkParsePath::FromSVGString(gCW[i], &path);
+        REPORTER_ASSERT(reporter, valid);
+        REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
+    }
+    
+    static const char* gCCW[] = {
+        "M 10 10 L 10 10 L 20 10 Q 20 -20 30 -30",
+        "M 10 10 C 20 10 20 -20 20 -20",
+    };
+    for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
+        path.reset();
+        bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
+        REPORTER_ASSERT(reporter, valid);
+        REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
+    }
+}
+
 static void add_rect(SkPath* path, const SkRect& r) {
     path->moveTo(r.fLeft, r.fTop);
     path->lineTo(r.fRight, r.fTop);
@@ -312,9 +358,11 @@
     path.reset();
     path.addRect(0, 0, 10, 10, SkPath::kCCW_Direction);
     REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path));
+    REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
     path.reset();
     path.addRect(0, 0, 10, 10, SkPath::kCW_Direction);
     REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path));
+    REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
     
     static const struct {
         const char*         fPathStr;
@@ -1039,6 +1087,7 @@
     test_isRect(reporter);
 
     test_zero_length_paths(reporter);
+    test_direction(reporter);
     test_convexity(reporter);
     test_convexity2(reporter);
     test_close(reporter);