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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 // Choose the candidate color types for image decoding | 610 // Choose the candidate color types for image decoding |
611 const SkColorType colorTypes[] = | 611 const SkColorType colorTypes[] = |
612 { kN32_SkColorType, | 612 { kN32_SkColorType, |
613 kRGB_565_SkColorType, | 613 kRGB_565_SkColorType, |
614 kAlpha_8_SkColorType, | 614 kAlpha_8_SkColorType, |
615 kIndex_8_SkColorType, | 615 kIndex_8_SkColorType, |
616 kGray_8_SkColorType }; | 616 kGray_8_SkColorType }; |
617 fColorTypes.reset(colorTypes, SK_ARRAY_COUNT(colorTypes)); | 617 fColorTypes.reset(colorTypes, SK_ARRAY_COUNT(colorTypes)); |
618 } | 618 } |
619 | 619 |
620 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | 620 static sk_sp<SkPicture> ReadPicture(const char* path) { |
621 // Not strictly necessary, as it will be checked again later, | 621 // Not strictly necessary, as it will be checked again later, |
622 // but helps to avoid a lot of pointless work if we're going to skip it. | 622 // but helps to avoid a lot of pointless work if we're going to skip it. |
623 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path)
.c_str())) { | 623 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path)
.c_str())) { |
624 return false; | 624 return nullptr; |
625 } | 625 } |
626 | 626 |
627 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 627 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
628 if (stream.get() == nullptr) { | 628 if (stream.get() == nullptr) { |
629 SkDebugf("Could not read %s.\n", path); | 629 SkDebugf("Could not read %s.\n", path); |
630 return false; | 630 return nullptr; |
631 } | 631 } |
632 | 632 |
633 pic->reset(SkPicture::CreateFromStream(stream.get())); | 633 return SkPicture::MakeFromStream(stream.get()); |
634 if (pic->get() == nullptr) { | |
635 SkDebugf("Could not read %s as an SkPicture.\n", path); | |
636 return false; | |
637 } | |
638 return true; | |
639 } | 634 } |
640 | 635 |
641 Benchmark* next() { | 636 Benchmark* next() { |
642 SkAutoTDelete<Benchmark> bench; | 637 SkAutoTDelete<Benchmark> bench; |
643 do { | 638 do { |
644 bench.reset(this->rawNext()); | 639 bench.reset(this->rawNext()); |
645 if (!bench) { | 640 if (!bench) { |
646 return nullptr; | 641 return nullptr; |
647 } | 642 } |
648 } while(SkCommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) || | 643 } while(SkCommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) || |
(...skipping 16 matching lines...) Expand all Loading... |
665 if (gm->runAsBench()) { | 660 if (gm->runAsBench()) { |
666 fSourceType = "gm"; | 661 fSourceType = "gm"; |
667 fBenchType = "micro"; | 662 fBenchType = "micro"; |
668 return new GMBench(gm.release()); | 663 return new GMBench(gm.release()); |
669 } | 664 } |
670 } | 665 } |
671 | 666 |
672 // First add all .skps as RecordingBenches. | 667 // First add all .skps as RecordingBenches. |
673 while (fCurrentRecording < fSKPs.count()) { | 668 while (fCurrentRecording < fSKPs.count()) { |
674 const SkString& path = fSKPs[fCurrentRecording++]; | 669 const SkString& path = fSKPs[fCurrentRecording++]; |
675 SkAutoTUnref<SkPicture> pic; | 670 sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
676 if (!ReadPicture(path.c_str(), &pic)) { | 671 if (!pic) { |
677 continue; | 672 continue; |
678 } | 673 } |
679 SkString name = SkOSPath::Basename(path.c_str()); | 674 SkString name = SkOSPath::Basename(path.c_str()); |
680 fSourceType = "skp"; | 675 fSourceType = "skp"; |
681 fBenchType = "recording"; | 676 fBenchType = "recording"; |
682 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed
(pic)); | 677 fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed
(pic.get())); |
683 fSKPOps = pic->approximateOpCount(); | 678 fSKPOps = pic->approximateOpCount(); |
684 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); | 679 return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); |
685 } | 680 } |
686 | 681 |
687 // Then once each for each scale as SKPBenches (playback). | 682 // Then once each for each scale as SKPBenches (playback). |
688 while (fCurrentScale < fScales.count()) { | 683 while (fCurrentScale < fScales.count()) { |
689 while (fCurrentSKP < fSKPs.count()) { | 684 while (fCurrentSKP < fSKPs.count()) { |
690 const SkString& path = fSKPs[fCurrentSKP]; | 685 const SkString& path = fSKPs[fCurrentSKP]; |
691 SkAutoTUnref<SkPicture> pic; | 686 sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
692 if (!ReadPicture(path.c_str(), &pic)) { | 687 if (!pic) { |
693 fCurrentSKP++; | 688 fCurrentSKP++; |
694 continue; | 689 continue; |
695 } | 690 } |
696 | 691 |
697 while (fCurrentUseMPD < fUseMPDs.count()) { | 692 while (fCurrentUseMPD < fUseMPDs.count()) { |
698 if (FLAGS_bbh) { | 693 if (FLAGS_bbh) { |
699 // The SKP we read off disk doesn't have a BBH. Re-reco
rd so it grows one. | 694 // The SKP we read off disk doesn't have a BBH. Re-reco
rd so it grows one. |
700 SkRTreeFactory factory; | 695 SkRTreeFactory factory; |
701 SkPictureRecorder recorder; | 696 SkPictureRecorder recorder; |
702 static const int kFlags = SkPictureRecorder::kComputeSav
eLayerInfo_RecordFlag; | 697 static const int kFlags = SkPictureRecorder::kComputeSav
eLayerInfo_RecordFlag; |
703 pic->playback(recorder.beginRecording(pic->cullRect().wi
dth(), | 698 pic->playback(recorder.beginRecording(pic->cullRect().wi
dth(), |
704 pic->cullRect().he
ight(), | 699 pic->cullRect().he
ight(), |
705 &factory, | 700 &factory, |
706 fUseMPDs[fCurrentU
seMPD] ? kFlags : 0)); | 701 fUseMPDs[fCurrentU
seMPD] ? kFlags : 0)); |
707 pic.reset(recorder.endRecording()); | 702 pic = recorder.finishRecordingAsPicture(); |
708 } | 703 } |
709 SkString name = SkOSPath::Basename(path.c_str()); | 704 SkString name = SkOSPath::Basename(path.c_str()); |
710 fSourceType = "skp"; | 705 fSourceType = "skp"; |
711 fBenchType = "playback"; | 706 fBenchType = "playback"; |
712 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[
fCurrentScale], | 707 return new SKPBench(name.c_str(), pic.get(), fClip, fScales[
fCurrentScale], |
713 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSK
P); | 708 fUseMPDs[fCurrentUseMPD++], FLAGS_loopSK
P); |
714 } | 709 } |
715 fCurrentUseMPD = 0; | 710 fCurrentUseMPD = 0; |
716 fCurrentSKP++; | 711 fCurrentSKP++; |
717 } | 712 } |
718 fCurrentSKP = 0; | 713 fCurrentSKP = 0; |
719 fCurrentScale++; | 714 fCurrentScale++; |
720 } | 715 } |
721 | 716 |
722 // Now loop over each skp again if we have an animation | 717 // Now loop over each skp again if we have an animation |
723 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { | 718 if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { |
724 while (fCurrentAnimSKP < fSKPs.count()) { | 719 while (fCurrentAnimSKP < fSKPs.count()) { |
725 const SkString& path = fSKPs[fCurrentAnimSKP]; | 720 const SkString& path = fSKPs[fCurrentAnimSKP]; |
726 SkAutoTUnref<SkPicture> pic; | 721 sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
727 if (!ReadPicture(path.c_str(), &pic)) { | 722 if (!pic) { |
728 fCurrentAnimSKP++; | 723 fCurrentAnimSKP++; |
729 continue; | 724 continue; |
730 } | 725 } |
731 | 726 |
732 fCurrentAnimSKP++; | 727 fCurrentAnimSKP++; |
733 SkString name = SkOSPath::Basename(path.c_str()); | 728 SkString name = SkOSPath::Basename(path.c_str()); |
734 SkAutoTUnref<SKPAnimationBench::Animation> animation( | 729 SkAutoTUnref<SKPAnimationBench::Animation> animation( |
735 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriod
Ms)); | 730 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriod
Ms)); |
736 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, ani
mation, | 731 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, ani
mation, |
737 FLAGS_loopSKP); | 732 FLAGS_loopSKP); |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 | 1281 |
1287 return 0; | 1282 return 0; |
1288 } | 1283 } |
1289 | 1284 |
1290 #if !defined SK_BUILD_FOR_IOS | 1285 #if !defined SK_BUILD_FOR_IOS |
1291 int main(int argc, char** argv) { | 1286 int main(int argc, char** argv) { |
1292 SkCommandLineFlags::Parse(argc, argv); | 1287 SkCommandLineFlags::Parse(argc, argv); |
1293 return nanobench_main(); | 1288 return nanobench_main(); |
1294 } | 1289 } |
1295 #endif | 1290 #endif |
OLD | NEW |