OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SampleApp.h" | 8 #include "SampleApp.h" |
9 | 9 |
10 #include "OverView.h" | 10 #include "OverView.h" |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 SkString title; | 698 SkString title; |
699 SampleCode::RequestTitle(view, &title); | 699 SampleCode::RequestTitle(view, &title); |
700 view->unref(); | 700 view->unref(); |
701 return title; | 701 return title; |
702 } | 702 } |
703 | 703 |
704 static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory*
second) { | 704 static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory*
second) { |
705 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; | 705 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; |
706 } | 706 } |
707 | 707 |
| 708 static int find_by_title(const SkViewFactory* const* factories, int count, const
char title[]) { |
| 709 for (int i = 0; i < count; i++) { |
| 710 if (getSampleTitle(factories[i]).equals(title)) { |
| 711 return i; |
| 712 } |
| 713 } |
| 714 return -1; |
| 715 } |
| 716 |
| 717 static void restrict_samples(SkTDArray<const SkViewFactory*>& factories, const S
kString titles[], |
| 718 int count) { |
| 719 int newCount = 0; |
| 720 for (int i = 0; i < count; ++i) { |
| 721 int index = find_by_title(factories.begin(), factories.count(), titles[i
].c_str()); |
| 722 if (index >= 0) { |
| 723 SkTSwap(factories.begin()[newCount], factories.begin()[index]); |
| 724 newCount += 1; |
| 725 } |
| 726 } |
| 727 if (newCount) { |
| 728 factories.setCount(newCount); |
| 729 } |
| 730 } |
| 731 |
708 DEFINE_string(slide, "", "Start on this sample."); | 732 DEFINE_string(slide, "", "Start on this sample."); |
709 DEFINE_int32(msaa, 0, "Request multisampling with this count."); | 733 DEFINE_int32(msaa, 0, "Request multisampling with this count."); |
710 DEFINE_string(pictureDir, "", "Read pictures from here."); | 734 DEFINE_string(pictureDir, "", "Read pictures from here."); |
711 DEFINE_string(picture, "", "Path to single picture."); | 735 DEFINE_string(picture, "", "Path to single picture."); |
| 736 DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to
show."); |
712 DEFINE_bool(sort, false, "Sort samples by title."); | 737 DEFINE_bool(sort, false, "Sort samples by title."); |
713 DEFINE_bool(list, false, "List samples?"); | 738 DEFINE_bool(list, false, "List samples?"); |
714 DEFINE_bool(gpu, false, "Start up with gpu?"); | 739 DEFINE_bool(gpu, false, "Start up with gpu?"); |
715 DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-spec
ific names | 740 DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-spec
ific names |
716 #ifdef SAMPLE_PDF_FILE_VIEWER | 741 #ifdef SAMPLE_PDF_FILE_VIEWER |
717 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); | 742 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); |
718 #endif | 743 #endif |
719 | 744 |
720 #include "SkTaskGroup.h" | 745 #include "SkTaskGroup.h" |
721 | 746 |
(...skipping 30 matching lines...) Expand all Loading... |
752 #endif | 777 #endif |
753 SkGMRegistyToSampleRegistry(); | 778 SkGMRegistyToSampleRegistry(); |
754 { | 779 { |
755 const SkViewRegister* reg = SkViewRegister::Head(); | 780 const SkViewRegister* reg = SkViewRegister::Head(); |
756 while (reg) { | 781 while (reg) { |
757 *fSamples.append() = reg->factory(); | 782 *fSamples.append() = reg->factory(); |
758 reg = reg->next(); | 783 reg = reg->next(); |
759 } | 784 } |
760 } | 785 } |
761 | 786 |
| 787 if (!FLAGS_sequence.isEmpty()) { |
| 788 // The sequence file just contains a list (separated by CRs) of the samp
les or GM:gms |
| 789 // you want to restrict to. Only these will appear when you cycle throug
h. |
| 790 // If none are found, or the file is empty, then it will be ignored, and
all samples |
| 791 // will be available. |
| 792 SkFILEStream stream(FLAGS_sequence[0]); |
| 793 if (stream.isValid()) { |
| 794 size_t len = stream.getLength(); |
| 795 SkAutoMalloc storage(len + 1); |
| 796 char* buffer = (char*)storage.get(); |
| 797 stream.read(buffer, len); |
| 798 buffer[len] = 0; |
| 799 |
| 800 SkTArray<SkString> titles; |
| 801 SkStrSplit(buffer, "\n\r", &titles); |
| 802 restrict_samples(fSamples, titles.begin(), titles.count()); |
| 803 } |
| 804 } |
| 805 |
762 if (FLAGS_sort) { | 806 if (FLAGS_sort) { |
763 // Sort samples, so foo.skp and foo.pdf are consecutive and we can quick
ly spot where | 807 // Sort samples, so foo.skp and foo.pdf are consecutive and we can quick
ly spot where |
764 // skp -> pdf -> png fails. | 808 // skp -> pdf -> png fails. |
765 SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : nullptr
, compareSampleTitle); | 809 SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : nullptr
, compareSampleTitle); |
766 } | 810 } |
767 | 811 |
768 if (!FLAGS_slide.isEmpty()) { | 812 if (!FLAGS_slide.isEmpty()) { |
769 fCurrIndex = findByTitle(FLAGS_slide[0]); | 813 fCurrIndex = findByTitle(FLAGS_slide[0]); |
770 if (fCurrIndex < 0) { | 814 if (fCurrIndex < 0) { |
771 fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]); | 815 fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]); |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 #ifdef SK_BUILD_FOR_MAC | 2447 #ifdef SK_BUILD_FOR_MAC |
2404 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2448 setenv("ANDROID_ROOT", "/android/device/data", 0); |
2405 #endif | 2449 #endif |
2406 SkGraphics::Init(); | 2450 SkGraphics::Init(); |
2407 SkEvent::Init(); | 2451 SkEvent::Init(); |
2408 } | 2452 } |
2409 | 2453 |
2410 void application_term() { | 2454 void application_term() { |
2411 SkEvent::Term(); | 2455 SkEvent::Term(); |
2412 } | 2456 } |
OLD | NEW |