add options to bench: -repeat N -forceOpaque -forceBlend -forceAA -forceBW
output stats for all configs (should be a option) git-svn-id: http://skia.googlecode.com/svn/trunk@73 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
f13c6e113c
commit
4bc1983e01
@ -44,13 +44,13 @@ protected:
|
|||||||
c->drawRect(r, p);
|
c->drawRect(r, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const char* onGetName() { return computeName("rectangles"); }
|
virtual const char* onGetName() { return computeName("rects"); }
|
||||||
virtual SkIPoint onGetSize() { return SkMakeIPoint(640, 480); }
|
virtual SkIPoint onGetSize() { return SkMakeIPoint(640, 480); }
|
||||||
virtual void onDraw(SkCanvas* canvas) {
|
virtual void onDraw(SkCanvas* canvas) {
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setAntiAlias(true);
|
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
paint.setColor(fColors[i]);
|
paint.setColor(fColors[i]);
|
||||||
|
this->setupPaint(&paint);
|
||||||
this->drawThisRect(canvas, fRects[i], paint);
|
this->drawThisRect(canvas, fRects[i], paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ 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);
|
||||||
}
|
}
|
||||||
virtual const char* onGetName() { return computeName("roundrects"); }
|
virtual const char* onGetName() { return computeName("rrects"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class PointsBench : public RectBench {
|
class PointsBench : public RectBench {
|
||||||
@ -93,11 +93,11 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setAntiAlias(true);
|
|
||||||
paint.setStrokeCap(SkPaint::kRound_Cap);
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
||||||
|
|
||||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gSizes); i++) {
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gSizes); i++) {
|
||||||
paint.setStrokeWidth(gSizes[i]);
|
paint.setStrokeWidth(gSizes[i]);
|
||||||
|
this->setupPaint(&paint);
|
||||||
canvas->drawPoints(fMode, N * 2,
|
canvas->drawPoints(fMode, N * 2,
|
||||||
reinterpret_cast<const SkPoint*>(fRects), paint);
|
reinterpret_cast<const SkPoint*>(fRects), paint);
|
||||||
paint.setColor(fColors[i]);
|
paint.setColor(fColors[i]);
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
#include "SkBenchmark.h"
|
#include "SkBenchmark.h"
|
||||||
|
#include "SkPaint.h"
|
||||||
|
|
||||||
|
SkBenchmark::SkBenchmark() {
|
||||||
|
fForceAlpha = 0xFF;
|
||||||
|
fForceAA = true;
|
||||||
|
}
|
||||||
|
|
||||||
const char* SkBenchmark::getName() {
|
const char* SkBenchmark::getName() {
|
||||||
return this->onGetName();
|
return this->onGetName();
|
||||||
@ -12,3 +18,9 @@ void SkBenchmark::draw(SkCanvas* canvas) {
|
|||||||
this->onDraw(canvas);
|
this->onDraw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkBenchmark::setupPaint(SkPaint* paint) {
|
||||||
|
paint->setAlpha(fForceAlpha);
|
||||||
|
paint->setAntiAlias(fForceAA);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,17 +5,34 @@
|
|||||||
#include "SkPoint.h"
|
#include "SkPoint.h"
|
||||||
|
|
||||||
class SkCanvas;
|
class SkCanvas;
|
||||||
|
class SkPaint;
|
||||||
|
|
||||||
class SkBenchmark : public SkRefCnt {
|
class SkBenchmark : public SkRefCnt {
|
||||||
public:
|
public:
|
||||||
|
SkBenchmark();
|
||||||
|
|
||||||
const char* getName();
|
const char* getName();
|
||||||
SkIPoint getSize();
|
SkIPoint getSize();
|
||||||
void draw(SkCanvas*);
|
void draw(SkCanvas*);
|
||||||
|
|
||||||
|
void setForceAlpha(int alpha) {
|
||||||
|
fForceAlpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setForceAA(bool aa) {
|
||||||
|
fForceAA = aa;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void setupPaint(SkPaint* paint);
|
||||||
|
|
||||||
virtual const char* onGetName() = 0;
|
virtual const char* onGetName() = 0;
|
||||||
virtual SkIPoint onGetSize() = 0;
|
virtual SkIPoint onGetSize() = 0;
|
||||||
virtual void onDraw(SkCanvas*) = 0;
|
virtual void onDraw(SkCanvas*) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int fForceAlpha;
|
||||||
|
bool fForceAA;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline SkIPoint SkMakeIPoint(int x, int y) {
|
static inline SkIPoint SkMakeIPoint(int x, int y) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkImageEncoder.h"
|
#include "SkImageEncoder.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
|
#include "SkTime.h"
|
||||||
|
|
||||||
#include "SkBenchmark.h"
|
#include "SkBenchmark.h"
|
||||||
|
|
||||||
@ -42,7 +43,21 @@ static void make_filename(const char name[], SkString* path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct {
|
||||||
|
SkBitmap::Config fConfig;
|
||||||
|
const char* fName;
|
||||||
|
} gConfigs[] = {
|
||||||
|
{ SkBitmap::kARGB_8888_Config, "8888" },
|
||||||
|
{ SkBitmap::kRGB_565_Config, "565", },
|
||||||
|
{ SkBitmap::kARGB_4444_Config, "4444", },
|
||||||
|
{ SkBitmap::kA8_Config, "A8", }
|
||||||
|
};
|
||||||
|
|
||||||
int main (int argc, char * const argv[]) {
|
int main (int argc, char * const argv[]) {
|
||||||
|
int repeatDraw = 1;
|
||||||
|
int forceAlpha = 0xFF;
|
||||||
|
bool forceAA = true;
|
||||||
|
|
||||||
SkString outDir;
|
SkString outDir;
|
||||||
SkBitmap::Config outConfig = SkBitmap::kARGB_8888_Config;
|
SkBitmap::Config outConfig = SkBitmap::kARGB_8888_Config;
|
||||||
|
|
||||||
@ -64,9 +79,31 @@ int main (int argc, char * const argv[]) {
|
|||||||
outConfig = SkBitmap::kARGB_4444_Config;
|
outConfig = SkBitmap::kARGB_4444_Config;
|
||||||
} else if (strcmp(*argv, "-a8") == 0) {
|
} else if (strcmp(*argv, "-a8") == 0) {
|
||||||
outConfig = SkBitmap::kA8_Config;
|
outConfig = SkBitmap::kA8_Config;
|
||||||
|
} else if (strcmp(*argv, "-repeat") == 0) {
|
||||||
|
argv++;
|
||||||
|
if (argv < stop) {
|
||||||
|
repeatDraw = atoi(*argv);
|
||||||
|
if (repeatDraw < 1) {
|
||||||
|
repeatDraw = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "missing arg for -repeat\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (strcmp(*argv, "-forceAA") == 0) {
|
||||||
|
forceAA = true;
|
||||||
|
} else if (strcmp(*argv, "-forceBW") == 0) {
|
||||||
|
forceAA = false;
|
||||||
|
} else if (strcmp(*argv, "-forceBlend") == 0) {
|
||||||
|
forceAlpha = 0x80;
|
||||||
|
} else if (strcmp(*argv, "-forceOpaque") == 0) {
|
||||||
|
forceAlpha = 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* configName = "";
|
||||||
|
int configCount = SK_ARRAY_COUNT(gConfigs);
|
||||||
|
|
||||||
Iter iter;
|
Iter iter;
|
||||||
SkBenchmark* bench;
|
SkBenchmark* bench;
|
||||||
while ((bench = iter.next()) != NULL) {
|
while ((bench = iter.next()) != NULL) {
|
||||||
@ -75,14 +112,34 @@ int main (int argc, char * const argv[]) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bench->setForceAlpha(forceAlpha);
|
||||||
|
bench->setForceAA(forceAA);
|
||||||
|
|
||||||
|
printf("running bench %16s", bench->getName());
|
||||||
|
|
||||||
|
for (int configIndex = 0; configIndex < configCount; configIndex++) {
|
||||||
|
if (configCount > 1) {
|
||||||
|
outConfig = gConfigs[configIndex].fConfig;
|
||||||
|
configName = gConfigs[configIndex].fName;
|
||||||
|
}
|
||||||
|
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
bm.setConfig(outConfig, dim.fX, dim.fY);
|
bm.setConfig(outConfig, dim.fX, dim.fY);
|
||||||
bm.allocPixels();
|
bm.allocPixels();
|
||||||
|
|
||||||
SkCanvas canvas(bm);
|
SkCanvas canvas(bm);
|
||||||
canvas.drawColor(SK_ColorWHITE);
|
canvas.drawColor(SK_ColorWHITE);
|
||||||
printf("running bench %s\n", bench->getName());
|
|
||||||
|
SkMSec now = SkTime::GetMSecs();
|
||||||
|
for (int i = 0; i < repeatDraw; i++) {
|
||||||
bench->draw(&canvas);
|
bench->draw(&canvas);
|
||||||
|
}
|
||||||
|
if (repeatDraw > 1) {
|
||||||
|
printf(" %4s:%7.2f", configName,
|
||||||
|
(SkTime::GetMSecs() - now) / (double)repeatDraw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
SkString str;
|
SkString str;
|
||||||
|
Loading…
Reference in New Issue
Block a user