diff --git a/bench/RectBench.cpp b/bench/RectBench.cpp index c88852666b..13239f1500 100644 --- a/bench/RectBench.cpp +++ b/bench/RectBench.cpp @@ -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(fRects), paint); paint.setColor(fColors[i]); diff --git a/bench/SkBenchmark.cpp b/bench/SkBenchmark.cpp index ebeea9dd32..5d22b70352 100644 --- a/bench/SkBenchmark.cpp +++ b/bench/SkBenchmark.cpp @@ -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); +} + + diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h index 6256029283..00dfb8425b 100644 --- a/bench/SkBenchmark.h +++ b/bench/SkBenchmark.h @@ -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) { diff --git a/bench/main.cpp b/bench/main.cpp index 1b914ce821..7c6848ef80 100644 --- a/bench/main.cpp +++ b/bench/main.cpp @@ -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;