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);
|
||||
}
|
||||
|
||||
virtual const char* onGetName() { return computeName("rectangles"); }
|
||||
virtual const char* onGetName() { return computeName("rects"); }
|
||||
virtual SkIPoint onGetSize() { return SkMakeIPoint(640, 480); }
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
for (int i = 0; i < N; i++) {
|
||||
paint.setColor(fColors[i]);
|
||||
this->setupPaint(&paint);
|
||||
this->drawThisRect(canvas, fRects[i], paint);
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ protected:
|
||||
virtual void drawThisRect(SkCanvas* c, const SkRect& r, const SkPaint& 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 {
|
||||
@ -93,11 +93,11 @@ protected:
|
||||
};
|
||||
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStrokeCap(SkPaint::kRound_Cap);
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gSizes); i++) {
|
||||
paint.setStrokeWidth(gSizes[i]);
|
||||
this->setupPaint(&paint);
|
||||
canvas->drawPoints(fMode, N * 2,
|
||||
reinterpret_cast<const SkPoint*>(fRects), paint);
|
||||
paint.setColor(fColors[i]);
|
||||
|
@ -1,4 +1,10 @@
|
||||
#include "SkBenchmark.h"
|
||||
#include "SkPaint.h"
|
||||
|
||||
SkBenchmark::SkBenchmark() {
|
||||
fForceAlpha = 0xFF;
|
||||
fForceAA = true;
|
||||
}
|
||||
|
||||
const char* SkBenchmark::getName() {
|
||||
return this->onGetName();
|
||||
@ -12,3 +18,9 @@ void SkBenchmark::draw(SkCanvas* canvas) {
|
||||
this->onDraw(canvas);
|
||||
}
|
||||
|
||||
void SkBenchmark::setupPaint(SkPaint* paint) {
|
||||
paint->setAlpha(fForceAlpha);
|
||||
paint->setAntiAlias(fForceAA);
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,17 +5,34 @@
|
||||
#include "SkPoint.h"
|
||||
|
||||
class SkCanvas;
|
||||
class SkPaint;
|
||||
|
||||
class SkBenchmark : public SkRefCnt {
|
||||
public:
|
||||
SkBenchmark();
|
||||
|
||||
const char* getName();
|
||||
SkIPoint getSize();
|
||||
void draw(SkCanvas*);
|
||||
|
||||
void setForceAlpha(int alpha) {
|
||||
fForceAlpha = alpha;
|
||||
}
|
||||
|
||||
void setForceAA(bool aa) {
|
||||
fForceAA = aa;
|
||||
}
|
||||
|
||||
protected:
|
||||
void setupPaint(SkPaint* paint);
|
||||
|
||||
virtual const char* onGetName() = 0;
|
||||
virtual SkIPoint onGetSize() = 0;
|
||||
virtual void onDraw(SkCanvas*) = 0;
|
||||
|
||||
private:
|
||||
int fForceAlpha;
|
||||
bool fForceAA;
|
||||
};
|
||||
|
||||
static inline SkIPoint SkMakeIPoint(int x, int y) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "SkCanvas.h"
|
||||
#include "SkImageEncoder.h"
|
||||
#include "SkString.h"
|
||||
#include "SkTime.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 repeatDraw = 1;
|
||||
int forceAlpha = 0xFF;
|
||||
bool forceAA = true;
|
||||
|
||||
SkString outDir;
|
||||
SkBitmap::Config outConfig = SkBitmap::kARGB_8888_Config;
|
||||
|
||||
@ -64,9 +79,31 @@ int main (int argc, char * const argv[]) {
|
||||
outConfig = SkBitmap::kARGB_4444_Config;
|
||||
} else if (strcmp(*argv, "-a8") == 0) {
|
||||
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;
|
||||
SkBenchmark* bench;
|
||||
while ((bench = iter.next()) != NULL) {
|
||||
@ -74,15 +111,35 @@ int main (int argc, char * const argv[]) {
|
||||
if (dim.fX <= 0 || dim.fY <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SkBitmap bm;
|
||||
bm.setConfig(outConfig, dim.fX, dim.fY);
|
||||
bm.allocPixels();
|
||||
|
||||
SkCanvas canvas(bm);
|
||||
canvas.drawColor(SK_ColorWHITE);
|
||||
printf("running bench %s\n", bench->getName());
|
||||
bench->draw(&canvas);
|
||||
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;
|
||||
bm.setConfig(outConfig, dim.fX, dim.fY);
|
||||
bm.allocPixels();
|
||||
|
||||
SkCanvas canvas(bm);
|
||||
canvas.drawColor(SK_ColorWHITE);
|
||||
|
||||
SkMSec now = SkTime::GetMSecs();
|
||||
for (int i = 0; i < repeatDraw; i++) {
|
||||
bench->draw(&canvas);
|
||||
}
|
||||
if (repeatDraw > 1) {
|
||||
printf(" %4s:%7.2f", configName,
|
||||
(SkTime::GetMSecs() - now) / (double)repeatDraw);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
#if 0
|
||||
SkString str;
|
||||
|
Loading…
Reference in New Issue
Block a user