Switch over to SkPathBuilder

Bug: skia:9000
Change-Id: If7192dfb8df01db9acb83a3c331fbbde981e5e2e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307017
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/samplecode/SampleChart.cpp b/samplecode/SampleChart.cpp
index 6437d3e..46e4dec 100644
--- a/samplecode/SampleChart.cpp
+++ b/samplecode/SampleChart.cpp
@@ -7,7 +7,7 @@
 
 #include "include/core/SkCanvas.h"
 #include "include/core/SkPaint.h"
-#include "include/core/SkPath.h"
+#include "include/core/SkPathBuilder.h"
 #include "include/utils/SkRandom.h"
 #include "samplecode/Sample.h"
 
@@ -30,9 +30,7 @@
                       SkScalar yBase,
                       SkScalar xLeft, SkScalar xDelta,
                       int leftShift,
-                      SkPath* plot, SkPath* fill) {
-    plot->rewind();
-    fill->rewind();
+                      SkPathBuilder* plot, SkPathBuilder* fill) {
     plot->incReserve(topData.count());
     if (nullptr == bottomData) {
         fill->incReserve(topData.count() + 2);
@@ -121,9 +119,6 @@
             }
         }
 
-        SkPath plotPath;
-        SkPath fillPath;
-
         static const SkScalar kStrokeWidth = SkIntToScalar(2);
         SkPaint plotPaint;
         SkPaint fillPaint;
@@ -135,7 +130,9 @@
         fillPaint.setAntiAlias(true);
         fillPaint.setStyle(SkPaint::kFill_Style);
 
+        SkPathBuilder plotPath, fillPath;
         SkTDArray<SkScalar>* prevData = nullptr;
+
         for (int i = 0; i < kNumGraphs; ++i) {
             gen_paths(fData[i],
                       prevData,
@@ -148,10 +145,10 @@
 
             // Make the fills partially transparent
             fillPaint.setColor((gColors[i] & 0x00ffffff) | 0x80000000);
-            canvas->drawPath(fillPath, fillPaint);
+            canvas->drawPath(fillPath.detach(), fillPaint);
 
             plotPaint.setColor(gColors[i]);
-            canvas->drawPath(plotPath, plotPaint);
+            canvas->drawPath(plotPath.detach(), plotPaint);
 
             prevData = fData + i;
         }
diff --git a/samplecode/SampleClip.cpp b/samplecode/SampleClip.cpp
index 014d034..4a6c25d 100644
--- a/samplecode/SampleClip.cpp
+++ b/samplecode/SampleClip.cpp
@@ -9,7 +9,7 @@
 #include "include/core/SkColorPriv.h"
 #include "include/core/SkFont.h"
 #include "include/core/SkPaint.h"
-#include "include/core/SkPath.h"
+#include "include/core/SkPathBuilder.h"
 #include "include/utils/SkRandom.h"
 #include "samplecode/Sample.h"
 #include "src/core/SkClipOpPriv.h"
@@ -39,7 +39,6 @@
 
     for (int i = 0; i < 50; ++i) {
         SkRect r;
-        SkPath p;
 
         r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
                   rand.nextUScalar1() * W, rand.nextUScalar1() * H);
@@ -49,8 +48,7 @@
         r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
                   rand.nextUScalar1() * W, rand.nextUScalar1() * H);
         paint.setColor(rand.nextU());
-        p.addOval(r);
-        canvas->drawPath(p, paint);
+        canvas->drawOval(r, paint);
     }
 }
 
@@ -68,7 +66,6 @@
 
     for (int i = 0; i < n; ++i) {
         SkRect r;
-        SkPath p;
 
         r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
                   rand.nextUScalar1() * W, rand.nextUScalar1() * H);
@@ -78,8 +75,7 @@
         r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
                   rand.nextUScalar1() * W, rand.nextUScalar1() * H);
         paint.setColor(rand.nextU());
-        p.addOval(r);
-        canvas->drawPath(p, paint);
+        canvas->drawOval(r, paint);
 
         const SkScalar minx = -SkIntToScalar(W)/4;
         const SkScalar maxx = 5*SkIntToScalar(W)/4;
