| 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 "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
| 11 #include "SkString.h" | 12 #include "SkString.h" |
| 12 | 13 |
| 14 DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for Dec
odeBench."); |
| 15 |
| 13 static const char* gConfigName[] = { | 16 static const char* gConfigName[] = { |
| 14 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" | 17 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" |
| 15 }; | 18 }; |
| 16 | 19 |
| 17 class DecodeBench : public SkBenchmark { | 20 class DecodeBench : public SkBenchmark { |
| 18 const char* fFilename; | |
| 19 SkBitmap::Config fPrefConfig; | 21 SkBitmap::Config fPrefConfig; |
| 20 SkString fName; | 22 SkString fName; |
| 21 enum { N = SkBENCHLOOP(10) }; | |
| 22 public: | 23 public: |
| 23 DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) { | 24 DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) { |
| 24 fFilename = this->findDefine("decode-filename"); | |
| 25 fPrefConfig = c; | 25 fPrefConfig = c; |
| 26 | 26 |
| 27 const char* fname = NULL; | 27 const char* fname = strrchr(FLAGS_decodeBenchFilename[0], '/'); |
| 28 if (fFilename) { | 28 if (fname) { |
| 29 fname = strrchr(fFilename, '/'); | 29 fname++; // skip the slash |
| 30 if (fname) { | |
| 31 fname += 1; // skip the slash | |
| 32 } | |
| 33 } | 30 } |
| 34 fName.printf("decode_%s_%s", gConfigName[c], fname); | 31 fName.printf("decode_%s_%s", gConfigName[c], fname); |
| 35 fIsRendering = false; | 32 fIsRendering = false; |
| 36 } | 33 } |
| 37 | 34 |
| 38 protected: | 35 protected: |
| 39 virtual const char* onGetName() { | 36 virtual const char* onGetName() { |
| 40 return fName.c_str(); | 37 return fName.c_str(); |
| 41 } | 38 } |
| 42 | 39 |
| 43 virtual void onDraw(SkCanvas*) { | 40 virtual void onDraw(SkCanvas*) { |
| 44 if (fFilename) { | 41 for (int i = 0; i < this->getLoops(); i++) { |
| 45 for (int i = 0; i < N; i++) { | 42 SkBitmap bm; |
| 46 SkBitmap bm; | 43 SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], |
| 47 SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig, | 44 &bm, |
| 48 SkImageDecoder::kDecodePixels_Mode); | 45 fPrefConfig, |
| 49 } | 46 SkImageDecoder::kDecodePixels_Mode); |
| 50 } | 47 } |
| 51 } | 48 } |
| 52 | 49 |
| 53 private: | 50 private: |
| 54 typedef SkBenchmark INHERITED; | 51 typedef SkBenchmark INHERITED; |
| 55 }; | 52 }; |
| 56 | 53 |
| 57 static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8
888_Config); } | 54 static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8
888_Config); } |
| 58 static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_56
5_Config); } | 55 static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_56
5_Config); } |
| 59 static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4
444_Config); } | 56 static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4
444_Config); } |
| 60 | 57 |
| 61 static BenchRegistry gReg0(Fact0); | 58 static BenchRegistry gReg0(Fact0); |
| 62 static BenchRegistry gReg1(Fact1); | 59 static BenchRegistry gReg1(Fact1); |
| 63 static BenchRegistry gReg2(Fact2); | 60 static BenchRegistry gReg2(Fact2); |
| OLD | NEW |