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

Unified Diff: bench/subset/SubsetSingleBench.cpp

Issue 1160953002: Subset decoding benchmarks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added FIXME Created 5 years, 6 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
« no previous file with comments | « bench/subset/SubsetSingleBench.h ('k') | bench/subset/SubsetTranslateBench.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/subset/SubsetSingleBench.cpp
diff --git a/bench/subset/SubsetSingleBench.cpp b/bench/subset/SubsetSingleBench.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..68c94cd246b125a27ba26e6bec7a2f6409006bb4
--- /dev/null
+++ b/bench/subset/SubsetSingleBench.cpp
@@ -0,0 +1,94 @@
+/*
+ * 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 "SubsetSingleBench.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 an input width, height, left, and top to decode a single subset.
+ *
+ */
+
+SubsetSingleBench::SubsetSingleBench(const SkString& path,
+ SkColorType colorType,
+ uint32_t subsetWidth,
+ uint32_t subsetHeight,
+ uint32_t offsetLeft,
+ uint32_t offsetTop,
+ bool useCodec)
+ : fColorType(colorType)
+ , fSubsetWidth(subsetWidth)
+ , fSubsetHeight(subsetHeight)
+ , fOffsetLeft(offsetLeft)
+ , fOffsetTop(offsetTop)
+ , fUseCodec(useCodec)
+{
+ // Parse the filename
+ SkString baseName = SkOSPath::Basename(path.c_str());
+
+ // Choose an informative color name
+ const char* colorName = get_color_name(fColorType);
+
+ fName.printf("%sSubsetSingle_%dx%d +%d_+%d_%s_%s", fUseCodec ? "Codec" : "Image", fSubsetWidth,
+ fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName);
+
+ // Perform the decode setup
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
+ fStream.reset(new SkMemoryStream(encoded));
+}
+
+const char* SubsetSingleBench::onGetName() {
+ return fName.c_str();
+}
+
+bool SubsetSingleBench::isSuitableFor(Backend backend) {
+ return kNonRendering_Backend == backend;
+}
+
+void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) {
+ // When the color type is kIndex8, we will need to store the color table. If it is
+ // used, it will be initialized by the codec.
+ int colorCount;
+ SkPMColor colors[256];
+ if (fUseCodec) {
+ for (int count = 0; count < n; count++) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()));
+ const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
+ SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()));
+ SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(
+ info, NULL, colors, &colorCount);
+
+ SkBitmap bitmap;
+ bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight));
+
+ scanlineDecoder->skipScanlines(fOffsetTop);
+ uint32_t bpp = info.bytesPerPixel();
+ for (uint32_t y = 0; y < fSubsetHeight; y++) {
+ scanlineDecoder->getScanlines(row.get(), 1, 0);
+ memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp,
+ fSubsetWidth * bpp);
+ }
+ }
+ } else {
+ for (int count = 0; count < n; count++) {
+ SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
+ int width, height;
+ decoder->buildTileIndex(fStream->duplicate(), &width, &height);
+ SkBitmap bitmap;
+ SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWidth,
+ fSubsetHeight);
+ decoder->decodeSubset(&bitmap, rect, fColorType);
+ }
+ }
+}
« no previous file with comments | « bench/subset/SubsetSingleBench.h ('k') | bench/subset/SubsetTranslateBench.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698