Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: bench/nanobench.cpp

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

Powered by Google App Engine
This is Rietveld 408576698