aboutsummaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-04-14 09:57:06 -0400
committerDerek Sollenberger <djsollen@google.com>2011-04-14 15:01:11 -0400
commit87b8e645865f9633f410c02252a0fd3feb18f09b (patch)
tree21e2521ed6f69bf466849f7c9579c37aa6b22b06 /bench
parent7f10e10e25231b613ebb242fa14ad8c924ce694f (diff)
downloadexternal_skia-87b8e645865f9633f410c02252a0fd3feb18f09b.zip
external_skia-87b8e645865f9633f410c02252a0fd3feb18f09b.tar.gz
external_skia-87b8e645865f9633f410c02252a0fd3feb18f09b.tar.bz2
Skia Merge (revision 1116)
There is a companion change in external/webkit Change-Id: I1c4110e7520bbef3f4e5f9551adb7ec79ac1e3ed
Diffstat (limited to 'bench')
-rw-r--r--bench/PathBench.cpp189
-rw-r--r--bench/RectBench.cpp29
-rw-r--r--bench/benchmain.cpp13
3 files changed, 220 insertions, 11 deletions
diff --git a/bench/PathBench.cpp b/bench/PathBench.cpp
new file mode 100644
index 0000000..19e3aae
--- /dev/null
+++ b/bench/PathBench.cpp
@@ -0,0 +1,189 @@
+#include "SkBenchmark.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkColorPriv.h"
+#include "SkPaint.h"
+#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;
+ enum { N = 1000 };
+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;
+ virtual bool iscomplex() { return false; }
+
+protected:
+ virtual const char* onGetName() {
+ fName.printf("path_%s_%s_",
+ fFlags & kStroke_Flag ? "stroke" : "fill",
+ fFlags & kBig_Flag ? "big" : "small");
+ this->appendName(&fName);
+ return fName.c_str();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ 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;
+ }
+ if (this->iscomplex()) {
+ count >>= 3;
+ }
+
+ 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) {}
+
+ virtual void appendName(SkString* name) {
+ name->append("triangle");
+ }
+ virtual void makePath(SkPath* path) {
+ 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) {}
+
+ virtual void appendName(SkString* name) {
+ name->append("rect");
+ }
+ virtual void makePath(SkPath* path) {
+ 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) {}
+
+ virtual void appendName(SkString* name) {
+ name->append("oval");
+ }
+ virtual void makePath(SkPath* path) {
+ SkRect r = { 10, 10, 20, 20 };
+ path->addOval(r);
+ }
+private:
+ typedef PathBench INHERITED;
+};
+
+class SawToothPathBench : public PathBench {
+public:
+ SawToothPathBench(void* param, Flags flags) : INHERITED(param, flags) {}
+
+ virtual void appendName(SkString* name) {
+ 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();
+ }
+ virtual bool iscomplex() { return true; }
+private:
+ typedef PathBench INHERITED;
+};
+
+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); }
+
+static SkBenchmark* FactS00(void* p) { return new SawToothPathBench(p, FLAGS00); }
+static SkBenchmark* FactS01(void* p) { return new SawToothPathBench(p, FLAGS01); }
+
+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);
+
+static BenchRegistry gRegS00(FactS00);
+static BenchRegistry gRegS01(FactS01);
+
diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp
index a6f300e..fb54640 100644
--- a/bench/RectBench.cpp
+++ b/bench/RectBench.cpp
@@ -7,7 +7,7 @@
class RectBench : public SkBenchmark {
public:
- int fShift;
+ int fShift, fStroke;
enum {
W = 640,
H = 480,
@@ -16,8 +16,9 @@ public:
SkRect fRects[N];
SkColor fColors[N];
- RectBench(void* param, int shift) : INHERITED(param), fShift(shift) {
+ RectBench(void* param, int shift, int stroke = 0) : INHERITED(param), fShift(shift), fStroke(stroke) {
SkRandom rand;
+ const SkScalar offset = SK_Scalar1/3;
for (int i = 0; i < N; i++) {
int x = rand.nextU() % W;
int y = rand.nextU() % H;
@@ -29,14 +30,17 @@ public:
y -= h/2;
fRects[i].set(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(x+w), SkIntToScalar(y+h));
+ fRects[i].offset(offset, offset);
fColors[i] = rand.nextU() | 0xFF808080;
}
}
SkString fName;
const char* computeName(const char root[]) {
- fName.set(root);
- fName.appendS32(fShift);
+ fName.printf("%s_%d", root, fShift);
+ if (fStroke > 0) {
+ fName.appendf("_stroke_%d", fStroke);
+ }
return fName.c_str();
}
@@ -48,6 +52,10 @@ protected:
virtual const char* onGetName() { return computeName("rects"); }
virtual void onDraw(SkCanvas* canvas) {
SkPaint paint;
+ if (fStroke > 0) {
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(SkIntToScalar(fStroke));
+ }
for (int i = 0; i < N; i++) {
paint.setColor(fColors[i]);
this->setupPaint(&paint);
@@ -192,8 +200,10 @@ private:
};
-static SkBenchmark* RectFactory1(void* p) { return SkNEW_ARGS(RectBench, (p, 1)); }
-static SkBenchmark* RectFactory2(void* p) { return SkNEW_ARGS(RectBench, (p, 3)); }
+static SkBenchmark* RectFactory1F(void* p) { return SkNEW_ARGS(RectBench, (p, 1)); }
+static SkBenchmark* RectFactory1S(void* p) { return SkNEW_ARGS(RectBench, (p, 1, 4)); }
+static SkBenchmark* RectFactory2F(void* p) { return SkNEW_ARGS(RectBench, (p, 3)); }
+static SkBenchmark* RectFactory2S(void* p) { return SkNEW_ARGS(RectBench, (p, 3, 4)); }
static SkBenchmark* OvalFactory1(void* p) { return SkNEW_ARGS(OvalBench, (p, 1)); }
static SkBenchmark* OvalFactory2(void* p) { return SkNEW_ARGS(OvalBench, (p, 3)); }
static SkBenchmark* RRectFactory1(void* p) { return SkNEW_ARGS(RRectBench, (p, 1)); }
@@ -234,8 +244,11 @@ static SkBenchmark* BlitMaskShaderFactory(void* p) {
BlitMaskBench::KMaskShader, "maskshader")
);
}
-static BenchRegistry gRectReg1(RectFactory1);
-static BenchRegistry gRectReg2(RectFactory2);
+
+static BenchRegistry gRectReg1F(RectFactory1F);
+static BenchRegistry gRectReg1S(RectFactory1S);
+static BenchRegistry gRectReg2F(RectFactory2F);
+static BenchRegistry gRectReg2S(RectFactory2S);
static BenchRegistry gOvalReg1(OvalFactory1);
static BenchRegistry gOvalReg2(OvalFactory2);
static BenchRegistry gRRectReg1(RRectFactory1);
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index 3b6dfdf..4f6d81c 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -317,6 +317,14 @@ int main (int argc, char * const argv[]) {
}
}
+ // report our current settings
+ {
+ SkString str;
+ str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d\n",
+ forceAlpha, forceAA, forceFilter);
+ log_progress(str);
+ }
+
Iter iter(&defineDict);
SkBenchmark* bench;
while ((bench = iter.next()) != NULL) {
@@ -340,7 +348,7 @@ int main (int argc, char * const argv[]) {
{
SkString str;
- str.printf("running bench [%d %d] %16s", dim.fX, dim.fY,
+ str.printf("running bench [%d %d] %28s", dim.fX, dim.fY,
bench->getName());
log_progress(str);
}
@@ -397,8 +405,7 @@ int main (int argc, char * const argv[]) {
if (repeatDraw > 1) {
double duration = SkTime::GetMSecs() - now;
SkString str;
- str.printf(" %4s: msecs = %7.2f, fps = %7.2f", configName,
- duration / repeatDraw, repeatDraw * 1000.0 / duration);
+ str.printf(" %4s: msecs = %5.2f", configName, duration / repeatDraw);
log_progress(str);
}
if (outDir.size() > 0) {