aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/BitmapRegionDecoderBench.cpp
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2015-09-22 11:56:16 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-22 11:56:16 -0700
commit7f69144aaabbedf51ad2a1feddc9e0689f2c5ee9 (patch)
tree9ed42dfc6bd44387571d5d5db61bbf7c23036675 /bench/BitmapRegionDecoderBench.cpp
parentcc334b36de5c4508266c322dfa44039d8156dc70 (diff)
Add nanobench tests for BitmapRegionDecoder
SkBitmapRegionDecoderInterface provides an interface for multiple implementations of Android's BitmapRegionDecoder. We already have correctness tests in DM that will enable us to compare the quality of our various BRD implementations. We also need these performance tests to compare the speed of our various implementations. BUG=skia:4357 Review URL: https://codereview.chromium.org/1344993003
Diffstat (limited to 'bench/BitmapRegionDecoderBench.cpp')
-rw-r--r--bench/BitmapRegionDecoderBench.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/bench/BitmapRegionDecoderBench.cpp b/bench/BitmapRegionDecoderBench.cpp
new file mode 100644
index 0000000000..77d342331d
--- /dev/null
+++ b/bench/BitmapRegionDecoderBench.cpp
@@ -0,0 +1,68 @@
+/*
+ * 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 "BitmapRegionDecoderBench.h"
+#include "CodecBenchPriv.h"
+#include "SkBitmap.h"
+#include "SkCodecTools.h"
+#include "SkOSFile.h"
+
+BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
+ SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType,
+ uint32_t sampleSize, const SkIRect& subset)
+ : fBRD(nullptr)
+ , fData(SkRef(encoded))
+ , fStrategy(strategy)
+ , fColorType(colorType)
+ , fSampleSize(sampleSize)
+ , fSubset(subset)
+{
+ // Choose a useful name for the region decoding strategy
+ const char* strategyName;
+ switch (strategy) {
+ case SkBitmapRegionDecoderInterface::kOriginal_Strategy:
+ strategyName = "Original";
+ break;
+ case SkBitmapRegionDecoderInterface::kCanvas_Strategy:
+ strategyName = "Canvas";
+ break;
+ default:
+ SkASSERT(false);
+ strategyName = "";
+ break;
+ }
+
+ // Choose a useful name for the color type
+ const char* colorName = color_type_to_str(colorType);
+
+ fName.printf("BRD_%s_%s_%s", baseName, strategyName, colorName);
+ if (1 != sampleSize) {
+ fName.appendf("_%.3f", get_scale_from_sample_size(sampleSize));
+ }
+}
+
+const char* BitmapRegionDecoderBench::onGetName() {
+ return fName.c_str();
+}
+
+bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
+ return kNonRendering_Backend == backend;
+}
+
+void BitmapRegionDecoderBench::onPreDraw() {
+ SkStreamRewindable* stream = new SkMemoryStream(fData);
+ fBRD.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stream, fStrategy));
+}
+
+void BitmapRegionDecoderBench::onDraw(const int n, SkCanvas* canvas) {
+ SkAutoTDelete<SkBitmap> bitmap;
+ for (int i = 0; i < n; i++) {
+ bitmap.reset(fBRD->decodeRegion(fSubset.left(), fSubset.top(), fSubset.width(),
+ fSubset.height(), fSampleSize, fColorType));
+ SkASSERT(nullptr != bitmap.get());
+ }
+}