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.
|
|
|
|
*/
|
2011-04-11 13:12:51 +00:00
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
class PathBench : public SkBenchmark {
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
|
|
|
Flags fFlags;
|
2011-10-28 15:34:49 +00:00
|
|
|
enum { N = SkBENCHLOOP(1000) };
|
2011-04-11 13:12:51 +00:00
|
|
|
public:
|
|
|
|
PathBench(void* param, Flags flags) : INHERITED(param), fFlags(flags) {
|
|
|
|
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:
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual const char* onGetName() SK_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();
|
|
|
|
}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2011-04-11 13:12:51 +00:00
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
this->makePath(&path);
|
|
|
|
if (fFlags & kBig_Flag) {
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
path.transform(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = N;
|
|
|
|
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:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TrianglePathBench : public PathBench {
|
|
|
|
public:
|
|
|
|
TrianglePathBench(void* param, Flags flags) : INHERITED(param, flags) {}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void appendName(SkString* name) SK_OVERRIDE {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("triangle");
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void makePath(SkPath* path) SK_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:
|
|
|
|
RectPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void appendName(SkString* name) SK_OVERRIDE {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("rect");
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void makePath(SkPath* path) SK_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:
|
|
|
|
OvalPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void appendName(SkString* name) SK_OVERRIDE {
|
2011-04-11 13:12:51 +00:00
|
|
|
name->append("oval");
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void makePath(SkPath* path) SK_OVERRIDE {
|
2011-04-11 13:12:51 +00:00
|
|
|
SkRect r = { 10, 10, 20, 20 };
|
|
|
|
path->addOval(r);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
class CirclePathBench: public PathBench {
|
|
|
|
public:
|
|
|
|
CirclePathBench(void* param, Flags flags) : INHERITED(param, flags) {}
|
|
|
|
|
|
|
|
virtual void appendName(SkString* name) SK_OVERRIDE {
|
|
|
|
name->append("circle");
|
|
|
|
}
|
|
|
|
virtual void makePath(SkPath* path) SK_OVERRIDE {
|
|
|
|
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:
|
|
|
|
SawToothPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void appendName(SkString* name) SK_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();
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual int complexity() SK_OVERRIDE { return 1; }
|
2011-06-22 17:16:35 +00:00
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LongCurvedPathBench : public PathBench {
|
|
|
|
public:
|
|
|
|
LongCurvedPathBench(void * param, Flags flags)
|
|
|
|
: INHERITED(param, flags) {
|
|
|
|
}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void appendName(SkString* name) SK_OVERRIDE {
|
2011-06-22 17:16:35 +00:00
|
|
|
name->append("long_curved");
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void makePath(SkPath* path) SK_OVERRIDE {
|
2011-06-22 17:16:35 +00:00
|
|
|
SkRandom rand (12);
|
|
|
|
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();
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual int complexity() SK_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:
|
|
|
|
LongLinePathBench(void * param, Flags flags)
|
|
|
|
: INHERITED(param, flags) {
|
|
|
|
}
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void appendName(SkString* name) SK_OVERRIDE {
|
2012-01-12 19:10:35 +00:00
|
|
|
name->append("long_line");
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual void makePath(SkPath* path) SK_OVERRIDE {
|
2012-01-12 19:10:35 +00:00
|
|
|
SkRandom rand;
|
|
|
|
path->moveTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
for (size_t i = 1; i < 100; i++) {
|
|
|
|
path->lineTo(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 15:34:46 +00:00
|
|
|
virtual int complexity() SK_OVERRIDE { return 2; }
|
2012-01-12 19:10:35 +00:00
|
|
|
private:
|
|
|
|
typedef PathBench INHERITED;
|
|
|
|
};
|
2011-06-22 17:16:35 +00:00
|
|
|
|
|
|
|
|
2011-04-11 13:12:51 +00:00
|
|
|
static SkBenchmark* FactT00(void* p) { return new TrianglePathBench(p, FLAGS00); }
|
|
|
|
static SkBenchmark* FactT01(void* p) { return new TrianglePathBench(p, FLAGS01); }
|
|
|
|
static SkBenchmark* FactT10(void* p) { return new TrianglePathBench(p, FLAGS10); }
|
|
|
|
static SkBenchmark* FactT11(void* p) { return new TrianglePathBench(p, FLAGS11); }
|
|
|
|
|
|
|
|
static SkBenchmark* FactR00(void* p) { return new RectPathBench(p, FLAGS00); }
|
|
|
|
static SkBenchmark* FactR01(void* p) { return new RectPathBench(p, FLAGS01); }
|
|
|
|
static SkBenchmark* FactR10(void* p) { return new RectPathBench(p, FLAGS10); }
|
|
|
|
static SkBenchmark* FactR11(void* p) { return new RectPathBench(p, FLAGS11); }
|
|
|
|
|
|
|
|
static SkBenchmark* FactO00(void* p) { return new OvalPathBench(p, FLAGS00); }
|
|
|
|
static SkBenchmark* FactO01(void* p) { return new OvalPathBench(p, FLAGS01); }
|
|
|
|
static SkBenchmark* FactO10(void* p) { return new OvalPathBench(p, FLAGS10); }
|
|
|
|
static SkBenchmark* FactO11(void* p) { return new OvalPathBench(p, FLAGS11); }
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
static SkBenchmark* FactC00(void* p) { return new CirclePathBench(p, FLAGS00); }
|
|
|
|
static SkBenchmark* FactC01(void* p) { return new CirclePathBench(p, FLAGS01); }
|
|
|
|
static SkBenchmark* FactC10(void* p) { return new CirclePathBench(p, FLAGS10); }
|
|
|
|
static SkBenchmark* FactC11(void* p) { return new CirclePathBench(p, FLAGS11); }
|
|
|
|
|
2011-04-11 13:12:51 +00:00
|
|
|
static SkBenchmark* FactS00(void* p) { return new SawToothPathBench(p, FLAGS00); }
|
|
|
|
static SkBenchmark* FactS01(void* p) { return new SawToothPathBench(p, FLAGS01); }
|
|
|
|
|
2011-06-22 17:16:35 +00:00
|
|
|
static SkBenchmark* FactLC00(void* p) {
|
|
|
|
return new LongCurvedPathBench(p, FLAGS00);
|
|
|
|
}
|
|
|
|
static SkBenchmark* FactLC01(void* p) {
|
|
|
|
return new LongCurvedPathBench(p, FLAGS01);
|
|
|
|
}
|
|
|
|
|
2012-01-12 19:10:35 +00:00
|
|
|
static SkBenchmark* FactLL00(void* p) {
|
|
|
|
return new LongLinePathBench(p, FLAGS00);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkBenchmark* FactLL01(void* p) {
|
|
|
|
return new LongLinePathBench(p, FLAGS01);
|
|
|
|
}
|
|
|
|
|
2011-04-11 13:12:51 +00:00
|
|
|
static BenchRegistry gRegT00(FactT00);
|
|
|
|
static BenchRegistry gRegT01(FactT01);
|
|
|
|
static BenchRegistry gRegT10(FactT10);
|
|
|
|
static BenchRegistry gRegT11(FactT11);
|
|
|
|
|
|
|
|
static BenchRegistry gRegR00(FactR00);
|
|
|
|
static BenchRegistry gRegR01(FactR01);
|
|
|
|
static BenchRegistry gRegR10(FactR10);
|
|
|
|
static BenchRegistry gRegR11(FactR11);
|
|
|
|
|
|
|
|
static BenchRegistry gRegO00(FactO00);
|
|
|
|
static BenchRegistry gRegO01(FactO01);
|
|
|
|
static BenchRegistry gRegO10(FactO10);
|
|
|
|
static BenchRegistry gRegO11(FactO11);
|
|
|
|
|
2012-04-11 15:34:46 +00:00
|
|
|
static BenchRegistry gRegC00(FactC00);
|
|
|
|
static BenchRegistry gRegC01(FactC01);
|
|
|
|
static BenchRegistry gRegC10(FactC10);
|
|
|
|
static BenchRegistry gRegC11(FactC11);
|
|
|
|
|
2011-04-11 13:12:51 +00:00
|
|
|
static BenchRegistry gRegS00(FactS00);
|
|
|
|
static BenchRegistry gRegS01(FactS01);
|
|
|
|
|
2011-06-22 17:16:35 +00:00
|
|
|
static BenchRegistry gRegLC00(FactLC00);
|
|
|
|
static BenchRegistry gRegLC01(FactLC01);
|
|
|
|
|
2012-01-12 19:10:35 +00:00
|
|
|
static BenchRegistry gRegLL00(FactLL00);
|
|
|
|
static BenchRegistry gRegLL01(FactLL01);
|
|
|
|
|