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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 break; | 506 break; |
507 } | 507 } |
508 | 508 |
509 if (!target->init(info, bench)) { | 509 if (!target->init(info, bench)) { |
510 delete target; | 510 delete target; |
511 return nullptr; | 511 return nullptr; |
512 } | 512 } |
513 return target; | 513 return target; |
514 } | 514 } |
515 | 515 |
516 static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoder::Strategy str
ategy, | 516 static bool valid_brd_bench(SkData* encoded, SkColorType colorType, uint32_t sam
pleSize, |
517 SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int*
width, | 517 uint32_t minOutputSize, int* width, int* height) { |
518 int* height) { | |
519 SkAutoTDelete<SkBitmapRegionDecoder> brd( | 518 SkAutoTDelete<SkBitmapRegionDecoder> brd( |
520 SkBitmapRegionDecoder::Create(encoded, strategy)); | 519 SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndro
idCodec_Strategy)); |
521 if (nullptr == brd.get()) { | 520 if (nullptr == brd.get()) { |
522 // This is indicates that subset decoding is not supported for a particu
lar image format. | 521 // This is indicates that subset decoding is not supported for a particu
lar image format. |
523 return false; | 522 return false; |
524 } | 523 } |
525 | 524 |
526 SkBitmap bitmap; | |
527 if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, brd->width(
), brd->height()), | |
528 1, colorType, false)) { | |
529 return false; | |
530 } | |
531 | |
532 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * min
OutputSize > | 525 if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * min
OutputSize > |
533 (uint32_t) brd->height()) { | 526 (uint32_t) brd->height()) { |
534 // This indicates that the image is not large enough to decode a | 527 // This indicates that the image is not large enough to decode a |
535 // minOutputSize x minOutputSize subset at the given sampleSize. | 528 // minOutputSize x minOutputSize subset at the given sampleSize. |
536 return false; | 529 return false; |
537 } | 530 } |
538 | 531 |
539 // Set the image width and height. The calling code will use this to choose
subsets to decode. | 532 // Set the image width and height. The calling code will use this to choose
subsets to decode. |
540 *width = brd->width(); | 533 *width = brd->width(); |
541 *height = brd->height(); | 534 *height = brd->height(); |
(...skipping 19 matching lines...) Expand all Loading... |
561 , fCurrentRecording(0) | 554 , fCurrentRecording(0) |
562 , fCurrentScale(0) | 555 , fCurrentScale(0) |
563 , fCurrentSKP(0) | 556 , fCurrentSKP(0) |
564 , fCurrentUseMPD(0) | 557 , fCurrentUseMPD(0) |
565 , fCurrentCodec(0) | 558 , fCurrentCodec(0) |
566 , fCurrentAndroidCodec(0) | 559 , fCurrentAndroidCodec(0) |
567 , fCurrentBRDImage(0) | 560 , fCurrentBRDImage(0) |
568 , fCurrentColorType(0) | 561 , fCurrentColorType(0) |
569 , fCurrentAlphaType(0) | 562 , fCurrentAlphaType(0) |
570 , fCurrentSubsetType(0) | 563 , fCurrentSubsetType(0) |
571 , fCurrentBRDStrategy(0) | |
572 , fCurrentSampleSize(0) | 564 , fCurrentSampleSize(0) |
573 , fCurrentAnimSKP(0) { | 565 , fCurrentAnimSKP(0) { |
574 for (int i = 0; i < FLAGS_skps.count(); i++) { | 566 for (int i = 0; i < FLAGS_skps.count(); i++) { |
575 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 567 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
576 fSKPs.push_back() = FLAGS_skps[i]; | 568 fSKPs.push_back() = FLAGS_skps[i]; |
577 } else { | 569 } else { |
578 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 570 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
579 SkString path; | 571 SkString path; |
580 while (it.next(&path)) { | 572 while (it.next(&path)) { |
581 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); | 573 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // Avoid benchmarking scaled decodes of already small images
. | 827 // Avoid benchmarking scaled decodes of already small images
. |
836 break; | 828 break; |
837 } | 829 } |
838 | 830 |
839 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), e
ncoded, sampleSize); | 831 return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), e
ncoded, sampleSize); |
840 } | 832 } |
841 fCurrentSampleSize = 0; | 833 fCurrentSampleSize = 0; |
842 } | 834 } |
843 | 835 |
844 // Run the BRDBenches | 836 // Run the BRDBenches |
845 // We will benchmark multiple BRD strategies. | |
846 static const struct { | |
847 SkBitmapRegionDecoder::Strategy fStrategy; | |
848 const char* fName; | |
849 } strategies[] = { | |
850 { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" }, | |
851 { SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec"
}, | |
852 }; | |
853 | |
854 // We intend to create benchmarks that model the use cases in | 837 // We intend to create benchmarks that model the use cases in |
855 // android/libraries/social/tiledimage. In this library, an image is de
coded in 512x512 | 838 // android/libraries/social/tiledimage. In this library, an image is de
coded in 512x512 |
856 // tiles. The image can be translated freely, so the location of a tile
may be anywhere in | 839 // tiles. The image can be translated freely, so the location of a tile
may be anywhere in |
857 // the image. For that reason, we will benchmark decodes in five repres
entative locations | 840 // the image. For that reason, we will benchmark decodes in five repres
entative locations |
858 // in the image. Additionally, this use case utilizes power of two scal
ing, so we will | 841 // in the image. Additionally, this use case utilizes power of two scal
ing, so we will |
859 // test on power of two sample sizes. The output tile is always 512x512
, so, when a | 842 // test on power of two sample sizes. The output tile is always 512x512
, so, when a |
860 // sampleSize is used, the size of the subset that is decoded is always | 843 // sampleSize is used, the size of the subset that is decoded is always |
861 // (sampleSize*512)x(sampleSize*512). | 844 // (sampleSize*512)x(sampleSize*512). |
862 // There are a few good reasons to only test on power of two sample size
s at this time: | 845 // There are a few good reasons to only test on power of two sample size
s at this time: |
863 // All use cases we are aware of only scale by powers of two. | 846 // All use cases we are aware of only scale by powers of two. |
864 // PNG decodes use the indicated sampling strategy regardless of the
sample size, so | 847 // PNG decodes use the indicated sampling strategy regardless of the
sample size, so |
865 // these tests are sufficient to provide good coverage of our sc
aling options. | 848 // these tests are sufficient to provide good coverage of our sc
aling options. |
866 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; | 849 const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; |
867 const uint32_t minOutputSize = 512; | 850 const uint32_t minOutputSize = 512; |
868 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { | 851 for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { |
| 852 fSourceType = "image"; |
| 853 fBenchType = "BRD"; |
| 854 |
869 const SkString& path = fImages[fCurrentBRDImage]; | 855 const SkString& path = fImages[fCurrentBRDImage]; |
870 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { | 856 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
871 continue; | 857 continue; |
872 } | 858 } |
873 while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { | |
874 fSourceType = "image"; | |
875 fBenchType = strategies[fCurrentBRDStrategy].fName; | |
876 | 859 |
877 const SkBitmapRegionDecoder::Strategy strategy = | 860 while (fCurrentColorType < fColorTypes.count()) { |
878 strategies[fCurrentBRDStrategy].fStrategy; | 861 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)
) { |
| 862 while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
879 | 863 |
880 while (fCurrentColorType < fColorTypes.count()) { | 864 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(pat
h.c_str())); |
881 while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSi
zes)) { | 865 const SkColorType colorType = fColorTypes[fCurrentColorT
ype]; |
882 while (fCurrentSubsetType <= kLastSingle_SubsetType) { | 866 uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize]
; |
| 867 int currentSubsetType = fCurrentSubsetType++; |
883 | 868 |
884 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName
(path.c_str())); | 869 int width = 0; |
885 const SkColorType colorType = fColorTypes[fCurrentCo
lorType]; | 870 int height = 0; |
886 uint32_t sampleSize = brdSampleSizes[fCurrentSampleS
ize]; | 871 if (!valid_brd_bench(encoded.get(), colorType, sampleSiz
e, minOutputSize, |
887 int currentSubsetType = fCurrentSubsetType++; | 872 &width, &height)) { |
| 873 break; |
| 874 } |
888 | 875 |
889 int width = 0; | 876 SkString basename = SkOSPath::Basename(path.c_str()); |
890 int height = 0; | 877 SkIRect subset; |
891 if (!valid_brd_bench(encoded.get(), strategy, colorT
ype, sampleSize, | 878 const uint32_t subsetSize = sampleSize * minOutputSize; |
892 minOutputSize, &width, &height)) { | 879 switch (currentSubsetType) { |
| 880 case kTopLeft_SubsetType: |
| 881 basename.append("_TopLeft"); |
| 882 subset = SkIRect::MakeXYWH(0, 0, subsetSize, sub
setSize); |
893 break; | 883 break; |
894 } | 884 case kTopRight_SubsetType: |
| 885 basename.append("_TopRight"); |
| 886 subset = SkIRect::MakeXYWH(width - subsetSize, 0
, subsetSize, |
| 887 subsetSize); |
| 888 break; |
| 889 case kMiddle_SubsetType: |
| 890 basename.append("_Middle"); |
| 891 subset = SkIRect::MakeXYWH((width - subsetSize)
/ 2, |
| 892 (height - subsetSize) / 2, subsetSize, s
ubsetSize); |
| 893 break; |
| 894 case kBottomLeft_SubsetType: |
| 895 basename.append("_BottomLeft"); |
| 896 subset = SkIRect::MakeXYWH(0, height - subsetSiz
e, subsetSize, |
| 897 subsetSize); |
| 898 break; |
| 899 case kBottomRight_SubsetType: |
| 900 basename.append("_BottomRight"); |
| 901 subset = SkIRect::MakeXYWH(width - subsetSize, |
| 902 height - subsetSize, subsetSize, subsetS
ize); |
| 903 break; |
| 904 default: |
| 905 SkASSERT(false); |
| 906 } |
895 | 907 |
896 SkString basename = SkOSPath::Basename(path.c_str())
; | 908 return new BitmapRegionDecoderBench(basename.c_str(), en
coded.get(), |
897 SkIRect subset; | 909 colorType, sampleSize, subset); |
898 const uint32_t subsetSize = sampleSize * minOutputSi
ze; | |
899 switch (currentSubsetType) { | |
900 case kTopLeft_SubsetType: | |
901 basename.append("_TopLeft"); | |
902 subset = SkIRect::MakeXYWH(0, 0, subsetSize,
subsetSize); | |
903 break; | |
904 case kTopRight_SubsetType: | |
905 basename.append("_TopRight"); | |
906 subset = SkIRect::MakeXYWH(width - subsetSiz
e, 0, subsetSize, | |
907 subsetSize); | |
908 break; | |
909 case kMiddle_SubsetType: | |
910 basename.append("_Middle"); | |
911 subset = SkIRect::MakeXYWH((width - subsetSi
ze) / 2, | |
912 (height - subsetSize) / 2, subsetSiz
e, subsetSize); | |
913 break; | |
914 case kBottomLeft_SubsetType: | |
915 basename.append("_BottomLeft"); | |
916 subset = SkIRect::MakeXYWH(0, height - subse
tSize, subsetSize, | |
917 subsetSize); | |
918 break; | |
919 case kBottomRight_SubsetType: | |
920 basename.append("_BottomRight"); | |
921 subset = SkIRect::MakeXYWH(width - subsetSiz
e, | |
922 height - subsetSize, subsetSize, sub
setSize); | |
923 break; | |
924 default: | |
925 SkASSERT(false); | |
926 } | |
927 | |
928 return new BitmapRegionDecoderBench(basename.c_str()
, encoded.get(), | |
929 strategy, colorType, sampleSize, subset); | |
930 } | |
931 fCurrentSubsetType = 0; | |
932 fCurrentSampleSize++; | |
933 } | 910 } |
934 fCurrentSampleSize = 0; | 911 fCurrentSubsetType = 0; |
935 fCurrentColorType++; | 912 fCurrentSampleSize++; |
936 } | 913 } |
937 fCurrentColorType = 0; | 914 fCurrentSampleSize = 0; |
938 fCurrentBRDStrategy++; | 915 fCurrentColorType++; |
939 } | 916 } |
940 fCurrentBRDStrategy = 0; | 917 fCurrentColorType = 0; |
941 } | 918 } |
942 | 919 |
943 return nullptr; | 920 return nullptr; |
944 } | 921 } |
945 | 922 |
946 void fillCurrentOptions(ResultsWriter* log) const { | 923 void fillCurrentOptions(ResultsWriter* log) const { |
947 log->configOption("source_type", fSourceType); | 924 log->configOption("source_type", fSourceType); |
948 log->configOption("bench_type", fBenchType); | 925 log->configOption("bench_type", fBenchType); |
949 if (0 == strcmp(fSourceType, "skp")) { | 926 if (0 == strcmp(fSourceType, "skp")) { |
950 log->configOption("clip", | 927 log->configOption("clip", |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 int fCurrentRecording; | 971 int fCurrentRecording; |
995 int fCurrentScale; | 972 int fCurrentScale; |
996 int fCurrentSKP; | 973 int fCurrentSKP; |
997 int fCurrentUseMPD; | 974 int fCurrentUseMPD; |
998 int fCurrentCodec; | 975 int fCurrentCodec; |
999 int fCurrentAndroidCodec; | 976 int fCurrentAndroidCodec; |
1000 int fCurrentBRDImage; | 977 int fCurrentBRDImage; |
1001 int fCurrentColorType; | 978 int fCurrentColorType; |
1002 int fCurrentAlphaType; | 979 int fCurrentAlphaType; |
1003 int fCurrentSubsetType; | 980 int fCurrentSubsetType; |
1004 int fCurrentBRDStrategy; | |
1005 int fCurrentSampleSize; | 981 int fCurrentSampleSize; |
1006 int fCurrentAnimSKP; | 982 int fCurrentAnimSKP; |
1007 }; | 983 }; |
1008 | 984 |
1009 // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've
hung. | 985 // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've
hung. |
1010 // This prints something every once in a while so that it knows we're still work
ing. | 986 // This prints something every once in a while so that it knows we're still work
ing. |
1011 static void start_keepalive() { | 987 static void start_keepalive() { |
1012 struct Loop { | 988 struct Loop { |
1013 static void forever(void*) { | 989 static void forever(void*) { |
1014 for (;;) { | 990 for (;;) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 | 1259 |
1284 return 0; | 1260 return 0; |
1285 } | 1261 } |
1286 | 1262 |
1287 #if !defined SK_BUILD_FOR_IOS | 1263 #if !defined SK_BUILD_FOR_IOS |
1288 int main(int argc, char** argv) { | 1264 int main(int argc, char** argv) { |
1289 SkCommandLineFlags::Parse(argc, argv); | 1265 SkCommandLineFlags::Parse(argc, argv); |
1290 return nanobench_main(); | 1266 return nanobench_main(); |
1291 } | 1267 } |
1292 #endif | 1268 #endif |
OLD | NEW |