blob: 676169059ff6663e861c2a28dc9c043d37166494 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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 */
reed@android.come9d00602009-09-02 21:12:42 +00008#include "SkBenchmark.h"
9#include "SkBitmap.h"
10#include "SkImageDecoder.h"
11#include "SkString.h"
12
13static const char* gConfigName[] = {
14 "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
15};
16
17class DecodeBench : public SkBenchmark {
18 const char* fFilename;
19 SkBitmap::Config fPrefConfig;
20 SkString fName;
tomhudson@google.comca529d32011-10-28 15:34:49 +000021 enum { N = SkBENCHLOOP(10) };
reed@android.come9d00602009-09-02 21:12:42 +000022public:
23 DecodeBench(void* param, SkBitmap::Config c) : SkBenchmark(param) {
24 fFilename = this->findDefine("decode-filename");
25 fPrefConfig = c;
26
27 const char* fname = NULL;
28 if (fFilename) {
29 fname = strrchr(fFilename, '/');
30 if (fname) {
31 fname += 1; // skip the slash
32 }
33 }
34 fName.printf("decode_%s_%s", gConfigName[c], fname);
35 }
36
37protected:
38 virtual const char* onGetName() {
39 return fName.c_str();
40 }
41
42 virtual void onDraw(SkCanvas* canvas) {
reed@google.com757cdc42011-05-09 21:59:56 +000043 if (fFilename) {
44 for (int i = 0; i < N; i++) {
45 SkBitmap bm;
46 SkImageDecoder::DecodeFile(fFilename, &bm, fPrefConfig,
47 SkImageDecoder::kDecodePixels_Mode);
48 }
reed@android.come9d00602009-09-02 21:12:42 +000049 }
50 }
51
52private:
53 typedef SkBenchmark INHERITED;
54};
55
56static SkBenchmark* Fact0(void* p) { return new DecodeBench(p, SkBitmap::kARGB_8888_Config); }
57static SkBenchmark* Fact1(void* p) { return new DecodeBench(p, SkBitmap::kRGB_565_Config); }
58static SkBenchmark* Fact2(void* p) { return new DecodeBench(p, SkBitmap::kARGB_4444_Config); }
59
60static BenchRegistry gReg0(Fact0);
61static BenchRegistry gReg1(Fact1);
62static BenchRegistry gReg2(Fact2);