aboutsummaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
authorMike Reed <reed@google.com>2009-09-02 14:03:53 -0400
committerMike Reed <reed@google.com>2009-09-02 14:03:53 -0400
commit57382d688c1d6928b1d9bbbaf27188d54dd9e002 (patch)
treed9c53b7bdd40415ecdfc1131b2d18c0ddeb0bca3 /bench
parentfa194bff67a9cedd2bfc1f0d2840e64fd678b9e9 (diff)
downloadexternal_skia-57382d688c1d6928b1d9bbbaf27188d54dd9e002.zip
external_skia-57382d688c1d6928b1d9bbbaf27188d54dd9e002.tar.gz
external_skia-57382d688c1d6928b1d9bbbaf27188d54dd9e002.tar.bz2
add decoding bitmaps to bench tool
refresh misc. skia files
Diffstat (limited to 'bench')
-rw-r--r--bench/Android.mk1
-rw-r--r--bench/BitmapBench.cpp11
-rw-r--r--bench/DecodeBench.cpp53
-rw-r--r--bench/RectBench.cpp36
-rw-r--r--bench/RepeatTileBench.cpp10
-rw-r--r--bench/SkBenchmark.cpp13
-rw-r--r--bench/SkBenchmark.h8
-rw-r--r--bench/TextBench.cpp19
-rw-r--r--bench/benchmain.cpp17
9 files changed, 126 insertions, 42 deletions
diff --git a/bench/Android.mk b/bench/Android.mk
index ba29622..f084eb9 100644
--- a/bench/Android.mk
+++ b/bench/Android.mk
@@ -4,6 +4,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
BitmapBench.cpp \
+ DecodeBench.cpp \
RectBench.cpp \
RepeatTileBench.cpp \
TextBench.cpp \
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp
index 22c0a01..89dfa74 100644
--- a/bench/BitmapBench.cpp
+++ b/bench/BitmapBench.cpp
@@ -96,7 +96,8 @@ class BitmapBench : public SkBenchmark {
SkString fName;
enum { N = 300 };
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 h = 128;
SkBitmap bm;
@@ -153,10 +154,10 @@ private:
typedef SkBenchmark INHERITED;
};
-static SkBenchmark* Fact0(void*) { return new BitmapBench(SkBitmap::kARGB_8888_Config); }
-static SkBenchmark* Fact1(void*) { return new BitmapBench(SkBitmap::kRGB_565_Config); }
-static SkBenchmark* Fact2(void*) { return new BitmapBench(SkBitmap::kARGB_4444_Config); }
-static SkBenchmark* Fact3(void*) { return new BitmapBench(SkBitmap::kIndex8_Config); }
+static SkBenchmark* Fact0(void* p) { return new BitmapBench(p, SkBitmap::kARGB_8888_Config); }
+static SkBenchmark* Fact1(void* p) { return new BitmapBench(p, SkBitmap::kRGB_565_Config); }
+static SkBenchmark* Fact2(void* p) { return new BitmapBench(p, SkBitmap::kARGB_4444_Config); }
+static SkBenchmark* Fact3(void* p) { return new BitmapBench(p, SkBitmap::kIndex8_Config); }
static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1);
diff --git a/bench/DecodeBench.cpp b/bench/DecodeBench.cpp
new file mode 100644
index 0000000..6abd054
--- /dev/null
+++ b/bench/DecodeBench.cpp
@@ -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);
diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp
index 69e0b00..6f34eb5 100644
--- a/bench/RectBench.cpp
+++ b/bench/RectBench.cpp
@@ -15,7 +15,7 @@ public:
SkRect fRects[N];
SkColor fColors[N];
- RectBench(int shift) : fShift(shift) {
+ RectBench(void* param, int shift) : INHERITED(param), fShift(shift) {
SkRandom rand;
for (int i = 0; i < N; i++) {
int x = rand.nextU() % W;
@@ -53,11 +53,13 @@ protected:
this->drawThisRect(canvas, fRects[i], paint);
}
}
+private:
+ typedef SkBenchmark INHERITED;
};
class OvalBench : public RectBench {
public:
- OvalBench(int shift) : RectBench(shift) {}
+ OvalBench(void* param, int shift) : RectBench(param, shift) {}
protected:
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
c->drawOval(r, p);
@@ -67,7 +69,7 @@ protected:
class RRectBench : public RectBench {
public:
- RRectBench(int shift) : RectBench(shift) {}
+ RRectBench(void* param, int shift) : RectBench(param, shift) {}
protected:
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& p) {
c->drawRoundRect(r, r.width() / 4, r.height() / 4, p);
@@ -80,8 +82,8 @@ public:
SkCanvas::PointMode fMode;
const char* fName;
- PointsBench(SkCanvas::PointMode mode, const char* name) :
- RectBench(2), fMode(mode) {
+ PointsBench(void* param, SkCanvas::PointMode mode, const char* name) :
+ RectBench(param, 2), fMode(mode) {
fName = name;
}
@@ -105,20 +107,20 @@ protected:
virtual const char* onGetName() { return fName; }
};
-static SkBenchmark* RectFactory1(void*) { return SkNEW_ARGS(RectBench, (1)); }
-static SkBenchmark* RectFactory2(void*) { return SkNEW_ARGS(RectBench, (3)); }
-static SkBenchmark* OvalFactory1(void*) { return SkNEW_ARGS(OvalBench, (1)); }
-static SkBenchmark* OvalFactory2(void*) { return SkNEW_ARGS(OvalBench, (3)); }
-static SkBenchmark* RRectFactory1(void*) { return SkNEW_ARGS(RRectBench, (1)); }
-static SkBenchmark* RRectFactory2(void*) { return SkNEW_ARGS(RRectBench, (3)); }
-static SkBenchmark* PointsFactory(void*) {
- return SkNEW_ARGS(PointsBench, (SkCanvas::kPoints_PointMode, "points"));
+static SkBenchmark* RectFactory1(void* p) { return SkNEW_ARGS(RectBench, (p, 1)); }
+static SkBenchmark* RectFactory2(void* p) { return SkNEW_ARGS(RectBench, (p, 3)); }
+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)); }
+static SkBenchmark* RRectFactory2(void* p) { return SkNEW_ARGS(RRectBench, (p, 3)); }
+static SkBenchmark* PointsFactory(void* p) {
+ return SkNEW_ARGS(PointsBench, (p, SkCanvas::kPoints_PointMode, "points"));
}
-static SkBenchmark* LinesFactory(void*) {
- return SkNEW_ARGS(PointsBench, (SkCanvas::kLines_PointMode, "lines"));
+static SkBenchmark* LinesFactory(void* p) {
+ return SkNEW_ARGS(PointsBench, (p, SkCanvas::kLines_PointMode, "lines"));
}
-static SkBenchmark* PolygonFactory(void*) {
- return SkNEW_ARGS(PointsBench, (SkCanvas::kPolygon_PointMode, "polygon"));
+static SkBenchmark* PolygonFactory(void* p) {
+ return SkNEW_ARGS(PointsBench, (p, SkCanvas::kPolygon_PointMode, "polygon"));
}
static BenchRegistry gRectReg1(RectFactory1);
diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp
index 48c1f6f..97bbeb8 100644
--- a/bench/RepeatTileBench.cpp
+++ b/bench/RepeatTileBench.cpp
@@ -81,7 +81,7 @@ class RepeatTileBench : public SkBenchmark {
SkString fName;
enum { N = 20 };
public:
- RepeatTileBench(SkBitmap::Config c) {
+ RepeatTileBench(void* param, SkBitmap::Config c) : INHERITED(param) {
const int w = 50;
const int h = 50;
SkBitmap bm;
@@ -127,10 +127,10 @@ private:
typedef SkBenchmark INHERITED;
};
-static SkBenchmark* Fact0(void*) { return new RepeatTileBench(SkBitmap::kARGB_8888_Config); }
-static SkBenchmark* Fact1(void*) { return new RepeatTileBench(SkBitmap::kRGB_565_Config); }
-static SkBenchmark* Fact2(void*) { return new RepeatTileBench(SkBitmap::kARGB_4444_Config); }
-static SkBenchmark* Fact3(void*) { return new RepeatTileBench(SkBitmap::kIndex8_Config); }
+static SkBenchmark* Fact0(void* p) { return new RepeatTileBench(p, SkBitmap::kARGB_8888_Config); }
+static SkBenchmark* Fact1(void* p) { return new RepeatTileBench(p, SkBitmap::kRGB_565_Config); }
+static SkBenchmark* Fact2(void* p) { return new RepeatTileBench(p, SkBitmap::kARGB_4444_Config); }
+static SkBenchmark* Fact3(void* p) { return new RepeatTileBench(p, SkBitmap::kIndex8_Config); }
static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1);
diff --git a/bench/SkBenchmark.cpp b/bench/SkBenchmark.cpp
index 7bc87ee..8dd66f0 100644
--- a/bench/SkBenchmark.cpp
+++ b/bench/SkBenchmark.cpp
@@ -3,7 +3,8 @@
template BenchRegistry* BenchRegistry::gHead;
-SkBenchmark::SkBenchmark() {
+SkBenchmark::SkBenchmark(void* defineDict) {
+ fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict);
fForceAlpha = 0xFF;
fForceAA = true;
}
@@ -26,6 +27,16 @@ void SkBenchmark::setupPaint(SkPaint* paint) {
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() {
diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h
index 2058251..5ecff3b 100644
--- a/bench/SkBenchmark.h
+++ b/bench/SkBenchmark.h
@@ -3,6 +3,7 @@
#include "SkRefCnt.h"
#include "SkPoint.h"
+#include "SkTDict.h"
#include "SkTRegistry.h"
class SkCanvas;
@@ -10,7 +11,7 @@ class SkPaint;
class SkBenchmark : public SkRefCnt {
public:
- SkBenchmark();
+ SkBenchmark(void* defineDict);
const char* getName();
SkIPoint getSize();
@@ -27,7 +28,9 @@ public:
void setForceFilter(bool filter) {
fForceFilter = filter;
}
-
+
+ const char* findDefine(const char* key) const;
+
protected:
void setupPaint(SkPaint* paint);
@@ -37,6 +40,7 @@ protected:
virtual SkIPoint onGetSize();
private:
+ const SkTDict<const char*>* fDict;
int fForceAlpha;
bool fForceAA;
bool fForceFilter;
diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp
index a4ed9f2..93ef1c5 100644
--- a/bench/TextBench.cpp
+++ b/bench/TextBench.cpp
@@ -24,7 +24,8 @@ class TextBench : public SkBenchmark {
SkString fName;
enum { N = 300 };
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);
fPaint.setAntiAlias(true);
@@ -97,14 +98,14 @@ private:
#define SMALL 9
#define BIG 48
-static SkBenchmark* Fact0(void*) { return new TextBench(STR, SMALL, false, false); }
-static SkBenchmark* Fact1(void*) { return new TextBench(STR, SMALL, false, true); }
-static SkBenchmark* Fact2(void*) { return new TextBench(STR, SMALL, true, false); }
-static SkBenchmark* Fact3(void*) { return new TextBench(STR, SMALL, true, true); }
-static SkBenchmark* Fact4(void*) { return new TextBench(STR, BIG, false, false); }
-static SkBenchmark* Fact5(void*) { return new TextBench(STR, BIG, false, true); }
-static SkBenchmark* Fact6(void*) { return new TextBench(STR, BIG, true, false); }
-static SkBenchmark* Fact7(void*) { return new TextBench(STR, BIG, true, true); }
+static SkBenchmark* Fact0(void* p) { return new TextBench(p, STR, SMALL, false, false); }
+static SkBenchmark* Fact1(void* p) { return new TextBench(p, STR, SMALL, false, true); }
+static SkBenchmark* Fact2(void* p) { return new TextBench(p, STR, SMALL, true, false); }
+static SkBenchmark* Fact3(void* p) { return new TextBench(p, STR, SMALL, true, true); }
+static SkBenchmark* Fact4(void* p) { return new TextBench(p, STR, BIG, false, false); }
+static SkBenchmark* Fact5(void* p) { return new TextBench(p, STR, BIG, false, true); }
+static SkBenchmark* Fact6(void* p) { return new TextBench(p, STR, BIG, true, false); }
+static SkBenchmark* Fact7(void* p) { return new TextBench(p, STR, BIG, true, true); }
static BenchRegistry gReg0(Fact0);
static BenchRegistry gReg1(Fact1);
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index 501e86a..8ccb373 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -49,21 +49,23 @@ static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) {
class Iter {
public:
- Iter() {
+ Iter(void* param) {
fBench = BenchRegistry::Head();
+ fParam = param;
}
SkBenchmark* next() {
if (fBench) {
BenchRegistry::Factory f = fBench->factory();
fBench = fBench->next();
- return f(0);
+ return f(fParam);
}
return NULL;
}
private:
const BenchRegistry* fBench;
+ void* fParam;
};
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[]) {
SkAutoGraphics ag;
+ SkTDict<const char*> defineDict(1024);
int repeatDraw = 1;
int forceAlpha = 0xFF;
bool forceAA = true;
@@ -273,6 +276,14 @@ int main (int argc, char * const argv[]) {
log_error("missing arg for -config\n");
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 {
SkString str;
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;
while ((bench = iter.next()) != NULL) {
SkIPoint dim = bench->getSize();