diff options
author | msarett <msarett@google.com> | 2016-02-11 06:45:51 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-11 06:45:51 -0800 |
commit | 84451024bfe06d138629dd7c27cf2ec0f9774dbe (patch) | |
tree | b73d5b4a8a871088a73ecaa10627a9ad85dbb83a | |
parent | fff055cc5f9ca5015678f4f13a4f842084bd62d5 (diff) |
Add AndroidCodecBench to time scaled decodes
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1685693003
Review URL: https://codereview.chromium.org/1685693003
-rw-r--r-- | bench/AndroidCodecBench.cpp | 56 | ||||
-rw-r--r-- | bench/AndroidCodecBench.h | 39 | ||||
-rw-r--r-- | bench/nanobench.cpp | 52 |
3 files changed, 137 insertions, 10 deletions
diff --git a/bench/AndroidCodecBench.cpp b/bench/AndroidCodecBench.cpp new file mode 100644 index 0000000000..97e1176044 --- /dev/null +++ b/bench/AndroidCodecBench.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "AndroidCodecBench.h" +#include "CodecBenchPriv.h" +#include "SkBitmap.h" +#include "SkAndroidCodec.h" +#include "SkCommandLineFlags.h" +#include "SkOSFile.h" + +AndroidCodecBench::AndroidCodecBench(SkString baseName, SkData* encoded, int sampleSize) + : fData(SkRef(encoded)) + , fSampleSize(sampleSize) +{ + // Parse filename and the color type to give the benchmark a useful name + fName.printf("AndroidCodec_%s_SampleSize%d", baseName.c_str(), sampleSize); +} + +const char* AndroidCodecBench::onGetName() { + return fName.c_str(); +} + +bool AndroidCodecBench::isSuitableFor(Backend backend) { + return kNonRendering_Backend == backend; +} + +void AndroidCodecBench::onDelayedSetup() { + SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(fData)); + SkISize scaledSize = codec->getSampledDimensions(fSampleSize); + + fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height()) + .makeColorType(kN32_SkColorType); + if (kUnpremul_SkAlphaType == fInfo.alphaType()) { + fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType); + } + + fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); +} + +void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) { + SkAutoTDelete<SkAndroidCodec> codec; + SkAndroidCodec::AndroidOptions options; + options.fSampleSize = fSampleSize; + for (int i = 0; i < n; i++) { + codec.reset(SkAndroidCodec::NewFromData(fData)); +#ifdef SK_DEBUG + const SkCodec::Result result = +#endif + codec->getAndroidPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), &options); + SkASSERT(result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput); + } +} diff --git a/bench/AndroidCodecBench.h b/bench/AndroidCodecBench.h new file mode 100644 index 0000000000..fdbec5258a --- /dev/null +++ b/bench/AndroidCodecBench.h @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef AndroidCodecBench_DEFINED +#define AndroidCodecBench_DEFINED + +#include "Benchmark.h" +#include "SkData.h" +#include "SkImageInfo.h" +#include "SkRefCnt.h" +#include "SkString.h" + +/** + * Time SkAndroidCodec. + */ +class AndroidCodecBench : public Benchmark { +public: + // Calls encoded->ref() + AndroidCodecBench(SkString basename, SkData* encoded, int sampleSize); + +protected: + const char* onGetName() override; + bool isSuitableFor(Backend backend) override; + void onDraw(int n, SkCanvas* canvas) override; + void onDelayedSetup() override; + +private: + SkString fName; + SkAutoTUnref<SkData> fData; + const int fSampleSize; + SkImageInfo fInfo; // Set in onDelayedSetup. + SkAutoMalloc fPixelStorage; // Set in onDelayedSetup. + typedef Benchmark INHERITED; +}; +#endif // AndroidCodecBench_DEFINED diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 4d8ba4497d..a5c3ca11c8 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -9,6 +9,7 @@ #include "nanobench.h" +#include "AndroidCodecBench.h" #include "Benchmark.h" #include "BitmapRegionDecoderBench.h" #include "CodecBench.h" @@ -22,6 +23,7 @@ #include "SKPBench.h" #include "Stats.h" +#include "SkAndroidCodec.h" #include "SkBitmapRegionDecoder.h" #include "SkBBoxHierarchy.h" #include "SkCanvas.h" @@ -546,12 +548,13 @@ public: , fCurrentSKP(0) , fCurrentUseMPD(0) , fCurrentCodec(0) + , fCurrentAndroidCodec(0) , fCurrentBRDImage(0) , fCurrentColorType(0) , fCurrentAlphaType(0) , fCurrentSubsetType(0) , fCurrentBRDStrategy(0) - , fCurrentBRDSampleSize(0) + , fCurrentSampleSize(0) , fCurrentAnimSKP(0) { for (int i = 0; i < FLAGS_skps.count(); i++) { if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { @@ -797,6 +800,37 @@ public: fCurrentColorType = 0; } + // Run AndroidCodecBenches + const int sampleSizes[] = { 2, 4, 8 }; + for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) { + fSourceType = "image"; + fBenchType = "skandroidcodec"; + + const SkString& path = fImages[fCurrentAndroidCodec]; + if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { + continue; + } + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); + SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); + if (!codec) { + // Nothing to time. + SkDebugf("Cannot find codec for %s\n", path.c_str()); + continue; + } + + while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { + int sampleSize = sampleSizes[fCurrentSampleSize]; + fCurrentSampleSize++; + if (10 * sampleSize > SkTMin(codec->getInfo().width(), codec->getInfo().height())) { + // Avoid benchmarking scaled decodes of already small images. + break; + } + + return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), encoded, sampleSize); + } + fCurrentSampleSize = 0; + } + // Run the BRDBenches // We will benchmark multiple BRD strategies. static const struct { @@ -816,12 +850,10 @@ public: // sampleSize is used, the size of the subset that is decoded is always // (sampleSize*512)x(sampleSize*512). // There are a few good reasons to only test on power of two sample sizes at this time: - // JPEG decodes using kOriginal_Strategy are broken for non-powers of two. - // https://bug.skia.org/4319 // All use cases we are aware of only scale by powers of two. // PNG decodes use the indicated sampling strategy regardless of the sample size, so // these tests are sufficient to provide good coverage of our scaling options. - const uint32_t sampleSizes[] = { 1, 2, 4, 8, 16, 32, 64 }; + const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; const uint32_t minOutputSize = 512; for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { const SkString& path = fImages[fCurrentBRDImage]; @@ -836,13 +868,12 @@ public: strategies[fCurrentBRDStrategy].fStrategy; while (fCurrentColorType < fColorTypes.count()) { - while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { + while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) { while (fCurrentSubsetType <= kLastSingle_SubsetType) { - SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); const SkColorType colorType = fColorTypes[fCurrentColorType]; - uint32_t sampleSize = sampleSizes[fCurrentBRDSampleSize]; + uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize]; int currentSubsetType = fCurrentSubsetType++; int width = 0; @@ -888,9 +919,9 @@ public: strategy, colorType, sampleSize, subset); } fCurrentSubsetType = 0; - fCurrentBRDSampleSize++; + fCurrentSampleSize++; } - fCurrentBRDSampleSize = 0; + fCurrentSampleSize = 0; fCurrentColorType++; } fCurrentColorType = 0; @@ -955,12 +986,13 @@ private: int fCurrentSKP; int fCurrentUseMPD; int fCurrentCodec; + int fCurrentAndroidCodec; int fCurrentBRDImage; int fCurrentColorType; int fCurrentAlphaType; int fCurrentSubsetType; int fCurrentBRDStrategy; - int fCurrentBRDSampleSize; + int fCurrentSampleSize; int fCurrentAnimSKP; }; |