add decode bench

add dictionary for bench tools to see optional cmdline args



git-svn-id: http://skia.googlecode.com/svn/trunk@351 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-09-02 21:12:42 +00:00
parent 34e85803c2
commit e9d0060f4d
8 changed files with 125 additions and 42 deletions

View File

@ -96,7 +96,8 @@ class BitmapBench : public SkBenchmark {
SkString fName; SkString fName;
enum { N = 300 }; enum { N = 300 };
public: public:
BitmapBench(SkBitmap::Config c, int tx = -1, int ty = -1) : fTileX(tx), fTileY(ty) { BitmapBench(void* param, SkBitmap::Config c, int tx = -1, int ty = -1)
: INHERITED(param), fTileX(tx), fTileY(ty) {
const int w = 128; const int w = 128;
const int h = 128; const int h = 128;
SkBitmap bm; SkBitmap bm;
@ -153,10 +154,10 @@ private:
typedef SkBenchmark INHERITED; typedef SkBenchmark INHERITED;
}; };
static SkBenchmark* Fact0(void*) { return new BitmapBench(SkBitmap::kARGB_8888_Config); } static SkBenchmark* Fact0(void* p) { return new BitmapBench(p, SkBitmap::kARGB_8888_Config); }
static SkBenchmark* Fact1(void*) { return new BitmapBench(SkBitmap::kRGB_565_Config); } static SkBenchmark* Fact1(void* p) { return new BitmapBench(p, SkBitmap::kRGB_565_Config); }
static SkBenchmark* Fact2(void*) { return new BitmapBench(SkBitmap::kARGB_4444_Config); } static SkBenchmark* Fact2(void* p) { return new BitmapBench(p, SkBitmap::kARGB_4444_Config); }
static SkBenchmark* Fact3(void*) { return new BitmapBench(SkBitmap::kIndex8_Config); } static SkBenchmark* Fact3(void* p) { return new BitmapBench(p, SkBitmap::kIndex8_Config); }
static BenchRegistry gReg0(Fact0); static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1); static BenchRegistry gReg1(Fact1);

53
bench/DecodeBench.cpp Normal file
View File

@ -0,0 +1,53 @@
#include "SkBenchmark.h"
#include "SkBitmap.h"
#include "SkImageDecoder.h"
#include "SkString.h"
static const char* gConfigName[] = {
"ERROR", "a1", "a8", "index8", "565", "4444", "8888"
};
class DecodeBench : public SkBenchmark {
const char* fFilename;
SkBitmap::Config fPrefConfig;
SkString fName;
enum { N = 10 };
public:
DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) {
fFilename = this->findDefine("decode-filename");
fPrefConfig = c;
const char* fname = NULL;
if (fFilename) {
fname = strrchr(fFilename, '/');
if (fname) {
fname += 1; // skip the slash
}
}
fName.printf("decode_%s_%s", gConfigName[c], fname);
}
protected:
virtual const char* onGetName() {
return fName.c_str();
}
virtual void onDraw(SkCanvas* canvas) {
for (int i = 0; i < N; i++) {
SkBitmap bm;
SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig,
SkImageDecoder::kDecodePixels_Mode);
}
}
private:
typedef SkBenchmark INHERITED;
};
static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); }
static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); }
static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); }
static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1);
static BenchRegistry gReg2(Fact2);

View File

