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.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-05-07 13:46:32 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
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 {
|
2012-05-07 13:46:32 +00:00
|
|
|
SkString fName;
|
|
|
|
SkPath fPath;
|
|
|
|
bool fRaw;
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathIterBench(bool raw) {
|
2012-05-07 13:46:32 +00:00
|
|
|
fName.printf("pathiter_%s", raw ? "raw" : "consume");
|
|
|
|
fRaw = raw;
|
|
|
|
|
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-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2012-05-07 13:46:32 +00:00
|
|
|
if (fRaw) {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-05-07 13:46:32 +00:00
|
|
|
SkPath::RawIter iter(fPath);
|
|
|
|
SkPath::Verb verb;
|
|
|
|
SkPoint pts[4];
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-07-23 11:13:56 +00:00
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { }
|
2012-05-07 13:46:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-05-07 13:46:32 +00:00
|
|
|
SkPath::Iter iter(fPath, false);
|
|
|
|
SkPath::Verb verb;
|
|
|
|
SkPoint pts[4];
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-07-23 11:13:56 +00:00
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { }
|
2012-05-07 13:46:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-05-07 13:46:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new PathIterBench(false); )
|
|
|
|
DEF_BENCH( return new PathIterBench(true); )
|