blob: 4397eef65df071c9499c96454953313e6a7d4fa7 [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"
mtklein@google.comc2897432013-09-10 19:23:38 +000010#include "SkCommandLineFlags.h"
reed@android.come9d00602009-09-02 21:12:42 +000011#include "SkImageDecoder.h"
12#include "SkString.h"
13
mtklein@google.comc2897432013-09-10 19:23:38 +000014DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");
15
reed@android.come9d00602009-09-02 21:12:42 +000016static const char* gConfigName[] = {
17 "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
18};
19
20class DecodeBench : public SkBenchmark {
reed@android.come9d00602009-09-02 21:12:42 +000021 SkBitmap::Config fPrefConfig;
22 SkString fName;
reed@android.come9d00602009-09-02 21:12:42 +000023public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000024 DecodeBench(SkBitmap::Config c) {
reed@android.come9d00602009-09-02 21:12:42 +000025 fPrefConfig = c;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000026
mtklein@google.comc2897432013-09-10 19:23:38 +000027 const char* fname = strrchr(FLAGS_decodeBenchFilename[0], '/');
28 if (fname) {
29 fname++; // skip the slash
reed@android.come9d00602009-09-02 21:12:42 +000030 }
31 fName.printf("decode_%s_%s", gConfigName[c], fname);
robertphillips@google.com433ce5e2012-09-17 10:49:30 +000032 fIsRendering = false;
reed@android.come9d00602009-09-02 21:12:42 +000033 }
34
35protected:
36 virtual const char* onGetName() {
37 return fName.c_str();
38 }
39
sugoi@google.com77472f02013-03-05 18:50:01 +000040 virtual void onDraw(SkCanvas*) {
mtklein@google.comc2897432013-09-10 19:23:38 +000041 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);
reed@android.come9d00602009-09-02 21:12:42 +000047 }
48 }
49
50private:
51 typedef SkBenchmark INHERITED;
52};
53
mtklein@google.com410e6e82013-09-13 19:52:27 +000054DEF_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); )