diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-16 15:57:13 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-16 15:57:13 +0000 |
commit | b8b92ea089a380e17984e4df7b49b379cb6bd929 (patch) | |
tree | 1c5f5652c7dac5c06e9a913d3592800d01468b5c | |
parent | dfdb7e5240276493077b7c6e1f3cc8b8a0e195ba (diff) |
add DEF_BENCH marco to make it easy to register new benches
extend bitmaprect bench to include drawing with non-opaque alpha
git-svn-id: http://skia.googlecode.com/svn/trunk@5965 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/BitmapRectBench.cpp | 17 | ||||
-rw-r--r-- | bench/SkBenchmark.h | 20 |
2 files changed, 31 insertions, 6 deletions
diff --git a/bench/BitmapRectBench.cpp b/bench/BitmapRectBench.cpp index 2bed21d6dc..b9e71f753b 100644 --- a/bench/BitmapRectBench.cpp +++ b/bench/BitmapRectBench.cpp @@ -41,11 +41,15 @@ static void drawIntoBitmap(const SkBitmap& bm) { class BitmapRectBench : public SkBenchmark { SkBitmap fBitmap; bool fDoFilter; + uint8_t fAlpha; SkString fName; SkRect fSrcR, fDstR; enum { N = SkBENCHLOOP(300) }; public: - BitmapRectBench(void* param, bool doFilter) : INHERITED(param), fDoFilter(doFilter) { + BitmapRectBench(void* param, U8CPU alpha, bool doFilter) : INHERITED(param) { + fAlpha = SkToU8(alpha); + fDoFilter = doFilter; + const int w = 128; const int h = 128; @@ -61,7 +65,7 @@ public: protected: virtual const char* onGetName() { - fName.printf("bitmaprect_%sfilter", fDoFilter ? "" : "no"); + fName.printf("bitmaprect_%02X_%sfilter", fAlpha, fDoFilter ? "" : "no"); return fName.c_str(); } @@ -72,6 +76,7 @@ protected: SkPaint paint; this->setupPaint(&paint); paint.setFilterBitmap(fDoFilter); + paint.setAlpha(fAlpha); for (int i = 0; i < N; i++) { canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint); @@ -82,8 +87,8 @@ private: typedef SkBenchmark INHERITED; }; -static SkBenchmark* Fact0(void* p) { return new BitmapRectBench(p, false); } -static SkBenchmark* Fact1(void* p) { return new BitmapRectBench(p, true); } +DEF_BENCH(return new BitmapRectBench(p, 0xFF, false)) +DEF_BENCH(return new BitmapRectBench(p, 0x80, false)) +DEF_BENCH(return new BitmapRectBench(p, 0xFF, true)) +DEF_BENCH(return new BitmapRectBench(p, 0x80, true)) -static BenchRegistry gReg0(Fact0); -static BenchRegistry gReg1(Fact1); diff --git a/bench/SkBenchmark.h b/bench/SkBenchmark.h index 5cfbdab25c..b72162f44c 100644 --- a/bench/SkBenchmark.h +++ b/bench/SkBenchmark.h @@ -13,6 +13,26 @@ #include "SkTDict.h" #include "SkTRegistry.h" + +#define SK_MACRO_CONCAT(X, Y) SK_MACRO_CONCAT_IMPL(X, Y) +#define SK_MACRO_CONCAT_IMPL(X, Y) X ## Y + +#define SK_MACRO_APPEND_LINE(name) SK_MACRO_CONCAT(name, __LINE__) + +#define DEF_BENCH(code) \ +static SkBenchmark* SK_MACRO_APPEND_LINE(F_)(void* p) { code; } \ +static BenchRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); + +/* + * With the above macros, you can register benches as follows (at the bottom + * of your .cpp) + * + * DEF_BENCH(new MyBenchmark(p, ...)) + * DEF_BENCH(new MyBenchmark(p, ...)) + * DEF_BENCH(new MyBenchmark(p, ...)) + */ + + #ifdef SK_DEBUG #define SkBENCHLOOP(n) 1 #else |