Chromium Code Reviews| Index: bench/nanobench.cpp |
| diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp |
| index 07600ef3a447445737dc50626dc6d35e90bd97bd..a627b50a3a221ed0523c18176711bf7bfaca9cca 100644 |
| --- a/bench/nanobench.cpp |
| +++ b/bench/nanobench.cpp |
| @@ -10,6 +10,7 @@ |
| #include "nanobench.h" |
| #include "Benchmark.h" |
| +#include "CodecBench.h" |
| #include "CrashHandler.h" |
| #include "DecodingBench.h" |
| #include "DecodingSubsetBench.h" |
| @@ -23,6 +24,7 @@ |
| #include "SkBBoxHierarchy.h" |
| #include "SkCanvas.h" |
| +#include "SkCodec.h" |
| #include "SkCommonFlags.h" |
| #include "SkData.h" |
| #include "SkForceLinking.h" |
| @@ -485,6 +487,7 @@ public: |
| , fCurrentScale(0) |
| , fCurrentSKP(0) |
| , fCurrentUseMPD(0) |
| + , fCurrentCodec(0) |
| , fCurrentImage(0) |
| , fCurrentSubsetImage(0) |
| , fCurrentColorType(0) |
| @@ -632,16 +635,57 @@ public: |
| fCurrentScale++; |
| } |
| + for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
|
djsollen
2015/04/01 16:06:07
range based for loop? C++11!!
scroggo
2015/04/01 17:18:04
Will that work here? I need to use fCurrentCodec,
|
| + const SkString& path = fImages[fCurrentCodec]; |
| + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| + SkASSERT(codec); |
|
scroggo
2015/03/31 19:20:03
Maybe we should add the filter from DM that says t
|
| + if (!codec) { |
| + // Nothing to time. |
| + continue; |
| + } |
| + while (fCurrentColorType < fColorTypes.count()) { |
|
djsollen
2015/04/01 16:06:07
range based loop
scroggo
2015/04/01 17:18:04
Again, I do not think that will work, unless I'm m
|
| + SkColorType colorType = fColorTypes[fCurrentColorType]; |
| + fCurrentColorType++; |
| + // Make sure we can decode to this color type. |
| + SkBitmap bitmap; |
| + SkImageInfo info = codec->getInfo().makeColorType(colorType); |
| + bitmap.allocPixels(info); |
| + const SkImageGenerator::Result result = codec->getPixels( |
| + bitmap.info(), bitmap.getPixels(), bitmap.rowBytes()); |
| + switch (result) { |
| + case SkImageGenerator::kSuccess: |
| + case SkImageGenerator::kIncompleteInput: |
| + return new CodecBench(SkOSPath::Basename(path.c_str()), |
| + encoded, colorType); |
| + case SkImageGenerator::kInvalidConversion: |
| + // This is okay. Not all conversions are valid. |
| + break; |
| + case SkImageGenerator::kCouldNotRewind: |
| + // FIXME: This is due to a bug in some implementations |
| + // of SkCodec. All should support rewinding. |
|
scroggo
2015/03/31 19:20:03
All should support rewinding - in the case where w
djsollen
2015/04/01 16:06:07
Should this fire an assert then?
scroggo
2015/04/01 17:18:04
Once I fix all our SkCodecs to handle rewinding pr
|
| + break; |
| + default: |
| + // This represents some sort of failure. |
| + SkASSERT(false); |
| + break; |
| + } |
| + } |
| + fCurrentColorType = 0; |
| + } |
| + |
| // Run the DecodingBenches |
| while (fCurrentImage < fImages.count()) { |
| while (fCurrentColorType < fColorTypes.count()) { |
| const SkString& path = fImages[fCurrentImage]; |
| SkColorType colorType = fColorTypes[fCurrentColorType]; |
| fCurrentColorType++; |
| - // Check if the image decodes before creating the benchmark |
| + // Check if the image decodes to the right color type |
| + // before creating the benchmark |
| SkBitmap bitmap; |
| if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
| - colorType, SkImageDecoder::kDecodePixels_Mode)) { |
| + colorType, SkImageDecoder::kDecodePixels_Mode) |
| + && bitmap.colorType() == colorType) { |
| return new DecodingBench(path, colorType); |
| } |
| } |
| @@ -741,6 +785,7 @@ private: |
| int fCurrentScale; |
| int fCurrentSKP; |
| int fCurrentUseMPD; |
| + int fCurrentCodec; |
| int fCurrentImage; |
| int fCurrentSubsetImage; |
| int fCurrentColorType; |