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
diff --git a/bench/CodecBench.cpp b/bench/CodecBench.cpp
index 1384480..66831fb 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 @@
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 a574b4c..b465eae 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 @@
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 d8585b6..5028573 100644
--- a/bench/CodecBenchPriv.h
+++ b/bench/CodecBenchPriv.h
@@ -27,4 +27,18 @@
}
}
+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 5a83860..b791ab7 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -564,6 +564,7 @@
, fCurrentImage(0)
, fCurrentBRDImage(0)
, fCurrentColorType(0)
+ , fCurrentAlphaType(0)
, fCurrentSubsetType(0)
, fCurrentBRDStrategy(0)
, fCurrentBRDSampleSize(0)
@@ -752,19 +753,35 @@
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 @@
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 @@
int fCurrentImage;
int fCurrentBRDImage;
int fCurrentColorType;
+ int fCurrentAlphaType;
int fCurrentSubsetType;
int fCurrentBRDStrategy;
int fCurrentBRDSampleSize;