epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 8 | #include "SkBenchmark.h" |
| 9 | #include "SkBitmap.h" |
| 10 | #include "SkImageDecoder.h" |
| 11 | #include "SkString.h" |
| 12 | |
| 13 | static const char* gConfigName[] = { |
| 14 | "ERROR", "a1", "a8", "index8", "565", "4444", "8888" |
| 15 | }; |
| 16 | |
| 17 | class DecodeBench : public SkBenchmark { |
| 18 | const char* fFilename; |
| 19 | SkBitmap::Config fPrefConfig; |
| 20 | SkString fName; |
tomhudson@google.com | ca529d3 | 2011-10-28 15:34:49 +0000 | [diff] [blame] | 21 | enum { N = SkBENCHLOOP(10) }; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 22 | public: |
| 23 | DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) { |
| 24 | fFilename = this->findDefine("decode-filename"); |
| 25 | fPrefConfig = c; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 26 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 27 | const char* fname = NULL; |
| 28 | if (fFilename) { |
| 29 | fname = strrchr(fFilename, '/'); |
| 30 | if (fname) { |
| 31 | fname += 1; // skip the slash |
| 32 | } |
| 33 | } |
| 34 | fName.printf("decode_%s_%s", gConfigName[c], fname); |
robertphillips@google.com | 433ce5e | 2012-09-17 10:49:30 +0000 | [diff] [blame] | 35 | fIsRendering = false; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | protected: |
| 39 | virtual const char* onGetName() { |
| 40 | return fName.c_str(); |
| 41 | } |
| 42 | |
| 43 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | 757cdc4 | 2011-05-09 21:59:56 +0000 | [diff] [blame] | 44 | if (fFilename) { |
| 45 | for (int i = 0; i < N; i++) { |
| 46 | SkBitmap bm; |
| 47 | SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig, |
| 48 | SkImageDecoder::kDecodePixels_Mode); |
| 49 | } |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | typedef SkBenchmark INHERITED; |
| 55 | }; |
| 56 | |
| 57 | static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); } |
| 58 | static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); } |
| 59 | static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); } |
| 60 | |
| 61 | static BenchRegistry gReg0(Fact0); |
| 62 | static BenchRegistry gReg1(Fact1); |
| 63 | static BenchRegistry gReg2(Fact2); |