Chromium Code Reviews| Index: bench/nanobench.cpp |
| diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp |
| index e7019dcb8c97c0713ce653a7b3a35865e6696ef7..dff732fe8df58bcf31c1a40fd3e12bf008b72e79 100644 |
| --- a/bench/nanobench.cpp |
| +++ b/bench/nanobench.cpp |
| @@ -10,6 +10,7 @@ |
| #include "nanobench.h" |
| #include "Benchmark.h" |
| +#include "BitmapRegionDecoderBench.h" |
| #include "CodecBench.h" |
| #include "CrashHandler.h" |
| #include "DecodingBench.h" |
| @@ -26,6 +27,7 @@ |
| #include "Stats.h" |
| #include "Timer.h" |
| +#include "SkBitmapRegionDecoderInterface.h" |
| #include "SkBBoxHierarchy.h" |
| #include "SkCanvas.h" |
| #include "SkCodec.h" |
| @@ -557,6 +559,33 @@ static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool |
| return true; |
| } |
| +static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoderInterface::Strategy strategy, |
| + SkColorType colorType, SkIRect* subset) { |
| + SkStreamRewindable* stream = new SkMemoryStream(encoded); |
| + SkAutoTDelete<SkBitmapRegionDecoderInterface> brd( |
| + SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stream, strategy)); |
| + if (nullptr == brd.get()) { |
| + // This is indicates that subset decoding is not supported for a particular image format. |
| + return false; |
| + } |
| + |
| + SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(), brd->height(), 1, |
| + colorType)); |
| + if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { |
| + // This indicates that conversion to the requested color type is not supported for the |
| + // particular image. |
| + return false; |
| + } |
| + |
| + // We can set the subset rect here, since we now know the height of the image. We will choose |
|
scroggo
2015/09/17 20:05:38
Since we're only decoding one subset, and we're co
msarett
2015/09/18 13:22:30
Yeah you're right, this is unfair. I should give
scroggo
2015/09/18 15:07:23
I'm starting to wonder whether we want to include
msarett
2015/09/18 17:41:17
I think we do want to include SkImageDecoder. I f
|
| + // the maximum size square subset centered at the center of the image. |
| + uint32_t dimension = SkTMin(brd->width(), brd->height()); |
| + uint32_t left = (brd->width() - dimension) / 2; |
| + uint32_t top = (brd->height() - dimension) / 2; |
| + *subset = SkIRect::MakeXYWH(left, top, dimension, dimension); |
| + return true; |
| +} |
| + |
| static void cleanup_run(Target* target) { |
| delete target; |
| #if SK_SUPPORT_GPU |
| @@ -580,9 +609,12 @@ public: |
| , fCurrentCodec(0) |
| , fCurrentImage(0) |
| , fCurrentSubsetImage(0) |
| + , fCurrentBRDImage(0) |
| , fCurrentColorType(0) |
| , fCurrentSubsetType(0) |
| , fUseCodec(0) |
| + , fCurrentBRDStrategy(0) |
| + , fCurrentBRDSampleSize(0) |
| , fCurrentAnimSKP(0) { |
| for (int i = 0; i < FLAGS_skps.count(); i++) { |
| if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| @@ -876,6 +908,44 @@ public: |
| fUseCodec++; |
| } |
| + // Run the BRDBenches |
| + // We will benchmark multiple BRD strategies. |
| + const SkBitmapRegionDecoderInterface::Strategy strategies[] = { |
| + SkBitmapRegionDecoderInterface::kOriginal_Strategy, |
| + SkBitmapRegionDecoderInterface::kCanvas_Strategy, |
| + }; |
| + // We will focus on these sample sizes, since they are most often used in real code. |
| + const uint32_t sampleSizes[] = { 1, 2, 4, 8 }; |
| + while (fCurrentBRDImage < fImages.count()) { |
| + while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { |
| + while (fCurrentColorType < fColorTypes.count()) { |
| + while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { |
| + const SkString& path = fImages[fCurrentBRDImage]; |
| + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| + const SkBitmapRegionDecoderInterface::Strategy strategy = |
| + strategies[fCurrentBRDStrategy]; |
| + const SkColorType colorType = fColorTypes[fCurrentColorType]; |
| + uint32_t sampleSize = sampleSizes[fCurrentBRDSampleSize]; |
| + fCurrentBRDSampleSize++; |
| + |
| + SkIRect subset; |
| + if (valid_brd_bench(encoded.get(), strategy, colorType, &subset)) { |
| + return new BitmapRegionDecoderBench(SkOSPath::Basename(path.c_str()), |
| + encoded.get(), strategy, colorType, sampleSize, subset); |
| + } else { |
| + break; |
| + } |
| + } |
| + fCurrentBRDSampleSize = 0; |
| + fCurrentColorType++; |
| + } |
| + fCurrentColorType = 0; |
| + fCurrentBRDStrategy++; |
| + } |
| + fCurrentBRDStrategy = 0; |
| + fCurrentBRDImage++; |
| + } |
| + |
| return nullptr; |
| } |
| @@ -932,9 +1002,12 @@ private: |
| int fCurrentCodec; |
| int fCurrentImage; |
| int fCurrentSubsetImage; |
| + int fCurrentBRDImage; |
| int fCurrentColorType; |
| int fCurrentSubsetType; |
| int fUseCodec; |
| + int fCurrentBRDStrategy; |
| + int fCurrentBRDSampleSize; |
| int fCurrentAnimSKP; |
| }; |