| 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 SampleWindow::kANGLE_DeviceType, | 712 SampleWindow::kANGLE_DeviceType, |
| 713 #endif // SK_ANGLE | 713 #endif // SK_ANGLE |
| 714 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal
cycling | 714 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal
cycling |
| 715 #endif // SK_SUPPORT_GPU | 715 #endif // SK_SUPPORT_GPU |
| 716 SampleWindow::kRaster_DeviceType | 716 SampleWindow::kRaster_DeviceType |
| 717 }; | 717 }; |
| 718 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); | 718 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); |
| 719 return gCT[ct]; | 719 return gCT[ct]; |
| 720 } | 720 } |
| 721 | 721 |
| 722 static void usage(const char * argv0) { | |
| 723 SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--
pictureDir dirPath] [--picture path] [--sort]\n", argv0); | |
| 724 #ifdef SAMPLE_PDF_FILE_VIEWER | |
| 725 SkDebugf(" [--pdfDir pdfPath]\n"); | |
| 726 SkDebugf(" pdfPath: path to directory pdf files are read from\n"); | |
| 727 #endif // SAMPLE_PDF_FILE_VIEWER | |
| 728 SkDebugf(" sampleName: sample at which to start.\n"); | |
| 729 SkDebugf(" resourcePath: directory that stores image resources.\n"); | |
| 730 SkDebugf(" msaa: request multisampling with the given sample count.\n"); | |
| 731 SkDebugf(" dirPath: path to directory skia pictures are read from\n"); | |
| 732 SkDebugf(" path: path to skia picture\n"); | |
| 733 SkDebugf(" --sort: sort samples by title, this would help to compare pdf
rendering (P:foo.pdf) with skp rendering (P:foo.pdf)\n"); | |
| 734 } | |
| 735 | |
| 736 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { | 722 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { |
| 737 SkView* view = (*sampleFactory)(); | 723 SkView* view = (*sampleFactory)(); |
| 738 SkString title; | 724 SkString title; |
| 739 SampleCode::RequestTitle(view, &title); | 725 SampleCode::RequestTitle(view, &title); |
| 740 view->unref(); | 726 view->unref(); |
| 741 return title; | 727 return title; |
| 742 } | 728 } |
| 743 | 729 |
| 744 static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory*
second) { | 730 static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory*
second) { |
| 745 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; | 731 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; |
| 746 } | 732 } |
| 747 | 733 |
| 734 DEFINE_string(slide, "", "Start on this sample."); |
| 735 DEFINE_int32(msaa, 0, "Request multisampling with this count."); |
| 736 DEFINE_string(pictureDir, "", "Read pictures from here."); |
| 737 DEFINE_string(picture, "", "Path to single picture."); |
| 738 DEFINE_bool(sort, false, "Sort samples by title."); |
| 739 DEFINE_bool(list, false, "List samples?"); |
| 740 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 741 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); |
| 742 #endif |
| 743 |
| 748 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
Manager) | 744 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
Manager) |
| 749 : INHERITED(hwnd) | 745 : INHERITED(hwnd) |
| 750 , fDevManager(NULL) { | 746 , fDevManager(NULL) { |
| 751 | 747 |
| 748 SkCommandLineFlags::Parse(argc, argv); |
| 749 |
| 752 fCurrIndex = -1; | 750 fCurrIndex = -1; |
| 753 | 751 |
| 754 this->registerPictFileSamples(argv, argc); | 752 if (!FLAGS_pictureDir.isEmpty()) { |
| 755 this->registerPictFileSample(argv, argc); | 753 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp"); |
| 754 SkString filename; |
| 755 while (iter.next(&filename)) { |
| 756 *fSamples.append() = new PictFileFactory( |
| 757 SkOSPath::SkPathJoin(FLAGS_pictureDir[0], filename.c_str()))
; |
| 758 } |
| 759 } |
| 760 if (!FLAGS_picture.isEmpty()) { |
| 761 SkString path(FLAGS_picture[0]); |
| 762 fCurrIndex = fSamples.count(); |
| 763 *fSamples.append() = new PictFileFactory(path); |
| 764 } |
| 756 #ifdef SAMPLE_PDF_FILE_VIEWER | 765 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 757 this->registerPdfFileViewerSamples(argv, argc); | 766 if (!FLAGS_pdfPath.isEmpty()) { |
| 758 #endif // SAMPLE_PDF_FILE_VIEWER | 767 SkOSFile::Iter iter(FLAGS_pdfPath[0], "pdf"); |
| 768 SkString filename; |
| 769 while (iter.next(&filename)) { |
| 770 *fSamples.append() = new PdfFileViewerFactory( |
| 771 SkOSPath::SkPathJoin(FLAGS_pictureDir[0], filename.c_str()))
; |
| 772 } |
| 773 } |
| 774 #endif |
| 759 SkGMRegistyToSampleRegistry(); | 775 SkGMRegistyToSampleRegistry(); |
| 760 { | 776 { |
| 761 const SkViewRegister* reg = SkViewRegister::Head(); | 777 const SkViewRegister* reg = SkViewRegister::Head(); |
| 762 while (reg) { | 778 while (reg) { |
| 763 *fSamples.append() = reg->factory(); | 779 *fSamples.append() = reg->factory(); |
| 764 reg = reg->next(); | 780 reg = reg->next(); |
| 765 } | 781 } |
| 766 } | 782 } |
| 767 | 783 |
| 768 bool sort = false; | 784 if (FLAGS_sort) { |
| 769 for (int i = 0; i < argc; ++i) { | |
| 770 if (!strcmp(argv[i], "--sort")) { | |
| 771 sort = true; | |
| 772 break; | |
| 773 } | |
| 774 } | |
| 775 | |
| 776 if (sort) { | |
| 777 // Sort samples, so foo.skp and foo.pdf are consecutive and we can quick
ly spot where | 785 // Sort samples, so foo.skp and foo.pdf are consecutive and we can quick
ly spot where |
| 778 // skp -> pdf -> png fails. | 786 // skp -> pdf -> png fails. |
| 779 SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, c
ompareSampleTitle); | 787 SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, c
ompareSampleTitle); |
| 780 } | 788 } |
| 781 | 789 |
| 782 fMSAASampleCount = 0; | 790 if (!FLAGS_slide.isEmpty()) { |
| 791 fCurrIndex = findByTitle(FLAGS_slide[0]); |
| 792 if (fCurrIndex < 0) { |
| 793 fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]); |
| 794 listTitles(); |
| 795 } |
| 796 } |
| 783 | 797 |
| 784 SkCommandLineFlags::Parse(argc, argv); | 798 fMSAASampleCount = FLAGS_msaa; |
| 785 | 799 |
| 786 const char* const commandName = argv[0]; | 800 if (FLAGS_list) { |
| 787 char* const* stop = argv + argc; | 801 listTitles(); |
| 788 for (++argv; argv < stop; ++argv) { | |
| 789 if (strcmp(*argv, "--slide") == 0) { | |
| 790 argv++; | |
| 791 if (argv < stop && **argv) { | |
| 792 fCurrIndex = findByTitle(*argv); | |
| 793 if (fCurrIndex < 0) { | |
| 794 fprintf(stderr, "Unknown sample \"%s\"\n", *argv); | |
| 795 listTitles(); | |
| 796 } | |
| 797 } | |
| 798 } else if (strcmp(*argv, "--msaa") == 0) { | |
| 799 ++argv; | |
| 800 if (argv < stop && **argv) { | |
| 801 fMSAASampleCount = atoi(*argv); | |
| 802 } | |
| 803 } else if (strcmp(*argv, "--list") == 0) { | |
| 804 listTitles(); | |
| 805 } else if (strcmp(*argv, "--pictureDir") == 0) { | |
| 806 ++argv; // This case is dealt with in registerPictFileSamples(). | |
| 807 } else if (strcmp(*argv, "--picture") == 0) { | |
| 808 ++argv; // This case is dealt with in registerPictFileSample(). | |
| 809 } | |
| 810 else { | |
| 811 usage(commandName); | |
| 812 } | |
| 813 } | 802 } |
| 814 | 803 |
| 815 if (fCurrIndex < 0) { | 804 if (fCurrIndex < 0) { |
| 816 SkString title; | 805 SkString title; |
| 817 if (readTitleFromPrefs(&title)) { | 806 if (readTitleFromPrefs(&title)) { |
| 818 fCurrIndex = findByTitle(title.c_str()); | 807 fCurrIndex = findByTitle(title.c_str()); |
| 819 } | 808 } |
| 820 } | 809 } |
| 821 | 810 |
| 822 if (fCurrIndex < 0) { | 811 if (fCurrIndex < 0) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); | 971 post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); |
| 983 } | 972 } |
| 984 | 973 |
| 985 SampleWindow::~SampleWindow() { | 974 SampleWindow::~SampleWindow() { |
| 986 delete fPdfCanvas; | 975 delete fPdfCanvas; |
| 987 fTypeface->unref(); | 976 fTypeface->unref(); |
| 988 | 977 |
| 989 SkSafeUnref(fDevManager); | 978 SkSafeUnref(fDevManager); |
| 990 } | 979 } |
| 991 | 980 |
| 992 static void make_filepath(SkString* path, const char* dir, const SkString& name)
{ | |
| 993 size_t len = strlen(dir); | |
| 994 path->set(dir); | |
| 995 if (len > 0 && dir[len - 1] != '/') { | |
| 996 path->append("/"); | |
| 997 } | |
| 998 path->append(name); | |
| 999 } | |
| 1000 | |
| 1001 void SampleWindow::registerPictFileSample(char** argv, int argc) { | |
| 1002 const char* pict = NULL; | |
| 1003 | |
| 1004 for (int i = 0; i < argc; ++i) { | |
| 1005 if (!strcmp(argv[i], "--picture")) { | |
| 1006 i += 1; | |
| 1007 if (i < argc) { | |
| 1008 pict = argv[i]; | |
| 1009 break; | |
| 1010 } | |
| 1011 } | |
| 1012 } | |
| 1013 if (pict) { | |
| 1014 SkString path(pict); | |
| 1015 fCurrIndex = fSamples.count(); | |
| 1016 *fSamples.append() = new PictFileFactory(path); | |
| 1017 } | |
| 1018 } | |
| 1019 | |
| 1020 void SampleWindow::registerPictFileSamples(char** argv, int argc) { | |
| 1021 const char* pictDir = NULL; | |
| 1022 | |
| 1023 for (int i = 0; i < argc; ++i) { | |
| 1024 if (!strcmp(argv[i], "--pictureDir")) { | |
| 1025 i += 1; | |
| 1026 if (i < argc) { | |
| 1027 pictDir = argv[i]; | |
| 1028 break; | |
| 1029 } | |
| 1030 } | |
| 1031 } | |
| 1032 if (pictDir) { | |
| 1033 SkOSFile::Iter iter(pictDir, "skp"); | |
| 1034 SkString filename; | |
| 1035 while (iter.next(&filename)) { | |
| 1036 SkString path; | |
| 1037 make_filepath(&path, pictDir, filename); | |
| 1038 *fSamples.append() = new PictFileFactory(path); | |
| 1039 } | |
| 1040 } | |
| 1041 } | |
| 1042 | |
| 1043 #ifdef SAMPLE_PDF_FILE_VIEWER | |
| 1044 void SampleWindow::registerPdfFileViewerSamples(char** argv, int argc) { | |
| 1045 const char* pdfDir = NULL; | |
| 1046 | |
| 1047 for (int i = 0; i < argc; ++i) { | |
| 1048 if (!strcmp(argv[i], "--pdfDir")) { | |
| 1049 i += 1; | |
| 1050 if (i < argc) { | |
| 1051 pdfDir = argv[i]; | |
| 1052 break; | |
| 1053 } | |
| 1054 } | |
| 1055 } | |
| 1056 if (pdfDir) { | |
| 1057 SkOSFile::Iter iter(pdfDir, "pdf"); | |
| 1058 SkString filename; | |
| 1059 while (iter.next(&filename)) { | |
| 1060 SkString path; | |
| 1061 make_filepath(&path, pdfDir, filename); | |
| 1062 *fSamples.append() = new PdfFileViewerFactory(path); | |
| 1063 } | |
| 1064 } | |
| 1065 } | |
| 1066 #endif // SAMPLE_PDF_FILE_VIEWER | |
| 1067 | |
| 1068 | 981 |
| 1069 int SampleWindow::findByTitle(const char title[]) { | 982 int SampleWindow::findByTitle(const char title[]) { |
| 1070 int i, count = fSamples.count(); | 983 int i, count = fSamples.count(); |
| 1071 for (i = 0; i < count; i++) { | 984 for (i = 0; i < count; i++) { |
| 1072 if (getSampleTitle(i).equals(title)) { | 985 if (getSampleTitle(i).equals(title)) { |
| 1073 return i; | 986 return i; |
| 1074 } | 987 } |
| 1075 } | 988 } |
| 1076 return -1; | 989 return -1; |
| 1077 } | 990 } |
| (...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2504 SkGraphics::Init(); | 2417 SkGraphics::Init(); |
| 2505 SkEvent::Init(); | 2418 SkEvent::Init(); |
| 2506 } | 2419 } |
| 2507 | 2420 |
| 2508 // FIXME: this should be in a header | 2421 // FIXME: this should be in a header |
| 2509 void application_term(); | 2422 void application_term(); |
| 2510 void application_term() { | 2423 void application_term() { |
| 2511 SkEvent::Term(); | 2424 SkEvent::Term(); |
| 2512 SkGraphics::Term(); | 2425 SkGraphics::Term(); |
| 2513 } | 2426 } |
| OLD | NEW |