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

Unified Diff: bench/SubsetTranslateBench.cpp

Issue 1160953002: Subset decoding benchmarks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Separate subclass for each benchmark Created 5 years, 7 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/SubsetTranslateBench.cpp
diff --git a/bench/SubsetTranslateBench.cpp b/bench/SubsetTranslateBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d69ab6034d953bd83d3c9acfbf03815792370e73
--- /dev/null
+++ b/bench/SubsetTranslateBench.cpp
@@ -0,0 +1,148 @@
+/*
+ * 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 "SubsetTranslateBench.h"
+#include "SubsetBenchPriv.h"
+#include "SkData.h"
+#include "SkCodec.h"
+#include "SkImageDecoder.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+
+/*
+ *
+ * This benchmark is designed to test the performance of subset decoding.
+ * It uses input dimensions to decode the entire image where each block is susbetW x subsetH.
+ *
+ */
+
+SubsetTranslateBench* SubsetTranslateBench::Create(SkString* path,
+ SkColorType colorType,
+ uint32_t subsetWidth,
+ uint32_t subsetHeight,
+ bool useCodec) {
+ // Check that the decode will succeed
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path->c_str()));
+ SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
+ if (!valid_subset_bench(stream, colorType, useCodec)) {
+ return NULL;
+ }
+ return new SubsetTranslateBench(path, colorType, subsetWidth, subsetHeight, useCodec);
+}
+
+SubsetTranslateBench::SubsetTranslateBench(SkString* path,
+ SkColorType colorType,
+ uint32_t subsetWidth,
+ uint32_t subsetHeight,
+ bool useCodec)
+ : fColorType(colorType)
+ , fSubsetWidth(subsetWidth)
+ , fSubsetHeight(subsetHeight)
+ , fUseCodec(useCodec)
+{
+ // Parse the filename
+ SkString baseName = SkOSPath::Basename(path->c_str());
+
+ // Choose an informative color name
+ const char* colorName;
+ switch(fColorType) {
+ case kN32_SkColorType:
+ colorName = "N32";
+ break;
+ case kRGB_565_SkColorType:
+ colorName = "565";
+ break;
+ case kGray_8_SkColorType:
+ colorName = "Gray8";
+ break;
+ case kIndex_8_SkColorType:
+ colorName = "Gray8";
+ break;
+ case kAlpha_8_SkColorType:
+ colorName = "Alpha8";
+ break;
+ default:
+ colorName = "Unknown";
+ }
+ fName.printf("%sSubsetTranslate_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fSubsetWidth,
+ fSubsetHeight, baseName.c_str(), colorName);
+
+ // Perform the decode setup
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path->c_str()));
+ fStream.reset(new SkMemoryStream(encoded));
+}
+
+const char* SubsetTranslateBench::onGetName() {
+ return fName.c_str();
+}
+
+bool SubsetTranslateBench::isSuitableFor(Backend backend) {
+ return kNonRendering_Backend == backend;
+}
+
+void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) {
+ if (fUseCodec) {
+ for (int count = 0; count < n; count++) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
+ const SkImageInfo info = codec->getInfo();
+ SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()));
+ SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info);
+
+ SkBitmap bitmap;
+ // Note that we use the same bitmap for all of the subsets.
+ // It might be larger than necessary for the end subsets.
+ if (!bitmap.tryAllocPixels(info.makeWH(fSubsetWidth, fSubsetHeight))) {
+ SkDebugf("Could not allocate memory. Aborting bench.\n");
+ return;
+ }
+
+ for (int x = 0; x < info.width(); x += fSubsetWidth) {
+ for (int y = 0; y < info.height(); y += fSubsetHeight) {
+ scanlineDecoder->skipScanlines(y);
+ const uint32_t currSubsetWidth =
+ x + (int) fSubsetWidth > info.width() ?
+ info.width() - x : fSubsetWidth;
+ const uint32_t currSubsetHeight =
+ y + (int) fSubsetHeight > info.height() ?
+ info.height() - y : fSubsetHeight;
+ const uint32_t bpp = info.bytesPerPixel();
+ for (uint32_t y = 0; y < currSubsetHeight; y++) {
+ scanlineDecoder->getScanlines(row.get(), 1, 0);
+ memcpy(bitmap.getAddr(0, y), row.get() + x * bpp,
+ currSubsetWidth * bpp);
+ }
+ }
+ }
+ }
+ } else {
+ for (int count = 0; count < n; count++) {
+ int width, height;
+ SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
+ decoder->buildTileIndex(fStream->duplicate(), &width, &height);
+ SkBitmap bitmap;
+ // Note that we use the same bitmap for all of the subsets.
+ // It might be larger than necessary for the end subsets.
+ if (!bitmap.tryAllocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight,
+ fColorType, kOpaque_SkAlphaType))) {
+ SkDebugf("Could not allocate memory. Aborting bench.\n");
+ return;
+ }
+
+ for (int x = 0; x < width; x += fSubsetWidth) {
+ for (int y = 0; y < height; y += fSubsetHeight) {
+ const uint32_t currSubsetWidth = x + (int) fSubsetWidth > width ?
+ width - x : fSubsetWidth;
+ const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ?
+ height - y : fSubsetHeight;
+ SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth,
+ currSubsetHeight);
+ decoder->decodeSubset(&bitmap, rect, fColorType);
+ }
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698