diff options
author | msarett <msarett@google.com> | 2016-01-07 14:20:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-07 14:20:20 -0800 |
commit | c7796b93f02e736df967301d3c46cec46dd02d5c (patch) | |
tree | b4697f6079e8f1fe895dffbf56b8f047a6752921 /bench | |
parent | 1243b702eed1fa6f37da7d3ce71f41b4bc45ea7c (diff) |
Make CodecBench test kPremul and kUnpremul
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1568913002
Review URL: https://codereview.chromium.org/1568913002
Diffstat (limited to 'bench')
-rw-r--r-- | bench/CodecBench.cpp | 17 | ||||
-rw-r--r-- | bench/CodecBench.h | 5 | ||||
-rw-r--r-- | bench/CodecBenchPriv.h | 14 | ||||
-rw-r--r-- | bench/nanobench.cpp | 40 |
4 files changed, 52 insertions, 24 deletions
diff --git a/bench/CodecBench.cpp b/bench/CodecBench.cpp index 1384480f43..66831fb24c 100644 --- a/bench/CodecBench.cpp +++ b/bench/CodecBench.cpp @@ -11,12 +11,15 @@ #include "SkCodec.h" #include "SkOSFile.h" -CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType) +CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType, + SkAlphaType alphaType) : fColorType(colorType) + , fAlphaType(alphaType) , fData(SkRef(encoded)) { // Parse filename and the color type to give the benchmark a useful name - fName.printf("Codec_%s_%s", baseName.c_str(), color_type_to_str(colorType)); + fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType), + alpha_type_to_str(alphaType)); #ifdef SK_DEBUG // Ensure that we can create an SkCodec from this data. SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); @@ -35,15 +38,7 @@ bool CodecBench::isSuitableFor(Backend backend) { void CodecBench::onDelayedSetup() { SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData)); - fInfo = codec->getInfo().makeColorType(fColorType); - SkAlphaType alphaType; - // Caller should not have created this CodecBench if the alpha type was - // invalid. - SkAssertResult(SkColorTypeValidateAlphaType(fColorType, fInfo.alphaType(), - &alphaType)); - if (alphaType != fInfo.alphaType()) { - fInfo = fInfo.makeAlphaType(alphaType); - } + fInfo = codec->getInfo().makeColorType(fColorType).makeAlphaType(fAlphaType); fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes())); } diff --git a/bench/CodecBench.h b/bench/CodecBench.h index a574b4c67a..b465eae36a 100644 --- a/bench/CodecBench.h +++ b/bench/CodecBench.h @@ -20,7 +20,7 @@ class CodecBench : public Benchmark { public: // Calls encoded->ref() - CodecBench(SkString basename, SkData* encoded, SkColorType colorType); + CodecBench(SkString basename, SkData* encoded, SkColorType colorType, SkAlphaType alphaType); protected: const char* onGetName() override; @@ -31,8 +31,9 @@ protected: private: SkString fName; const SkColorType fColorType; + const SkAlphaType fAlphaType; SkAutoTUnref<SkData> fData; - SkImageInfo fInfo; // Set in onPreDraw. + SkImageInfo fInfo; // Set in onDelayedSetup. SkAutoMalloc fPixelStorage; typedef Benchmark INHERITED; }; diff --git a/bench/CodecBenchPriv.h b/bench/CodecBenchPriv.h index d8585b6006..5028573ad2 100644 --- a/bench/CodecBenchPriv.h +++ b/bench/CodecBenchPriv.h @@ -27,4 +27,18 @@ inline const char* color_type_to_str(SkColorType colorType) { } } +inline const char* alpha_type_to_str(SkAlphaType alphaType) { + switch (alphaType) { + case kOpaque_SkAlphaType: + return ""; + case kPremul_SkAlphaType: + return "Premul"; + case kUnpremul_SkAlphaType: + return "Unpremul"; + default: + SkASSERT(false); + return "Unknown"; + } +} + #endif // CodecBenchPriv_DEFINED diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 5a83860713..b791ab7db7 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -564,6 +564,7 @@ public: , fCurrentImage(0) , fCurrentBRDImage(0) , fCurrentColorType(0) + , fCurrentAlphaType(0) , fCurrentSubsetType(0) , fCurrentBRDStrategy(0) , fCurrentBRDSampleSize(0) @@ -752,19 +753,35 @@ public: while (fCurrentColorType < fColorTypes.count()) { const SkColorType colorType = fColorTypes[fCurrentColorType]; - fCurrentColorType++; - // Make sure we can decode to this color type. - SkImageInfo info = codec->getInfo().makeColorType(colorType); - SkAlphaType alphaType; - if (!SkColorTypeValidateAlphaType(colorType, info.alphaType(), - &alphaType)) { - continue; - } - if (alphaType != info.alphaType()) { - info = info.makeAlphaType(alphaType); + SkAlphaType alphaType = codec->getInfo().alphaType(); + switch (alphaType) { + case kOpaque_SkAlphaType: + // We only need to test one alpha type (opaque). + fCurrentColorType++; + break; + case kUnpremul_SkAlphaType: + case kPremul_SkAlphaType: + if (0 == fCurrentAlphaType) { + // Test unpremul first. + alphaType = kUnpremul_SkAlphaType; + fCurrentAlphaType++; + } else { + // Test premul. + alphaType = kPremul_SkAlphaType; + fCurrentAlphaType = 0; + fCurrentColorType++; + } + break; + default: + SkASSERT(false); + fCurrentColorType++; + break; } + // Make sure we can decode to this color type and alpha type. + SkImageInfo info = + codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType); const size_t rowBytes = info.minRowBytes(); SkAutoMalloc storage(info.getSafeSize(rowBytes)); @@ -779,7 +796,7 @@ public: case SkCodec::kSuccess: case SkCodec::kIncompleteInput: return new CodecBench(SkOSPath::Basename(path.c_str()), - encoded, colorType); + encoded, colorType, alphaType); case SkCodec::kInvalidConversion: // This is okay. Not all conversions are valid. break; @@ -972,6 +989,7 @@ private: int fCurrentImage; int fCurrentBRDImage; int fCurrentColorType; + int fCurrentAlphaType; int fCurrentSubsetType; int fCurrentBRDStrategy; int fCurrentBRDSampleSize; |