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; | |
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 (SkImageDecoder::kWEBP_Format == decoder->getFormat() && | |
scroggo
2015/06/09 12:58:13
How is this only a WEBP problem? What is different
msarett
2015/06/09 20:49:54
You are right. This occurs for pngs and jpegs as
| |
527 (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == col orType)) { | |
scroggo
2015/06/09 12:58:13
Please add a FIXME: See skbug.com/####, and/or an
msarett
2015/06/09 20:49:54
Done.
| |
528 return false; | |
529 } | |
530 if (!decoder->buildTileIndex(stream.detach(), width, height)) { | |
531 SkDebugf("Could not build tile index for %s. Skipping bench.\n", pa th.c_str()); | |
532 return false; | |
533 } | |
534 } | |
535 return true; | |
536 } | |
485 | 537 |
486 class BenchmarkStream { | 538 class BenchmarkStream { |
487 public: | 539 public: |
488 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 540 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
489 , fGMs(skiagm::GMRegistry::Head()) | 541 , fGMs(skiagm::GMRegistry::Head()) |
490 , fCurrentRecording(0) | 542 , fCurrentRecording(0) |
491 , fCurrentScale(0) | 543 , fCurrentScale(0) |
492 , fCurrentSKP(0) | 544 , fCurrentSKP(0) |
493 , fCurrentUseMPD(0) | 545 , fCurrentUseMPD(0) |
494 , fCurrentCodec(0) | 546 , fCurrentCodec(0) |
495 , fCurrentImage(0) | 547 , fCurrentImage(0) |
496 , fCurrentSubsetImage(0) | 548 , fCurrentSubsetImage(0) |
497 , fCurrentColorType(0) | 549 , fCurrentColorType(0) |
498 , fCurrentAnimSKP(0) | 550 , fCurrentSubsetType(0) |
499 , fDivisor(2) { | 551 , fUseCodec(0) |
552 , fCurrentAnimSKP(0) { | |
500 for (int i = 0; i < FLAGS_skps.count(); i++) { | 553 for (int i = 0; i < FLAGS_skps.count(); i++) { |
501 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 554 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
502 fSKPs.push_back() = FLAGS_skps[i]; | 555 fSKPs.push_back() = FLAGS_skps[i]; |
503 } else { | 556 } else { |
504 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 557 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
505 SkString path; | 558 SkString path; |
506 while (it.next(&path)) { | 559 while (it.next(&path)) { |
507 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | 560 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); |
508 } | 561 } |
509 } | 562 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); | 596 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); |
544 } | 597 } |
545 } else if (sk_exists(flag)) { | 598 } else if (sk_exists(flag)) { |
546 // Also add the value if it is a single image | 599 // Also add the value if it is a single image |
547 fImages.push_back() = flag; | 600 fImages.push_back() = flag; |
548 } | 601 } |
549 } | 602 } |
550 | 603 |
551 // Choose the candidate color types for image decoding | 604 // Choose the candidate color types for image decoding |
552 const SkColorType colorTypes[] = | 605 const SkColorType colorTypes[] = |
553 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType, kInd ex_8_SkColorType }; | 606 { kN32_SkColorType, |
607 kRGB_565_SkColorType, | |
608 kAlpha_8_SkColorType, | |
609 kIndex_8_SkColorType, | |
610 kGray_8_SkColorType }; | |
554 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); | 611 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); |
555 } | 612 } |
556 | 613 |
557 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | 614 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
558 // Not strictly necessary, as it will be checked again later, | 615 // 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. | 616 // but helps to avoid a lot of pointless work if we're going to skip it. |
560 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | 617 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
561 return false; | 618 return false; |
562 } | 619 } |
563 | 620 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, | 787 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
731 colorType, SkImageDecoder::kDecodePixels_Mode) | 788 colorType, SkImageDecoder::kDecodePixels_Mode) |
732 && bitmap.colorType() == colorType) { | 789 && bitmap.colorType() == colorType) { |
733 return new DecodingBench(path, colorType); | 790 return new DecodingBench(path, colorType); |
734 } | 791 } |
735 } | 792 } |
736 fCurrentColorType = 0; | 793 fCurrentColorType = 0; |
737 fCurrentImage++; | 794 fCurrentImage++; |
738 } | 795 } |
739 | 796 |
740 // Run the DecodingSubsetBenches | 797 // Run the SubsetBenches |
741 while (fCurrentSubsetImage < fImages.count()) { | 798 bool useCodecOpts[] = { true, false }; |
742 while (fCurrentColorType < fColorTypes.count()) { | 799 while (fUseCodec < 2) { |
743 const SkString& path = fImages[fCurrentSubsetImage]; | 800 bool useCodec = useCodecOpts[fUseCodec]; |
744 SkColorType colorType = fColorTypes[fCurrentColorType]; | 801 while (fCurrentSubsetImage < fImages.count()) { |
745 fCurrentColorType++; | 802 while (fCurrentColorType < fColorTypes.count()) { |
746 // Check if the image decodes before creating the benchmark | 803 const SkString& path = fImages[fCurrentSubsetImage]; |
747 SkAutoTUnref<SkData> encoded( | 804 SkColorType colorType = fColorTypes[fCurrentColorType]; |
748 SkData::NewFromFileName(path.c_str())); | 805 while (fCurrentSubsetType <= kLast_SubsetType) { |
749 SkAutoTDelete<SkMemoryStream> stream( | 806 int width = 0; |
750 new SkMemoryStream(encoded)); | 807 int height = 0; |
751 SkAutoTDelete<SkImageDecoder> | 808 int currentSubsetType = fCurrentSubsetType++; |
752 decoder(SkImageDecoder::Factory(stream.get())); | 809 if (valid_subset_bench(path, colorType, useCodec, &width , &height)) { |
753 if (!decoder) { | 810 switch (currentSubsetType) { |
754 SkDebugf("Cannot find decoder for %s\n", path.c_str()); | 811 case kTopLeft_SubsetType: |
755 } else { | 812 return new SubsetSingleBench(path, colorType , width/2, |
756 stream->rewind(); | 813 height/2, 0, 0, useCodec); |
757 int w, h; | 814 case kTopRight_SubsetType: |
758 bool success; | 815 return new SubsetSingleBench(path, colorType , width/2, |
759 if (!decoder->buildTileIndex(stream.detach(), &w, &h) | 816 height/2, width/2, 0, useCodec); |
760 || w*h == 1) { | 817 case kBottomLeft_SubsetType: |
761 // This is not an error, but in this case we still | 818 return new SubsetSingleBench(path, colorType , width/2, |
762 // do not want to run the benchmark. | 819 height/2, 0, height/2, useCodec); |
763 success = false; | 820 case kBottomRight_SubsetType: |
764 } else if (fDivisor > w || fDivisor > h) { | 821 return new SubsetSingleBench(path, colorType , width/2, |
765 SkDebugf("Divisor %d is too big for %s %dx%d\n", | 822 height/2, width/2, height/2, useCode c); |
766 fDivisor, path.c_str(), w, h); | 823 case k2x2_SubsetType: |
767 success = false; | 824 return new SubsetDivisorBench(path, colorTyp e, 2, useCodec); |
768 } else { | 825 case k3x3_SubsetType: |
769 const int sW = w / fDivisor; | 826 return new SubsetDivisorBench(path, colorTyp e, 3, useCodec); |
770 const int sH = h / fDivisor; | 827 case kTranslate_SubsetType: |
771 SkBitmap bitmap; | 828 return new SubsetTranslateBench(path, colorT ype, 512, 512, |
772 success = true; | 829 useCodec); |
773 for (int y = 0; y < h; y += sH) { | 830 case kZoom_SubsetType: |
774 for (int x = 0; x < w; x += sW) { | 831 return new SubsetZoomBench(path, colorType, 512, 512, |
775 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); | 832 useCodec); |
776 success &= decoder->decodeSubset(&bitmap, rect, | |
777 colorType); | |
778 } | 833 } |
834 } else { | |
835 break; | |
779 } | 836 } |
780 } | 837 } |
781 // Create the benchmark if successful | 838 fCurrentSubsetType = 0; |
782 if (success) { | 839 fCurrentColorType++; |
783 return new DecodingSubsetBench(path, colorType, | |
784 fDivisor); | |
785 } | |
786 } | 840 } |
841 fCurrentColorType = 0; | |
842 fCurrentSubsetImage++; | |
787 } | 843 } |
788 fCurrentColorType = 0; | 844 fCurrentSubsetImage = 0; |
789 fCurrentSubsetImage++; | 845 fUseCodec++; |
790 } | 846 } |
791 | 847 |
792 return NULL; | 848 return NULL; |
793 } | 849 } |
794 | 850 |
795 void fillCurrentOptions(ResultsWriter* log) const { | 851 void fillCurrentOptions(ResultsWriter* log) const { |
796 log->configOption("source_type", fSourceType); | 852 log->configOption("source_type", fSourceType); |
797 log->configOption("bench_type", fBenchType); | 853 log->configOption("bench_type", fBenchType); |
798 if (0 == strcmp(fSourceType, "skp")) { | 854 if (0 == strcmp(fSourceType, "skp")) { |
799 log->configOption("clip", | 855 log->configOption("clip", |
800 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 856 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
801 fClip.fRight, fClip.fBottom).c _str()); | 857 fClip.fRight, fClip.fBottom).c _str()); |
802 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); | 858 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); |
803 if (fCurrentUseMPD > 0) { | 859 if (fCurrentUseMPD > 0) { |
804 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); | 860 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
805 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); | 861 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false"); |
806 } | 862 } |
807 } | 863 } |
808 if (0 == strcmp(fBenchType, "recording")) { | 864 if (0 == strcmp(fBenchType, "recording")) { |
809 log->metric("bytes", fSKPBytes); | 865 log->metric("bytes", fSKPBytes); |
810 log->metric("ops", fSKPOps); | 866 log->metric("ops", fSKPOps); |
811 } | 867 } |
812 } | 868 } |
813 | 869 |
814 private: | 870 private: |
871 enum SubsetType { | |
872 kTopLeft_SubsetType = 0, | |
873 kTopRight_SubsetType = 1, | |
874 kBottomLeft_SubsetType = 2, | |
875 kBottomRight_SubsetType = 3, | |
876 k2x2_SubsetType = 4, | |
877 k3x3_SubsetType = 5, | |
878 kTranslate_SubsetType = 6, | |
879 kZoom_SubsetType = 7, | |
880 kLast_SubsetType = kZoom_SubsetType | |
881 }; | |
882 | |
815 const BenchRegistry* fBenches; | 883 const BenchRegistry* fBenches; |
816 const skiagm::GMRegistry* fGMs; | 884 const skiagm::GMRegistry* fGMs; |
817 SkIRect fClip; | 885 SkIRect fClip; |
818 SkTArray<SkScalar> fScales; | 886 SkTArray<SkScalar> fScales; |
819 SkTArray<SkString> fSKPs; | 887 SkTArray<SkString> fSKPs; |
820 SkTArray<bool> fUseMPDs; | 888 SkTArray<bool> fUseMPDs; |
821 SkTArray<SkString> fImages; | 889 SkTArray<SkString> fImages; |
822 SkTArray<SkColorType> fColorTypes; | 890 SkTArray<SkColorType> fColorTypes; |
823 SkScalar fZoomScale; | 891 SkScalar fZoomScale; |
824 int fZoomSteps; | 892 int fZoomSteps; |
825 | 893 |
826 double fSKPBytes, fSKPOps; | 894 double fSKPBytes, fSKPOps; |
827 | 895 |
828 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 896 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
829 const char* fBenchType; // How we bench it: micro, recording, playback, .. . | 897 const char* fBenchType; // How we bench it: micro, recording, playback, .. . |
830 int fCurrentRecording; | 898 int fCurrentRecording; |
831 int fCurrentScale; | 899 int fCurrentScale; |
832 int fCurrentSKP; | 900 int fCurrentSKP; |
833 int fCurrentUseMPD; | 901 int fCurrentUseMPD; |
834 int fCurrentCodec; | 902 int fCurrentCodec; |
835 int fCurrentImage; | 903 int fCurrentImage; |
836 int fCurrentSubsetImage; | 904 int fCurrentSubsetImage; |
837 int fCurrentColorType; | 905 int fCurrentColorType; |
906 int fCurrentSubsetType; | |
907 int fUseCodec; | |
838 int fCurrentAnimSKP; | 908 int fCurrentAnimSKP; |
839 const int fDivisor; | |
840 }; | 909 }; |
841 | 910 |
842 int nanobench_main(); | 911 int nanobench_main(); |
843 int nanobench_main() { | 912 int nanobench_main() { |
844 SetupCrashHandler(); | 913 SetupCrashHandler(); |
845 SkAutoGraphics ag; | 914 SkAutoGraphics ag; |
846 SkTaskGroup::Enabler enabled; | 915 SkTaskGroup::Enabler enabled; |
847 | 916 |
848 #if SK_SUPPORT_GPU | 917 #if SK_SUPPORT_GPU |
849 GrContextOptions grContextOpts; | 918 GrContextOptions grContextOpts; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 | 1097 |
1029 return 0; | 1098 return 0; |
1030 } | 1099 } |
1031 | 1100 |
1032 #if !defined SK_BUILD_FOR_IOS | 1101 #if !defined SK_BUILD_FOR_IOS |
1033 int main(int argc, char** argv) { | 1102 int main(int argc, char** argv) { |
1034 SkCommandLineFlags::Parse(argc, argv); | 1103 SkCommandLineFlags::Parse(argc, argv); |
1035 return nanobench_main(); | 1104 return nanobench_main(); |
1036 } | 1105 } |
1037 #endif | 1106 #endif |
OLD | NEW |