Improved subset benchmarks

I think these changes to the subset benchmarks cover what we discussed yesterday.

I removed the divisor benchmarks (2x2, 3x3) and changed the single subset benchmarks.

Also, we will no longer benchmark subset decodes on small images.

BUG=skia:

Review URL: https://codereview.chromium.org/1188223002
This commit is contained in:
msarett 2015-06-17 10:28:22 -07:00 committed by Commit bot
parent 6b7f34e34c
commit ab80e35fbd
3 changed files with 24 additions and 188 deletions

View File

@ -20,7 +20,6 @@
#include "SKPAnimationBench.h"
#include "SKPBench.h"
#include "SubsetBenchPriv.h"
#include "SubsetDivisorBench.h"
#include "SubsetSingleBench.h"
#include "SubsetTranslateBench.h"
#include "SubsetZoomBench.h"
@ -496,6 +495,7 @@ static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
// Check that we can create a codec or image decoder.
if (useCodec) {
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
if (NULL == codec) {
@ -535,6 +535,13 @@ static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool
return false;
}
}
// Check if the image is large enough for a meaningful subset benchmark.
if (*width <= 512 && *height <= 512) {
// This should not print a message since it is not an error.
return false;
}
return true;
}
@ -812,21 +819,20 @@ public:
if (valid_subset_bench(path, colorType, useCodec, &width, &height)) {
switch (currentSubsetType) {
case kTopLeft_SubsetType:
return new SubsetSingleBench(path, colorType, width/2,
height/2, 0, 0, useCodec);
return new SubsetSingleBench(path, colorType, width/3,
height/3, 0, 0, useCodec);
case kTopRight_SubsetType:
return new SubsetSingleBench(path, colorType, width/2,
height/2, width/2, 0, useCodec);
return new SubsetSingleBench(path, colorType, width/3,
height/3, 2*width/3, 0, useCodec);
case kMiddle_SubsetType:
return new SubsetSingleBench(path, colorType, width/3,
height/3, width/3, height/3, useCodec);
case kBottomLeft_SubsetType:
return new SubsetSingleBench(path, colorType, width/2,
height/2, 0, height/2, useCodec);
return new SubsetSingleBench(path, colorType, width/3,
height/3, 0, 2*height/3, useCodec);
case kBottomRight_SubsetType:
return new SubsetSingleBench(path, colorType, width/2,
height/2, width/2, height/2, useCodec);
case k2x2_SubsetType:
return new SubsetDivisorBench(path, colorType, 2, useCodec);
case k3x3_SubsetType:
return new SubsetDivisorBench(path, colorType, 3, useCodec);
return new SubsetSingleBench(path, colorType, width/3,
height/3, 2*width/3, 2*height/3, useCodec);
case kTranslate_SubsetType:
return new SubsetTranslateBench(path, colorType, 512, 512,
useCodec);
@ -874,12 +880,11 @@ private:
enum SubsetType {
kTopLeft_SubsetType = 0,
kTopRight_SubsetType = 1,
kBottomLeft_SubsetType = 2,
kBottomRight_SubsetType = 3,
k2x2_SubsetType = 4,
k3x3_SubsetType = 5,
kTranslate_SubsetType = 6,
kZoom_SubsetType = 7,
kMiddle_SubsetType = 2,
kBottomLeft_SubsetType = 3,
kBottomRight_SubsetType = 4,
kTranslate_SubsetType = 5,
kZoom_SubsetType = 6,
kLast_SubsetType = kZoom_SubsetType
};

View File

@ -1,129 +0,0 @@
/*
* 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 "SubsetDivisorBench.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 a divisor to decode the entire image in a grid of divisor x divisor blocks.
*
*/
SubsetDivisorBench::SubsetDivisorBench(const SkString& path,
SkColorType colorType,
uint32_t divisor,
bool useCodec)
: fColorType(colorType)
, fDivisor(divisor)
, 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("%sSubsetDivisor_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fDivisor, fDivisor,
baseName.c_str(), colorName);
// Perform the decode setup
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
fStream.reset(new SkMemoryStream(encoded));
}
const char* SubsetDivisorBench::onGetName() {
return fName.c_str();
}
bool SubsetDivisorBench::isSuitableFor(Backend backend) {
return kNonRendering_Backend == backend;
}
void SubsetDivisorBench::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);
const uint32_t subsetWidth = info.width() / fDivisor;
const uint32_t subsetHeight = info.height() / fDivisor;
const uint32_t maxSubsetWidth = subsetWidth + info.width() % fDivisor;
const uint32_t maxSubsetHeight = subsetHeight + info.height() % fDivisor;
SkBitmap bitmap;
// Note that we use the same bitmap for all of the subsets.
// It might be slightly larger than necessary for some of the subsets.
bitmap.allocPixels(info.makeWH(maxSubsetWidth, maxSubsetHeight));
for (uint32_t blockX = 0; blockX < fDivisor; blockX++) {
for (uint32_t blockY = 0; blockY < fDivisor; blockY++) {
scanlineDecoder->skipScanlines(blockY * subsetHeight);
const uint32_t currSubsetWidth =
(blockX == fDivisor - 1) ? maxSubsetWidth : subsetWidth;
const uint32_t currSubsetHeight =
(blockY == fDivisor - 1) ? maxSubsetHeight : subsetHeight;
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() + blockX * subsetWidth * bpp,
currSubsetWidth * bpp);
}
}
}
}
} else {
// We create a color table here to satisfy allocPixels() when the output
// type is kIndex8. It's okay that this is uninitialized since we never
// use it.
SkColorTable* colorTable = SkNEW_ARGS(SkColorTable, (colors, 0));
for (int count = 0; count < n; count++) {
int width, height;
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream));
decoder->buildTileIndex(fStream->duplicate(), &width, &height);
const uint32_t subsetWidth = width / fDivisor;
const uint32_t subsetHeight = height / fDivisor;
const uint32_t maxSubsetWidth = subsetWidth + width % fDivisor;
const uint32_t maxSubsetHeight = subsetHeight + height % fDivisor;
SkBitmap bitmap;
// Note that we use the same bitmap for all of the subsets.
// It might be slightly larger than necessary for some of the subsets.
// If we do not include this step, decodeSubset() would allocate space
// for the pixels automatically, but this would not allow us to reuse the
// same bitmap as the other subsets. We want to reuse the same bitmap
// because it gives a more fair comparison with SkCodec and is a common
// use case of BitmapRegionDecoder.
bitmap.allocPixels(SkImageInfo::Make(maxSubsetWidth, maxSubsetHeight,
fColorType, kOpaque_SkAlphaType), NULL, colorTable);
for (uint32_t blockX = 0; blockX < fDivisor; blockX++) {
for (uint32_t blockY = 0; blockY < fDivisor; blockY++) {
const uint32_t currSubsetWidth =
(blockX == fDivisor - 1) ? maxSubsetWidth : subsetWidth;
const uint32_t currSubsetHeight =
(blockY == fDivisor - 1) ? maxSubsetHeight : subsetHeight;
SkIRect rect = SkIRect::MakeXYWH(blockX * subsetWidth,
blockY * subsetHeight, currSubsetWidth, currSubsetHeight);
decoder->decodeSubset(&bitmap, rect, fColorType);
}
}
}
}
}

View File

@ -1,40 +0,0 @@
/*
* 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 "Benchmark.h"
#include "SkImageDecoder.h"
#include "SkImageInfo.h"
#include "SkStream.h"
#include "SkString.h"
/*
*
* This benchmark is designed to test the performance of subset decoding.
* It uses a divisor to decode the entire image in a grid of divisor x divisor blocks.
*
*/
class SubsetDivisorBench : public Benchmark {
public:
SubsetDivisorBench(const SkString& path,
SkColorType colorType,
uint32_t divisor,
bool useCodec);
protected:
const char* onGetName() override;
bool isSuitableFor(Backend backend) override;
void onDraw(const int n, SkCanvas* canvas) override;
private:
SkString fName;
SkColorType fColorType;
const uint32_t fDivisor;
const bool fUseCodec;
SkAutoTDelete<SkMemoryStream> fStream;
typedef Benchmark INHERITED;
};