2011-07-28 14:26:00 +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"
|
2011-04-11 13:12:51 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkPaint.h"
|
2011-06-22 17:16:35 +00:00
|
|
|
#include "SkRandom.h"
|
2011-04-11 13:12:51 +00:00
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
2012-08-13 14:03:31 +00:00
|
|
|
#include "SkTArray.h"
|
|
|
|
|
2011-04-11 13:12:51 +00:00
|
|
|
enum Flags {
|
|
|
|
kStroke_Flag = 1 << 0,
|
|
|
|
kBig_Flag = 1 << 1
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FLAGS00 Flags(0)
|
|
|
|
#define FLAGS01 Flags(kStroke_Flag)
|
|
|
|
#define FLAGS10 Flags(kBig_Flag)
|
|
|
|
#define FLAGS11 Flags(kStroke_Flag | kBig_Flag)
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class PathBench : public Benchmark {
|
2011-04-11 13:12:51 +00:00
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
|
|
|
Flags fFlags;
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathBench(Flags flags) : fFlags(flags) {
|
2011-04-11 13:12:51 +00:00
|
|
|
fPaint.setStyle(flags & kStroke_Flag ? SkPaint::kStroke_Style :
|
|
|
|
SkPaint::kFill_Style);
|
|
|
|
fPaint.setStrokeWidth(SkIntToScalar(5));
|
|
|
|
fPaint.setStrokeJoin(SkPaint::kBevel_Join);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void appendName(SkString*) = 0;
|
|
|
|
virtual void makePath(SkPath*) = 0;
|
2011-06-22 17:16:35 +00:00
|
|
|
virtual int complexity() { return 0; }
|
2011-04-11 13:12:51 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2011-04-11 13:12:51 +00:00
|
|
|
fName.printf("path_%s_%s_",
|
|
|
|
fFlags & kStroke_Flag ? "stroke" : "fill",
|
|
|
|
fFlags & kBig_Flag ? "big" : "small");
|
|
|
|
this->appendName(&fName);
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
this->makePath(&path);
|
|
|
|
if (fFlags & kBig_Flag) {
|
2015-03-27 02:57:08 +00:00
|
|
|
const SkMatrix m = SkMatrix::MakeScale(SkIntToScalar(10), SkIntToScalar(10));
|
2011-04-11 13:12:51 +00:00
|
|
|
path.transform(m);
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
int count = loops;
|
2011-04-11 13:12:51 +00:00
|
|
|
if (fFlags & kBig_Flag) {
|
|
|
|
count >>= 2;
|
|
|
|
}
|
2011-06-22 17:16:35 +00:00
|
|
|
count >>= (3 * complexity());
|
2011-04-11 13:12:51 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-04-11 13:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TrianglePathBench : public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
TrianglePathBench(Flags flags) : INHERITED(flags) {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("triangle");
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void makePath(SkPath* path) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
static const int gCoord[] = {
|
|
|
|
10, 10, 15, 5, 20, 20
|
|
|
|
};
|
|
|
|
path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1]));
|
|
|
|
path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3]));
|
|
|
|
path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5]));
|
|
|
|
path->close();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RectPathBench : public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
RectPathBench(Flags flags) : INHERITED(flags) {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("rect");
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void makePath(SkPath* path) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
SkRect r = { 10, 10, 20, 20 };
|
|
|
|
path->addRect(r);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OvalPathBench : public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
OvalPathBench(Flags flags) : INHERITED(flags) {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("oval");
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void makePath(SkPath* path) override {
|
2013-01-24 15:45:35 +00:00
|
|
|
SkRect r = { 10, 10, 23, 20 };
|
2011-04-11 13:12:51 +00:00
|
|
|
path->addOval(r);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
class CirclePathBench: public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
CirclePathBench(Flags flags) : INHERITED(flags) {}
|
2012-04-11 15:34:46 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2012-04-11 15:34:46 +00:00
|
|
|
name->append("circle");
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void makePath(SkPath* path) override {
|
2012-04-11 15:34:46 +00:00
|
|
|
path->addCircle(SkIntToScalar(20), SkIntToScalar(20),
|
|
|
|
SkIntToScalar(10));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2011-04-11 13:12:51 +00:00
|
|
|
class SawToothPathBench : public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
SawToothPathBench(Flags flags) : INHERITED(flags) {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("sawtooth");
|
|
|
|
}
|
|
|
|
virtual void makePath(SkPath* path) {
|
|
|
|
SkScalar x = SkIntToScalar(20);
|
|
|
|
SkScalar y = SkIntToScalar(20);
|
|
|
|
const SkScalar x0 = x;
|
|
|
|
const SkScalar dx = SK_Scalar1 * 5;
|
|
|
|
const SkScalar dy = SK_Scalar1 * 10;
|
|
|
|
|
|
|
|
path->moveTo(x, y);
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
x += dx;
|
|
|
|
path->lineTo(x, y - dy);
|
|
|
|
x += dx;
|
|
|
|
path->lineTo(x, y + dy);
|
|
|
|
}
|
|
|
|
path->lineTo(x, y + 2 * dy);
|
|
|
|
path->lineTo(x0, y + 2 * dy);
|
|
|
|
path->close();
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
int complexity() override { return 1; }
|
2011-06-22 17:16:35 +00:00
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LongCurvedPathBench : public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
LongCurvedPathBench(Flags flags) : INHERITED(flags) {}
|
2011-06-22 17:16:35 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2011-06-22 17:16:35 +00:00
|
|
|
name->append("long_curved");
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void makePath(SkPath* path) override {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand (12);
|
2011-06-22 17:16:35 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
path->quadTo(SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
|
|
|
|
SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)),
|
|
|
|
SkScalarMul(rand.nextUScalar1(), SkIntToScalar(640)),
|
|
|
|
SkScalarMul(rand.nextUScalar1(), SkIntToScalar(480)));
|
|
|
|
}
|
|
|
|
path->close();
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
int complexity() override { return 2; }
|
2011-04-11 13:12:51 +00:00
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-01-12 19:10:35 +00:00
|
|
|
class LongLinePathBench : public PathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
LongLinePathBench(Flags flags) : INHERITED(flags) {}
|
2012-01-12 19:10:35 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void appendName(SkString* name) override {
|
2012-01-12 19:10:35 +00:00
|
|
|
name->append("long_line");
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void makePath(SkPath* path) override {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-01-12 19:10:35 +00:00
|
|
|
path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
for (size_t i = 1; i < 100; i++) {
|
|
|
|
path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
}
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
int complexity() override { return 2; }
|
2012-01-12 19:10:35 +00:00
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
2011-06-22 17:16:35 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class RandomPathBench : public Benchmark {
|
2012-08-13 14:03:31 +00:00
|
|
|
public:
|
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-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void createData(int minVerbs,
|
|
|
|
int maxVerbs,
|
|
|
|
bool allowMoves = true,
|
|
|
|
SkRect* bounds = NULL) {
|
|
|
|
SkRect tempBounds;
|
|
|
|
if (NULL == bounds) {
|
|
|
|
tempBounds.setXYWH(0, 0, SK_Scalar1, SK_Scalar1);
|
|
|
|
bounds = &tempBounds;
|
|
|
|
}
|
2012-08-14 15:10:09 +00:00
|
|
|
fVerbCnts.reset(kNumVerbCnts);
|
|
|
|
for (int i = 0; i < kNumVerbCnts; ++i) {
|
|
|
|
fVerbCnts[i] = fRandom.nextRangeU(minVerbs, maxVerbs + 1);
|
|
|
|
}
|
|
|
|
fVerbs.reset(kNumVerbs);
|
|
|
|
for (int i = 0; i < kNumVerbs; ++i) {
|
|
|
|
do {
|
|
|
|
fVerbs[i] = static_cast<SkPath::Verb>(fRandom.nextULessThan(SkPath::kDone_Verb));
|
|
|
|
} while (!allowMoves && SkPath::kMove_Verb == fVerbs[i]);
|
|
|
|
}
|
|
|
|
fPoints.reset(kNumPoints);
|
|
|
|
for (int i = 0; i < kNumPoints; ++i) {
|
|
|
|
fPoints[i].set(fRandom.nextRangeScalar(bounds->fLeft, bounds->fRight),
|
|
|
|
fRandom.nextRangeScalar(bounds->fTop, bounds->fBottom));
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
this->restartMakingPaths();
|
|
|
|
}
|
|
|
|
|
|
|
|
void restartMakingPaths() {
|
|
|
|
fCurrPath = 0;
|
|
|
|
fCurrVerb = 0;
|
|
|
|
fCurrPoint = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void makePath(SkPath* path) {
|
2012-08-14 15:10:09 +00:00
|
|
|
int vCount = fVerbCnts[(fCurrPath++) & (kNumVerbCnts - 1)];
|
2012-08-13 14:03:31 +00:00
|
|
|
for (int v = 0; v < vCount; ++v) {
|
2012-08-14 15:10:09 +00:00
|
|
|
int verb = fVerbs[(fCurrVerb++) & (kNumVerbs - 1)];
|
|
|
|
switch (verb) {
|
2012-08-13 14:03:31 +00:00
|
|
|
case SkPath::kMove_Verb:
|
2012-08-14 15:10:09 +00:00
|
|
|
path->moveTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
|
2012-08-13 14:03:31 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kLine_Verb:
|
2012-08-14 15:10:09 +00:00
|
|
|
path->lineTo(fPoints[(fCurrPoint++) & (kNumPoints - 1)]);
|
2012-08-13 14:03:31 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
2012-09-26 13:08:56 +00:00
|
|
|
path->quadTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)],
|
|
|
|
fPoints[(fCurrPoint + 1) & (kNumPoints - 1)]);
|
|
|
|
fCurrPoint += 2;
|
2012-08-13 14:03:31 +00:00
|
|
|
break;
|
2013-05-31 15:17:50 +00:00
|
|
|
case SkPath::kConic_Verb:
|
|
|
|
path->conicTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)],
|
|
|
|
fPoints[(fCurrPoint + 1) & (kNumPoints - 1)],
|
|
|
|
SK_ScalarHalf);
|
|
|
|
fCurrPoint += 2;
|
|
|
|
break;
|
2012-08-13 14:03:31 +00:00
|
|
|
case SkPath::kCubic_Verb:
|
2012-09-26 13:08:56 +00:00
|
|
|
path->cubicTo(fPoints[(fCurrPoint + 0) & (kNumPoints - 1)],
|
|
|
|
fPoints[(fCurrPoint + 1) & (kNumPoints - 1)],
|
|
|
|
fPoints[(fCurrPoint + 2) & (kNumPoints - 1)]);
|
|
|
|
fCurrPoint += 3;
|
2012-08-13 14:03:31 +00:00
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
path->close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("Unexpected path verb");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void finishedMakingPaths() {
|
2012-08-14 15:10:09 +00:00
|
|
|
fVerbCnts.reset(0);
|
|
|
|
fVerbs.reset(0);
|
|
|
|
fPoints.reset(0);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-14 15:10:09 +00:00
|
|
|
enum {
|
|
|
|
// these should all be pow 2
|
2012-08-14 17:49:46 +00:00
|
|
|
kNumVerbCnts = 1 << 5,
|
|
|
|
kNumVerbs = 1 << 5,
|
|
|
|
kNumPoints = 1 << 5,
|
2012-08-14 15:10:09 +00:00
|
|
|
};
|
|
|
|
SkAutoTArray<int> fVerbCnts;
|
|
|
|
SkAutoTArray<SkPath::Verb> fVerbs;
|
|
|
|
SkAutoTArray<SkPoint> fPoints;
|
|
|
|
int fCurrPath;
|
|
|
|
int fCurrVerb;
|
|
|
|
int fCurrPoint;
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom fRandom;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-08-13 14:03:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PathCreateBench : public RandomPathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathCreateBench() {
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
return "path_create";
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2012-08-14 15:10:09 +00:00
|
|
|
this->createData(10, 100);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2014-01-06 20:19:14 +00:00
|
|
|
if (i % 1000 == 0) {
|
|
|
|
fPath.reset(); // PathRef memory can grow without bound otherwise.
|
|
|
|
}
|
|
|
|
this->makePath(&fPath);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
this->restartMakingPaths();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-01-06 20:19:14 +00:00
|
|
|
SkPath fPath;
|
2012-08-13 14:03:31 +00:00
|
|
|
|
|
|
|
typedef RandomPathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PathCopyBench : public RandomPathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathCopyBench() {
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
return "path_copy";
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2012-08-14 15:10:09 +00:00
|
|
|
this->createData(10, 100);
|
2012-08-14 17:49:46 +00:00
|
|
|
fPaths.reset(kPathCnt);
|
|
|
|
fCopies.reset(kPathCnt);
|
|
|
|
for (int i = 0; i < kPathCnt; ++i) {
|
2012-08-13 14:03:31 +00:00
|
|
|
this->makePath(&fPaths[i]);
|
|
|
|
}
|
|
|
|
this->finishedMakingPaths();
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
fCopies[idx] = fPaths[idx];
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-14 17:49:46 +00:00
|
|
|
enum {
|
|
|
|
// must be a pow 2
|
|
|
|
kPathCnt = 1 << 5,
|
|
|
|
};
|
|
|
|
SkAutoTArray<SkPath> fPaths;
|
|
|
|
SkAutoTArray<SkPath> fCopies;
|
2012-08-13 14:03:31 +00:00
|
|
|
|
|
|
|
typedef RandomPathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PathTransformBench : public RandomPathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathTransformBench(bool inPlace) : fInPlace(inPlace) {}
|
2012-08-13 14:03:31 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
return fInPlace ? "path_transform_in_place" : "path_transform_copy";
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
fMatrix.setScale(5 * SK_Scalar1, 6 * SK_Scalar1);
|
2012-08-14 15:10:09 +00:00
|
|
|
this->createData(10, 100);
|
2012-08-14 17:49:46 +00:00
|
|
|
fPaths.reset(kPathCnt);
|
|
|
|
for (int i = 0; i < kPathCnt; ++i) {
|
2012-08-13 14:03:31 +00:00
|
|
|
this->makePath(&fPaths[i]);
|
|
|
|
}
|
2012-08-14 17:49:46 +00:00
|
|
|
this->finishedMakingPaths();
|
2012-08-13 14:03:31 +00:00
|
|
|
if (!fInPlace) {
|
2012-08-14 17:49:46 +00:00
|
|
|
fTransformed.reset(kPathCnt);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2012-08-13 14:03:31 +00:00
|
|
|
if (fInPlace) {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
fPaths[i & (kPathCnt - 1)].transform(fMatrix);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
fPaths[idx].transform(fMatrix, &fTransformed[idx]);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-14 17:49:46 +00:00
|
|
|
enum {
|
|
|
|
// must be a pow 2
|
|
|
|
kPathCnt = 1 << 5,
|
|
|
|
};
|
|
|
|
SkAutoTArray<SkPath> fPaths;
|
|
|
|
SkAutoTArray<SkPath> fTransformed;
|
|
|
|
|
2012-08-13 14:03:31 +00:00
|
|
|
SkMatrix fMatrix;
|
|
|
|
bool fInPlace;
|
|
|
|
typedef RandomPathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PathEqualityBench : public RandomPathBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
PathEqualityBench() { }
|
2012-08-13 14:03:31 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
return "path_equality_50%";
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
fParity = 0;
|
2012-08-14 15:10:09 +00:00
|
|
|
this->createData(10, 100);
|
2012-08-14 17:49:46 +00:00
|
|
|
fPaths.reset(kPathCnt);
|
|
|
|
fCopies.reset(kPathCnt);
|
|
|
|
for (int i = 0; i < kPathCnt; ++i) {
|
2012-08-13 14:03:31 +00:00
|
|
|
this->makePath(&fPaths[i]);
|
|
|
|
fCopies[i] = fPaths[i];
|
|
|
|
}
|
|
|
|
this->finishedMakingPaths();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
fParity ^= (fPaths[idx] == fCopies[idx & ~0x1]);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fParity; // attempt to keep compiler from optimizing out the ==
|
2012-08-14 17:49:46 +00:00
|
|
|
enum {
|
|
|
|
// must be a pow 2
|
|
|
|
kPathCnt = 1 << 5,
|
|
|
|
};
|
|
|
|
SkAutoTArray<SkPath> fPaths;
|
|
|
|
SkAutoTArray<SkPath> fCopies;
|
2012-08-13 14:03:31 +00:00
|
|
|
typedef RandomPathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkBench_AddPathTest : public RandomPathBench {
|
|
|
|
public:
|
|
|
|
enum AddType {
|
|
|
|
kAdd_AddType,
|
|
|
|
kAddTrans_AddType,
|
|
|
|
kAddMatrix_AddType,
|
|
|
|
kReverseAdd_AddType,
|
|
|
|
kReversePathTo_AddType,
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
SkBench_AddPathTest(AddType type) : fType(type) {
|
2012-08-13 14:03:31 +00:00
|
|
|
fMatrix.setRotate(60 * SK_Scalar1);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-08-13 14:03:31 +00:00
|
|
|
switch (fType) {
|
|
|
|
case kAdd_AddType:
|
|
|
|
return "path_add_path";
|
|
|
|
case kAddTrans_AddType:
|
|
|
|
return "path_add_path_trans";
|
|
|
|
case kAddMatrix_AddType:
|
|
|
|
return "path_add_path_matrix";
|
|
|
|
case kReverseAdd_AddType:
|
|
|
|
return "path_reverse_add_path";
|
|
|
|
case kReversePathTo_AddType:
|
|
|
|
return "path_reverse_path_to";
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("Bad add type");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2013-11-14 16:53:22 +00:00
|
|
|
// reversePathTo assumes a single contour path.
|
|
|
|
bool allowMoves = kReversePathTo_AddType != fType;
|
2012-08-14 15:10:09 +00:00
|
|
|
this->createData(10, 100, allowMoves);
|
2012-08-14 17:49:46 +00:00
|
|
|
fPaths0.reset(kPathCnt);
|
|
|
|
fPaths1.reset(kPathCnt);
|
|
|
|
for (int i = 0; i < kPathCnt; ++i) {
|
2012-08-13 14:03:31 +00:00
|
|
|
this->makePath(&fPaths0[i]);
|
|
|
|
this->makePath(&fPaths1[i]);
|
|
|
|
}
|
|
|
|
this->finishedMakingPaths();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2012-08-13 14:03:31 +00:00
|
|
|
switch (fType) {
|
|
|
|
case kAdd_AddType:
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
SkPath result = fPaths0[idx];
|
|
|
|
result.addPath(fPaths1[idx]);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kAddTrans_AddType:
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
SkPath result = fPaths0[idx];
|
|
|
|
result.addPath(fPaths1[idx], 2 * SK_Scalar1, 5 * SK_Scalar1);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kAddMatrix_AddType:
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
SkPath result = fPaths0[idx];
|
|
|
|
result.addPath(fPaths1[idx], fMatrix);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kReverseAdd_AddType:
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
SkPath result = fPaths0[idx];
|
|
|
|
result.reverseAddPath(fPaths1[idx]);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kReversePathTo_AddType:
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-14 17:49:46 +00:00
|
|
|
int idx = i & (kPathCnt - 1);
|
|
|
|
SkPath result = fPaths0[idx];
|
|
|
|
result.reversePathTo(fPaths1[idx]);
|
2012-08-13 14:03:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AddType fType; // or reverseAddPath
|
2012-08-14 17:49:46 +00:00
|
|
|
enum {
|
|
|
|
// must be a pow 2
|
|
|
|
kPathCnt = 1 << 5,
|
|
|
|
};
|
|
|
|
SkAutoTArray<SkPath> fPaths0;
|
|
|
|
SkAutoTArray<SkPath> fPaths1;
|
2012-08-13 14:03:31 +00:00
|
|
|
SkMatrix fMatrix;
|
|
|
|
typedef RandomPathBench INHERITED;
|
|
|
|
};
|
2011-06-22 17:16:35 +00:00
|
|
|
|
2012-08-20 17:24:16 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class CirclesBench : public Benchmark {
|
2012-08-20 17:24:16 +00:00
|
|
|
protected:
|
|
|
|
SkString fName;
|
2013-01-22 13:34:01 +00:00
|
|
|
Flags fFlags;
|
2012-08-20 17:24:16 +00:00
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
CirclesBench(Flags flags) : fFlags(flags) {
|
2013-01-22 13:34:01 +00:00
|
|
|
fName.printf("circles_%s", fFlags & kStroke_Flag ? "stroke" : "fill");
|
2012-08-20 17:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-08-20 17:24:16 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2012-08-20 17:24:16 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
paint.setAntiAlias(true);
|
2013-01-22 13:34:01 +00:00
|
|
|
if (fFlags & kStroke_Flag) {
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
}
|
2012-08-20 17:24:16 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-08-20 17:24:16 +00:00
|
|
|
|
|
|
|
SkRect r;
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-08-20 17:24:16 +00:00
|
|
|
SkScalar radius = rand.nextUScalar1() * 3;
|
|
|
|
r.fLeft = rand.nextUScalar1() * 300;
|
|
|
|
r.fTop = rand.nextUScalar1() * 300;
|
|
|
|
r.fRight = r.fLeft + 2 * radius;
|
|
|
|
r.fBottom = r.fTop + 2 * radius;
|
|
|
|
|
2013-01-22 13:34:01 +00:00
|
|
|
if (fFlags & kStroke_Flag) {
|
|
|
|
paint.setStrokeWidth(rand.nextUScalar1() * 5.0f);
|
|
|
|
}
|
|
|
|
|
2012-08-20 17:24:16 +00:00
|
|
|
SkPath temp;
|
|
|
|
|
|
|
|
// mimic how Chrome does circles
|
|
|
|
temp.arcTo(r, 0, 0, false);
|
|
|
|
temp.addOval(r, SkPath::kCCW_Direction);
|
|
|
|
temp.arcTo(r, 360, 0, true);
|
|
|
|
temp.close();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-08-20 17:24:16 +00:00
|
|
|
canvas->drawPath(temp, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-08-20 17:24:16 +00:00
|
|
|
};
|
|
|
|
|
2013-01-22 13:34:01 +00:00
|
|
|
|
2012-10-23 16:56:56 +00:00
|
|
|
// Chrome creates its own round rects with each corner possibly being different.
|
|
|
|
// In its "zero radius" incarnation it creates degenerate round rects.
|
2012-10-24 02:01:24 +00:00
|
|
|
// Note: PathTest::test_arb_round_rect_is_convex and
|
2012-10-23 16:56:56 +00:00
|
|
|
// test_arb_zero_rad_round_rect_is_rect perform almost exactly
|
2012-10-18 15:26:12 +00:00
|
|
|
// the same test (but with no drawing)
|
2014-06-19 19:32:29 +00:00
|
|
|
class ArbRoundRectBench : public Benchmark {
|
2012-10-17 15:23:21 +00:00
|
|
|
protected:
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ArbRoundRectBench(bool zeroRad) : fZeroRad(zeroRad) {
|
2012-10-23 16:56:56 +00:00
|
|
|
if (zeroRad) {
|
|
|
|
fName.printf("zeroradroundrect");
|
|
|
|
} else {
|
|
|
|
fName.printf("arbroundrect");
|
|
|
|
}
|
2012-10-17 15:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-10-17 15:23:21 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2012-10-18 02:01:23 +00:00
|
|
|
static void add_corner_arc(SkPath* path, const SkRect& rect,
|
|
|
|
SkScalar xIn, SkScalar yIn,
|
2012-10-17 15:23:21 +00:00
|
|
|
int startAngle)
|
|
|
|
{
|
|
|
|
|
|
|
|
SkScalar rx = SkMinScalar(rect.width(), xIn);
|
|
|
|
SkScalar ry = SkMinScalar(rect.height(), yIn);
|
|
|
|
|
|
|
|
SkRect arcRect;
|
|
|
|
arcRect.set(-rx, -ry, rx, ry);
|
|
|
|
switch (startAngle) {
|
|
|
|
case 0:
|
|
|
|
arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
|
|
|
|
break;
|
|
|
|
case 90:
|
|
|
|
arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
|
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
|
|
|
|
}
|
|
|
|
|
2012-10-18 02:01:23 +00:00
|
|
|
static void make_arb_round_rect(SkPath* path, const SkRect& r,
|
2012-10-17 15:23:21 +00:00
|
|
|
SkScalar xCorner, SkScalar yCorner) {
|
|
|
|
// we are lazy here and use the same x & y for each corner
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 270);
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 0);
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 90);
|
|
|
|
add_corner_arc(path, r, xCorner, yCorner, 180);
|
2012-10-23 16:56:56 +00:00
|
|
|
path->close();
|
2012-10-17 15:23:21 +00:00
|
|
|
|
2012-10-18 15:26:12 +00:00
|
|
|
SkASSERT(path->isConvex());
|
2012-10-17 15:23:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) override {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-10-17 15:23:21 +00:00
|
|
|
SkRect r;
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-10-17 15:23:21 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xff000000 | rand.nextU());
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2012-10-23 16:56:56 +00:00
|
|
|
SkScalar size = rand.nextUScalar1() * 30;
|
|
|
|
if (size < SK_Scalar1) {
|
2012-10-18 15:26:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-10-17 15:23:21 +00:00
|
|
|
r.fLeft = rand.nextUScalar1() * 300;
|
|
|
|
r.fTop = rand.nextUScalar1() * 300;
|
2012-10-23 16:56:56 +00:00
|
|
|
r.fRight = r.fLeft + 2 * size;
|
|
|
|
r.fBottom = r.fTop + 2 * size;
|
2012-10-17 15:23:21 +00:00
|
|
|
|
|
|
|
SkPath temp;
|
|
|
|
|
2012-10-23 16:56:56 +00:00
|
|
|
if (fZeroRad) {
|
|
|
|
make_arb_round_rect(&temp, r, 0, 0);
|
|
|
|
|
|
|
|
SkASSERT(temp.isRect(NULL));
|
|
|
|
} else {
|
|
|
|
make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
|
|
|
|
}
|
2012-10-17 15:23:21 +00:00
|
|
|
|
|
|
|
canvas->drawPath(temp, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-10-23 16:56:56 +00:00
|
|
|
bool fZeroRad; // should 0 radius rounds rects be tested?
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-10-17 15:23:21 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ConservativelyContainsBench : public Benchmark {
|
2012-11-13 21:51:38 +00:00
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
kRect_Type,
|
|
|
|
kRoundRect_Type,
|
|
|
|
kOval_Type,
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
ConservativelyContainsBench(Type type) {
|
2012-11-13 21:51:38 +00:00
|
|
|
fParity = false;
|
|
|
|
fName = "conservatively_contains_";
|
|
|
|
switch (type) {
|
|
|
|
case kRect_Type:
|
|
|
|
fName.append("rect");
|
|
|
|
fPath.addRect(kBaseRect);
|
|
|
|
break;
|
|
|
|
case kRoundRect_Type:
|
|
|
|
fName.append("round_rect");
|
|
|
|
fPath.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1]);
|
|
|
|
break;
|
|
|
|
case kOval_Type:
|
|
|
|
fName.append("oval");
|
|
|
|
fPath.addOval(kBaseRect);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-11-13 21:51:38 +00:00
|
|
|
private:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2012-11-13 21:51:38 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2012-11-13 21:51:38 +00:00
|
|
|
const SkRect& rect = fQueryRects[i % kQueryRectCnt];
|
|
|
|
fParity = fParity != fPath.conservativelyContainsRect(rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onPreDraw() override {
|
2012-11-13 21:51:38 +00:00
|
|
|
fQueryRects.setCount(kQueryRectCnt);
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-11-13 21:51:38 +00:00
|
|
|
for (int i = 0; i < kQueryRectCnt; ++i) {
|
|
|
|
SkSize size;
|
|
|
|
SkPoint xy;
|
|
|
|
size.fWidth = rand.nextRangeScalar(kQueryMin.fWidth, kQueryMax.fWidth);
|
|
|
|
size.fHeight = rand.nextRangeScalar(kQueryMin.fHeight, kQueryMax.fHeight);
|
|
|
|
xy.fX = rand.nextRangeScalar(kBounds.fLeft, kBounds.fRight - size.fWidth);
|
|
|
|
xy.fY = rand.nextRangeScalar(kBounds.fTop, kBounds.fBottom - size.fHeight);
|
|
|
|
|
|
|
|
fQueryRects[i] = SkRect::MakeXYWH(xy.fX, xy.fY, size.fWidth, size.fHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kQueryRectCnt = 400,
|
|
|
|
};
|
|
|
|
static const SkRect kBounds; // bounds for all random query rects
|
|
|
|
static const SkSize kQueryMin; // minimum query rect size, should be <= kQueryMax
|
|
|
|
static const SkSize kQueryMax; // max query rect size, should < kBounds
|
|
|
|
static const SkRect kBaseRect; // rect that is used to construct the path
|
|
|
|
static const SkScalar kRRRadii[2]; // x and y radii for round rect
|
|
|
|
|
|
|
|
SkString fName;
|
|
|
|
SkPath fPath;
|
|
|
|
bool fParity;
|
|
|
|
SkTDArray<SkRect> fQueryRects;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-11-13 21:51:38 +00:00
|
|
|
};
|
|
|
|
|
2013-04-14 02:40:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "SkGeometry.h"
|
|
|
|
|
2015-03-26 16:10:22 +00:00
|
|
|
class ConicBench_Chop : public Benchmark {
|
2015-03-20 20:23:43 +00:00
|
|
|
protected:
|
|
|
|
SkConic fRQ, fDst[2];
|
|
|
|
SkString fName;
|
2013-04-14 02:40:50 +00:00
|
|
|
public:
|
2015-03-26 16:10:22 +00:00
|
|
|
ConicBench_Chop() : fName("conic-chop") {
|
2013-04-14 02:40:50 +00:00
|
|
|
fRQ.fPts[0].set(0, 0);
|
|
|
|
fRQ.fPts[1].set(100, 0);
|
|
|
|
fRQ.fPts[2].set(100, 100);
|
|
|
|
fRQ.fW = SkScalarCos(SK_ScalarPI/4);
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2015-03-20 20:23:43 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-04-14 02:40:50 +00:00
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-03-20 20:23:43 +00:00
|
|
|
private:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2015-03-20 20:23:43 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2015-03-26 16:10:22 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
fRQ.chop(fDst);
|
2013-04-14 02:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-30 02:14:58 +00:00
|
|
|
};
|
2015-03-26 16:10:22 +00:00
|
|
|
DEF_BENCH( return new ConicBench_Chop; )
|
2015-03-20 20:23:43 +00:00
|
|
|
|
2015-03-26 16:10:22 +00:00
|
|
|
class ConicBench_EvalPos : public ConicBench_Chop {
|
|
|
|
const bool fUseV2;
|
2015-03-20 20:23:43 +00:00
|
|
|
public:
|
2015-03-26 16:10:22 +00:00
|
|
|
ConicBench_EvalPos(bool useV2) : fUseV2(useV2) {
|
2015-03-20 20:23:43 +00:00
|
|
|
fName.printf("conic-eval-pos%d", useV2);
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2015-03-20 20:23:43 +00:00
|
|
|
if (fUseV2) {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < 1000; ++j) {
|
|
|
|
fDst[0].fPts[0] = fRQ.evalAt(0.4f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < 1000; ++j) {
|
|
|
|
fRQ.evalAt(0.4f, &fDst[0].fPts[0], NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH( return new ConicBench_EvalPos(false); )
|
|
|
|
DEF_BENCH( return new ConicBench_EvalPos(true); )
|
|
|
|
|
2015-03-26 16:10:22 +00:00
|
|
|
class ConicBench_EvalTan : public ConicBench_Chop {
|
|
|
|
const bool fUseV2;
|
2015-03-20 20:23:43 +00:00
|
|
|
public:
|
2015-03-26 16:10:22 +00:00
|
|
|
ConicBench_EvalTan(bool useV2) : fUseV2(useV2) {
|
2015-03-20 20:23:43 +00:00
|
|
|
fName.printf("conic-eval-tan%d", useV2);
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2015-03-20 20:23:43 +00:00
|
|
|
if (fUseV2) {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < 1000; ++j) {
|
|
|
|
fDst[0].fPts[0] = fRQ.evalTangentAt(0.4f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
for (int j = 0; j < 1000; ++j) {
|
|
|
|
fRQ.evalAt(0.4f, NULL, &fDst[0].fPts[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH( return new ConicBench_EvalTan(false); )
|
|
|
|
DEF_BENCH( return new ConicBench_EvalTan(true); )
|
2013-04-30 02:14:58 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2013-04-14 07:01:08 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static void rand_conic(SkConic* conic, SkRandom& rand) {
|
2013-04-30 02:14:58 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
conic->fPts[i].set(rand.nextUScalar1() * 100, rand.nextUScalar1() * 100);
|
|
|
|
}
|
|
|
|
if (rand.nextUScalar1() > 0.5f) {
|
|
|
|
conic->fW = rand.nextUScalar1();
|
|
|
|
} else {
|
|
|
|
conic->fW = 1 + rand.nextUScalar1() * 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class ConicBench : public Benchmark {
|
2013-04-30 02:14:58 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ConicBench() {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-04-30 02:14:58 +00:00
|
|
|
for (int i = 0; i < CONICS; ++i) {
|
|
|
|
rand_conic(&fConics[i], rand);
|
|
|
|
}
|
2013-11-21 06:21:58 +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;
|
2013-04-30 02:14:58 +00:00
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
protected:
|
|
|
|
enum {
|
|
|
|
CONICS = 100
|
|
|
|
};
|
|
|
|
SkConic fConics[CONICS];
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-04-14 02:40:50 +00:00
|
|
|
};
|
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
class ConicBench_ComputeError : public ConicBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ConicBench_ComputeError() {}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-30 02:14:58 +00:00
|
|
|
return "conic-compute-error";
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-04-30 02:14:58 +00:00
|
|
|
SkVector err;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-04-30 02:14:58 +00:00
|
|
|
for (int j = 0; j < CONICS; ++j) {
|
|
|
|
fConics[j].computeAsQuadError(&err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
private:
|
|
|
|
typedef ConicBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConicBench_asQuadTol : public ConicBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ConicBench_asQuadTol() {}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-30 02:14:58 +00:00
|
|
|
return "conic-asQuadTol";
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-04-30 02:14:58 +00:00
|
|
|
for (int j = 0; j < CONICS; ++j) {
|
|
|
|
fConics[j].asQuadTol(SK_ScalarHalf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
private:
|
|
|
|
typedef ConicBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConicBench_quadPow2 : public ConicBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
ConicBench_quadPow2() {}
|
2013-04-30 02:14:58 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-04-30 02:14:58 +00:00
|
|
|
return "conic-quadPow2";
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(const int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2013-04-30 02:14:58 +00:00
|
|
|
for (int j = 0; j < CONICS; ++j) {
|
|
|
|
fConics[j].computeQuadPOW2(SK_ScalarHalf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 07:01:03 +00:00
|
|
|
|
2013-04-30 02:14:58 +00:00
|
|
|
private:
|
|
|
|
typedef ConicBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-04-14 02:40:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-13 21:51:38 +00:00
|
|
|
const SkRect ConservativelyContainsBench::kBounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
const SkSize ConservativelyContainsBench::kQueryMin = SkSize::Make(SkIntToScalar(1), SkIntToScalar(1));
|
|
|
|
const SkSize ConservativelyContainsBench::kQueryMax = SkSize::Make(SkIntToScalar(40), SkIntToScalar(40));
|
|
|
|
const SkRect ConservativelyContainsBench::kBaseRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), SkIntToScalar(50), SkIntToScalar(50));
|
|
|
|
const SkScalar ConservativelyContainsBench::kRRRadii[2] = {SkIntToScalar(5), SkIntToScalar(10)};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new TrianglePathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new TrianglePathBench(FLAGS01); )
|
|
|
|
DEF_BENCH( return new TrianglePathBench(FLAGS10); )
|
|
|
|
DEF_BENCH( return new TrianglePathBench(FLAGS11); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new RectPathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new RectPathBench(FLAGS01); )
|
|
|
|
DEF_BENCH( return new RectPathBench(FLAGS10); )
|
|
|
|
DEF_BENCH( return new RectPathBench(FLAGS11); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new OvalPathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new OvalPathBench(FLAGS01); )
|
|
|
|
DEF_BENCH( return new OvalPathBench(FLAGS10); )
|
|
|
|
DEF_BENCH( return new OvalPathBench(FLAGS11); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new CirclePathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new CirclePathBench(FLAGS01); )
|
|
|
|
DEF_BENCH( return new CirclePathBench(FLAGS10); )
|
|
|
|
DEF_BENCH( return new CirclePathBench(FLAGS11); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new SawToothPathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new SawToothPathBench(FLAGS01); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new LongCurvedPathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new LongCurvedPathBench(FLAGS01); )
|
|
|
|
DEF_BENCH( return new LongLinePathBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new LongLinePathBench(FLAGS01); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new PathCreateBench(); )
|
|
|
|
DEF_BENCH( return new PathCopyBench(); )
|
|
|
|
DEF_BENCH( return new PathTransformBench(true); )
|
|
|
|
DEF_BENCH( return new PathTransformBench(false); )
|
|
|
|
DEF_BENCH( return new PathEqualityBench(); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAdd_AddType); )
|
|
|
|
DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAddTrans_AddType); )
|
|
|
|
DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kAddMatrix_AddType); )
|
|
|
|
DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kReverseAdd_AddType); )
|
|
|
|
DEF_BENCH( return new SkBench_AddPathTest(SkBench_AddPathTest::kReversePathTo_AddType); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new CirclesBench(FLAGS00); )
|
|
|
|
DEF_BENCH( return new CirclesBench(FLAGS01); )
|
|
|
|
DEF_BENCH( return new ArbRoundRectBench(false); )
|
|
|
|
DEF_BENCH( return new ArbRoundRectBench(true); )
|
|
|
|
DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::kRect_Type); )
|
|
|
|
DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::kRoundRect_Type); )
|
|
|
|
DEF_BENCH( return new ConservativelyContainsBench(ConservativelyContainsBench::kOval_Type); )
|
|
|
|
|
2015-03-20 20:23:43 +00:00
|
|
|
|
2014-07-17 00:23:43 +00:00
|
|
|
// These seem to be optimized away, which is troublesome for timing.
|
|
|
|
/*
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new ConicBench_Chop5() )
|
|
|
|
DEF_BENCH( return new ConicBench_ComputeError() )
|
|
|
|
DEF_BENCH( return new ConicBench_asQuadTol() )
|
|
|
|
DEF_BENCH( return new ConicBench_quadPow2() )
|
2014-07-17 00:23:43 +00:00
|
|
|
*/
|