@@ -114,9 +110,8 @@
         };
 
         SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
-        SkPath clipPath;
         r.inset(SK_Scalar1 / 4, SK_Scalar1 / 4);
-        clipPath.addRoundRect(r, SkIntToScalar(20), SkIntToScalar(20));
+        SkPath clipPath = SkPathBuilder().addRRect(SkRRect::MakeRectXY(r, 20, 20)).detach();
 
 //        clipPath.toggleInverseFillType();
 
@@ -213,7 +208,7 @@
 
 #include "src/core/SkEdgeClipper.h"
 
-static void clip(const SkPath& path, SkPoint p0, SkPoint p1, SkPath* clippedPath) {
+static SkPath clip(const SkPath& path, SkPoint p0, SkPoint p1) {
     SkMatrix mx, inv;
     SkVector v = p1 - p0;
     mx.setAll(v.fX, -v.fY, p0.fX,
@@ -228,9 +223,9 @@
     SkRect clip = {-big, 0, big, big };
 
     struct Rec {
-        SkPath* fResult;
-        SkPoint fPrev;
-    } rec = { clippedPath, {0, 0} };
+        SkPathBuilder   fResult;
+        SkPoint         fPrev = {0, 0};
+    } rec;
 
     SkEdgeClipper::ClipPath(rotated, clip, false,
                             [](SkEdgeClipper* clipper, bool newCtr, void* ctx) {
@@ -241,26 +236,26 @@
         SkPath::Verb verb;
         while ((verb = clipper->next(pts)) != SkPath::kDone_Verb) {
             if (newCtr) {
-                rec->fResult->moveTo(pts[0]);
+                rec->fResult.moveTo(pts[0]);
                 rec->fPrev = pts[0];
                 newCtr = false;
             }
 
             if (addLineTo || pts[0] != rec->fPrev) {
-                rec->fResult->lineTo(pts[0]);
+                rec->fResult.lineTo(pts[0]);
             }
 
             switch (verb) {
                 case SkPath::kLine_Verb:
-                    rec->fResult->lineTo(pts[1]);
+                    rec->fResult.lineTo(pts[1]);
                     rec->fPrev = pts[1];
                     break;
                 case SkPath::kQuad_Verb:
-                    rec->fResult->quadTo(pts[1], pts[2]);
+                    rec->fResult.quadTo(pts[1], pts[2]);
                     rec->fPrev = pts[2];
                     break;
                 case SkPath::kCubic_Verb:
-                    rec->fResult->cubicTo(pts[1], pts[2], pts[3]);
+                    rec->fResult.cubicTo(pts[1], pts[2], pts[3]);
                     rec->fPrev = pts[3];
                     break;
                 default: break;
@@ -269,7 +264,7 @@
         }
     }, &rec);
 
-    rec.fResult->transform(mx);
+    return rec.fResult.detach().makeTransform(mx);
 }
 
 static void draw_halfplane(SkCanvas* canvas, SkPoint p0, SkPoint p1, SkColor c) {
@@ -290,7 +285,7 @@
         return SkPoint{x * 400, y * 400};
     };
 
-    SkPath path;
+    SkPathBuilder path;
     for (int i = 0; i < 4; ++i) {
         SkPoint pts[6];
         for (auto& p : pts) {
@@ -298,7 +293,7 @@
         }
         path.moveTo(pts[0]).quadTo(pts[1], pts[2]).quadTo(pts[3], pts[4]).lineTo(pts[5]);
     }
-    return path;
+    return path.detach();
 }
 
 class HalfPlaneView : public Sample {
@@ -321,9 +316,7 @@
 
         paint.setColor({0, 0, 0, 1}, nullptr);
 
-        SkPath clippedPath;
-        clip(fPath, fPts[0], fPts[1], &clippedPath);
-        canvas->drawPath(clippedPath, paint);
+        canvas->drawPath(clip(fPath, fPts[0], fPts[1]), paint);
 
         draw_halfplane(canvas, fPts[0], fPts[1], SK_ColorRED);
     }