aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/DecodeBench.cpp
blob: b03f8980cd1d89437f4f3f6d047b28089b13635b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "Benchmark.h"
#include "SkBitmap.h"
#include "SkCommandLineFlags.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkString.h"
#include "sk_tool_utils.h"

DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");

class DecodeBench : public Benchmark {
    const SkColorType fPrefColorType;
    SkString          fName;
public:
    DecodeBench(SkColorType ct) : fPrefColorType(ct) {
        SkString fname = SkOSPath::Basename(FLAGS_decodeBenchFilename[0]);
        fName.printf("decode_%s_%s", sk_tool_utils::colortype_name(ct), fname.c_str());
    }

    virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
        return backend == kNonRendering_Backend;
    }

protected:
    virtual const char* onGetName() {
        return fName.c_str();
    }

    virtual void onDraw(const int loops, SkCanvas*) {
        for (int i = 0; i < loops; i++) {
            SkBitmap bm;
            SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], &bm, fPrefColorType,
                                       SkImageDecoder::kDecodePixels_Mode);
        }
    }

private:
    typedef Benchmark INHERITED;
};

DEF_BENCH( return new DecodeBench(kN32_SkColorType); )
DEF_BENCH( return new DecodeBench(kRGB_565_SkColorType); )
DEF_BENCH( return new DecodeBench(kARGB_4444_SkColorType); )