Index: bench/DecodingBench.cpp |
diff --git a/bench/DecodingBench.cpp b/bench/DecodingBench.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0781f4859c7aa29b99249226f08a32548abe877e |
--- /dev/null |
+++ b/bench/DecodingBench.cpp |
@@ -0,0 +1,56 @@ |
+/* |
+ * 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" |
+ |
+/* |
+ * |
+ * 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: |
scroggo
2015/02/12 14:19:02
Skia coding style dictates this should be indented
msarett
2015/02/12 18:52:56
Done.
|
+ 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) { |
+ // Decode each image file n times |
+ for (int i = 0; i < n; i++) { |
+ SkBitmap bitmap; |
+ SkImageDecoder::DecodeFile(fPath.c_str(), &bitmap, fColorType, |
+ SkImageDecoder::kDecodePixels_Mode); |
+ } |
scroggo
2015/02/12 14:19:02
Didn't Mike suggest drawing to the canvas? Oh, I t
mtklein
2015/02/12 14:41:38
Yeah, I think in this case you'll find canvas is a
msarett
2015/02/12 18:52:56
We discussed and decided it's best to use the non-
|
+} |