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