use pathbuilder
Change-Id: Icb4d3f98440b53ba38270cc1f43fc43e6724d36b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315736
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/complexclip.cpp b/gm/complexclip.cpp
index 4a7e0ec..368e3ea 100644
--- a/gm/complexclip.cpp
+++ b/gm/complexclip.cpp
@@ -12,7 +12,7 @@
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkPaint.h"
-#include "include/core/SkPath.h"
+#include "include/core/SkPathBuilder.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
@@ -54,21 +54,22 @@
SkISize onISize() override { return SkISize::Make(388, 780); }
void onDraw(SkCanvas* canvas) override {
- SkPath path;
- path.moveTo(0, 50)
- .quadTo(0, 0, 50, 0)
- .lineTo(175, 0)
- .quadTo(200, 0, 200, 25)
- .lineTo(200, 150)
- .quadTo(200, 200, 150, 200)
- .lineTo(0, 200)
- .close()
- .moveTo(50, 50)
- .lineTo(150, 50)
- .lineTo(150, 125)
- .quadTo(150, 150, 125, 150)
- .lineTo(50, 150)
- .close();
+ SkPath path = SkPathBuilder()
+ .moveTo(0, 50)
+ .quadTo(0, 0, 50, 0)
+ .lineTo(175, 0)
+ .quadTo(200, 0, 200, 25)
+ .lineTo(200, 150)
+ .quadTo(200, 200, 150, 200)
+ .lineTo(0, 200)
+ .close()
+ .moveTo(50, 50)
+ .lineTo(150, 50)
+ .lineTo(150, 125)
+ .quadTo(150, 150, 125, 150)
+ .lineTo(50, 150)
+ .close()
+ .detach();
if (fInvertDraw) {
path.setFillType(SkPathFillType::kInverseEvenOdd);
} else {
@@ -78,11 +79,9 @@
pathPaint.setAntiAlias(true);
pathPaint.setColor(gPathColor);
- SkPath clipA;
- clipA.addPoly({{10, 20}, {165, 22}, {70, 105}, {165, 177}, {-5, 180}}, false).close();
+ SkPath clipA = SkPath::Polygon({{10, 20}, {165, 22}, {70, 105}, {165, 177}, {-5, 180}}, true);
- SkPath clipB;
- clipB.addPoly({{40, 10}, {190, 15}, {195, 190}, {40, 185}, {155, 100}}, false).close();
+ SkPath clipB = SkPath::Polygon({{40, 10}, {190, 15}, {195, 190}, {40, 185}, {155, 100}}, true);
SkFont font(ToolUtils::create_portable_typeface(), 20);
diff --git a/gm/convexpolyclip.cpp b/gm/convexpolyclip.cpp
index 3e78054..0953ee7 100644
--- a/gm/convexpolyclip.cpp
+++ b/gm/convexpolyclip.cpp
@@ -207,8 +207,7 @@
canvas->save();
}
canvas->translate(x, y);
- SkPath closedClipPath;
- clip->asClosedPath(&closedClipPath);
+ SkPath closedClipPath = clip->asClosedPath();
canvas->drawPath(closedClipPath, clipOutlinePaint);
clip->setOnCanvas(canvas, kIntersect_SkClipOp, SkToBool(aa));
canvas->scale(1.f, 1.8f);
@@ -240,7 +239,7 @@
void setOnCanvas(SkCanvas* canvas, SkClipOp op, bool aa) const {
switch (fClipType) {
case kPath_ClipType:
- canvas->clipPath(fPath, op, aa);
+ canvas->clipPath(fPathBuilder.snapshot(), op, aa);
break;
case kRect_ClipType:
canvas->clipRect(fRect, op, aa);
@@ -251,31 +250,29 @@
}
}
- void asClosedPath(SkPath* path) const {
+ SkPath asClosedPath() const {
switch (fClipType) {
case kPath_ClipType:
- *path = fPath;
- path->close();
+ return SkPathBuilder(fPathBuilder).close().detach();
break;
case kRect_ClipType:
- path->reset();
- path->addRect(fRect);
- break;
+ return SkPath::Rect(fRect);
case kNone_ClipType:
SkDEBUGFAIL("Uninitialized Clip.");
break;
}
+ return SkPath();
}
void setPath(const SkPath& path) {
fClipType = kPath_ClipType;
- fPath = path;
+ fPathBuilder = path;
}
void setRect(const SkRect& rect) {
fClipType = kRect_ClipType;
fRect = rect;
- fPath.reset();
+ fPathBuilder.reset();
}
ClipType getType() const { return fClipType; }
@@ -283,7 +280,7 @@
void getBounds(SkRect* bounds) const {
switch (fClipType) {
case kPath_ClipType:
- *bounds = fPath.getBounds();
+ *bounds = fPathBuilder.computeBounds();
break;
case kRect_ClipType:
*bounds = fRect;
@@ -296,7 +293,7 @@
private:
ClipType fClipType;
- SkPath fPath;
+ SkPathBuilder fPathBuilder;
SkRect fRect;
};