Chromium Code Reviews| 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 |