add pathops bench for simplify
Bug: skia:
Change-Id: Ic4aa213d5cb394f47e07cc19a5da89f7389a7c1f
Reviewed-on: https://skia-review.googlesource.com/c/163224
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Allan MacKinnon <allanmac@google.com>
Reviewed-by: Cary Clark <caryclark@google.com>
diff --git a/bench/PathOpsBench.cpp b/bench/PathOpsBench.cpp
new file mode 100644
index 0000000..4d2e9e1
--- /dev/null
+++ b/bench/PathOpsBench.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+#include "SkPath.h"
+#include "SkPathOps.h"
+#include "SkRandom.h"
+#include "SkShader.h"
+#include "SkString.h"
+#include "SkTArray.h"
+
+class PathOpsBench : public Benchmark {
+ SkString fName;
+ SkPath fPath1, fPath2;
+ SkPathOp fOp;
+
+public:
+ PathOpsBench(const char suffix[], SkPathOp op) : fOp(op) {
+ fName.printf("pathops_%s", suffix);
+
+ fPath1.addOval({-10, -20, 10, 20});
+ fPath2.addOval({-20, -10, 20, 10});
+ }
+
+ bool isSuitableFor(Backend backend) override {
+ return backend == kNonRendering_Backend;
+ }
+
+protected:
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ for (int i = 0; i < loops; i++) {
+ for (int j = 0; j < 1000; ++j) {
+ SkPath result;
+ Op(fPath1, fPath2, fOp, &result);
+ }
+ }
+ }
+
+private:
+ typedef Benchmark INHERITED;
+};
+
+class PathOpsSimplifyBench : public Benchmark {
+ SkString fName;
+ SkPath fPath;
+
+public:
+ PathOpsSimplifyBench(const char suffix[], const SkPath& path) : fPath(path) {
+ fName.printf("pathops_simplify_%s", suffix);
+ }
+
+ bool isSuitableFor(Backend backend) override {
+ return backend == kNonRendering_Backend;
+ }
+
+protected:
+ const char* onGetName() override {
+ return fName.c_str();
+ }
+
+ void onDraw(int loops, SkCanvas* canvas) override {
+ for (int i = 0; i < loops; i++) {
+ for (int j = 0; j < 100; ++j) {
+ SkPath result;
+ Simplify(fPath, &result);
+ }
+ }
+ }
+
+private:
+ typedef Benchmark INHERITED;
+};
+
+
+DEF_BENCH( return new PathOpsBench("sect", kIntersect_SkPathOp); )
+DEF_BENCH( return new PathOpsBench("join", kUnion_SkPathOp); )
+
+static SkPath makerects() {
+ SkRandom rand;
+ SkPath path;
+ SkScalar scale = 100;
+ for (int i = 0; i < 20; ++i) {
+ SkScalar x = rand.nextUScalar1() * scale;
+ SkScalar y = rand.nextUScalar1() * scale;
+ path.addRect({x, y, x + scale, y + scale});
+ }
+ return path;
+}
+
+DEF_BENCH( return new PathOpsSimplifyBench("rects", makerects()); )
diff --git a/gn/bench.gni b/gn/bench.gni
index 2457162..40abf9b 100644
--- a/gn/bench.gni
+++ b/gn/bench.gni
@@ -83,6 +83,7 @@
"$_bench/PatchBench.cpp",
"$_bench/PathBench.cpp",
"$_bench/PathIterBench.cpp",
+ "$_bench/PathOpsBench.cpp",
"$_bench/PathTextBench.cpp",
"$_bench/PDFBench.cpp",
"$_bench/PerlinNoiseBench.cpp",
diff --git a/gn/core.gni b/gn/core.gni
index ff326b4..84d19f0 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -486,7 +486,6 @@
"$_src/pathops/SkPathOpsDebug.cpp",
"$_src/pathops/SkPathOpsLine.cpp",
"$_src/pathops/SkPathOpsOp.cpp",
- "$_src/pathops/SkPathOpsPoint.cpp",
"$_src/pathops/SkPathOpsQuad.cpp",
"$_src/pathops/SkPathOpsRect.cpp",
"$_src/pathops/SkPathOpsSimplify.cpp",
diff --git a/src/pathops/SkPathOpsPoint.cpp b/src/pathops/SkPathOpsPoint.cpp
deleted file mode 100644
index e0f175d..0000000
--- a/src/pathops/SkPathOpsPoint.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkPathOpsPoint.h"
-
-SkDVector operator-(const SkDPoint& a, const SkDPoint& b) {
- SkDVector v = {a.fX - b.fX, a.fY - b.fY};
- return v;
-}
diff --git a/src/pathops/SkPathOpsPoint.h b/src/pathops/SkPathOpsPoint.h
index f314f69..6cd2984 100644
--- a/src/pathops/SkPathOpsPoint.h
+++ b/src/pathops/SkPathOpsPoint.h
@@ -100,7 +100,9 @@
fY = pt.fY;
}
- friend SkDVector operator-(const SkDPoint& a, const SkDPoint& b);
+ friend SkDVector operator-(const SkDPoint& a, const SkDPoint& b) {
+ return { a.fX - b.fX, a.fY - b.fY };
+ }
friend bool operator==(const SkDPoint& a, const SkDPoint& b) {
return a.fX == b.fX && a.fY == b.fY;
diff --git a/src/pathops/SkPathOpsTSect.h b/src/pathops/SkPathOpsTSect.h
index 8cf7ad3..6b7a2f9 100644
--- a/src/pathops/SkPathOpsTSect.h
+++ b/src/pathops/SkPathOpsTSect.h
@@ -353,7 +353,7 @@
void validateBounded() const;
const SkTCurve& fCurve;
- SkArenaAlloc fHeap;
+ SkSTArenaAlloc<1024> fHeap;
SkTSpan* fHead;
SkTSpan* fCoincident;
SkTSpan* fDeleted;