Skip to content

Commit ef4047d

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
add bench for computing convexity
Bug: skia: Change-Id: Iaa2971c28f6a8e869b92887e0c0595c73b0aebdb Reviewed-on: https://skia-review.googlesource.com/c/173225 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Reed <reed@google.com>
1 parent 8ac81b7 commit ef4047d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

bench/GeometryBench.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,52 @@ class ChopCubicAt : public QuadBenchBase {
243243
}
244244
};
245245
DEF_BENCH( return new ChopCubicAt; )
246+
247+
#include "SkPath.h"
248+
249+
class ConvexityBench : public Benchmark {
250+
SkPath fPath;
251+
252+
public:
253+
ConvexityBench(const char suffix[]) {
254+
fName.printf("convexity_%s", suffix);
255+
}
256+
257+
const char* onGetName() override {
258+
return fName.c_str();
259+
}
260+
261+
bool isSuitableFor(Backend backend) override {
262+
return kNonRendering_Backend == backend;
263+
}
264+
265+
virtual void preparePath(SkPath*) = 0;
266+
267+
protected:
268+
void onPreDraw(SkCanvas*) override {
269+
this->preparePath(&fPath);
270+
}
271+
272+
void onDraw(int loops, SkCanvas* canvas) override {
273+
for (int i = 0; i < loops; ++i) {
274+
fPath.setConvexity(SkPath::kUnknown_Convexity);
275+
(void)fPath.isConvex();
276+
}
277+
}
278+
279+
private:
280+
SkString fName;
281+
};
282+
283+
class RRectConvexityBench : public ConvexityBench {
284+
public:
285+
RRectConvexityBench() : ConvexityBench("rrect") {}
286+
287+
void preparePath(SkPath* path) override {
288+
SkRRect rr;
289+
rr.setRectXY({0, 0, 100, 100}, 20, 30);
290+
path->addRRect(rr);
291+
}
292+
};
293+
DEF_BENCH( return new RRectConvexityBench; )
294+

0 commit comments

Comments
 (0)