• 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         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 
45 private:
46     typedef SkBenchmark INHERITED;
47 };
48 
Fact0(void * p)49 static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); }
Fact1(void * p)50 static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); }
Fact2(void * p)51 static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); }
52 
53 static BenchRegistry gReg0(Fact0);
54 static BenchRegistry gReg1(Fact1);
55 static BenchRegistry gReg2(Fact2);
56