skia2/bench/DecodeBench.cpp
commit-bot@chromium.org 3361471a35 Simplify benchmark internal API.
I'm not quite sure why I wrote such a convoluted API with setLoops()/getLoops().
This replaces it with a loops argument passed to onDraw().

This CL is largely mechanical translation from the old API to the new one.
MathBench used this->getLoops() outside onDraw(), which seems incorrect.  I
fixed it.

BUG=
R=djsollen@google.com

Author: mtklein@google.com

Review URL: https://codereview.chromium.org/99893003

git-svn-id: http://skia.googlecode.com/svn/trunk@12466 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-12-03 18:17:16 +00:00

60 lines
1.6 KiB
C++

/*
* 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 "SkBenchmark.h"
#include "SkBitmap.h"
#include "SkCommandLineFlags.h"
#include "SkImageDecoder.h"
#include "SkString.h"
DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");
static const char* gConfigName[] = {
"ERROR", "a1", "a8", "index8", "565", "4444", "8888"
};
class DecodeBench : public SkBenchmark {
SkBitmap::Config fPrefConfig;
SkString fName;
public:
DecodeBench(SkBitmap::Config c) {
fPrefConfig = c;
const char* fname = strrchr(FLAGS_decodeBenchFilename[0], '/');
if (fname) {
fname++; // skip the slash
}
fName.printf("decode_%s_%s", gConfigName[c], fname);
}
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,
fPrefConfig,
SkImageDecoder::kDecodePixels_Mode);
}
}
private:
typedef SkBenchmark INHERITED;
};
DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_8888_Config); )
DEF_BENCH( return new DecodeBench(SkBitmap::kRGB_565_Config); )
DEF_BENCH( return new DecodeBench(SkBitmap::kARGB_4444_Config); )