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

Unified Diff: bench/SubsetBenchPriv.h

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
« no previous file with comments | « no previous file | bench/SubsetDivisorBench.h » ('j') | bench/SubsetDivisorBench.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/SubsetBenchPriv.h
diff --git a/bench/SubsetBenchPriv.h b/bench/SubsetBenchPriv.h
new file mode 100644
index 0000000000000000000000000000000000000000..a643ae8a636c5326d27e7adb419dfc931428a83f
--- /dev/null
+++ b/bench/SubsetBenchPriv.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SubsetBenchPriv_DEFINED
+#define SubsetBenchPriv_DEFINED
+
+#include "SkCodec.h"
+#include "SkImageGenerator.h"
+
+/*
+ * Returns true if a subset decode succeeds, false otherwise
+ */
+static bool valid_subset_bench(SkMemoryStream* stream, SkColorType colorType, bool useCodec) {
scroggo 2015/06/01 17:25:14 Does this need to be an SkMemoryStream? In general
msarett 2015/06/01 20:37:01 Yes, I think this makes a lot more sense.
+ if (useCodec) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream->duplicate()));
scroggo 2015/06/01 17:25:14 Not sure whether we need to duplicate the stream h
msarett 2015/06/01 20:37:01 Acknowledged.
+ if (NULL == codec) {
+ return false;
scroggo 2015/06/01 17:25:14 Can you add a debug statement? This seems like a b
msarett 2015/06/01 20:37:01 I agree! Adding informative error messages throug
+ }
+
+ const SkImageInfo info = codec->getInfo();
+ SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()));
+ SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info);
+ if (NULL == scanlineDecoder) {
+ return false;
scroggo 2015/06/01 17:25:14 Maybe add a debug statement here, as well?
msarett 2015/06/01 20:37:01 Done.
+ }
+
+ const uint32_t subsetWidth = info.width() / 2;
scroggo 2015/06/01 17:25:14 It seems somewhat weird that we decode an arbitrar
msarett 2015/06/01 20:37:01 Yeah I thought this was awkward too. I didn't wan
+ const uint32_t subsetHeight = info.height() / 2;
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocPixels(info.makeWH(subsetWidth, subsetHeight))) {
+ SkDebugf("Could not allocate memory. Aborting bench.\n");
scroggo 2015/06/01 17:25:14 Skipping*
msarett 2015/06/01 20:37:01 Acknowledged.
+ return false;
+ }
+
+ if (SkImageGenerator::kSuccess != scanlineDecoder->skipScanlines(subsetHeight)) {
scroggo 2015/06/01 17:25:14 We probably want a debug statement here, too. Alth
msarett 2015/06/01 20:37:01 Acknowledged.
+ return false;
+ }
+ uint32_t bpp = info.bytesPerPixel();
+ for (uint32_t y = 0; y < subsetHeight; y++) {
+ if (SkImageGenerator::kSuccess != scanlineDecoder->getScanlines(row.get(), 1, 0)) {
+ return false;
+ }
+ memcpy(bitmap.getAddr(0, y), row.get(), subsetWidth * bpp);
scroggo 2015/06/01 17:25:14 This seems unnecessary. We're trying to make sure
msarett 2015/06/01 20:37:01 Acknowledged.
+ }
+ } else {
+ SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
+ if (NULL == decoder) {
+ return false;
+ }
+ int width, height;
+ if (!decoder->buildTileIndex(stream->duplicate(), &width, &height)) {
scroggo 2015/06/01 17:25:14 If width and height are not 1, isn't this a bug fo
msarett 2015/06/01 20:37:02 Acknowledged.
+ return false;
+ }
+ const uint32_t subsetWidth = width / 2;
+ const uint32_t subsetHeight = height / 2;
+ SkBitmap bitmap;
+ SkIRect rect = SkIRect::MakeXYWH(subsetWidth, subsetHeight, subsetWidth,
+ subsetHeight);
+ if (!decoder->decodeSubset(&bitmap, rect, colorType)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+#endif // SubsetBenchPriv_DEFINED
« no previous file with comments | « no previous file | bench/SubsetDivisorBench.h » ('j') | bench/SubsetDivisorBench.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698