aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/nanobench.cpp
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2015-04-01 12:09:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-01 12:09:17 -0700
commit60869a42a133942f852dd0f1696444c2a5c9ad83 (patch)
treea7320359778214a324d323138f4b3c5c49a59b2f /bench/nanobench.cpp
parent2b6acb4ed52483bc2a89dbbaa6f0db4fdb217cd3 (diff)
Add timing SkCodec to nanobench.
CodecBench: Add new class for timing using SkCodec. DecodingBench: Include creating a decoder inside the loop. This is to have a better comparison against SkCodec. SkCodec's factory function does not necessarily read the same amount as SkImageDecoder's, so in order to have a meaningful comparison, read the entire stream from the beginning. Also for comparison, create a new SkStream from the SkData each time. Add a debugging check to make sure we have an SkImageDecoder. Add include guards. nanobench.cpp: Decode using SkCodec. When decoding using SkImageDecoder, exclude benches where we decoded to a different color type than requested. SkImageDecoder may decide to decode to a different type, in which case the name is misleading. TODOs: Now that we ignore color types that do not match the desired color type, we should add Index8. This also means calling the more complex version of getPixels so CodecBench can support kIndex8. BUG=skia:3257 Review URL: https://codereview.chromium.org/1044363002
Diffstat (limited to 'bench/nanobench.cpp')
-rw-r--r--bench/nanobench.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 07600ef3a4..a627b50a3a 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -10,6 +10,7 @@
#include "nanobench.h"
#include "Benchmark.h"
+#include "CodecBench.h"
#include "CrashHandler.h"
#include "DecodingBench.h"
#include "DecodingSubsetBench.h"
@@ -23,6 +24,7 @@
#include "SkBBoxHierarchy.h"
#include "SkCanvas.h"
+#include "SkCodec.h"
#include "SkCommonFlags.h"
#include "SkData.h"
#include "SkForceLinking.h"
@@ -485,6 +487,7 @@ public:
, fCurrentScale(0)
, fCurrentSKP(0)
, fCurrentUseMPD(0)
+ , fCurrentCodec(0)
, fCurrentImage(0)
, fCurrentSubsetImage(0)
, fCurrentColorType(0)
@@ -632,16 +635,57 @@ public:
fCurrentScale++;
}
+ for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
+ const SkString& path = fImages[fCurrentCodec];
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkASSERT(codec);
+ if (!codec) {
+ // Nothing to time.
+ continue;
+ }
+ while (fCurrentColorType < fColorTypes.count()) {
+ SkColorType colorType = fColorTypes[fCurrentColorType];
+ fCurrentColorType++;
+ // Make sure we can decode to this color type.
+ SkBitmap bitmap;
+ SkImageInfo info = codec->getInfo().makeColorType(colorType);
+ bitmap.allocPixels(info);
+ const SkImageGenerator::Result result = codec->getPixels(
+ bitmap.info(), bitmap.getPixels(), bitmap.rowBytes());
+ switch (result) {
+ case SkImageGenerator::kSuccess:
+ case SkImageGenerator::kIncompleteInput:
+ return new CodecBench(SkOSPath::Basename(path.c_str()),
+ encoded, colorType);
+ case SkImageGenerator::kInvalidConversion:
+ // This is okay. Not all conversions are valid.
+ break;
+ case SkImageGenerator::kCouldNotRewind:
+ // FIXME: This is due to a bug in some implementations
+ // of SkCodec. All should support rewinding.
+ break;
+ default:
+ // This represents some sort of failure.
+ SkASSERT(false);
+ break;
+ }
+ }
+ fCurrentColorType = 0;
+ }
+
// Run the DecodingBenches
while (fCurrentImage < fImages.count()) {
while (fCurrentColorType < fColorTypes.count()) {
const SkString& path = fImages[fCurrentImage];
SkColorType colorType = fColorTypes[fCurrentColorType];
fCurrentColorType++;
- // Check if the image decodes before creating the benchmark
+ // Check if the image decodes to the right color type
+ // before creating the benchmark
SkBitmap bitmap;
if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap,
- colorType, SkImageDecoder::kDecodePixels_Mode)) {
+ colorType, SkImageDecoder::kDecodePixels_Mode)
+ && bitmap.colorType() == colorType) {
return new DecodingBench(path, colorType);
}
}
@@ -741,6 +785,7 @@ private:
int fCurrentScale;
int fCurrentSKP;
int fCurrentUseMPD;
+ int fCurrentCodec;
int fCurrentImage;
int fCurrentSubsetImage;
int fCurrentColorType;