• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "SkBenchmark.h"
2 #include "SkBitmap.h"
3 #include "SkImageDecoder.h"
4 #include "SkString.h"
5 
6 static const char* gConfigName[] = {
7     "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
8 };
9 
10 class DecodeBench : public SkBenchmark {
11     const char* fFilename;
12     SkBitmap::Config fPrefConfig;
13     SkString fName;
14     enum { N = 10 };
15 public:
DecodeBench(void * param,SkBitmap::Config c)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 
30 protected:
onGetName()31     virtual const char* onGetName() {
32         return fName.c_str();
33     }
34 
onDraw(SkCanvas * canvas)35     virtual void onDraw(SkCanvas* canvas) {
36         for (int i = 0; i < N; i++) {
37             SkBitmap bm;
38             SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig,
39                                        SkImageDecoder::kDecodePixels_Mode);
40         }
41     }
42 
43 private:
44     typedef SkBenchmark INHERITED;
45 };
46 
Fact0(void * p)47 static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); }
Fact1(void * p)48 static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); }
Fact2(void * p)49 static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); }
50 
51 static BenchRegistry gReg0(Fact0);
52 static BenchRegistry gReg1(Fact1);
53 static BenchRegistry gReg2(Fact2);
54