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" |
11 | 11 |
12 #include "Benchmark.h" | 12 #include "Benchmark.h" |
13 #include "BitmapRegionDecoderBench.h" | 13 #include "BitmapRegionDecoderBench.h" |
14 #include "CodecBench.h" | 14 #include "CodecBench.h" |
15 #include "CodecBenchPriv.h" | 15 #include "CodecBenchPriv.h" |
16 #include "CrashHandler.h" | 16 #include "CrashHandler.h" |
17 #include "DecodingBench.h" | 17 #include "DecodingBench.h" |
18 #include "GMBench.h" | 18 #include "GMBench.h" |
19 #include "ProcStats.h" | 19 #include "ProcStats.h" |
20 #include "ResultsWriter.h" | 20 #include "ResultsWriter.h" |
21 #include "RecordingBench.h" | 21 #include "RecordingBench.h" |
22 #include "SKPAnimationBench.h" | 22 #include "SKPAnimationBench.h" |
23 #include "SKPBench.h" | 23 #include "SKPBench.h" |
24 #include "SubsetSingleBench.h" | |
25 #include "SubsetTranslateBench.h" | |
26 #include "SubsetZoomBench.h" | |
27 #include "Stats.h" | 24 #include "Stats.h" |
28 | 25 |
29 #include "SkBitmapRegionDecoder.h" | 26 #include "SkBitmapRegionDecoder.h" |
30 #include "SkBBoxHierarchy.h" | 27 #include "SkBBoxHierarchy.h" |
31 #include "SkCanvas.h" | 28 #include "SkCanvas.h" |
32 #include "SkCodec.h" | 29 #include "SkCodec.h" |
33 #include "SkCommonFlags.h" | 30 #include "SkCommonFlags.h" |
34 #include "SkData.h" | 31 #include "SkData.h" |
35 #include "SkForceLinking.h" | 32 #include "SkForceLinking.h" |
36 #include "SkGraphics.h" | 33 #include "SkGraphics.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 break; | 496 break; |
500 } | 497 } |
501 | 498 |
502 if (!target->init(info, bench)) { | 499 if (!target->init(info, bench)) { |
503 delete target; | 500 delete target; |
504 return nullptr; | 501 return nullptr; |
505 } | 502 } |
506 return target; | 503 return target; |
507 } | 504 } |
508 | 505 |
509 /* | |
510 * We only run our subset benches on files that are supported by BitmapRegionDec
oder: | |
511 * i.e. PNG, JPEG, and WEBP. We do *not* test WEBP, since we do not have a scanl
ine | |
512 * decoder for WEBP, which is necessary for running the subset bench. (Another b
ench | |
513 * must be used to test WEBP, which decodes subsets natively.) | |
514 */ | |
515 static bool run_subset_bench(const SkString& path) { | |
516 static const char* const exts[] = { | |
517 "jpg", "jpeg", "png", | |
518 "JPG", "JPEG", "PNG", | |
519 }; | |
520 | |
521 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { | |
522 if (path.endsWith(exts[i])) { | |
523 return true; | |
524 } | |
525 } | |
526 | |
527 return false; | |
528 } | |
529 | |
530 /* | |
531 * Returns true if set up for a subset decode succeeds, false otherwise | |
532 * If the set-up succeeds, the width and height parameters will be set | |
533 */ | |
534 static bool valid_subset_bench(const SkString& path, SkColorType colorType, | |
535 int* width, int* height) { | |
536 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
537 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | |
538 | |
539 // Check that we can create a codec. | |
540 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | |
541 if (nullptr == codec) { | |
542 SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c_str
()); | |
543 return false; | |
544 } | |
545 | |
546 // These will be initialized by SkCodec if the color type is kIndex8 and | |
547 // unused otherwise. | |
548 SkPMColor colors[256]; | |
549 int colorCount; | |
550 const SkImageInfo info = codec->getInfo().makeColorType(colorType); | |
551 if (codec->startScanlineDecode(info, nullptr, colors, &colorCount) != SkCode
c::kSuccess) | |
552 { | |
553 SkDebugf("Could not create scanline decoder for %s with color type %s.
" | |
554 "Skipping bench.\n", path.c_str(), color_type_to_str(colorType))
; | |
555 return false; | |
556 } | |
557 *width = info.width(); | |
558 *height = info.height(); | |
559 | |
560 // Check if the image is large enough for a meaningful subset benchmark. | |
561 if (*width <= 512 && *height <= 512) { | |
562 // This should not print a message since it is not an error. | |
563 return false; | |
564 } | |
565 | |
566 return true; | |
567 } | |
568 | |
569 static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoder::Strategy str
ategy, | 506 static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoder::Strategy str
ategy, |
570 SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int*
width, | 507 SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int*
width, |
571 int* height) { | 508 int* height) { |
572 SkAutoTDelete<SkBitmapRegionDecoder> brd( | 509 SkAutoTDelete<SkBitmapRegionDecoder> brd( |
573 SkBitmapRegionDecoder::Create(encoded, strategy)); | 510 SkBitmapRegionDecoder::Create(encoded, strategy)); |
574 if (nullptr == brd.get()) { | 511 if (nullptr == brd.get()) { |
575 // This is indicates that subset decoding is not supported for a particu
lar image format. | 512 // This is indicates that subset decoding is not supported for a particu
lar image format. |
576 return false; | 513 return false; |
577 } | 514 } |
578 | 515 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 class BenchmarkStream { | 547 class BenchmarkStream { |
611 public: | 548 public: |
612 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 549 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
613 , fGMs(skiagm::GMRegistry::Head()) | 550 , fGMs(skiagm::GMRegistry::Head()) |
614 , fCurrentRecording(0) | 551 , fCurrentRecording(0) |
615 , fCurrentScale(0) | 552 , fCurrentScale(0) |
616 , fCurrentSKP(0) | 553 , fCurrentSKP(0) |
617 , fCurrentUseMPD(0) | 554 , fCurrentUseMPD(0) |
618 , fCurrentCodec(0) | 555 , fCurrentCodec(0) |
619 , fCurrentImage(0) | 556 , fCurrentImage(0) |
620 , fCurrentSubsetImage(0) | |
621 , fCurrentBRDImage(0) | 557 , fCurrentBRDImage(0) |
622 , fCurrentColorType(0) | 558 , fCurrentColorType(0) |
623 , fCurrentSubsetType(0) | 559 , fCurrentSubsetType(0) |
624 , fCurrentBRDStrategy(0) | 560 , fCurrentBRDStrategy(0) |
625 , fCurrentBRDSampleSize(0) | 561 , fCurrentBRDSampleSize(0) |
626 , fCurrentAnimSKP(0) { | 562 , fCurrentAnimSKP(0) { |
627 for (int i = 0; i < FLAGS_skps.count(); i++) { | 563 for (int i = 0; i < FLAGS_skps.count(); i++) { |
628 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 564 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
629 fSKPs.push_back() = FLAGS_skps[i]; | 565 fSKPs.push_back() = FLAGS_skps[i]; |
630 } else { | 566 } else { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, | 798 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
863 colorType, SkImageDecoder::kDecodePixels_Mode) | 799 colorType, SkImageDecoder::kDecodePixels_Mode) |
864 && bitmap.colorType() == colorType) { | 800 && bitmap.colorType() == colorType) { |
865 return new DecodingBench(path, colorType); | 801 return new DecodingBench(path, colorType); |
866 } | 802 } |
867 } | 803 } |
868 fCurrentColorType = 0; | 804 fCurrentColorType = 0; |
869 fCurrentImage++; | 805 fCurrentImage++; |
870 } | 806 } |
871 | 807 |
872 // Run the SubsetBenches | |
873 while (fCurrentSubsetImage < fImages.count()) { | |
874 fSourceType = "image"; | |
875 fBenchType = "skcodec"; | |
876 const SkString& path = fImages[fCurrentSubsetImage]; | |
877 if (!run_subset_bench(path)) { | |
878 fCurrentSubsetImage++; | |
879 continue; | |
880 } | |
881 while (fCurrentColorType < fColorTypes.count()) { | |
882 SkColorType colorType = fColorTypes[fCurrentColorType]; | |
883 while (fCurrentSubsetType <= kLast_SubsetType) { | |
884 int width = 0; | |
885 int height = 0; | |
886 int currentSubsetType = fCurrentSubsetType++; | |
887 if (valid_subset_bench(path, colorType, &width, &height)) { | |
888 switch (currentSubsetType) { | |
889 case kTopLeft_SubsetType: | |
890 return new SubsetSingleBench(path, colorType, wi
dth/3, | |
891 height/3, 0, 0); | |
892 case kTopRight_SubsetType: | |
893 return new SubsetSingleBench(path, colorType, wi
dth/3, | |
894 height/3, 2*width/3, 0); | |
895 case kMiddle_SubsetType: | |
896 return new SubsetSingleBench(path, colorType, wi
dth/3, | |
897 height/3, width/3, height/3); | |
898 case kBottomLeft_SubsetType: | |
899 return new SubsetSingleBench(path, colorType, wi
dth/3, | |
900 height/3, 0, 2*height/3); | |
901 case kBottomRight_SubsetType: | |
902 return new SubsetSingleBench(path, colorType, wi
dth/3, | |
903 height/3, 2*width/3, 2*height/3); | |
904 case kTranslate_SubsetType: | |
905 return new SubsetTranslateBench(path, colorType,
512, 512); | |
906 case kZoom_SubsetType: | |
907 return new SubsetZoomBench(path, colorType, 512,
512); | |
908 } | |
909 } else { | |
910 break; | |
911 } | |
912 } | |
913 fCurrentSubsetType = 0; | |
914 fCurrentColorType++; | |
915 } | |
916 fCurrentColorType = 0; | |
917 fCurrentSubsetImage++; | |
918 } | |
919 | |
920 // Run the BRDBenches | 808 // Run the BRDBenches |
921 // We will benchmark multiple BRD strategies. | 809 // We will benchmark multiple BRD strategies. |
922 static const struct { | 810 static const struct { |
923 SkBitmapRegionDecoder::Strategy fStrategy; | 811 SkBitmapRegionDecoder::Strategy fStrategy; |
924 const char* fName; | 812 const char* fName; |
925 } strategies[] = { | 813 } strategies[] = { |
926 { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" }, | 814 { SkBitmapRegionDecoder::kCanvas_Strategy, "BRD_canvas" }, |
927 { SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec"
}, | 815 { SkBitmapRegionDecoder::kAndroidCodec_Strategy, "BRD_android_codec"
}, |
928 }; | 816 }; |
929 | 817 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 double fSKPBytes, fSKPOps; | 955 double fSKPBytes, fSKPOps; |
1068 | 956 |
1069 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 957 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
1070 const char* fBenchType; // How we bench it: micro, recording, playback, ..
. | 958 const char* fBenchType; // How we bench it: micro, recording, playback, ..
. |
1071 int fCurrentRecording; | 959 int fCurrentRecording; |
1072 int fCurrentScale; | 960 int fCurrentScale; |
1073 int fCurrentSKP; | 961 int fCurrentSKP; |
1074 int fCurrentUseMPD; | 962 int fCurrentUseMPD; |
1075 int fCurrentCodec; | 963 int fCurrentCodec; |
1076 int fCurrentImage; | 964 int fCurrentImage; |
1077 int fCurrentSubsetImage; | |
1078 int fCurrentBRDImage; | 965 int fCurrentBRDImage; |
1079 int fCurrentColorType; | 966 int fCurrentColorType; |
1080 int fCurrentSubsetType; | 967 int fCurrentSubsetType; |
1081 int fCurrentBRDStrategy; | 968 int fCurrentBRDStrategy; |
1082 int fCurrentBRDSampleSize; | 969 int fCurrentBRDSampleSize; |
1083 int fCurrentAnimSKP; | 970 int fCurrentAnimSKP; |
1084 }; | 971 }; |
1085 | 972 |
1086 int nanobench_main(); | 973 int nanobench_main(); |
1087 int nanobench_main() { | 974 int nanobench_main() { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 | 1195 |
1309 return 0; | 1196 return 0; |
1310 } | 1197 } |
1311 | 1198 |
1312 #if !defined SK_BUILD_FOR_IOS | 1199 #if !defined SK_BUILD_FOR_IOS |
1313 int main(int argc, char** argv) { | 1200 int main(int argc, char** argv) { |
1314 SkCommandLineFlags::Parse(argc, argv); | 1201 SkCommandLineFlags::Parse(argc, argv); |
1315 return nanobench_main(); | 1202 return nanobench_main(); |
1316 } | 1203 } |
1317 #endif | 1204 #endif |
OLD | NEW |