1#include "SkBenchmark.h" 2#include "SkBitmap.h" 3#include "SkImageDecoder.h" 4#include "SkString.h" 5 6static const char* gConfigName[] = { 7 "ERROR", "a1", "a8", "index8", "565", "4444", "8888" 8}; 9 10class DecodeBench : public SkBenchmark { 11 const char* fFilename; 12 SkBitmap::Config fPrefConfig; 13 SkString fName; 14 enum { N = 10 }; 15public: 16 DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) { 17 fFilename = this->findDefine("decode-filename"); 18 fPrefConfig = c; 19 20 const char* fname = NULL; 21 if (fFilename) { 22 fname = strrchr(fFilename, '/'); 23 if (fname) { 24 fname += 1; // skip the slash 25 } 26 } 27 fName.printf("decode_%s_%s", gConfigName[c], fname); 28 } 29 30protected: 31 virtual const char* onGetName() { 32 return fName.c_str(); 33 } 34 35 virtual void onDraw(SkCanvas* canvas) { 36 if (fFilename) { 37 for (int i = 0; i < N; i++) { 38 SkBitmap bm; 39 SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig, 40 SkImageDecoder::kDecodePixels_Mode); 41 } 42 } 43 } 44 45private: 46 typedef SkBenchmark INHERITED; 47}; 48 49static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); } 50static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); } 51static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); } 52 53static BenchRegistry gReg0(Fact0); 54static BenchRegistry gReg1(Fact1); 55static BenchRegistry gReg2(Fact2); 56