Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: bench/DecodingBench.cpp

Issue 918673002: Adding new benchmark to test image decoding performance. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Missed a few minor comments (sorry!) Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: bench/DecodingBench.cpp
diff --git a/bench/DecodingBench.cpp b/bench/DecodingBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ed96e05d88d0e74ca0570fe9c22d6b851a6ff1dc
--- /dev/null
+++ b/bench/DecodingBench.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "DecodingBench.h"
+#include "SkImageDecoder.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+
+/*
+ *
+ * This benchmark is designed to test the performance of image decoding.
+ * It is invoked from the nanobench.cpp file.
+ *
+ */
+DecodingBench::DecodingBench(SkString path, SkColorType colorType)
+ : fPath(path)
+ , fColorType(colorType)
+{
+ // Parse filename and the color type to give the benchmark a useful name
+ SkString baseName = SkOSPath::Basename(path.c_str());
+ const char* colorName;
+ switch(colorType) {
+ case kN32_SkColorType:
+ colorName = "N32";
+ break;
+ case kRGB_565_SkColorType:
+ colorName = "565";
+ break;
+ case kAlpha_8_SkColorType:
+ colorName = "Alpha8";
+ break;
+ default:
+ colorName = "Unknown";
+ }
+ fName.printf("Decode_%s_%s", baseName.c_str(), colorName);
+}
+
+const char* DecodingBench::onGetName() {
+ return fName.c_str();
+}
+
+bool DecodingBench::isSuitableFor(Backend backend) {
+ return kNonRendering_Backend == backend;
+}
+
+void DecodingBench::onDraw(const int n, SkCanvas* canvas) {
+ // Perform setup for the decode
+ SkAutoTDelete<SkStreamRewindable> stream(
scroggo 2015/02/12 19:53:28 I was thinking more like what DM does: Read the fi
msarett 2015/02/12 22:05:45 Yes this makes significantly more sense.
+ SkStream::NewFromFile(fPath.c_str()));
+ SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
+ SkBitmap bitmap;
+
+ // Decode each image file n times
+ for (int i = 0; i < n; i++) {
+ decoder->decode(stream, &bitmap, fColorType,
+ SkImageDecoder::kDecodePixels_Mode);
+ stream->rewind();
+ }
+
+ // Clean up after the decode
+ delete decoder;
+}
« no previous file with comments | « bench/DecodingBench.h ('k') | bench/DecodingSubsetBench.h » ('j') | bench/nanobench.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698