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 "SkString.h" | 13 #include "SkString.h" |
13 | 14 |
14 DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for Dec
odeBench."); | 15 DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for Dec
odeBench."); |
15 | 16 |
16 static const char* gConfigName[] = { | 17 static const char* gConfigName[] = { |
17 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" | 18 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" |
18 }; | 19 }; |
19 | 20 |
20 class DecodeBench : public SkBenchmark { | 21 class DecodeBench : public SkBenchmark { |
21 SkBitmap::Config fPrefConfig; | 22 SkBitmap::Config fPrefConfig; |
22 SkString fName; | 23 SkString fName; |
23 public: | 24 public: |
24 DecodeBench(SkBitmap::Config c) { | 25 DecodeBench(SkBitmap::Config c) { |
25 fPrefConfig = c; | 26 fPrefConfig = c; |
26 | 27 |
27 const char* fname = strrchr(FLAGS_decodeBenchFilename[0], '/'); | 28 SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]); |
28 if (fname) { | 29 fName.printf("decode_%s_%s", gConfigName[c], fname.c_str()); |
29 fname++; // skip the slash | |
30 } | |
31 fName.printf("decode_%s_%s", gConfigName[c], fname); | |
32 } | 30 } |
33 | 31 |
34 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 32 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
35 return backend == kNonRendering_Backend; | 33 return backend == kNonRendering_Backend; |
36 } | 34 } |
37 | 35 |
38 protected: | 36 protected: |
39 virtual const char* onGetName() { | 37 virtual const char* onGetName() { |
40 return fName.c_str(); | 38 return fName.c_str(); |
41 } | 39 } |
42 | 40 |
43 virtual void onDraw(const int loops, SkCanvas*) { | 41 virtual void onDraw(const int loops, SkCanvas*) { |
44 for (int i = 0; i < loops; i++) { | 42 for (int i = 0; i < loops; i++) { |
45 SkBitmap bm; | 43 SkBitmap bm; |
46 SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], | 44 SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], |
47 &bm, | 45 &bm, |
48 fPrefConfig, | 46 fPrefConfig, |
49 SkImageDecoder::kDecodePixels_Mode); | 47 SkImageDecoder::kDecodePixels_Mode); |
50 } | 48 } |
51 } | 49 } |
52 | 50 |
53 private: | 51 private: |
54 typedef SkBenchmark INHERITED; | 52 typedef SkBenchmark INHERITED; |
55 }; | 53 }; |
56 | 54 |
57 DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); ) | 55 DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); ) |
58 DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); ) | 56 DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); ) |
59 DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); ) | 57 DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); ) |
OLD | NEW |