Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <ctype.h> | 8 #include <ctype.h> |
| 9 | 9 |
| 10 #include "nanobench.h" | 10 #include "nanobench.h" |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 } | 494 } |
| 495 | 495 |
| 496 if (!target->init(info, bench)) { | 496 if (!target->init(info, bench)) { |
| 497 delete target; | 497 delete target; |
| 498 return nullptr; | 498 return nullptr; |
| 499 } | 499 } |
| 500 return target; | 500 return target; |
| 501 } | 501 } |
| 502 | 502 |
| 503 /* | 503 /* |
| 504 * We only run our subset benches on files that are supported by BitmapRegionDec oder: | |
| 505 * i.e. PNG, JPEG, and WEBP. We do *not* test WEBP when using codec, since we do not | |
| 506 * have a scanline decoder for WEBP, which is necessary for running the subset b ench. | |
| 507 * (Another bench must be used to test WEBP, which decodes subsets natively.) | |
| 508 */ | |
| 509 static bool run_subset_bench(const SkString& path, bool useCodec) { | |
| 510 static const char* const exts[] = { | |
| 511 "jpg", "jpeg", "png", | |
| 512 "JPG", "JPEG", "PNG", | |
| 513 }; | |
| 514 | |
| 515 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { | |
| 516 if (path.endsWith(exts[i])) { | |
| 517 return true; | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 return !useCodec && (path.endsWith("webp") || path.endsWith("WEBP")); | |
|
msarett
2015/10/07 20:06:08
It occurs to me that we've done very little to ben
scroggo
2015/10/07 20:09:10
Yes. I do think it's worth benchmarking in general
| |
| 522 } | |
| 523 | |
| 524 /* | |
| 504 * Returns true if set up for a subset decode succeeds, false otherwise | 525 * Returns true if set up for a subset decode succeeds, false otherwise |
| 505 * If the set-up succeeds, the width and height parameters will be set | 526 * If the set-up succeeds, the width and height parameters will be set |
| 506 */ | 527 */ |
| 507 static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec, | 528 static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec, |
| 508 int* width, int* height) { | 529 int* width, int* height) { |
| 509 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 530 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 510 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 531 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
| 511 | 532 |
| 512 // Check that we can create a codec or image decoder. | 533 // Check that we can create a codec or image decoder. |
| 513 if (useCodec) { | 534 if (useCodec) { |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 } | 881 } |
| 861 fCurrentColorType = 0; | 882 fCurrentColorType = 0; |
| 862 fCurrentImage++; | 883 fCurrentImage++; |
| 863 } | 884 } |
| 864 | 885 |
| 865 // Run the SubsetBenches | 886 // Run the SubsetBenches |
| 866 bool useCodecOpts[] = { true, false }; | 887 bool useCodecOpts[] = { true, false }; |
| 867 while (fUseCodec < 2) { | 888 while (fUseCodec < 2) { |
| 868 bool useCodec = useCodecOpts[fUseCodec]; | 889 bool useCodec = useCodecOpts[fUseCodec]; |
| 869 while (fCurrentSubsetImage < fImages.count()) { | 890 while (fCurrentSubsetImage < fImages.count()) { |
| 891 const SkString& path = fImages[fCurrentSubsetImage]; | |
| 892 if (!run_subset_bench(path, useCodec)) { | |
| 893 fCurrentSubsetImage++; | |
| 894 continue; | |
| 895 } | |
| 870 while (fCurrentColorType < fColorTypes.count()) { | 896 while (fCurrentColorType < fColorTypes.count()) { |
| 871 const SkString& path = fImages[fCurrentSubsetImage]; | |
| 872 SkColorType colorType = fColorTypes[fCurrentColorType]; | 897 SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 873 while (fCurrentSubsetType <= kLast_SubsetType) { | 898 while (fCurrentSubsetType <= kLast_SubsetType) { |
| 874 int width = 0; | 899 int width = 0; |
| 875 int height = 0; | 900 int height = 0; |
| 876 int currentSubsetType = fCurrentSubsetType++; | 901 int currentSubsetType = fCurrentSubsetType++; |
| 877 if (valid_subset_bench(path, colorType, useCodec, &width , &height)) { | 902 if (valid_subset_bench(path, colorType, useCodec, &width , &height)) { |
| 878 switch (currentSubsetType) { | 903 switch (currentSubsetType) { |
| 879 case kTopLeft_SubsetType: | 904 case kTopLeft_SubsetType: |
| 880 return new SubsetSingleBench(path, colorType , width/3, | 905 return new SubsetSingleBench(path, colorType , width/3, |
| 881 height/3, 0, 0, useCodec); | 906 height/3, 0, 0, useCodec); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1292 | 1317 |
| 1293 return 0; | 1318 return 0; |
| 1294 } | 1319 } |
| 1295 | 1320 |
| 1296 #if !defined SK_BUILD_FOR_IOS | 1321 #if !defined SK_BUILD_FOR_IOS |
| 1297 int main(int argc, char** argv) { | 1322 int main(int argc, char** argv) { |
| 1298 SkCommandLineFlags::Parse(argc, argv); | 1323 SkCommandLineFlags::Parse(argc, argv); |
| 1299 return nanobench_main(); | 1324 return nanobench_main(); |
| 1300 } | 1325 } |
| 1301 #endif | 1326 #endif |
| OLD | NEW |