Stop creating CodecSrcs with unused scale

Only JPEG and WEBP support native scaling, so only create a CodecSrc
with a scale for those types.

If I run

    dm --src image --images resources

this cuts down the number of Srcs from 11063 to 8032. All of these
trimmed Srcs would have failed quickly for each Sink (3 Sinks with the
above flags), but this will avoid creating them.

It drops the runtime on my mac from 13.2s to 11.4s, for about a 14%
speedup.

BUG=skia:5307
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1999103002

Review-Url: https://codereview.chromium.org/1999103002
This commit is contained in:
scroggo 2016-05-20 08:38:54 -07:00 committed by Commit bot
parent 56f7dfebac
commit 9366aff1fa

View File

@ -481,9 +481,8 @@ static void push_codec_srcs(Path path) {
return; return;
} }
// Native Scales // native scaling is only supported by WEBP and JPEG
// SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875 bool supportsNativeScaling = false;
const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
SkTArray<CodecSrc::Mode> nativeModes; SkTArray<CodecSrc::Mode> nativeModes;
nativeModes.push_back(CodecSrc::kCodec_Mode); nativeModes.push_back(CodecSrc::kCodec_Mode);
@ -493,9 +492,11 @@ static void push_codec_srcs(Path path) {
nativeModes.push_back(CodecSrc::kScanline_Mode); nativeModes.push_back(CodecSrc::kScanline_Mode);
nativeModes.push_back(CodecSrc::kStripe_Mode); nativeModes.push_back(CodecSrc::kStripe_Mode);
nativeModes.push_back(CodecSrc::kCroppedScanline_Mode); nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
supportsNativeScaling = true;
break; break;
case SkEncodedFormat::kWEBP_SkEncodedFormat: case SkEncodedFormat::kWEBP_SkEncodedFormat:
nativeModes.push_back(CodecSrc::kSubset_Mode); nativeModes.push_back(CodecSrc::kSubset_Mode);
supportsNativeScaling = true;
break; break;
case SkEncodedFormat::kDNG_SkEncodedFormat: case SkEncodedFormat::kDNG_SkEncodedFormat:
break; break;
@ -529,24 +530,26 @@ static void push_codec_srcs(Path path) {
} }
for (CodecSrc::Mode mode : nativeModes) { for (CodecSrc::Mode mode : nativeModes) {
for (float scale : nativeScales) { for (CodecSrc::DstColorType colorType : colorTypes) {
for (CodecSrc::DstColorType colorType : colorTypes) { for (SkAlphaType alphaType : alphaModes) {
for (SkAlphaType alphaType : alphaModes) { // Only test kCroppedScanline_Mode when the alpha type is opaque. The test is
// Only test kCroppedScanline_Mode when the alpha type is opaque. The test is // slow and won't be interestingly different with different alpha types.
// slow and won't be interestingly different with different alpha types. if (CodecSrc::kCroppedScanline_Mode == mode &&
if (CodecSrc::kCroppedScanline_Mode == mode && kOpaque_SkAlphaType != alphaType) {
kOpaque_SkAlphaType != alphaType) { continue;
continue; }
}
// Skip kNonNative on different native scales. It won't be interestingly push_codec_src(path, mode, colorType, alphaType, 1.0f);
// different.
if (CodecSrc::kNonNative8888_Always_DstColorType == colorType && 1.0f != scale)
{
continue;
}
push_codec_src(path, mode, colorType, alphaType, scale); // Skip kNonNative on different native scales. It won't be interestingly
// different.
if (supportsNativeScaling &&
CodecSrc::kNonNative8888_Always_DstColorType == colorType) {
// Native Scales
// SkJpegCodec natively supports scaling to the following:
for (auto scale : { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f }) {
push_codec_src(path, mode, colorType, alphaType, scale);
}
} }
} }
} }