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" |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 if (NULL == codec) { | 507 if (NULL == codec) { |
508 SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c
_str()); | 508 SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c
_str()); |
509 return false; | 509 return false; |
510 } | 510 } |
511 | 511 |
512 // These will be initialized by SkCodec if the color type is kIndex8 and | 512 // These will be initialized by SkCodec if the color type is kIndex8 and |
513 // unused otherwise. | 513 // unused otherwise. |
514 SkPMColor colors[256]; | 514 SkPMColor colors[256]; |
515 int colorCount; | 515 int colorCount; |
516 const SkImageInfo info = codec->getInfo().makeColorType(colorType); | 516 const SkImageInfo info = codec->getInfo().makeColorType(colorType); |
517 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes())
); | 517 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); |
518 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewF
romData(encoded)); | 518 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewF
romData(encoded)); |
519 if (NULL == scanlineDecoder || scanlineDecoder->start(info, NULL, | 519 if (NULL == scanlineDecoder || scanlineDecoder->start(info, NULL, |
520 colors, &colorCount) != SkCodec::kSuccess) | 520 colors, &colorCount) != SkCodec::kSuccess) |
521 { | 521 { |
522 SkDebugf("Could not create scanline decoder for %s with color type %
s. " | 522 SkDebugf("Could not create scanline decoder for %s with color type %
s. " |
523 "Skipping bench.\n", path.c_str(), get_color_name(colorType)
); | 523 "Skipping bench.\n", path.c_str(), get_color_name(colorType)
); |
524 return false; | 524 return false; |
525 } | 525 } |
526 *width = info.width(); | 526 *width = info.width(); |
527 *height = info.height(); | 527 *height = info.height(); |
(...skipping 18 matching lines...) Expand all Loading... |
546 // Check if the image is large enough for a meaningful subset benchmark. | 546 // Check if the image is large enough for a meaningful subset benchmark. |
547 if (*width <= 512 && *height <= 512) { | 547 if (*width <= 512 && *height <= 512) { |
548 // This should not print a message since it is not an error. | 548 // This should not print a message since it is not an error. |
549 return false; | 549 return false; |
550 } | 550 } |
551 | 551 |
552 return true; | 552 return true; |
553 } | 553 } |
554 | 554 |
555 static void cleanup_run(Target* target) { | 555 static void cleanup_run(Target* target) { |
556 SkDELETE(target); | 556 delete target; |
557 #if SK_SUPPORT_GPU | 557 #if SK_SUPPORT_GPU |
558 if (FLAGS_abandonGpuContext) { | 558 if (FLAGS_abandonGpuContext) { |
559 gGrFactory->abandonContexts(); | 559 gGrFactory->abandonContexts(); |
560 } | 560 } |
561 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { | 561 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
562 gGrFactory->destroyContexts(); | 562 gGrFactory->destroyContexts(); |
563 } | 563 } |
564 #endif | 564 #endif |
565 } | 565 } |
566 | 566 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 fBenchType = "micro"; | 669 fBenchType = "micro"; |
670 return bench; | 670 return bench; |
671 } | 671 } |
672 | 672 |
673 while (fGMs) { | 673 while (fGMs) { |
674 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); | 674 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
675 fGMs = fGMs->next(); | 675 fGMs = fGMs->next(); |
676 if (gm->runAsBench()) { | 676 if (gm->runAsBench()) { |
677 fSourceType = "gm"; | 677 fSourceType = "gm"; |
678 fBenchType = "micro"; | 678 fBenchType = "micro"; |
679 return SkNEW_ARGS(GMBench, (gm.detach())); | 679 return new GMBench(gm.detach()); |
680 } | 680 } |
681 } | 681 } |
682 | 682 |
683 // First add all .skps as RecordingBenches. | 683 // First add all .skps as RecordingBenches. |
684 while (fCurrentRecording < fSKPs.count()) { | 684 while (fCurrentRecording < fSKPs.count()) { |
685 const SkString& path = fSKPs[fCurrentRecording++]; | 685 const SkString& path = fSKPs[fCurrentRecording++]; |
686 SkAutoTUnref<SkPicture> pic; | 686 SkAutoTUnref<SkPicture> pic; |
687 if (!ReadPicture(path.c_str(), &pic)) { | 687 if (!ReadPicture(path.c_str(), &pic)) { |
688 continue; | 688 continue; |
689 } | 689 } |
690 SkString name = SkOSPath::Basename(path.c_str()); | 690 SkString name = SkOSPath::Basename(path.c_str()); |
691 fSourceType = "skp"; | 691 fSourceType = "skp"; |
692 fBenchType = "recording"; | 692 fBenchType = "recording"; |
693 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed
(pic)); | 693 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed
(pic)); |
694 fSKPOps = pic->approximateOpCount(); | 694 fSKPOps = pic->approximateOpCount(); |
695 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb
h)); | 695 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); |
696 } | 696 } |
697 | 697 |
698 // Then once each for each scale as SKPBenches (playback). | 698 // Then once each for each scale as SKPBenches (playback). |
699 while (fCurrentScale < fScales.count()) { | 699 while (fCurrentScale < fScales.count()) { |
700 while (fCurrentSKP < fSKPs.count()) { | 700 while (fCurrentSKP < fSKPs.count()) { |
701 const SkString& path = fSKPs[fCurrentSKP]; | 701 const SkString& path = fSKPs[fCurrentSKP]; |
702 SkAutoTUnref<SkPicture> pic; | 702 SkAutoTUnref<SkPicture> pic; |
703 if (!ReadPicture(path.c_str(), &pic)) { | 703 if (!ReadPicture(path.c_str(), &pic)) { |
704 fCurrentSKP++; | 704 fCurrentSKP++; |
705 continue; | 705 continue; |
706 } | 706 } |
707 | 707 |
708 while (fCurrentUseMPD < fUseMPDs.count()) { | 708 while (fCurrentUseMPD < fUseMPDs.count()) { |
709 if (FLAGS_bbh) { | 709 if (FLAGS_bbh) { |
710 // The SKP we read off disk doesn't have a BBH. Re-reco
rd so it grows one. | 710 // The SKP we read off disk doesn't have a BBH. Re-reco
rd so it grows one. |
711 SkRTreeFactory factory; | 711 SkRTreeFactory factory; |
712 SkPictureRecorder recorder; | 712 SkPictureRecorder recorder; |
713 static const int kFlags = SkPictureRecorder::kComputeSav
eLayerInfo_RecordFlag; | 713 static const int kFlags = SkPictureRecorder::kComputeSav
eLayerInfo_RecordFlag; |
714 pic->playback(recorder.beginRecording(pic->cullRect().wi
dth(), | 714 pic->playback(recorder.beginRecording(pic->cullRect().wi
dth(), |
715 pic->cullRect().he
ight(), | 715 pic->cullRect().he
ight(), |
716 &factory, | 716 &factory, |
717 fUseMPDs[fCurrentU
seMPD] ? kFlags : 0)); | 717 fUseMPDs[fCurrentU
seMPD] ? kFlags : 0)); |
718 pic.reset(recorder.endRecording()); | 718 pic.reset(recorder.endRecording()); |
719 } | 719 } |
720 SkString name = SkOSPath::Basename(path.c_str()); | 720 SkString name = SkOSPath::Basename(path.c_str()); |
721 fSourceType = "skp"; | 721 fSourceType = "skp"; |
722 fBenchType = "playback"; | 722 fBenchType = "playback"; |
723 return SkNEW_ARGS(SKPBench, | 723 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[
fCurrentScale], |
724 (name.c_str(), pic.get(), fClip, fScales[f
CurrentScale], | 724 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSK
P); |
725 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP
)); | |
726 | |
727 } | 725 } |
728 fCurrentUseMPD = 0; | 726 fCurrentUseMPD = 0; |
729 fCurrentSKP++; | 727 fCurrentSKP++; |
730 } | 728 } |
731 fCurrentSKP = 0; | 729 fCurrentSKP = 0; |
732 fCurrentScale++; | 730 fCurrentScale++; |
733 } | 731 } |
734 | 732 |
735 // Now loop over each skp again if we have an animation | 733 // Now loop over each skp again if we have an animation |
736 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { | 734 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { |
737 while (fCurrentAnimSKP < fSKPs.count()) { | 735 while (fCurrentAnimSKP < fSKPs.count()) { |
738 const SkString& path = fSKPs[fCurrentAnimSKP]; | 736 const SkString& path = fSKPs[fCurrentAnimSKP]; |
739 SkAutoTUnref<SkPicture> pic; | 737 SkAutoTUnref<SkPicture> pic; |
740 if (!ReadPicture(path.c_str(), &pic)) { | 738 if (!ReadPicture(path.c_str(), &pic)) { |
741 fCurrentAnimSKP++; | 739 fCurrentAnimSKP++; |
742 continue; | 740 continue; |
743 } | 741 } |
744 | 742 |
745 fCurrentAnimSKP++; | 743 fCurrentAnimSKP++; |
746 SkString name = SkOSPath::Basename(path.c_str()); | 744 SkString name = SkOSPath::Basename(path.c_str()); |
747 SkAutoTUnref<SKPAnimationBench::Animation> animation( | 745 SkAutoTUnref<SKPAnimationBench::Animation> animation( |
748 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriod
Ms)); | 746 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriod
Ms)); |
749 return SkNEW_ARGS(SKPAnimationBench, (name.c_str(), pic.get(), f
Clip, animation, | 747 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, ani
mation, |
750 FLAGS_loopSKP)); | 748 FLAGS_loopSKP); |
751 } | 749 } |
752 } | 750 } |
753 | 751 |
754 | 752 |
755 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { | 753 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
756 const SkString& path = fImages[fCurrentCodec]; | 754 const SkString& path = fImages[fCurrentCodec]; |
757 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 755 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
758 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 756 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
759 if (!codec) { | 757 if (!codec) { |
760 // Nothing to time. | 758 // Nothing to time. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 | 935 |
938 int nanobench_main(); | 936 int nanobench_main(); |
939 int nanobench_main() { | 937 int nanobench_main() { |
940 SetupCrashHandler(); | 938 SetupCrashHandler(); |
941 SkAutoGraphics ag; | 939 SkAutoGraphics ag; |
942 SkTaskGroup::Enabler enabled(FLAGS_threads); | 940 SkTaskGroup::Enabler enabled(FLAGS_threads); |
943 | 941 |
944 #if SK_SUPPORT_GPU | 942 #if SK_SUPPORT_GPU |
945 GrContextOptions grContextOpts; | 943 GrContextOptions grContextOpts; |
946 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; | 944 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; |
947 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts))); | 945 gGrFactory.reset(new GrContextFactory(grContextOpts)); |
948 #endif | 946 #endif |
949 | 947 |
950 if (FLAGS_veryVerbose) { | 948 if (FLAGS_veryVerbose) { |
951 FLAGS_verbose = true; | 949 FLAGS_verbose = true; |
952 } | 950 } |
953 | 951 |
954 double samplingTimeMs = 0; | 952 double samplingTimeMs = 0; |
955 if (0 != strcmp("0", FLAGS_samplingTime[0])) { | 953 if (0 != strcmp("0", FLAGS_samplingTime[0])) { |
956 SkSTArray<8, char> timeUnit; | 954 SkSTArray<8, char> timeUnit; |
957 timeUnit.push_back_n(static_cast<int>(strlen(FLAGS_samplingTime[0])) + 1
); | 955 timeUnit.push_back_n(static_cast<int>(strlen(FLAGS_samplingTime[0])) + 1
); |
(...skipping 17 matching lines...) Expand all Loading... |
975 } | 973 } |
976 | 974 |
977 if (!FLAGS_writePath.isEmpty()) { | 975 if (!FLAGS_writePath.isEmpty()) { |
978 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); | 976 SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
979 if (!sk_mkdir(FLAGS_writePath[0])) { | 977 if (!sk_mkdir(FLAGS_writePath[0])) { |
980 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_wri
tePath[0]); | 978 SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_wri
tePath[0]); |
981 FLAGS_writePath.set(0, NULL); | 979 FLAGS_writePath.set(0, NULL); |
982 } | 980 } |
983 } | 981 } |
984 | 982 |
985 SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter)); | 983 SkAutoTDelete<ResultsWriter> log(new ResultsWriter); |
986 if (!FLAGS_outResultsFile.isEmpty()) { | 984 if (!FLAGS_outResultsFile.isEmpty()) { |
987 log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0]))); | 985 log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0])); |
988 } | 986 } |
989 | 987 |
990 if (1 == FLAGS_properties.count() % 2) { | 988 if (1 == FLAGS_properties.count() % 2) { |
991 SkDebugf("ERROR: --properties must be passed with an even number of argu
ments.\n"); | 989 SkDebugf("ERROR: --properties must be passed with an even number of argu
ments.\n"); |
992 return 1; | 990 return 1; |
993 } | 991 } |
994 for (int i = 1; i < FLAGS_properties.count(); i += 2) { | 992 for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
995 log->property(FLAGS_properties[i-1], FLAGS_properties[i]); | 993 log->property(FLAGS_properties[i-1], FLAGS_properties[i]); |
996 } | 994 } |
997 | 995 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 | 1156 |
1159 return 0; | 1157 return 0; |
1160 } | 1158 } |
1161 | 1159 |
1162 #if !defined SK_BUILD_FOR_IOS | 1160 #if !defined SK_BUILD_FOR_IOS |
1163 int main(int argc, char** argv) { | 1161 int main(int argc, char** argv) { |
1164 SkCommandLineFlags::Parse(argc, argv); | 1162 SkCommandLineFlags::Parse(argc, argv); |
1165 return nanobench_main(); | 1163 return nanobench_main(); |
1166 } | 1164 } |
1167 #endif | 1165 #endif |
OLD | NEW |