DecodeBench.cpp revision 0a657bbc2c6fc9daf699942e023050536d5ec95f
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
14DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");
15
16static const char* gConfigName[] = {
17    "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
18};
19
20class DecodeBench : public SkBenchmark {
21    SkBitmap::Config fPrefConfig;
22    SkString fName;
23public:
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        fIsRendering = false;
33    }
34
35protected:
36    virtual const char* onGetName() {
37        return fName.c_str();
38    }
39
40    virtual void onDraw(SkCanvas*) {
41        for (int i = 0; i < this->getLoops(); i++) {
42            SkBitmap bm;
43            SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0],
44                                       &bm,
45                                       fPrefConfig,
46                                       SkImageDecoder::kDecodePixels_Mode);
47        }
48    }
49
50private:
51    typedef SkBenchmark INHERITED;
52};
53
54DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); )
55DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); )
56DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); )
57