OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
11 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
| 14 #include "sk_tool_utils.h" |
14 | 15 |
15 DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for Dec
odeBench."); | 16 DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for Dec
odeBench."); |
16 | 17 |
17 static const char* gConfigName[] = { | |
18 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" | |
19 }; | |
20 | |
21 class DecodeBench : public SkBenchmark { | 18 class DecodeBench : public SkBenchmark { |
22 SkBitmap::Config fPrefConfig; | 19 const SkColorType fPrefColorType; |
23 SkString fName; | 20 SkString fName; |
24 public: | 21 public: |
25 DecodeBench(SkBitmap::Config c) { | 22 DecodeBench(SkColorType ct) : fPrefColorType(ct) { |
26 fPrefConfig = c; | |
27 | |
28 SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]); | 23 SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]); |
29 fName.printf("decode_%s_%s", gConfigName[c], fname.c_str()); | 24 fName.printf("decode_%s_%s", sk_tool_utils::colortype_name(ct), fname.c_
str()); |
30 } | 25 } |
31 | 26 |
32 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 27 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
33 return backend == kNonRendering_Backend; | 28 return backend == kNonRendering_Backend; |
34 } | 29 } |
35 | 30 |
36 protected: | 31 protected: |
37 virtual const char* onGetName() { | 32 virtual const char* onGetName() { |
38 return fName.c_str(); | 33 return fName.c_str(); |
39 } | 34 } |
40 | 35 |
41 virtual void onDraw(const int loops, SkCanvas*) { | 36 virtual void onDraw(const int loops, SkCanvas*) { |
42 for (int i = 0; i < loops; i++) { | 37 for (int i = 0; i < loops; i++) { |
43 SkBitmap bm; | 38 SkBitmap bm; |
44 SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], | 39 SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], &bm, fPrefC
olorType, |
45 &bm, | |
46 fPrefConfig, | |
47 SkImageDecoder::kDecodePixels_Mode); | 40 SkImageDecoder::kDecodePixels_Mode); |
48 } | 41 } |
49 } | 42 } |
50 | 43 |
51 private: | 44 private: |
52 typedef SkBenchmark INHERITED; | 45 typedef SkBenchmark INHERITED; |
53 }; | 46 }; |
54 | 47 |
55 DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); ) | 48 DEF_BENCH( return new DecodeBench(kN32_SkColorType); ) |
56 DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); ) | 49 DEF_BENCH( return new DecodeBench(kRGB_565_SkColorType); ) |
57 DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); ) | 50 DEF_BENCH( return new DecodeBench(kARGB_4444_SkColorType); ) |
OLD | NEW |