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" | |
scroggo
2015/06/02 13:45:57
If this is no longer used, can we remove this clas
msarett
2015/06/02 17:14:10
Done.
| |
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 "SubsetDivisorBench.h" | |
23 #include "SubsetSingleBench.h" | |
24 #include "SubsetTranslateBench.h" | |
25 #include "SubsetZoomBench.h" | |
23 #include "Stats.h" | 26 #include "Stats.h" |
24 #include "Timer.h" | 27 #include "Timer.h" |
25 | 28 |
26 #include "SkBBoxHierarchy.h" | 29 #include "SkBBoxHierarchy.h" |
27 #include "SkCanvas.h" | 30 #include "SkCanvas.h" |
28 #include "SkCodec.h" | 31 #include "SkCodec.h" |
29 #include "SkCommonFlags.h" | 32 #include "SkCommonFlags.h" |
30 #include "SkData.h" | 33 #include "SkData.h" |
31 #include "SkForceLinking.h" | 34 #include "SkForceLinking.h" |
32 #include "SkGraphics.h" | 35 #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, | 478 static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, |
476 const SkTDArray<Config>& configs) { | 479 const SkTDArray<Config>& configs) { |
477 for (int i = 0; i < configs.count(); ++i) { | 480 for (int i = 0; i < configs.count(); ++i) { |
478 if (Target* t = is_enabled(b, configs[i])) { | 481 if (Target* t = is_enabled(b, configs[i])) { |
479 targets->push(t); | 482 targets->push(t); |
480 } | 483 } |
481 | 484 |
482 } | 485 } |
483 } | 486 } |
484 | 487 |
488 /* | |
489 * Returns true if set up for a subset decode succeeds, false otherwise | |
490 * If the set-up succeeds, the width and height parameters will be set | |
491 */ | |
492 static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec, | |
493 int* width, int* height) { | |
494 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
495 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | |
496 | |
497 if (useCodec) { | |
498 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | |
499 if (NULL == codec) { | |
500 SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c _str()); | |
501 return false; | |
502 } | |
503 | |
504 const SkImageInfo info = codec->getInfo(); | |
scroggo
2015/06/02 13:45:57
don't we need to convert to colorType?
msarett
2015/06/02 17:14:10
Done.
| |
505 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()) ); | |
506 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); | |
507 if (NULL == scanlineDecoder) { | |
508 SkDebugf("Could not create scanline decoder for %s. Skipping bench. \n", path.c_str()); | |
scroggo
2015/06/02 13:45:57
We might want to also report the colortype, since
msarett
2015/06/02 17:14:10
Done.
| |
509 return false; | |
510 } | |
511 *width = info.width(); | |
512 *height = info.height(); | |
513 } else { | |
514 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.det ach())); | |
scroggo
2015/06/02 13:45:57
For legacy reasons, SkImageDecoder::Factory does n
msarett
2015/06/02 17:14:10
Nice catch, thanks!
| |
515 if (NULL == decoder) { | |
516 SkDebugf("Could not create decoder for %s. Skipping bench.\n", path .c_str()); | |
517 return false; | |
518 } | |
519 if (!decoder->buildTileIndex(stream->duplicate(), width, height)) { | |
520 SkDebugf("Could not build tile index for %s. Skipping bench.\n", pa th.c_str()); | |
521 return false; | |
522 } | |
523 } | |
524 return true; | |
525 } | |
485 | 526 |
486 class BenchmarkStream { | 527 class BenchmarkStream { |
487 public: | 528 public: |
488 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 529 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
489 , fGMs(skiagm::GMRegistry::Head()) | 530 , fGMs(skiagm::GMRegistry::Head()) |
490 , fCurrentRecording(0) | 531 , fCurrentRecording(0) |
491 , fCurrentScale(0) | 532 , fCurrentScale(0) |
492 , fCurrentSKP(0) | 533 , fCurrentSKP(0) |
493 , fCurrentUseMPD(0) | 534 , fCurrentUseMPD(0) |
494 , fCurrentCodec(0) | 535 , fCurrentCodec(0) |
495 , fCurrentImage(0) | 536 , fCurrentImage(0) |
496 , fCurrentSubsetImage(0) | 537 , fCurrentSubsetImage(0) |
497 , fCurrentColorType(0) | 538 , fCurrentColorType(0) |
539 , fCurrentSubsetType(0) | |
498 , fCurrentAnimSKP(0) | 540 , fCurrentAnimSKP(0) |
499 , fDivisor(2) { | 541 , fUseCodec(true) { |
500 for (int i = 0; i < FLAGS_skps.count(); i++) { | 542 for (int i = 0; i < FLAGS_skps.count(); i++) { |
501 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 543 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
502 fSKPs.push_back() = FLAGS_skps[i]; | 544 fSKPs.push_back() = FLAGS_skps[i]; |
503 } else { | 545 } else { |
504 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 546 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
505 SkString path; | 547 SkString path; |
506 while (it.next(&path)) { | 548 while (it.next(&path)) { |
507 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | 549 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); |
508 } | 550 } |
509 } | 551 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, | 772 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
731 colorType, SkImageDecoder::kDecodePixels_Mode) | 773 colorType, SkImageDecoder::kDecodePixels_Mode) |
732 && bitmap.colorType() == colorType) { | 774 && bitmap.colorType() == colorType) { |
733 return new DecodingBench(path, colorType); | 775 return new DecodingBench(path, colorType); |
734 } | 776 } |
735 } | 777 } |
736 fCurrentColorType = 0; | 778 fCurrentColorType = 0; |
737 fCurrentImage++; | 779 fCurrentImage++; |
738 } | 780 } |
739 | 781 |
740 // Run the DecodingSubsetBenches | 782 // Reset the SubsetBenches for ImageDecoder after they have run for Code c |
783 if (fCurrentSubsetImage == fImages.count() && fCurrentColorType == fColo rTypes.count() && | |
784 fCurrentSubsetType > kLast_SubsetType && fUseCodec) { | |
785 fUseCodec = false; | |
786 fCurrentSubsetImage = 0; | |
787 fCurrentColorType = 0; | |
788 fCurrentSubsetType = 0; | |
789 } | |
790 | |
791 // Run the SubsetBenches | |
741 while (fCurrentSubsetImage < fImages.count()) { | 792 while (fCurrentSubsetImage < fImages.count()) { |
742 while (fCurrentColorType < fColorTypes.count()) { | 793 while (fCurrentColorType < fColorTypes.count()) { |
743 const SkString& path = fImages[fCurrentSubsetImage]; | 794 const SkString& path = fImages[fCurrentSubsetImage]; |
744 SkColorType colorType = fColorTypes[fCurrentColorType]; | 795 SkColorType colorType = fColorTypes[fCurrentColorType]; |
745 fCurrentColorType++; | 796 while (fCurrentSubsetType <= kLast_SubsetType) { |
746 // Check if the image decodes before creating the benchmark | 797 int width = 0; |
747 SkAutoTUnref<SkData> encoded( | 798 int height = 0; |
748 SkData::NewFromFileName(path.c_str())); | 799 if (valid_subset_bench(path, colorType, fUseCodec, &width, & height)) { |
749 SkAutoTDelete<SkMemoryStream> stream( | 800 int currentSubsetType = fCurrentSubsetType++; |
scroggo
2015/06/02 13:45:57
nit: 4 space indent
msarett
2015/06/02 17:14:10
Done.
| |
750 new SkMemoryStream(encoded)); | 801 switch (currentSubsetType) { |
751 SkAutoTDelete<SkImageDecoder> | 802 case kTopLeft_SubsetType: |
752 decoder(SkImageDecoder::Factory(stream.get())); | 803 return new SubsetSingleBench(path, colorType, widt h/2, height/2, |
753 if (!decoder) { | 804 0, 0, fUseCodec); |
754 SkDebugf("Cannot find decoder for %s\n", path.c_str()); | 805 case kTopRight_SubsetType: |
755 } else { | 806 return new SubsetSingleBench(path, colorType, widt h/2, height/2, |
756 stream->rewind(); | 807 width/2, 0, fUseCodec); |
757 int w, h; | 808 case kBottomLeft_SubsetType: |
758 bool success; | 809 return new SubsetSingleBench(path, colorType, widt h/2, height/2, |
759 if (!decoder->buildTileIndex(stream.detach(), &w, &h) | 810 0, height/2, fUseCodec); |
760 || w*h == 1) { | 811 case kBottomRight_SubsetType: |
761 // This is not an error, but in this case we still | 812 return new SubsetSingleBench(path, colorType, widt h/2, height/2, |
762 // do not want to run the benchmark. | 813 0, 0, fUseCodec); |
763 success = false; | 814 case k2x2_SubsetType: |
764 } else if (fDivisor > w || fDivisor > h) { | 815 return new SubsetDivisorBench(path, colorType, 2, fUseCodec); |
765 SkDebugf("Divisor %d is too big for %s %dx%d\n", | 816 case k3x3_SubsetType: |
766 fDivisor, path.c_str(), w, h); | 817 return new SubsetDivisorBench(path, colorType, 3, fUseCodec); |
767 success = false; | 818 case kTranslate_SubsetType: |
819 return new SubsetTranslateBench(path, colorType, 5 12, 512, fUseCodec); | |
820 case kZoom_SubsetType: | |
821 return new SubsetZoomBench(path, colorType, 512, 5 12, fUseCodec); | |
822 } | |
768 } else { | 823 } else { |
769 const int sW = w / fDivisor; | 824 fCurrentSubsetType = 0; |
scroggo
2015/06/02 13:45:57
Don't we need to reset this when we reach kLast_Su
msarett
2015/06/02 17:14:10
Yes for sure! It appears I should have tested thi
| |
770 const int sH = h / fDivisor; | 825 break; |
771 SkBitmap bitmap; | |
772 success = true; | |
773 for (int y = 0; y < h; y += sH) { | |
774 for (int x = 0; x < w; x += sW) { | |
775 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); | |
776 success &= decoder->decodeSubset(&bitmap, rect, | |
777 colorType); | |
778 } | |
779 } | |
780 } | |
781 // Create the benchmark if successful | |
782 if (success) { | |
783 return new DecodingSubsetBench(path, colorType, | |
784 fDivisor); | |
785 } | 826 } |
786 } | 827 } |
828 fCurrentColorType++; | |
787 } | 829 } |
788 fCurrentColorType = 0; | 830 fCurrentColorType = 0; |
789 fCurrentSubsetImage++; | 831 fCurrentSubsetImage++; |
790 } | 832 } |
791 | 833 |
792 return NULL; | 834 return NULL; |
793 } | 835 } |
794 | 836 |
795 void fillCurrentOptions(ResultsWriter* log) const { | 837 void fillCurrentOptions(ResultsWriter* log) const { |
796 log->configOption("source_type", fSourceType); | 838 log->configOption("source_type", fSourceType); |
797 log->configOption("bench_type", fBenchType); | 839 log->configOption("bench_type", fBenchType); |
798 if (0 == strcmp(fSourceType, "skp")) { | 840 if (0 == strcmp(fSourceType, "skp")) { |
799 log->configOption("clip", | 841 log->configOption("clip", |
800 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 842 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
801 fClip.fRight, fClip.fBottom).c _str()); | 843 fClip.fRight, fClip.fBottom).c _str()); |
802 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); | 844 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); |
803 if (fCurrentUseMPD > 0) { | 845 if (fCurrentUseMPD > 0) { |
804 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); | 846 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
805 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); | 847 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); |
806 } | 848 } |
807 } | 849 } |
808 if (0 == strcmp(fBenchType, "recording")) { | 850 if (0 == strcmp(fBenchType, "recording")) { |
809 log->metric("bytes", fSKPBytes); | 851 log->metric("bytes", fSKPBytes); |
810 log->metric("ops", fSKPOps); | 852 log->metric("ops", fSKPOps); |
811 } | 853 } |
812 } | 854 } |
813 | 855 |
814 private: | 856 private: |
857 enum SubsetType { | |
858 kTopLeft_SubsetType = 0, | |
859 kTopRight_SubsetType = 1, | |
860 kBottomLeft_SubsetType = 2, | |
861 kBottomRight_SubsetType = 3, | |
862 k2x2_SubsetType = 4, | |
863 k3x3_SubsetType = 5, | |
864 kTranslate_SubsetType = 6, | |
865 kZoom_SubsetType = 7, | |
866 kLast_SubsetType = kZoom_SubsetType | |
867 }; | |
868 | |
815 const BenchRegistry* fBenches; | 869 const BenchRegistry* fBenches; |
816 const skiagm::GMRegistry* fGMs; | 870 const skiagm::GMRegistry* fGMs; |
817 SkIRect fClip; | 871 SkIRect fClip; |
818 SkTArray<SkScalar> fScales; | 872 SkTArray<SkScalar> fScales; |
819 SkTArray<SkString> fSKPs; | 873 SkTArray<SkString> fSKPs; |
820 SkTArray<bool> fUseMPDs; | 874 SkTArray<bool> fUseMPDs; |
821 SkTArray<SkString> fImages; | 875 SkTArray<SkString> fImages; |
822 SkTArray<SkColorType> fColorTypes; | 876 SkTArray<SkColorType> fColorTypes; |
823 SkScalar fZoomScale; | 877 SkScalar fZoomScale; |
824 int fZoomSteps; | 878 int fZoomSteps; |
825 | 879 |
826 double fSKPBytes, fSKPOps; | 880 double fSKPBytes, fSKPOps; |
827 | 881 |
828 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 882 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
829 const char* fBenchType; // How we bench it: micro, recording, playback, .. . | 883 const char* fBenchType; // How we bench it: micro, recording, playback, .. . |
830 int fCurrentRecording; | 884 int fCurrentRecording; |
831 int fCurrentScale; | 885 int fCurrentScale; |
832 int fCurrentSKP; | 886 int fCurrentSKP; |
833 int fCurrentUseMPD; | 887 int fCurrentUseMPD; |
834 int fCurrentCodec; | 888 int fCurrentCodec; |
835 int fCurrentImage; | 889 int fCurrentImage; |
836 int fCurrentSubsetImage; | 890 int fCurrentSubsetImage; |
837 int fCurrentColorType; | 891 int fCurrentColorType; |
892 int fCurrentSubsetType; | |
838 int fCurrentAnimSKP; | 893 int fCurrentAnimSKP; |
839 const int fDivisor; | 894 bool fUseCodec; |
840 }; | 895 }; |
841 | 896 |
842 int nanobench_main(); | 897 int nanobench_main(); |
843 int nanobench_main() { | 898 int nanobench_main() { |
844 SetupCrashHandler(); | 899 SetupCrashHandler(); |
845 SkAutoGraphics ag; | 900 SkAutoGraphics ag; |
846 SkTaskGroup::Enabler enabled; | 901 SkTaskGroup::Enabler enabled; |
847 | 902 |
848 #if SK_SUPPORT_GPU | 903 #if SK_SUPPORT_GPU |
849 GrContextOptions grContextOpts; | 904 GrContextOptions grContextOpts; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 | 1083 |
1029 return 0; | 1084 return 0; |
1030 } | 1085 } |
1031 | 1086 |
1032 #if !defined SK_BUILD_FOR_IOS | 1087 #if !defined SK_BUILD_FOR_IOS |
1033 int main(int argc, char** argv) { | 1088 int main(int argc, char** argv) { |
1034 SkCommandLineFlags::Parse(argc, argv); | 1089 SkCommandLineFlags::Parse(argc, argv); |
1035 return nanobench_main(); | 1090 return nanobench_main(); |
1036 } | 1091 } |
1037 #endif | 1092 #endif |
OLD | NEW |