@ -15,7 +15,7 @@ public:
SkRect fRects[N]; SkRect fRects[N];
SkColor fColors[N]; SkColor fColors[N];
RectBench(int shift) : fShift(shift) { RectBench(void* param, int shift) : INHERITED(param), fShift(shift) {
SkRandom rand; SkRandom rand;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
int x = rand.nextU() % W; int x = rand.nextU() % W;
@ -53,11 +53,13 @@ protected:
this->drawThisRect(canvas, fRects[i], paint); this->drawThisRect(canvas, fRects[i], paint);
} }
} }
private:
typedef SkBenchmark INHERITED;
}; };
class OvalBench : public RectBench { class OvalBench : public RectBench {
public: public:
OvalBench(int shift) : RectBench(shift) {} OvalBench(void* param, int shift) : RectBench(param, shift) {}
protected: protected:
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
c->drawOval(r, p); c->drawOval(r, p);
@ -67,7 +69,7 @@ protected:
class RRectBench : public RectBench { class RRectBench : public RectBench {
public: public:
RRectBench(int shift) : RectBench(shift) {} RRectBench(void* param, int shift) : RectBench(param, shift) {}
protected: protected:
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) { virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
c->drawRoundRect(r, r.width() / 4, r.height() / 4, p); c->drawRoundRect(r, r.width() / 4, r.height() / 4, p);
@ -80,8 +82,8 @@ public:
SkCanvas::PointMode fMode; SkCanvas::PointMode fMode;
const char* fName; const char* fName;
PointsBench(SkCanvas::PointMode mode, const char* name) : PointsBench(void* param, SkCanvas::PointMode mode, const char* name) :
RectBench(2), fMode(mode) { RectBench(param, 2), fMode(mode) {
fName = name; fName = name;
} }
@ -105,20 +107,20 @@ protected:
virtual const char* onGetName() { return fName; } virtual const char* onGetName() { return fName; }
}; };
static SkBenchmark* RectFactory1(void*) { return SkNEW_ARGS(RectBench, (1)); } static SkBenchmark* RectFactory1(void* p) { return SkNEW_ARGS(RectBench, (p, 1)); }
static SkBenchmark* RectFactory2(void*) { return SkNEW_ARGS(RectBench, (3)); } static SkBenchmark* RectFactory2(void* p) { return SkNEW_ARGS(RectBench, (p, 3)); }
static SkBenchmark* OvalFactory1(void*) { return SkNEW_ARGS(OvalBench, (1)); } static SkBenchmark* OvalFactory1(void* p) { return SkNEW_ARGS(OvalBench, (p, 1)); }
static SkBenchmark* OvalFactory2(void*) { return SkNEW_ARGS(OvalBench, (3)); } static SkBenchmark* OvalFactory2(void* p) { return SkNEW_ARGS(OvalBench, (p, 3)); }
static SkBenchmark* RRectFactory1(void*) { return SkNEW_ARGS(RRectBench, (1)); } static SkBenchmark* RRectFactory1(void* p) { return SkNEW_ARGS(RRectBench, (p, 1)); }
static SkBenchmark* RRectFactory2(void*) { return SkNEW_ARGS(RRectBench, (3)); } static SkBenchmark* RRectFactory2(void* p) { return SkNEW_ARGS(RRectBench, (p, 3)); }
static SkBenchmark* PointsFactory(void*) { static SkBenchmark* PointsFactory(void* p) {
return SkNEW_ARGS(PointsBench, (SkCanvas::kPoints_PointMode, "points")); return SkNEW_ARGS(PointsBench, (p, SkCanvas::kPoints_PointMode, "points"));
} }
static SkBenchmark* LinesFactory(void*) { static SkBenchmark* LinesFactory(void* p) {
return SkNEW_ARGS(PointsBench, (SkCanvas::kLines_PointMode, "lines")); return SkNEW_ARGS(PointsBench, (p, SkCanvas::kLines_PointMode, "lines"));
} }
static SkBenchmark* PolygonFactory(void*) { static SkBenchmark* PolygonFactory(void* p) {
return SkNEW_ARGS(PointsBench, (SkCanvas::kPolygon_PointMode, "polygon")); return SkNEW_ARGS(PointsBench, (p, SkCanvas::kPolygon_PointMode, "polygon"));
} }
static BenchRegistry gRectReg1(RectFactory1); static BenchRegistry gRectReg1(RectFactory1);

View File

@ -81,7 +81,7 @@ class RepeatTileBench : public SkBenchmark {
SkString fName; SkString fName;
enum { N = 20 }; enum { N = 20 };
public: public:
RepeatTileBench(SkBitmap::Config c) { RepeatTileBench(void* param, SkBitmap::Config c) : INHERITED(param) {
const int w = 50; const int w = 50;
const int h = 50; const int h = 50;
SkBitmap bm; SkBitmap bm;
@ -127,10 +127,10 @@ private:
typedef SkBenchmark INHERITED; typedef SkBenchmark INHERITED;
}; };
static SkBenchmark* Fact0(void*) { return new RepeatTileBench(SkBitmap::kARGB_8888_Config); } static SkBenchmark* Fact0(void* p) { return new RepeatTileBench(p, SkBitmap::kARGB_8888_Config); }
static SkBenchmark* Fact1(void*) { return new RepeatTileBench(SkBitmap::kRGB_565_Config); } static SkBenchmark* Fact1(void* p) { return new RepeatTileBench(p, SkBitmap::kRGB_565_Config); }
static SkBenchmark* Fact2(void*) { return new RepeatTileBench(SkBitmap::kARGB_4444_Config); } static SkBenchmark* Fact2(void* p) { return new RepeatTileBench(p, SkBitmap::kARGB_4444_Config); }
static SkBenchmark* Fact3(void*) { return new RepeatTileBench(SkBitmap::kIndex8_Config); } static SkBenchmark* Fact3(void* p) { return new RepeatTileBench(p, SkBitmap::kIndex8_Config); }
static BenchRegistry gReg0(Fact0); static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1); static BenchRegistry gReg1(Fact1);

View File

@ -3,7 +3,8 @@
template BenchRegistry* BenchRegistry::gHead; template BenchRegistry* BenchRegistry::gHead;
SkBenchmark::SkBenchmark() { SkBenchmark::SkBenchmark(void* defineDict) {
fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict);
fForceAlpha = 0xFF; fForceAlpha = 0xFF;
fForceAA = true; fForceAA = true;
} }
@ -26,6 +27,16 @@ void SkBenchmark::setupPaint(SkPaint* paint) {
paint->setFilterBitmap(fForceFilter); paint->setFilterBitmap(fForceFilter);
} }
const char* SkBenchmark::findDefine(const char* key) const {
if (fDict) {
const char* value;
if (fDict->find(key, &value)) {
return value;
}
}
return NULL;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkIPoint SkBenchmark::onGetSize() { SkIPoint SkBenchmark::onGetSize() {

View File

@ -3,6 +3,7 @@
#include "SkRefCnt.h" #include "SkRefCnt.h"
#include "SkPoint.h" #include "SkPoint.h"
#include "SkTDict.h"
#include "SkTRegistry.h" #include "SkTRegistry.h"
class SkCanvas; class SkCanvas;
@ -10,7 +11,7 @@ class SkPaint;
class SkBenchmark : public SkRefCnt { class SkBenchmark : public SkRefCnt {
public: public:
SkBenchmark(); SkBenchmark(void* defineDict);
const char* getName(); const char* getName();
SkIPoint getSize(); SkIPoint getSize();
@ -27,7 +28,9 @@ public:
void setForceFilter(bool filter) { void setForceFilter(bool filter) {
fForceFilter = filter; fForceFilter = filter;
} }
const char* findDefine(const char* key) const;
protected: protected:
void setupPaint(SkPaint* paint); void setupPaint(SkPaint* paint);
@ -37,6 +40,7 @@ protected:
virtual SkIPoint onGetSize(); virtual SkIPoint onGetSize();
private: private:
const SkTDict<const char*>* fDict;
int fForceAlpha; int fForceAlpha;
bool fForceAA; bool fForceAA;
bool fForceFilter; bool fForceFilter;

View File

@ -24,7 +24,8 @@ class TextBench : public SkBenchmark {
SkString fName; SkString fName;
enum { N = 300 }; enum { N = 300 };
public: public:
TextBench(const char text[], int ps, bool linearText, bool posText) { TextBench(void* param, const char text[], int ps, bool linearText,
bool posText) : INHERITED(param) {
fText.set(text); fText.set(text);
fPaint.setAntiAlias(true); fPaint.setAntiAlias(true);
@ -97,14 +98,14 @@ private:
#define SMALL 9 #define SMALL 9
#define BIG 48 #define BIG 48
static SkBenchmark* Fact0(void*) { return new TextBench(STR, SMALL, false, false); } static SkBenchmark* Fact0(void* p) { return new TextBench(p, STR, SMALL, false, false); }
static SkBenchmark* Fact1(void*) { return new TextBench(STR, SMALL, false, true); } static SkBenchmark* Fact1(void* p) { return new TextBench(p, STR, SMALL, false, true); }
static SkBenchmark* Fact2(void*) { return new TextBench(STR, SMALL, true, false); } static SkBenchmark* Fact2(void* p) { return new TextBench(p, STR, SMALL, true, false); }
static SkBenchmark* Fact3(void*) { return new TextBench(STR, SMALL, true, true); } static SkBenchmark* Fact3(void* p) { return new TextBench(p, STR, SMALL, true, true); }
static SkBenchmark* Fact4(void*) { return new TextBench(STR, BIG, false, false); } static SkBenchmark* Fact4(void* p) { return new TextBench(p, STR, BIG, false, false); }
static SkBenchmark* Fact5(void*) { return new TextBench(STR, BIG, false, true); } static SkBenchmark* Fact5(void* p) { return new TextBench(p, STR, BIG, false, true); }
static SkBenchmark* Fact6(void*) { return new TextBench(STR, BIG, true, false); } static SkBenchmark* Fact6(void* p) { return new TextBench(p, STR, BIG, true, false); }
static SkBenchmark* Fact7(void*) { return new TextBench(STR, BIG, true, true); } static SkBenchmark* Fact7(void* p) { return new TextBench(p, STR, BIG, true, true); }
static BenchRegistry gReg0(Fact0); static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1); static BenchRegistry gReg1(Fact1);

View File

@ -49,21 +49,23 @@ static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) {
class Iter { class Iter {
public: public:
Iter() { Iter(void* param) {
fBench = BenchRegistry::Head(); fBench = BenchRegistry::Head();
fParam = param;
} }
SkBenchmark* next() { SkBenchmark* next() {
if (fBench) { if (fBench) {
BenchRegistry::Factory f = fBench->factory(); BenchRegistry::Factory f = fBench->factory();
fBench = fBench->next(); fBench = fBench->next();
return f(0); return f(fParam);
} }
return NULL; return NULL;
} }
private: private:
const BenchRegistry* fBench; const BenchRegistry* fBench;
void* fParam;
}; };
static void make_filename(const char name[], SkString* path) { static void make_filename(const char name[], SkString* path) {
@ -186,6 +188,7 @@ static int findConfig(const char config[]) {
int main (int argc, char * const argv[]) { int main (int argc, char * const argv[]) {
SkAutoGraphics ag; SkAutoGraphics ag;
SkTDict<const char*> defineDict(1024);
int repeatDraw = 1; int repeatDraw = 1;
int forceAlpha = 0xFF; int forceAlpha = 0xFF;
bool forceAA = true; bool forceAA = true;
@ -273,6 +276,14 @@ int main (int argc, char * const argv[]) {
log_error("missing arg for -config\n"); log_error("missing arg for -config\n");
return -1; return -1;
} }
} else if (strncmp(*argv, "-D", 2) == 0) {
argv++;
if (strlen(*argv) > 2 && argv < stop) {
defineDict.set(argv[-1] + 2, *argv);
} else {
log_error("incomplete '-Dfoo bar' definition\n");
return -1;
}
} else { } else {
SkString str; SkString str;
str.printf("unrecognized arg %s\n", *argv); str.printf("unrecognized arg %s\n", *argv);
@ -281,7 +292,7 @@ int main (int argc, char * const argv[]) {
} }
} }
Iter iter; Iter iter(&defineDict);
SkBenchmark* bench; SkBenchmark* bench;
while ((bench = iter.next()) != NULL) { while ((bench = iter.next()) != NULL) {
SkIPoint dim = bench->getSize(); SkIPoint dim = bench->getSize();