| Index: bench/SubsetSingleBench.cpp
|
| diff --git a/bench/SubsetSingleBench.cpp b/bench/SubsetSingleBench.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f75b03d86b410d8e378b938f7594b700c1755b0d
|
| --- /dev/null
|
| +++ b/bench/SubsetSingleBench.cpp
|
| @@ -0,0 +1,127 @@
|
| +/*
|
| + * 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::Create(SkString* path,
|
| + SkColorType colorType,
|
| + uint32_t subsetWidth,
|
| + uint32_t subsetHeight,
|
| + uint32_t offsetLeft,
|
| + uint32_t offsetTop,
|
| + 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 SubsetSingleBench(path, colorType, subsetWidth, subsetHeight, offsetLeft,
|
| + offsetTop, useCodec);
|
| +}
|
| +
|
| +SubsetSingleBench::SubsetSingleBench(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;
|
| + 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("%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) {
|
| + 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;
|
| + if (!bitmap.tryAllocPixels(info.makeWH(fSubsetWidth, fSubsetHeight))) {
|
| + SkDebugf("Could not allocate memory. Aborting bench.\n");
|
| + return;
|
| + }
|
| +
|
| + 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);
|
| + }
|
| + }
|
| +}
|
|
|