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" |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 10 | #include "SkCommandLineFlags.h" |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 11 | #include "SkImageDecoder.h" |
commit-bot@chromium.org | 6382263 | 2014-02-20 15:41:17 +0000 | [diff] [blame] | 12 | #include "SkOSFile.h" |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
| 14 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 15 | DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench."); |
| 16 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 17 | static const char* gConfigName[] = { |
| 18 | "ERROR", "a1", "a8", "index8", "565", "4444", "8888" |
| 19 | }; |
| 20 | |
| 21 | class DecodeBench : public SkBenchmark { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 22 | SkBitmap::Config fPrefConfig; |
| 23 | SkString fName; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 24 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 25 | DecodeBench(SkBitmap::Config c) { |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 26 | fPrefConfig = c; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 27 | |
commit-bot@chromium.org | 6382263 | 2014-02-20 15:41:17 +0000 | [diff] [blame] | 28 | SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]); |
| 29 | fName.printf("decode_%s_%s", gConfigName[c], fname.c_str()); |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
| 33 | return backend == kNonRendering_Backend; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | protected: |
| 37 | virtual const char* onGetName() { |
| 38 | return fName.c_str(); |
| 39 | } |
| 40 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 41 | virtual void onDraw(const int loops, SkCanvas*) { |
| 42 | for (int i = 0; i < loops; i++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 43 | SkBitmap bm; |
| 44 | SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], |
| 45 | &bm, |
| 46 | fPrefConfig, |
| 47 | SkImageDecoder::kDecodePixels_Mode); |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | typedef SkBenchmark INHERITED; |
| 53 | }; |
| 54 | |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 55 | DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); ) |
| 56 | DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); ) |
| 57 | DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); ) |