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

Unified Diff: bench/BitmapRegionDecoderBench.cpp

Issue 1344993003: Add nanobench tests for BitmapRegionDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/BitmapRegionDecoderBench.cpp
diff --git a/bench/BitmapRegionDecoderBench.cpp b/bench/BitmapRegionDecoderBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7df20eb6c8ef37f88b63b1faac3756e51f73f648
--- /dev/null
+++ b/bench/BitmapRegionDecoderBench.cpp
@@ -0,0 +1,85 @@
+/*
+ * 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 "SkBitmap.h"
+#include "SkOSFile.h"
+
+// FIXME (msarett): How can we share this code with DM?
+static float get_scale_from_sample_size(uint32_t sampleSize) {
+ return 1.0f / (float) sampleSize;
+}
+
+BitmapRegionDecoderBench::BitmapRegionDecoderBench(SkString baseName, SkData* encoded,
+ SkBitmapRegionDecoderInterface::Strategy strategy, SkColorType colorType,
+ uint32_t sampleSize, const SkIRect& subset)
+ : 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;
+ switch (colorType) {
+ case kN32_SkColorType:
scroggo 2015/09/17 20:05:38 This switch statement shows up a lot. Maybe we can
msarett 2015/09/18 13:22:30 I moved something into tools, but, on second look,
mtklein 2015/09/18 13:26:51 If the function's defined in the header, you'll wa
msarett 2015/09/18 17:41:17 Thanks for your explanation!
+ colorName = "N32";
+ break;
+ case kRGB_565_SkColorType:
+ colorName = "565";
+ break;
+ case kGray_8_SkColorType:
+ colorName = "Gray8";
+ break;
+ case kIndex_8_SkColorType:
+ colorName = "Index8";
+ break;
+ default:
+ colorName = "Unknown";
+ }
+ if (1 == sampleSize) {
+ fName.printf("BRD_%s_%s_%s", baseName.c_str(), strategyName, colorName);
+ } else {
+ fName.printf("BRD_%s_%s_%s_%.3f", baseName.c_str(), strategyName, colorName,
+ 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::onDraw(const int n, SkCanvas* canvas) {
+ SkAutoTDelete<SkBitmapRegionDecoderInterface> brd;
+ SkAutoTDelete<SkBitmap> bitmap;
+ for (int i = 0; i < n; i++) {
+ SkStreamRewindable* stream = new SkMemoryStream(fData);
+ brd.reset(SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stream, fStrategy));
+ bitmap.reset(brd->decodeRegion(fSubset.left(), fSubset.top(), fSubset.width(),
+ fSubset.height(), fSampleSize, fColorType));
+ SkASSERT(nullptr != bitmap.get());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698