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 #include "SampleApp.h" | 7 #include "SampleApp.h" |
8 | 8 |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
13 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
14 #include "SkImageEncoder.h" | 14 #include "SkImageEncoder.h" |
15 #include "SkPaint.h" | 15 #include "SkPaint.h" |
16 #include "SkPicture.h" | 16 #include "SkPicture.h" |
17 #include "SkStream.h" | 17 #include "SkStream.h" |
| 18 #include "SkTSort.h" |
18 #include "SkTime.h" | 19 #include "SkTime.h" |
19 #include "SkWindow.h" | 20 #include "SkWindow.h" |
20 | 21 |
21 #include "SampleCode.h" | 22 #include "SampleCode.h" |
22 #include "SkTypeface.h" | 23 #include "SkTypeface.h" |
23 | 24 |
24 #if SK_SUPPORT_GPU | 25 #if SK_SUPPORT_GPU |
25 #include "gl/GrGLInterface.h" | 26 #include "gl/GrGLInterface.h" |
26 #include "gl/GrGLUtil.h" | 27 #include "gl/GrGLUtil.h" |
27 #include "GrRenderTarget.h" | 28 #include "GrRenderTarget.h" |
(...skipping 19 matching lines...) Expand all Loading... |
47 | 48 |
48 class PictFileFactory : public SkViewFactory { | 49 class PictFileFactory : public SkViewFactory { |
49 SkString fFilename; | 50 SkString fFilename; |
50 public: | 51 public: |
51 PictFileFactory(const SkString& filename) : fFilename(filename) {} | 52 PictFileFactory(const SkString& filename) : fFilename(filename) {} |
52 virtual SkView* operator() () const SK_OVERRIDE { | 53 virtual SkView* operator() () const SK_OVERRIDE { |
53 return CreateSamplePictFileView(fFilename.c_str()); | 54 return CreateSamplePictFileView(fFilename.c_str()); |
54 } | 55 } |
55 }; | 56 }; |
56 | 57 |
| 58 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 59 extern SampleView* CreateSamplePdfFileViewer(const char filename[]); |
| 60 |
| 61 class PdfFileViewerFactory : public SkViewFactory { |
| 62 SkString fFilename; |
| 63 public: |
| 64 PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {} |
| 65 virtual SkView* operator() () const SK_OVERRIDE { |
| 66 return CreateSamplePdfFileViewer(fFilename.c_str()); |
| 67 } |
| 68 }; |
| 69 #endif // SAMPLE_PDF_FILE_VIEWER |
| 70 |
57 #define PIPE_FILEx | 71 #define PIPE_FILEx |
58 #ifdef PIPE_FILE | 72 #ifdef PIPE_FILE |
59 #define FILE_PATH "/path/to/drawing.data" | 73 #define FILE_PATH "/path/to/drawing.data" |
60 #endif | 74 #endif |
61 | 75 |
62 #define PIPE_NETx | 76 #define PIPE_NETx |
63 #ifdef PIPE_NET | 77 #ifdef PIPE_NET |
64 #include "SkSockets.h" | 78 #include "SkSockets.h" |
65 SkTCPServer gServer; | 79 SkTCPServer gServer; |
66 #endif | 80 #endif |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal
cycling | 698 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal
cycling |
685 #endif // SK_SUPPORT_GPU | 699 #endif // SK_SUPPORT_GPU |
686 SampleWindow::kRaster_DeviceType | 700 SampleWindow::kRaster_DeviceType |
687 }; | 701 }; |
688 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); | 702 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array
_size_mismatch); |
689 return gCT[ct]; | 703 return gCT[ct]; |
690 } | 704 } |
691 | 705 |
692 static void usage(const char * argv0) { | 706 static void usage(const char * argv0) { |
693 SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--
pictureDir dirPath] [--picture path]\n", argv0); | 707 SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--
pictureDir dirPath] [--picture path]\n", argv0); |
| 708 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 709 SkDebugf(" [--pdfDir pdfPath]\n"); |
| 710 SkDebugf(" pdfPath: path to directory pdf files are read from\n"); |
| 711 #endif // SAMPLE_PDF_FILE_VIEWER |
694 SkDebugf(" sampleName: sample at which to start.\n"); | 712 SkDebugf(" sampleName: sample at which to start.\n"); |
695 SkDebugf(" resourcePath: directory that stores image resources.\n"); | 713 SkDebugf(" resourcePath: directory that stores image resources.\n"); |
696 SkDebugf(" msaa: request multisampling with the given sample count.\n"); | 714 SkDebugf(" msaa: request multisampling with the given sample count.\n"); |
697 SkDebugf(" dirPath: path to directory skia pictures are read from\n"); | 715 SkDebugf(" dirPath: path to directory skia pictures are read from\n"); |
698 SkDebugf(" path: path to skia picture\n"); | 716 SkDebugf(" path: path to skia picture\n"); |
699 } | 717 } |
700 | 718 |
| 719 static SkString getSampleTitle(const SkViewFactory* sampleFactory) { |
| 720 SkView* view = (*sampleFactory)(); |
| 721 SkString title; |
| 722 SampleCode::RequestTitle(view, &title); |
| 723 view->unref(); |
| 724 return title; |
| 725 } |
| 726 |
| 727 bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory* second)
{ |
| 728 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str())
< 0; |
| 729 } |
| 730 |
701 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
Manager) | 731 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
Manager) |
702 : INHERITED(hwnd) | 732 : INHERITED(hwnd) |
703 , fDevManager(NULL) { | 733 , fDevManager(NULL) { |
704 | 734 |
705 fCurrIndex = -1; | 735 fCurrIndex = -1; |
706 | 736 |
707 this->registerPictFileSamples(argv, argc); | 737 this->registerPictFileSamples(argv, argc); |
708 this->registerPictFileSample(argv, argc); | 738 this->registerPictFileSample(argv, argc); |
| 739 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 740 this->registerPdfFileViewerSamples(argv, argc); |
| 741 #endif // SAMPLE_PDF_FILE_VIEWER |
709 SkGMRegistyToSampleRegistry(); | 742 SkGMRegistyToSampleRegistry(); |
710 { | 743 { |
711 const SkViewRegister* reg = SkViewRegister::Head(); | 744 const SkViewRegister* reg = SkViewRegister::Head(); |
712 while (reg) { | 745 while (reg) { |
713 *fSamples.append() = reg->factory(); | 746 *fSamples.append() = reg->factory(); |
714 reg = reg->next(); | 747 reg = reg->next(); |
715 } | 748 } |
716 } | 749 } |
717 | 750 |
| 751 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 752 // Sort samples, so foo.skp and foo.pdf are consecutive and we can quickly s
pot where |
| 753 // skp -> pdf -> png fails. |
| 754 SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, compa
reSampleTitle); |
| 755 #endif // SAMPLE_PDF_FILE_VIEWER |
| 756 |
718 const char* resourcePath = NULL; | 757 const char* resourcePath = NULL; |
719 fMSAASampleCount = 0; | 758 fMSAASampleCount = 0; |
720 | 759 |
721 const char* const commandName = argv[0]; | 760 const char* const commandName = argv[0]; |
722 char* const* stop = argv + argc; | 761 char* const* stop = argv + argc; |
723 for (++argv; argv < stop; ++argv) { | 762 for (++argv; argv < stop; ++argv) { |
724 if (strcmp(*argv, "-i") == 0) { | 763 if (strcmp(*argv, "-i") == 0) { |
725 argv++; | 764 argv++; |
726 if (argv < stop && **argv) { | 765 if (argv < stop && **argv) { |
727 resourcePath = *argv; | 766 resourcePath = *argv; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 SkOSFile::Iter iter(pictDir, "skp"); | 1001 SkOSFile::Iter iter(pictDir, "skp"); |
963 SkString filename; | 1002 SkString filename; |
964 while (iter.next(&filename)) { | 1003 while (iter.next(&filename)) { |
965 SkString path; | 1004 SkString path; |
966 make_filepath(&path, pictDir, filename); | 1005 make_filepath(&path, pictDir, filename); |
967 *fSamples.append() = new PictFileFactory(path); | 1006 *fSamples.append() = new PictFileFactory(path); |
968 } | 1007 } |
969 } | 1008 } |
970 } | 1009 } |
971 | 1010 |
| 1011 #ifdef SAMPLE_PDF_FILE_VIEWER |
| 1012 void SampleWindow::registerPdfFileViewerSamples(char** argv, int argc) { |
| 1013 const char* pdfDir = NULL; |
| 1014 |
| 1015 for (int i = 0; i < argc; ++i) { |
| 1016 if (!strcmp(argv[i], "--pdfDir")) { |
| 1017 i += 1; |
| 1018 if (i < argc) { |
| 1019 pdfDir = argv[i]; |
| 1020 break; |
| 1021 } |
| 1022 } |
| 1023 } |
| 1024 if (pdfDir) { |
| 1025 SkOSFile::Iter iter(pdfDir, "pdf"); |
| 1026 SkString filename; |
| 1027 while (iter.next(&filename)) { |
| 1028 SkString path; |
| 1029 make_filepath(&path, pdfDir, filename); |
| 1030 *fSamples.append() = new PdfFileViewerFactory(path); |
| 1031 } |
| 1032 } |
| 1033 } |
| 1034 #endif // SAMPLE_PDF_FILE_VIEWER |
| 1035 |
| 1036 |
972 int SampleWindow::findByTitle(const char title[]) { | 1037 int SampleWindow::findByTitle(const char title[]) { |
973 int i, count = fSamples.count(); | 1038 int i, count = fSamples.count(); |
974 for (i = 0; i < count; i++) { | 1039 for (i = 0; i < count; i++) { |
975 if (getSampleTitle(i).equals(title)) { | 1040 if (getSampleTitle(i).equals(title)) { |
976 return i; | 1041 return i; |
977 } | 1042 } |
978 } | 1043 } |
979 return -1; | 1044 return -1; |
980 } | 1045 } |
981 | 1046 |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 return true; | 1592 return true; |
1528 } | 1593 } |
1529 | 1594 |
1530 bool SampleWindow::goToSample(int i) { | 1595 bool SampleWindow::goToSample(int i) { |
1531 fCurrIndex = (i) % fSamples.count(); | 1596 fCurrIndex = (i) % fSamples.count(); |
1532 this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(),
6)); | 1597 this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(),
6)); |
1533 return true; | 1598 return true; |
1534 } | 1599 } |
1535 | 1600 |
1536 SkString SampleWindow::getSampleTitle(int i) { | 1601 SkString SampleWindow::getSampleTitle(int i) { |
1537 SkView* view = (*fSamples[i])(); | 1602 return ::getSampleTitle(fSamples[i]); |
1538 SkString title; | |
1539 SampleCode::RequestTitle(view, &title); | |
1540 view->unref(); | |
1541 return title; | |
1542 } | 1603 } |
1543 | 1604 |
1544 int SampleWindow::sampleCount() { | 1605 int SampleWindow::sampleCount() { |
1545 return fSamples.count(); | 1606 return fSamples.count(); |
1546 } | 1607 } |
1547 | 1608 |
1548 void SampleWindow::showOverview() { | 1609 void SampleWindow::showOverview() { |
1549 this->loadView(create_transition(curr_view(this), | 1610 this->loadView(create_transition(curr_view(this), |
1550 create_overview(fSamples.count(), fSamples.
begin()), | 1611 create_overview(fSamples.count(), fSamples.
begin()), |
1551 4)); | 1612 4)); |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2468 SkGraphics::Init(); | 2529 SkGraphics::Init(); |
2469 SkEvent::Init(); | 2530 SkEvent::Init(); |
2470 } | 2531 } |
2471 | 2532 |
2472 // FIXME: this should be in a header | 2533 // FIXME: this should be in a header |
2473 void application_term(); | 2534 void application_term(); |
2474 void application_term() { | 2535 void application_term() { |
2475 SkEvent::Term(); | 2536 SkEvent::Term(); |
2476 SkGraphics::Term(); | 2537 SkGraphics::Term(); |
2477 } | 2538 } |
OLD | NEW |