reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 1 | #include "SkBenchmark.h" |
| 2 | #include "SkBitmap.h" |
| 3 | #include "SkImageDecoder.h" |
| 4 | #include "SkString.h" |
| 5 | |
| 6 | static const char* gConfigName[] = { |
| 7 | "ERROR", "a1", "a8", "index8", "565", "4444", "8888" |
| 8 | }; |
| 9 | |
| 10 | class DecodeBench : public SkBenchmark { |
| 11 | const char* fFilename; |
| 12 | SkBitmap::Config fPrefConfig; |
| 13 | SkString fName; |
| 14 | enum { N = 10 }; |
| 15 | public: |
| 16 | DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) { |
| 17 | fFilename = this->findDefine("decode-filename"); |
| 18 | fPrefConfig = c; |
| 19 | |
| 20 | const char* fname = NULL; |
| 21 | if (fFilename) { |
| 22 | fname = strrchr(fFilename, '/'); |
| 23 | if (fname) { |
| 24 | fname += 1; // skip the slash |
| 25 | } |
| 26 | } |
| 27 | fName.printf("decode_%s_%s", gConfigName[c], fname); |
| 28 | } |
| 29 | |
| 30 | protected: |
| 31 | virtual const char* onGetName() { |
| 32 | return fName.c_str(); |
| 33 | } |
| 34 | |
| 35 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 757cdc4 | 2011-05-09 21:59:56 +0000 | [diff] [blame] | 36 | if (fFilename) { |
| 37 | for (int i = 0; i < N; i++) { |
| 38 | SkBitmap bm; |
| 39 | SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig, |
| 40 | SkImageDecoder::kDecodePixels_Mode); |
| 41 | } |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | typedef SkBenchmark INHERITED; |
| 47 | }; |
| 48 | |
| 49 | static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); } |
| 50 | static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); } |
| 51 | static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); } |
| 52 | |
| 53 | static BenchRegistry gReg0(Fact0); |
| 54 | static BenchRegistry gReg1(Fact1); |
| 55 | static BenchRegistry gReg2(Fact2); |