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 "CodecBench.h" | 13 #include "CodecBench.h" |
14 #include "CrashHandler.h" | 14 #include "CrashHandler.h" |
15 #include "DecodingBench.h" | 15 #include "DecodingBench.h" |
16 #include "DecodingSubsetBench.h" | |
17 #include "GMBench.h" | 16 #include "GMBench.h" |
18 #include "ProcStats.h" | 17 #include "ProcStats.h" |
19 #include "ResultsWriter.h" | 18 #include "ResultsWriter.h" |
20 #include "RecordingBench.h" | 19 #include "RecordingBench.h" |
21 #include "SKPAnimationBench.h" | 20 #include "SKPAnimationBench.h" |
22 #include "SKPBench.h" | 21 #include "SKPBench.h" |
22 #include "SubsetBenchPriv.h" | |
23 #include "SubsetDivisorBench.h" | |
24 #include "SubsetSingleBench.h" | |
25 #include "SubsetTranslateBench.h" | |
26 #include "SubsetZoomBench.h" | |
23 #include "Stats.h" | 27 #include "Stats.h" |
24 #include "Timer.h" | 28 #include "Timer.h" |
25 | 29 |
26 #include "SkBBoxHierarchy.h" | 30 #include "SkBBoxHierarchy.h" |
27 #include "SkCanvas.h" | 31 #include "SkCanvas.h" |
28 #include "SkCodec.h" | 32 #include "SkCodec.h" |
29 #include "SkCommonFlags.h" | 33 #include "SkCommonFlags.h" |
30 #include "SkData.h" | 34 #include "SkData.h" |
31 #include "SkForceLinking.h" | 35 #include "SkForceLinking.h" |
32 #include "SkGraphics.h" | 36 #include "SkGraphics.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, | 479 static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, |
476 const SkTDArray<Config>& configs) { | 480 const SkTDArray<Config>& configs) { |
477 for (int i = 0; i < configs.count(); ++i) { | 481 for (int i = 0; i < configs.count(); ++i) { |
478 if (Target* t = is_enabled(b, configs[i])) { | 482 if (Target* t = is_enabled(b, configs[i])) { |
479 targets->push(t); | 483 targets->push(t); |
480 } | 484 } |
481 | 485 |
482 } | 486 } |
483 } | 487 } |
484 | 488 |
489 /* | |
490 * Returns true if set up for a subset decode succeeds, false otherwise | |
491 * If the set-up succeeds, the width and height parameters will be set | |
492 */ | |
493 static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec, | |
494 int* width, int* height) { | |
495 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
496 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | |
497 | |
498 if (useCodec) { | |
499 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | |
500 if (NULL == codec) { | |
501 SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c _str()); | |
502 return false; | |
503 } | |
504 | |
505 // These will be initialized by SkCodec if the color type is kIndex8 and | |
506 // unused otherwise. | |
507 SkPMColor colors[256]; | |
508 int colorCount = 0; | |
scroggo
2015/06/08 18:06:42
Why did you use a colorCount of 0?
msarett
2015/06/08 23:40:47
SkCodec is required to initialize the colorCount i
| |
509 const SkImageInfo info = codec->getInfo().makeColorType(colorType); | |
510 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()) ); | |
511 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info, NUL L, | |
512 colors, &colorCount); | |
513 if (NULL == scanlineDecoder) { | |
514 SkDebugf("Could not create scanline decoder for %s with color type % s. " | |
515 "Skipping bench.\n", path.c_str(), get_color_name(colorType) ); | |
516 return false; | |
517 } | |
518 *width = info.width(); | |
519 *height = info.height(); | |
520 } else { | |
521 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); | |
522 if (NULL == decoder) { | |
523 SkDebugf("Could not create decoder for %s. Skipping bench.\n", path .c_str()); | |
524 return false; | |
525 } | |
526 if (!decoder->buildTileIndex(stream.detach(), width, height)) { | |
527 SkDebugf("Could not build tile index for %s. Skipping bench.\n", pa th.c_str()); | |
528 return false; | |
529 } | |
530 } | |
531 return true; | |
532 } | |
485 | 533 |
486 class BenchmarkStream { | 534 class BenchmarkStream { |
487 public: | 535 public: |
488 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 536 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
489 , fGMs(skiagm::GMRegistry::Head()) | 537 , fGMs(skiagm::GMRegistry::Head()) |
490 , fCurrentRecording(0) | 538 , fCurrentRecording(0) |
491 , fCurrentScale(0) | 539 , fCurrentScale(0) |
492 , fCurrentSKP(0) | 540 , fCurrentSKP(0) |
493 , fCurrentUseMPD(0) | 541 , fCurrentUseMPD(0) |
494 , fCurrentCodec(0) | 542 , fCurrentCodec(0) |
495 , fCurrentImage(0) | 543 , fCurrentImage(0) |
496 , fCurrentSubsetImage(0) | 544 , fCurrentSubsetImage(0) |
497 , fCurrentColorType(0) | 545 , fCurrentColorType(0) |
498 , fCurrentAnimSKP(0) | 546 , fCurrentSubsetType(0) |
499 , fDivisor(2) { | 547 , fUseCodec(0) |
548 , fCurrentAnimSKP(0) { | |
500 for (int i = 0; i < FLAGS_skps.count(); i++) { | 549 for (int i = 0; i < FLAGS_skps.count(); i++) { |
501 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 550 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
502 fSKPs.push_back() = FLAGS_skps[i]; | 551 fSKPs.push_back() = FLAGS_skps[i]; |
503 } else { | 552 } else { |
504 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 553 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
505 SkString path; | 554 SkString path; |
506 while (it.next(&path)) { | 555 while (it.next(&path)) { |
507 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | 556 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); |
508 } | 557 } |
509 } | 558 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); | 592 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); |
544 } | 593 } |
545 } else if (sk_exists(flag)) { | 594 } else if (sk_exists(flag)) { |
546 // Also add the value if it is a single image | 595 // Also add the value if it is a single image |
547 fImages.push_back() = flag; | 596 fImages.push_back() = flag; |
548 } | 597 } |
549 } | 598 } |
550 | 599 |
551 // Choose the candidate color types for image decoding | 600 // Choose the candidate color types for image decoding |
552 const SkColorType colorTypes[] = | 601 const SkColorType colorTypes[] = |
553 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType, kInd ex_8_SkColorType }; | 602 { kN32_SkColorType, |
603 kRGB_565_SkColorType, | |
604 kAlpha_8_SkColorType, | |
605 kIndex_8_SkColorType, | |
606 kGray_8_SkColorType }; | |
554 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); | 607 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); |
555 } | 608 } |
556 | 609 |
557 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | 610 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
558 // Not strictly necessary, as it will be checked again later, | 611 // Not strictly necessary, as it will be checked again later, |
559 // but helps to avoid a lot of pointless work if we're going to skip it. | 612 // but helps to avoid a lot of pointless work if we're going to skip it. |
560 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | 613 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
561 return false; | 614 return false; |
562 } | 615 } |
563 | 616 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, | 783 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
731 colorType, SkImageDecoder::kDecodePixels_Mode) | 784 colorType, SkImageDecoder::kDecodePixels_Mode) |
732 && bitmap.colorType() == colorType) { | 785 && bitmap.colorType() == colorType) { |
733 return new DecodingBench(path, colorType); | 786 return new DecodingBench(path, colorType); |
734 } | 787 } |
735 } | 788 } |
736 fCurrentColorType = 0; | 789 fCurrentColorType = 0; |
737 fCurrentImage++; | 790 fCurrentImage++; |
738 } | 791 } |
739 | 792 |
740 // Run the DecodingSubsetBenches | 793 // Run the SubsetBenches |
741 while (fCurrentSubsetImage < fImages.count()) { | 794 bool useCodecOpts[] = { true, false }; |
742 while (fCurrentColorType < fColorTypes.count()) { | 795 while (fUseCodec < 2) { |
743 const SkString& path = fImages[fCurrentSubsetImage]; | 796 bool useCodec = useCodecOpts[fUseCodec]; |
744 SkColorType colorType = fColorTypes[fCurrentColorType]; | 797 while (fCurrentSubsetImage < fImages.count()) { |
745 fCurrentColorType++; | 798 while (fCurrentColorType < fColorTypes.count()) { |
746 // Check if the image decodes before creating the benchmark | 799 const SkString& path = fImages[fCurrentSubsetImage]; |
747 SkAutoTUnref<SkData> encoded( | 800 SkColorType colorType = fColorTypes[fCurrentColorType]; |
748 SkData::NewFromFileName(path.c_str())); | 801 while (fCurrentSubsetType <= kLast_SubsetType) { |
749 SkAutoTDelete<SkMemoryStream> stream( | 802 int width = 0; |
750 new SkMemoryStream(encoded)); | 803 int height = 0; |
751 SkAutoTDelete<SkImageDecoder> | 804 int currentSubsetType = fCurrentSubsetType++; |
752 decoder(SkImageDecoder::Factory(stream.get())); | 805 if (valid_subset_bench(path, colorType, useCodec, &width , &height)) { |
753 if (!decoder) { | 806 switch (currentSubsetType) { |
754 SkDebugf("Cannot find decoder for %s\n", path.c_str()); | 807 case kTopLeft_SubsetType: |
755 } else { | 808 return new SubsetSingleBench(path, colorType , width/2, |
756 stream->rewind(); | 809 height/2, 0, 0, useCodec); |
757 int w, h; | 810 case kTopRight_SubsetType: |
758 bool success; | 811 return new SubsetSingleBench(path, colorType , width/2, |
759 if (!decoder->buildTileIndex(stream.detach(), &w, &h) | 812 height/2, width/2, 0, useCodec); |
760 || w*h == 1) { | 813 case kBottomLeft_SubsetType: |
761 // This is not an error, but in this case we still | 814 return new SubsetSingleBench(path, colorType , width/2, |
762 // do not want to run the benchmark. | 815 height/2, 0, height/2, useCodec); |
763 success = false; | 816 case kBottomRight_SubsetType: |
764 } else if (fDivisor > w || fDivisor > h) { | 817 return new SubsetSingleBench(path, colorType , width/2, |
765 SkDebugf("Divisor %d is too big for %s %dx%d\n", | 818 height/2, width/2, height/2, useCode c); |
766 fDivisor, path.c_str(), w, h); | 819 case k2x2_SubsetType: |
767 success = false; | 820 return new SubsetDivisorBench(path, colorTyp e, 2, useCodec); |
768 } else { | 821 case k3x3_SubsetType: |
769 const int sW = w / fDivisor; | 822 return new SubsetDivisorBench(path, colorTyp e, 3, useCodec); |
770 const int sH = h / fDivisor; | 823 case kTranslate_SubsetType: |
771 SkBitmap bitmap; | 824 return new SubsetTranslateBench(path, colorT ype, 512, 512, |
772 success = true; | 825 useCodec); |
773 for (int y = 0; y < h; y += sH) { | 826 case kZoom_SubsetType: |
774 for (int x = 0; x < w; x += sW) { | 827 return new SubsetZoomBench(path, colorType, 512, 512, |
775 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); | 828 useCodec); |
776 success &= decoder->decodeSubset(&bitmap, rect, | |
777 colorType); | |
778 } | 829 } |
830 } else { | |
831 break; | |
779 } | 832 } |
780 } | 833 } |
781 // Create the benchmark if successful | 834 fCurrentSubsetType = 0; |
782 if (success) { | 835 fCurrentColorType++; |
783 return new DecodingSubsetBench(path, colorType, | |
784 fDivisor); | |
785 } | |
786 } | 836 } |
837 fCurrentColorType = 0; | |
838 fCurrentSubsetImage++; | |
787 } | 839 } |
788 fCurrentColorType = 0; | 840 fCurrentSubsetImage = 0; |
789 fCurrentSubsetImage++; | 841 fUseCodec++; |
790 } | 842 } |
791 | 843 |
792 return NULL; | 844 return NULL; |
793 } | 845 } |
794 | 846 |
795 void fillCurrentOptions(ResultsWriter* log) const { | 847 void fillCurrentOptions(ResultsWriter* log) const { |
796 log->configOption("source_type", fSourceType); | 848 log->configOption("source_type", fSourceType); |
797 log->configOption("bench_type", fBenchType); | 849 log->configOption("bench_type", fBenchType); |
798 if (0 == strcmp(fSourceType, "skp")) { | 850 if (0 == strcmp(fSourceType, "skp")) { |
799 log->configOption("clip", | 851 log->configOption("clip", |
800 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 852 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
801 fClip.fRight, fClip.fBottom).c _str()); | 853 fClip.fRight, fClip.fBottom).c _str()); |
802 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); | 854 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); |
803 if (fCurrentUseMPD > 0) { | 855 if (fCurrentUseMPD > 0) { |
804 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); | 856 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
805 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); | 857 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); |
806 } | 858 } |
807 } | 859 } |
808 if (0 == strcmp(fBenchType, "recording")) { | 860 if (0 == strcmp(fBenchType, "recording")) { |
809 log->metric("bytes", fSKPBytes); | 861 log->metric("bytes", fSKPBytes); |
810 log->metric("ops", fSKPOps); | 862 log->metric("ops", fSKPOps); |
811 } | 863 } |
812 } | 864 } |
813 | 865 |
814 private: | 866 private: |
867 enum SubsetType { | |
868 kTopLeft_SubsetType = 0, | |
869 kTopRight_SubsetType = 1, | |
870 kBottomLeft_SubsetType = 2, | |
871 kBottomRight_SubsetType = 3, | |
872 k2x2_SubsetType = 4, | |
873 k3x3_SubsetType = 5, | |
874 kTranslate_SubsetType = 6, | |
875 kZoom_SubsetType = 7, | |
876 kLast_SubsetType = kZoom_SubsetType | |
877 }; | |
878 | |
815 const BenchRegistry* fBenches; | 879 const BenchRegistry* fBenches; |
816 const skiagm::GMRegistry* fGMs; | 880 const skiagm::GMRegistry* fGMs; |
817 SkIRect fClip; | 881 SkIRect fClip; |
818 SkTArray<SkScalar> fScales; | 882 SkTArray<SkScalar> fScales; |
819 SkTArray<SkString> fSKPs; | 883 SkTArray<SkString> fSKPs; |
820 SkTArray<bool> fUseMPDs; | 884 SkTArray<bool> fUseMPDs; |
821 SkTArray<SkString> fImages; | 885 SkTArray<SkString> fImages; |
822 SkTArray<SkColorType> fColorTypes; | 886 SkTArray<SkColorType> fColorTypes; |
823 SkScalar fZoomScale; | 887 SkScalar fZoomScale; |
824 int fZoomSteps; | 888 int fZoomSteps; |
825 | 889 |
826 double fSKPBytes, fSKPOps; | 890 double fSKPBytes, fSKPOps; |
827 | 891 |
828 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 892 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
829 const char* fBenchType; // How we bench it: micro, recording, playback, .. . | 893 const char* fBenchType; // How we bench it: micro, recording, playback, .. . |
830 int fCurrentRecording; | 894 int fCurrentRecording; |
831 int fCurrentScale; | 895 int fCurrentScale; |
832 int fCurrentSKP; | 896 int fCurrentSKP; |
833 int fCurrentUseMPD; | 897 int fCurrentUseMPD; |
834 int fCurrentCodec; | 898 int fCurrentCodec; |
835 int fCurrentImage; | 899 int fCurrentImage; |
836 int fCurrentSubsetImage; | 900 int fCurrentSubsetImage; |
837 int fCurrentColorType; | 901 int fCurrentColorType; |
902 int fCurrentSubsetType; | |
903 int fUseCodec; | |
838 int fCurrentAnimSKP; | 904 int fCurrentAnimSKP; |
839 const int fDivisor; | |
840 }; | 905 }; |
841 | 906 |
842 int nanobench_main(); | 907 int nanobench_main(); |
843 int nanobench_main() { | 908 int nanobench_main() { |
844 SetupCrashHandler(); | 909 SetupCrashHandler(); |
845 SkAutoGraphics ag; | 910 SkAutoGraphics ag; |
846 SkTaskGroup::Enabler enabled; | 911 SkTaskGroup::Enabler enabled; |
847 | 912 |
848 #if SK_SUPPORT_GPU | 913 #if SK_SUPPORT_GPU |
849 GrContextOptions grContextOpts; | 914 GrContextOptions grContextOpts; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 | 1093 |
1029 return 0; | 1094 return 0; |
1030 } | 1095 } |
1031 | 1096 |
1032 #if !defined SK_BUILD_FOR_IOS | 1097 #if !defined SK_BUILD_FOR_IOS |
1033 int main(int argc, char** argv) { | 1098 int main(int argc, char** argv) { |
1034 SkCommandLineFlags::Parse(argc, argv); | 1099 SkCommandLineFlags::Parse(argc, argv); |
1035 return nanobench_main(); | 1100 return nanobench_main(); |
1036 } | 1101 } |
1037 #endif | 1102 #endif |
OLD | NEW |