Chromium Code Reviews| Index: bench/nanobench.cpp |
| diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp |
| index 2fba1f053373c21e9aba473d65b79111f0464aaa..252e6df3448b5fd0a586af5c009dd73f1fe86458 100644 |
| --- a/bench/nanobench.cpp |
| +++ b/bench/nanobench.cpp |
| @@ -13,13 +13,16 @@ |
| #include "CodecBench.h" |
| #include "CrashHandler.h" |
| #include "DecodingBench.h" |
| -#include "DecodingSubsetBench.h" |
|
scroggo
2015/06/02 13:45:57
If this is no longer used, can we remove this clas
msarett
2015/06/02 17:14:10
Done.
|
| #include "GMBench.h" |
| #include "ProcStats.h" |
| #include "ResultsWriter.h" |
| #include "RecordingBench.h" |
| #include "SKPAnimationBench.h" |
| #include "SKPBench.h" |
| +#include "SubsetDivisorBench.h" |
| +#include "SubsetSingleBench.h" |
| +#include "SubsetTranslateBench.h" |
| +#include "SubsetZoomBench.h" |
| #include "Stats.h" |
| #include "Timer.h" |
| @@ -482,6 +485,44 @@ static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, |
| } |
| } |
| +/* |
| + * Returns true if set up for a subset decode succeeds, false otherwise |
| + * If the set-up succeeds, the width and height parameters will be set |
| + */ |
| +static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec, |
| + int* width, int* height) { |
| + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| + SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
| + |
| + if (useCodec) { |
| + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| + if (NULL == codec) { |
| + SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c_str()); |
| + return false; |
| + } |
| + |
| + const SkImageInfo info = codec->getInfo(); |
|
scroggo
2015/06/02 13:45:57
don't we need to convert to colorType?
msarett
2015/06/02 17:14:10
Done.
|
| + SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes())); |
| + SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); |
| + if (NULL == scanlineDecoder) { |
| + SkDebugf("Could not create scanline decoder for %s. Skipping bench.\n", path.c_str()); |
|
scroggo
2015/06/02 13:45:57
We might want to also report the colortype, since
msarett
2015/06/02 17:14:10
Done.
|
| + return false; |
| + } |
| + *width = info.width(); |
| + *height = info.height(); |
| + } else { |
| + SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.detach())); |
|
scroggo
2015/06/02 13:45:57
For legacy reasons, SkImageDecoder::Factory does n
msarett
2015/06/02 17:14:10
Nice catch, thanks!
|
| + if (NULL == decoder) { |
| + SkDebugf("Could not create decoder for %s. Skipping bench.\n", path.c_str()); |
| + return false; |
| + } |
| + if (!decoder->buildTileIndex(stream->duplicate(), width, height)) { |
| + SkDebugf("Could not build tile index for %s. Skipping bench.\n", path.c_str()); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| class BenchmarkStream { |
| public: |
| @@ -495,8 +536,9 @@ public: |
| , fCurrentImage(0) |
| , fCurrentSubsetImage(0) |
| , fCurrentColorType(0) |
| + , fCurrentSubsetType(0) |
| , fCurrentAnimSKP(0) |
| - , fDivisor(2) { |
| + , fUseCodec(true) { |
| for (int i = 0; i < FLAGS_skps.count(); i++) { |
| if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| fSKPs.push_back() = FLAGS_skps[i]; |
| @@ -737,53 +779,53 @@ public: |
| fCurrentImage++; |
| } |
| - // Run the DecodingSubsetBenches |
| + // Reset the SubsetBenches for ImageDecoder after they have run for Codec |
| + if (fCurrentSubsetImage == fImages.count() && fCurrentColorType == fColorTypes.count() && |
| + fCurrentSubsetType > kLast_SubsetType && fUseCodec) { |
| + fUseCodec = false; |
| + fCurrentSubsetImage = 0; |
| + fCurrentColorType = 0; |
| + fCurrentSubsetType = 0; |
| + } |
| + |
| + // Run the SubsetBenches |
| while (fCurrentSubsetImage < fImages.count()) { |
| while (fCurrentColorType < fColorTypes.count()) { |
| const SkString& path = fImages[fCurrentSubsetImage]; |
| SkColorType colorType = fColorTypes[fCurrentColorType]; |
| - fCurrentColorType++; |
| - // Check if the image decodes before creating the benchmark |
| - SkAutoTUnref<SkData> encoded( |
| - SkData::NewFromFileName(path.c_str())); |
| - SkAutoTDelete<SkMemoryStream> stream( |
| - new SkMemoryStream(encoded)); |
| - SkAutoTDelete<SkImageDecoder> |
| - decoder(SkImageDecoder::Factory(stream.get())); |
| - if (!decoder) { |
| - SkDebugf("Cannot find decoder for %s\n", path.c_str()); |
| - } else { |
| - stream->rewind(); |
| - int w, h; |
| - bool success; |
| - if (!decoder->buildTileIndex(stream.detach(), &w, &h) |
| - || w*h == 1) { |
| - // This is not an error, but in this case we still |
| - // do not want to run the benchmark. |
| - success = false; |
| - } else if (fDivisor > w || fDivisor > h) { |
| - SkDebugf("Divisor %d is too big for %s %dx%d\n", |
| - fDivisor, path.c_str(), w, h); |
| - success = false; |
| + while (fCurrentSubsetType <= kLast_SubsetType) { |
| + int width = 0; |
| + int height = 0; |
| + if (valid_subset_bench(path, colorType, fUseCodec, &width, &height)) { |
| + int currentSubsetType = fCurrentSubsetType++; |
|
scroggo
2015/06/02 13:45:57
nit: 4 space indent
msarett
2015/06/02 17:14:10
Done.
|
| + switch (currentSubsetType) { |
| + case kTopLeft_SubsetType: |
| + return new SubsetSingleBench(path, colorType, width/2, height/2, |
| + 0, 0, fUseCodec); |
| + case kTopRight_SubsetType: |
| + return new SubsetSingleBench(path, colorType, width/2, height/2, |
| + width/2, 0, fUseCodec); |
| + case kBottomLeft_SubsetType: |
| + return new SubsetSingleBench(path, colorType, width/2, height/2, |
| + 0, height/2, fUseCodec); |
| + case kBottomRight_SubsetType: |
| + return new SubsetSingleBench(path, colorType, width/2, height/2, |
| + 0, 0, fUseCodec); |
| + case k2x2_SubsetType: |
| + return new SubsetDivisorBench(path, colorType, 2, fUseCodec); |
| + case k3x3_SubsetType: |
| + return new SubsetDivisorBench(path, colorType, 3, fUseCodec); |
| + case kTranslate_SubsetType: |
| + return new SubsetTranslateBench(path, colorType, 512, 512, fUseCodec); |
| + case kZoom_SubsetType: |
| + return new SubsetZoomBench(path, colorType, 512, 512, fUseCodec); |
| + } |
| } else { |
| - const int sW = w / fDivisor; |
| - const int sH = h / fDivisor; |
| - SkBitmap bitmap; |
| - success = true; |
| - for (int y = 0; y < h; y += sH) { |
| - for (int x = 0; x < w; x += sW) { |
| - SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); |
| - success &= decoder->decodeSubset(&bitmap, rect, |
| - colorType); |
| - } |
| - } |
| - } |
| - // Create the benchmark if successful |
| - if (success) { |
| - return new DecodingSubsetBench(path, colorType, |
| - fDivisor); |
| + fCurrentSubsetType = 0; |
|
scroggo
2015/06/02 13:45:57
Don't we need to reset this when we reach kLast_Su
msarett
2015/06/02 17:14:10
Yes for sure! It appears I should have tested thi
|
| + break; |
| } |
| } |
| + fCurrentColorType++; |
| } |
| fCurrentColorType = 0; |
| fCurrentSubsetImage++; |
| @@ -812,6 +854,18 @@ public: |
| } |
| 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, |
| + kLast_SubsetType = kZoom_SubsetType |
| + }; |
| + |
| const BenchRegistry* fBenches; |
| const skiagm::GMRegistry* fGMs; |
| SkIRect fClip; |
| @@ -835,8 +889,9 @@ private: |
| int fCurrentImage; |
| int fCurrentSubsetImage; |
| int fCurrentColorType; |
| + int fCurrentSubsetType; |
| int fCurrentAnimSKP; |
| - const int fDivisor; |
| + bool fUseCodec; |
| }; |
| int nanobench_main(); |