2012-05-07 13:46:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2019-08-19 18:40:16 +00:00
|
|
|
#include "src/core/SkPathPriv.h"
|
|
|
|
|
|
|
|
enum class PathIterType {
|
|
|
|
kIter,
|
|
|
|
kRaw,
|
|
|
|
kEdge,
|
|
|
|
};
|
|
|
|
const char* gPathIterNames[] = {
|
|
|
|
"iter", "raw", "edge"
|
|
|
|
};
|
2012-05-07 13:46:32 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static int rand_pts(SkRandom& rand, SkPoint pts[4]) {
|
2012-05-07 13:46:32 +00:00
|
|
|
int n = rand.nextU() & 3;
|
|
|
|
n += 1;
|
|
|
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
pts[i].fX = rand.nextSScalar1();
|
|
|
|
pts[i].fY = rand.nextSScalar1();
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class PathIterBench : public Benchmark {
|
2019-08-19 18:40:16 +00:00
|
|
|
SkString fName;
|
|
|
|
SkPath fPath;
|
|
|
|
PathIterType fType;
|
2012-05-07 13:46:32 +00:00
|
|
|
|
2019-08-20 16:52:13 +00:00
|
|
|
int fVerbInc = 0;
|
|
|
|
SkScalar fXInc = 0, fYInc = 0;
|
|
|
|
|
2012-05-07 13:46:32 +00:00
|
|
|
public:
|
2019-08-19 18:40:16 +00:00
|
|
|
PathIterBench(PathIterType t) : fType(t) {
|
|
|
|
fName.printf("pathiter_%s", gPathIterNames[static_cast<unsigned>(t)]);
|
2012-05-07 13:46:32 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-05-07 13:46:32 +00:00
|
|
|
for (int i = 0; i < 1000; ++i) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
int n = rand_pts(rand, pts);
|
|
|
|
switch (n) {
|
|
|
|
case 1:
|
|
|
|
fPath.moveTo(pts[0]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fPath.lineTo(pts[1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
fPath.quadTo(pts[1], pts[2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
fPath.cubicTo(pts[1], pts[2], pts[3]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
2012-09-17 10:49:30 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2012-05-07 13:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-05-07 13:46:32 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2019-08-20 16:52:13 +00:00
|
|
|
// Need to do *something* with the results, so the compile doesn't elide
|
|
|
|
// away the code we want to time.
|
|
|
|
auto handle = [this](int verb, const SkPoint pts[]) {
|
|
|
|
fVerbInc += verb;
|
|
|
|
fXInc += pts[0].fX;
|
|
|
|
fYInc += pts[0].fY;
|
|
|
|
};
|
|
|
|
|
2019-08-19 18:40:16 +00:00
|
|
|
SkPath::Verb verb;
|
|
|
|
SkPoint pts[4];
|
|
|
|
switch (fType) {
|
|
|
|
case PathIterType::kIter:
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
SkPath::Iter iter(fPath, true);
|
2019-08-20 16:52:13 +00:00
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
|
|
|
|
handle(verb, pts);
|
|
|
|
}
|
2019-08-19 18:40:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PathIterType::kRaw:
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
2020-05-05 22:21:19 +00:00
|
|
|
for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
|
|
|
|
handle((SkPath::Verb)verb, pts);
|
2019-08-20 16:52:13 +00:00
|
|
|
}
|
2019-08-19 18:40:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PathIterType::kEdge:
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
SkPathEdgeIter iter(fPath);
|
2019-08-20 16:52:13 +00:00
|
|
|
while (auto r = iter.next()) {
|
|
|
|
handle((int)r.fEdge, r.fPts);
|
|
|
|
}
|
2019-08-19 18:40:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-05-07 13:46:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2012-05-07 13:46:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-08-19 18:40:16 +00:00
|
|
|
DEF_BENCH( return new PathIterBench(PathIterType::kIter); )
|
|
|
|
DEF_BENCH( return new PathIterBench(PathIterType::kRaw); )
|
|
|
|
DEF_BENCH( return new PathIterBench(PathIterType::kEdge); )
|