blob: a6ab4a5953bcf7927f5356284cd04a3397072a2d [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"
commit-bot@chromium.org63822632014-02-20 15:41:17 +000012#include "SkOSFile.h"
reed@android.come9d00602009-09-02 21:12:42 +000013#include "SkString.h"
14
mtklein@google.comc2897432013-09-10 19:23:38 +000015DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");
16
reed@android.come9d00602009-09-02 21:12:42 +000017static const char* gConfigName[] = {
18 "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
19};
20
21class DecodeBench : public SkBenchmark {
reed@android.come9d00602009-09-02 21:12:42 +000022 SkBitmap::Config fPrefConfig;
23 SkString fName;
reed@android.come9d00602009-09-02 21:12:42 +000024public:
mtklein@google.com410e6e82013-09-13 19:52:27 +000025 DecodeBench(SkBitmap::Config c) {
reed@android.come9d00602009-09-02 21:12:42 +000026 fPrefConfig = c;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000027
commit-bot@chromium.org63822632014-02-20 15:41:17 +000028 SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]);
29 fName.printf("decode_%s_%s", gConfigName[c], fname.c_str());
commit-bot@chromium.org644629c2013-11-21 06:21:58 +000030 }
31
32 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
33 return backend == kNonRendering_Backend;
reed@android.come9d00602009-09-02 21:12:42 +000034 }
35
36protected:
37 virtual const char* onGetName() {
38 return fName.c_str();
39 }
40
commit-bot@chromium.org33614712013-12-03 18:17:16 +000041 virtual void onDraw(const int loops, SkCanvas*) {
42 for (int i = 0; i < loops; i++) {
mtklein@google.comc2897432013-09-10 19:23:38 +000043 SkBitmap bm;
44 SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0],
45 &bm,
46 fPrefConfig,
47 SkImageDecoder::kDecodePixels_Mode);
reed@android.come9d00602009-09-02 21:12:42 +000048 }
49 }
50
51private:
52 typedef SkBenchmark INHERITED;
53};
54
mtklein@google.com410e6e82013-09-13 19:52:27 +000055DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); )
56DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); )
57DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); )